[apps/stats] Compute the number of values to fill in with the formula

This commit is contained in:
Léa Saviot
2018-06-01 11:22:46 +02:00
parent 5da90b5160
commit 79435ff3fb
6 changed files with 71 additions and 9 deletions

View File

@@ -21,12 +21,30 @@ StoreController::StoreController(Responder * parentResponder, Store * store, But
void StoreController::fillColumnWithFormula(Expression * formula) {
int currentColumn = selectedColumn();
// Fetch the series used in the formula to:
// - Make sure the current filled column is not inside
// - Compute the size of the filled in series
// 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};
int numberOfVariables = formula->getVariables(Symbol::isSeriesSymbol, variables);
assert(numberOfVariables >= 0);
int numberOfValuesToCompute = -1;
int index = 0;
while (variables[index] != 0) {
const char * seriesName = Symbol::textForSpecialSymbols(variables[index]);
assert(strlen(seriesName) == 2);
int series = (int)(seriesName[1] - '0') - 1;
assert(series >= 0 && series < FloatPairStore::k_numberOfSeries);
if (numberOfValuesToCompute == -1) {
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(series);
} else {
numberOfValuesToCompute = min(numberOfValuesToCompute, m_store->numberOfPairsOfSeries(series));
}
index++;
}
if (numberOfValuesToCompute == -1) {
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(selectedColumn()/FloatPairStore::k_numberOfColumnsPerSeries);
}
SeriesContext seriesContext(m_store, const_cast<AppsContainer *>(static_cast<const AppsContainer *>(app()->container()))->globalContext());
for (int j = 0; j < 2; j++) {
for (int j = 0; j < numberOfValuesToCompute; j++) {
// Set the context
seriesContext.setSeriesPairIndex(j);
// Compute the new value using the formula