[apps/stats/reg] Do not fill with formula if undefined values

This commit is contained in:
Léa Saviot
2018-06-11 11:24:16 +02:00
parent d44459bba2
commit 13a4057786
6 changed files with 25 additions and 11 deletions

View File

@@ -32,8 +32,8 @@ void StoreController::setFormulaLabel() {
static_cast<ContentView *>(view())->formulaInputView()->setBufferText(text);
}
void StoreController::fillColumnWithFormula(Expression * formula) {
privateFillColumnWithFormula(formula, Symbol::isRegressionSymbol);
bool StoreController::fillColumnWithFormula(Expression * formula) {
return privateFillColumnWithFormula(formula, Symbol::isRegressionSymbol);
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {

View File

@@ -14,7 +14,7 @@ public:
StoreController(Responder * parentResponder, Store * store, ButtonRowController * header);
Shared::StoreContext * storeContext() override;
void setFormulaLabel() override;
void fillColumnWithFormula(Poincare::Expression * formula) override;
bool fillColumnWithFormula(Poincare::Expression * formula) override;
void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override;
private:
HighlightCell * titleCells(int index) override;

View File

@@ -78,9 +78,10 @@ bool StoreController::textFieldDidFinishEditing(TextField * textField, const cha
return false;
}
contentView()->displayFormulaInput(false);
fillColumnWithFormula(expression);
if (fillColumnWithFormula(expression)) {
app()->setFirstResponder(contentView());
}
delete expression;
app()->setFirstResponder(contentView());
return true;
}
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
@@ -268,7 +269,7 @@ void StoreController::unloadView(View * view) {
delete view;
}
void StoreController::privateFillColumnWithFormula(Expression * formula, Expression::isVariableTest isVariable) {
bool StoreController::privateFillColumnWithFormula(Expression * formula, Expression::isVariableTest isVariable) {
int currentColumn = selectedColumn();
// Fetch the series used in the formula to compute the size of the filled in series
char variables[7] = {0, 0, 0, 0, 0, 0, 0};
@@ -292,14 +293,27 @@ void StoreController::privateFillColumnWithFormula(Expression * formula, Express
}
StoreContext * store = storeContext();
// Make sure no value is undef, else display an error
for (int j = 0; j < numberOfValuesToCompute; j++) {
// Set the context
store->setSeriesPairIndex(j);
// Compute the new value using the formula
double evaluation = formula->approximateToScalar<double>(*store);
if (std::isnan(evaluation) || std::isinf(evaluation)) {
app()->displayWarning(I18n::Message::UndefinedValue);
return false;
}
}
// Fill in the table with the formula values
for (int j = 0; j < numberOfValuesToCompute; j++) {
store->setSeriesPairIndex(j);
double evaluation = formula->approximateToScalar<double>(*store);
setDataAtLocation(evaluation, currentColumn, j + 1);
}
selectableTableView()->reloadData();
return true;
}
bool StoreController::cellShouldBeTransparent(int i, int j) {

View File

@@ -19,7 +19,7 @@ public:
virtual StoreContext * storeContext() = 0;
void displayFormulaInput();
virtual void setFormulaLabel() = 0;
virtual void fillColumnWithFormula(Poincare::Expression * formula) = 0;
virtual bool fillColumnWithFormula(Poincare::Expression * formula) = 0;
// TextFieldDelegate
bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override;
@@ -85,7 +85,7 @@ protected:
virtual HighlightCell * titleCells(int index) = 0;
char m_draftTextBuffer[TextField::maxBufferSize()];
int seriesAtColumn(int column) const { return column / DoublePairStore::k_numberOfColumnsPerSeries; }
void privateFillColumnWithFormula(Poincare::Expression * formula, Poincare::Expression::isVariableTest isVariable);
bool privateFillColumnWithFormula(Poincare::Expression * formula, Poincare::Expression::isVariableTest isVariable);
StoreCell * m_editableCells[k_maxNumberOfEditableCells];
DoublePairStore * m_store;
StoreParameterController m_storeParameterController;

View File

@@ -32,8 +32,8 @@ void StoreController::setFormulaLabel() {
static_cast<ContentView *>(view())->formulaInputView()->setBufferText(text);
}
void StoreController::fillColumnWithFormula(Expression * formula) {
privateFillColumnWithFormula(formula, Symbol::isSeriesSymbol);
bool StoreController::fillColumnWithFormula(Expression * formula) {
return privateFillColumnWithFormula(formula, Symbol::isSeriesSymbol);
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {

View File

@@ -14,7 +14,7 @@ public:
StoreController(Responder * parentResponder, Store * store, ButtonRowController * header);
Shared::StoreContext * storeContext() override;
void setFormulaLabel() override;
void fillColumnWithFormula(Poincare::Expression * formula) override;
bool fillColumnWithFormula(Poincare::Expression * formula) override;
void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override;
private:
bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override;