[apps/reg] Display the current regression model in store parameter menu

This commit is contained in:
Léa Saviot
2018-06-07 14:09:25 +02:00
committed by Émilie Feral
parent 8c5a208b31
commit 6c93e55687
6 changed files with 89 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ namespace Regression {
class RegressionController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
public:
constexpr static KDCoordinate k_logisticCellHeight = 47;
RegressionController(Responder * parentResponder, Store * store);
void setSeries(int series) { m_series = series; }
// ViewController
@@ -29,7 +30,6 @@ public:
int numberOfRows() override { return k_numberOfRows; }
void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override;
private:
constexpr static KDCoordinate k_logisticCellHeight = 47;
constexpr static int k_numberOfRows = 9;
constexpr static int k_numberOfCells = 6; // (240 - 70) / 35
MessageTableCellWithExpression m_regressionCells[k_numberOfCells];

View File

@@ -20,6 +20,9 @@ public:
// Regression
void setSeriesRegressionType(int series, Model::Type type);
Model::Type seriesRegressionType(int series) {
return m_regressionTypes[series];
}
Model * modelForSeries(int series) {
assert(series >= 0 && series < k_numberOfSeries);
assert((int)m_regressionTypes[series] >= 0 && (int)m_regressionTypes[series] < Model::k_numberOfModels);

View File

@@ -6,14 +6,14 @@ namespace Regression {
StoreParameterController::StoreParameterController(Responder * parentResponder, Store * store, StoreController * storeController) :
Shared::StoreParameterController(parentResponder, store, storeController),
m_changeRegression(I18n::Message::ChangeRegression),
m_changeRegressionCell(I18n::Message::ChangeRegression),
m_regressionController(this, store)
{
}
bool StoreParameterController::handleEvent(Ion::Events::Event event) {
if ((event == Ion::Events::OK || event == Ion::Events::EXE) && selectedRow() == numberOfRows() - 1) {
m_regressionController.setSeries(selectedColumn() % Store::k_numberOfColumnsPerSeries);
if ((event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) && selectedRow() == numberOfRows() - 1) {
m_regressionController.setSeries(m_series);
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->push(&m_regressionController);
return true;
@@ -21,13 +21,45 @@ bool StoreParameterController::handleEvent(Ion::Events::Event event) {
return Shared::StoreParameterController::handleEvent(event);
}
HighlightCell * StoreParameterController::reusableCell(int index) {
HighlightCell * StoreParameterController::reusableCell(int index, int type) {
assert(index >= 0);
assert(index < reusableCellCount());
if (index == reusableCellCount() - 1) {
return &m_changeRegression;
assert(index < reusableCellCount(type));
if (type == k_regressionCellType) {
assert(index == 0);
return &m_changeRegressionCell;
}
return Shared::StoreParameterController::reusableCell(index, type);
}
KDCoordinate StoreParameterController::rowHeight(int j) {
if (j == numberOfRows() - 1) {
if (static_cast<Store *>(m_store)->seriesRegressionType(m_series) == Model::Type::Logistic) {
return RegressionController::k_logisticCellHeight;
}
return Metric::ParameterCellHeight;
}
return Shared::StoreParameterController::rowHeight(j);
}
int StoreParameterController::reusableCellCount(int type) {
if (type == k_regressionCellType) {
return 1;
}
return Shared::StoreParameterController::reusableCellCount(type);
}
int StoreParameterController::typeAtLocation(int i, int j) {
assert(i == 0);
if (j == numberOfRows() -1) {
return k_regressionCellType;
}
return Shared::StoreParameterController::typeAtLocation(i, j);
}
void StoreParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
Shared::StoreParameterController::willDisplayCellForIndex(cell, index);
if (index == numberOfRows() - 1) {
m_changeRegressionCell.setExpressionLayout(static_cast<Store *>(m_store)->modelForSeries(m_series)->layout());
}
return Shared::StoreParameterController::reusableCell(index);
}
}

View File

@@ -13,11 +13,16 @@ class StoreParameterController : public Shared::StoreParameterController {
public:
StoreParameterController(Responder * parentResponder, Store * store, StoreController * storeController);
bool handleEvent(Ion::Events::Event event) override;
// ListViewDataSource
int numberOfRows() override { return Shared::StoreParameterController::numberOfRows() + 1; }
HighlightCell * reusableCell(int index) override;
int reusableCellCount() override { return Shared::StoreParameterController::reusableCellCount() + 1; }
KDCoordinate rowHeight(int j) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
private:
MessageTableCell m_changeRegression;
static constexpr int k_regressionCellType = 1;
MessageTableCellWithChevronAndExpression m_changeRegressionCell;
RegressionController m_regressionController;
};

View File

@@ -6,6 +6,8 @@ namespace Shared {
StoreParameterController::StoreParameterController(Responder * parentResponder, DoublePairStore * store, StoreController * storeController) :
ViewController(parentResponder),
m_store(store),
m_series(0),
m_deleteColumn(I18n::Message::ClearColumn),
m_fillWithFormula(I18n::Message::FillWithFormula),
#if COPY_IMPORT_LIST
@@ -13,10 +15,8 @@ StoreParameterController::StoreParameterController(Responder * parentResponder,
m_importList(I18n::Message::ImportList),
#endif
m_selectableTableView(this, this, this),
m_store(store),
m_storeController(storeController),
m_xColumnSelected(true),
m_series(0)
m_xColumnSelected(true)
{
}
@@ -66,7 +66,26 @@ bool StoreParameterController::handleEvent(Ion::Events::Event event) {
return false;
}
HighlightCell * StoreParameterController::reusableCell(int index) {
KDCoordinate StoreParameterController::cumulatedHeightFromIndex(int j) {
assert (j >= 0 && j <= numberOfRows());
KDCoordinate result = 0;
for (int i = 0; i < j; i++) {
result+= rowHeight(i);
}
return result;
}
int StoreParameterController::indexFromCumulatedHeight(KDCoordinate offsetY) {
int result = 0;
int j = 0;
while (result < offsetY && j < numberOfRows()) {
result += rowHeight(j++);
}
return (result < offsetY || offsetY == 0) ? j : j - 1;
}
HighlightCell * StoreParameterController::reusableCell(int index, int type) {
assert(type == k_standardCellType);
assert(index >= 0);
assert(index < k_totalNumberOfCell);
HighlightCell * cells[] = {&m_deleteColumn, &m_fillWithFormula};// {&m_deleteColumn, &m_fillWithFormula, &m_copyColumn, &m_importList};

View File

@@ -9,7 +9,7 @@ namespace Shared {
class StoreController;
class StoreParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
class StoreParameterController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
public:
StoreParameterController(Responder * parentResponder, DoublePairStore * store, StoreController * storeController);
void selectXColumn(bool xColumnSelected) { m_xColumnSelected = xColumnSelected; }
@@ -19,9 +19,19 @@ public:
bool handleEvent(Ion::Events::Event event) override;
void didBecomeFirstResponder() override;
int numberOfRows() override { return k_totalNumberOfCell; }
KDCoordinate cellHeight() override { return Metric::ParameterCellHeight; }
HighlightCell * reusableCell(int index) override;
int reusableCellCount() override { return k_totalNumberOfCell; }
KDCoordinate rowHeight(int j) override { return Metric::ParameterCellHeight; }
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override {
assert(type == k_standardCellType);
return k_totalNumberOfCell;
}
int typeAtLocation(int i, int j) override { return k_standardCellType; }
protected:
static constexpr int k_standardCellType = 0;
DoublePairStore * m_store;
int m_series;
private:
#if COPY_IMPORT_LIST
constexpr static int k_totalNumberOfCell = 4;
@@ -33,10 +43,8 @@ private:
MessageTableCell m_deleteColumn;
MessageTableCell m_fillWithFormula;
SelectableTableView m_selectableTableView;
DoublePairStore * m_store;
StoreController * m_storeController;
bool m_xColumnSelected;
int m_series;
};
}