Merge branch 'lea-statistics' into upgrade-1.6.0

This commit is contained in:
Émilie Feral
2018-06-12 10:16:05 +02:00
132 changed files with 3623 additions and 1519 deletions

View File

@@ -17,9 +17,10 @@ CalculationController::CalculationController(Responder * parentResponder, Button
ButtonRowDelegate(header, nullptr),
m_titleCells{},
m_r2TitleCell(nullptr),
m_columnTitleCell(nullptr),
m_columnTitleCells{},
m_doubleCalculationCells{},
m_calculationCells{},
m_hideableCell(nullptr),
m_store(store)
{
m_r2Layout = new HorizontalLayout(new CharLayout('r', KDText::FontSize::Small), new VerticalOffsetLayout(new CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayout::Type::Superscript, false), false);
@@ -66,14 +67,14 @@ void CalculationController::tableViewDidChangeSelection(SelectableTableView * t,
selectableTableView()->deselectTable();
app()->setFirstResponder(tabController());
} else {
t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY);
t->selectCellAtLocation(0, 1);
}
}
if (t->selectedColumn() == 1 && t->selectedRow() >= 0 && t->selectedRow() <= k_totalNumberOfDoubleBufferRows) {
EvenOddDoubleBufferTextCell * myCell = (EvenOddDoubleBufferTextCell *)t->selectedCell();
if (t->selectedColumn() > 0 && t->selectedRow() >= 0 && t->selectedRow() <= k_totalNumberOfDoubleBufferRows) {
EvenOddDoubleBufferTextCellWithSeparator * myCell = (EvenOddDoubleBufferTextCellWithSeparator *)t->selectedCell();
bool firstSubCellSelected = true;
if (previousSelectedCellX == 1 && previousSelectedCellY >= 0 && previousSelectedCellY <= k_totalNumberOfDoubleBufferRows) {
EvenOddDoubleBufferTextCell * myPreviousCell = (EvenOddDoubleBufferTextCell *)t->cellAtLocation(previousSelectedCellX, previousSelectedCellY);
if (previousSelectedCellX > 0 && previousSelectedCellY >= 0 && previousSelectedCellY <= k_totalNumberOfDoubleBufferRows) {
EvenOddDoubleBufferTextCellWithSeparator * myPreviousCell = (EvenOddDoubleBufferTextCellWithSeparator *)t->cellAtLocation(previousSelectedCellX, previousSelectedCellY);
firstSubCellSelected = myPreviousCell->firstTextSelected();
}
myCell->selectFirstText(firstSubCellSelected);
@@ -100,41 +101,51 @@ int CalculationController::numberOfRows() {
}
int CalculationController::numberOfColumns() {
return k_totalNumberOfColumns;
return 1 + m_store->numberOfNonEmptySeries();
}
void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
if (i == 0 && j == 0) {
return;
}
EvenOddCell * myCell = (EvenOddCell *)cell;
myCell->setEven(j%2 == 0);
myCell->setHighlighted(i == selectedColumn() && j == selectedRow());
if (j == 0 && i > 0) {
EvenOddDoubleBufferTextCell * myCell = (EvenOddDoubleBufferTextCell *)cell;
myCell->setFirstText("x");
myCell->setSecondText("y");
return;
}
// Calculation title
if (i == 0) {
if (j == numberOfRows()-1) {
EvenOddExpressionCell * myCell = (EvenOddExpressionCell *)cell;
EvenOddExpressionCellWithMargin * myCell = (EvenOddExpressionCellWithMargin *)cell;
myCell->setExpressionLayout(m_r2Layout);
return;
}
EvenOddMessageTextCell * myCell = (EvenOddMessageTextCell *)cell;
if (j == 0) {
myCell->setMessage(I18n::Message::Default);
return;
}
MarginEvenOddMessageTextCell * myCell = (MarginEvenOddMessageTextCell *)cell;
myCell->setAlignment(1.0f, 0.5f);
I18n::Message titles[k_totalNumberOfRows-1] = {I18n::Message::Mean, I18n::Message::Sum, I18n::Message::SquareSum, I18n::Message::StandardDeviation, I18n::Message::Deviation, I18n::Message::NumberOfDots, I18n::Message::Covariance, I18n::Message::Sxy, I18n::Message::Regression, I18n::Message::A, I18n::Message::B, I18n::Message::R, I18n::Message::Default};
myCell->setMessage(titles[j-1]);
return;
}
if (i == 1 && j > 0 && j <= k_totalNumberOfDoubleBufferRows) {
ArgCalculPointer calculationMethods[k_totalNumberOfDoubleBufferRows] = {&Store::meanOfColumn, &Store::sumOfColumn,
&Store::squaredValueSumOfColumn, &Store::standardDeviationOfColumn, &Store::varianceOfColumn};
double calculation1 = (m_store->*calculationMethods[j-1])(0);
double calculation2 = (m_store->*calculationMethods[j-1])(1);
EvenOddDoubleBufferTextCell * myCell = (EvenOddDoubleBufferTextCell *)cell;
int seriesNumber = m_store->indexOfKthNonEmptySeries(i - 1);
assert(i >= 0 && seriesNumber < DoublePairStore::k_numberOfSeries);
// Coordinate and series title
if (j == 0 && i > 0) {
ColumnTitleCell * myCell = (ColumnTitleCell *)cell;
char buffer[] = {'X', static_cast<char>('1' + seriesNumber), 0};
myCell->setFirstText(buffer);
buffer[0] = 'Y';
myCell->setSecondText(buffer);
myCell->setColor(Palette::DataColor[seriesNumber]);
return;
}
// Calculation cell
if (i > 0 && j > 0 && j <= k_totalNumberOfDoubleBufferRows) {
ArgCalculPointer calculationMethods[k_totalNumberOfDoubleBufferRows] = {&Store::meanOfColumn, &Store::sumOfColumn, &Store::squaredValueSumOfColumn, &Store::standardDeviationOfColumn, &Store::varianceOfColumn};
double calculation1 = (m_store->*calculationMethods[j-1])(seriesNumber, 0);
double calculation2 = (m_store->*calculationMethods[j-1])(seriesNumber, 1);
EvenOddDoubleBufferTextCellWithSeparator * myCell = (EvenOddDoubleBufferTextCellWithSeparator *)cell;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(calculation1, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setFirstText(buffer);
@@ -142,17 +153,16 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
myCell->setSecondText(buffer);
return;
}
if (i == 1 && j == 9) {
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
if (i > 0 && j == 9) {
SeparatorEvenOddBufferTextCell * myCell = (SeparatorEvenOddBufferTextCell *)cell;
myCell->setText("ax+b");
return;
}
if (i == 1 && j > k_totalNumberOfDoubleBufferRows) {
if (i > 0 && j > k_totalNumberOfDoubleBufferRows) {
assert(j != 9);
CalculPointer calculationMethods[k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows] = {&Store::numberOfPairs, &Store::covariance,
&Store::columnProductSum, nullptr, &Store::slope, &Store::yIntercept, &Store::correlationCoefficient, &Store::squaredCorrelationCoefficient};
double calculation = (m_store->*calculationMethods[j-k_totalNumberOfDoubleBufferRows-1])();
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
CalculPointer calculationMethods[k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows] = {&Store::doubleCastedNumberOfPairsOfSeries, &Store::covariance, &Store::columnProductSum, nullptr, &Store::slope, &Store::yIntercept, &Store::correlationCoefficient, &Store::squaredCorrelationCoefficient};
double calculation = (m_store->*calculationMethods[j-k_totalNumberOfDoubleBufferRows-1])(seriesNumber);
SeparatorEvenOddBufferTextCell * myCell = (SeparatorEvenOddBufferTextCell *)cell;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setText(buffer);
@@ -169,59 +179,69 @@ KDCoordinate CalculationController::rowHeight(int j) {
}
HighlightCell * CalculationController::reusableCell(int index, int type) {
if (type == 0) {
assert(index < k_maxNumberOfDisplayableRows);
if (type == k_standardCalculationTitleCellType) {
assert(index >= 0 && index < k_maxNumberOfDisplayableRows);
assert(m_titleCells[index] != nullptr);
return m_titleCells[index];
}
if (type == 1) {
if (type == k_r2CellType) {
assert(index == 0);
return m_r2TitleCell;
}
if (type == 2) {
assert(index == 0);
return m_columnTitleCell;
if (type == k_columnTitleCellType) {
assert(index >= 0 && index < Store::k_numberOfSeries);
return m_columnTitleCells[index];
}
if (type == 3) {
assert(index < k_totalNumberOfDoubleBufferRows);
if (type == k_doubleBufferCalculationCellType) {
assert(index >= 0 && index < k_numberOfDoubleCalculationCells);
assert(m_doubleCalculationCells[index] != nullptr);
return m_doubleCalculationCells[index];
}
assert(index < k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows);
assert(m_calculationCells[index] != nullptr);
if (type == k_hideableCellType) {
return m_hideableCell;
}
assert(index >= 0 && index < k_numberOfCalculationCells);
assert(m_calculationCells[index] != nullptr);
return m_calculationCells[index];
}
int CalculationController::reusableCellCount(int type) {
if (type == 0) {
if (type == k_standardCalculationTitleCellType) {
return k_maxNumberOfDisplayableRows;
}
if (type == 1) {
if (type == k_r2CellType) {
return 1;
}
if (type == 2) {
if (type == k_columnTitleCellType) {
return Store::k_numberOfSeries;
}
if (type == k_doubleBufferCalculationCellType) {
return k_numberOfDoubleCalculationCells;
}
if (type == k_hideableCellType) {
return 1;
}
if (type == 3) {
return k_totalNumberOfDoubleBufferRows;
}
return k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows;
assert(type == k_standardCalculationCellType);
return k_numberOfCalculationCells;
}
int CalculationController::typeAtLocation(int i, int j) {
if (i == 0 && j == 0) {
return k_hideableCellType;
}
if (i == 0 && j == k_totalNumberOfRows-1) {
return 1;
return k_r2CellType;
}
if (i == 0) {
return 0;
return k_standardCalculationTitleCellType;
}
if (j == 0) {
return 2;
return k_columnTitleCellType;
}
if (j > 0 && j <= k_totalNumberOfDoubleBufferRows) {
return 3;
return k_doubleBufferCalculationCellType;
}
return 4;
return k_standardCalculationCellType;
}
Responder * CalculationController::tabController() const {
@@ -232,34 +252,40 @@ View * CalculationController::loadView() {
SelectableTableView * tableView = new SelectableTableView(this, this, this, this);
tableView->setVerticalCellOverlap(0);
tableView->setBackgroundColor(Palette::WallScreenDark);
;
m_r2TitleCell = new EvenOddExpressionCell(1.0f, 0.5f);
m_columnTitleCell = new EvenOddDoubleBufferTextCell(tableView);
for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) {
m_titleCells[i] = new EvenOddMessageTextCell(KDText::FontSize::Small);
tableView->setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin);
m_r2TitleCell = new EvenOddExpressionCellWithMargin(1.0f, 0.5f);
for (int i = 0; i < Store::k_numberOfSeries; i++) {
m_columnTitleCells[i] = new ColumnTitleCell(tableView);
}
for (int i = 0; i < k_totalNumberOfDoubleBufferRows; i++) {
m_doubleCalculationCells[i] = new EvenOddDoubleBufferTextCell();
for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) {
m_titleCells[i] = new MarginEvenOddMessageTextCell(KDText::FontSize::Small);
}
for (int i = 0; i < k_numberOfDoubleCalculationCells; i++) {
m_doubleCalculationCells[i] = new EvenOddDoubleBufferTextCellWithSeparator();
m_doubleCalculationCells[i]->setTextColor(Palette::GreyDark);
m_doubleCalculationCells[i]->setParentResponder(tableView);
}
for (int i = 0; i < k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows;i++) {
m_calculationCells[i] = new EvenOddBufferTextCell(KDText::FontSize::Small);
for (int i = 0; i < k_numberOfCalculationCells;i++) {
m_calculationCells[i] = new SeparatorEvenOddBufferTextCell(KDText::FontSize::Small);
m_calculationCells[i]->setTextColor(Palette::GreyDark);
}
m_hideableCell = new HideableEvenOddCell();
m_hideableCell->setHide(true);
return tableView;
}
void CalculationController::unloadView(View * view) {
delete m_r2TitleCell;
m_r2TitleCell = nullptr;
delete m_columnTitleCell;
m_columnTitleCell = nullptr;
for (int i = 0; i < k_totalNumberOfDoubleBufferRows; i++) {
for (int i = 0; i < Store::k_numberOfSeries; i++) {
delete m_columnTitleCells[i];
m_columnTitleCells[i] = nullptr;
}
for (int i = 0; i < k_numberOfDoubleCalculationCells; i++) {
delete m_doubleCalculationCells[i];
m_doubleCalculationCells[i] = nullptr;
}
for (int i = 0; i < k_totalNumberOfRows-k_totalNumberOfDoubleBufferRows;i++) {
for (int i = 0; i < k_numberOfCalculationCells;i++) {
delete m_calculationCells[i];
m_calculationCells[i] = nullptr;
}
@@ -267,6 +293,8 @@ void CalculationController::unloadView(View * view) {
delete m_titleCells[i];
m_titleCells[i] = nullptr;
}
delete m_hideableCell;
m_hideableCell = nullptr;
TabTableController::unloadView(view);
}