[apps/i18n] Derive preferences from country

Each country comes with an set of preferences, built at compile time by
apps/i18n.py, used to define :
  - the exam mode
  - the method for computing quartiles
  - the unit system in which to output the results with units
Functions to access those preferences are available in
via sharedGlobalPreferences.

Change-Id: I220ebaa9b9e8954dfe33cd51936f47505b98978d
This commit is contained in:
Gabriel Ozouf
2020-07-08 16:30:29 +02:00
committed by Émilie Feral
parent e2a6edd78f
commit 2b59509fdd
6 changed files with 45 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
#include "store.h"
#include <apps/global_preferences.h>
#include <apps/i18n.h>
#include <assert.h>
#include <float.h>
#include <cmath>
@@ -199,20 +198,18 @@ double Store::sampleStandardDeviation(int series) const {
* the more general definition if non-integral frequencies are found.
* */
double Store::firstQuartile(int series) const {
if (GlobalPreferences::sharedGlobalPreferences()->country() == I18n::Country::FR
|| GlobalPreferences::sharedGlobalPreferences()->country() == I18n::Country::IT
|| !frequenciesAreInteger(series)) {
if (GlobalPreferences::sharedGlobalPreferences()->methodForQuartiles() == I18n::MethodForQuartiles::CumulatedFrequency || !frequenciesAreInteger(series)) {
return sortedElementAtCumulatedFrequency(series, 1.0/4.0);
}
assert(GlobalPreferences::sharedGlobalPreferences()->methodForQuartiles() == I18n::MethodForQuartiles::MedianOfSublist);
return sortedElementAtCumulatedPopulation(series, std::floor(sumOfOccurrences(series) / 2.) / 2., true);
}
double Store::thirdQuartile(int series) const {
if (GlobalPreferences::sharedGlobalPreferences()->country() == I18n::Country::FR
|| GlobalPreferences::sharedGlobalPreferences()->country() == I18n::Country::IT
|| !frequenciesAreInteger(series)) {
if (GlobalPreferences::sharedGlobalPreferences()->methodForQuartiles() == I18n::MethodForQuartiles::CumulatedFrequency || !frequenciesAreInteger(series)) {
return sortedElementAtCumulatedFrequency(series, 3.0/4.0);
}
assert(GlobalPreferences::sharedGlobalPreferences()->methodForQuartiles() == I18n::MethodForQuartiles::MedianOfSublist);
return sortedElementAtCumulatedPopulation(series, std::ceil(3./2. * sumOfOccurrences(series)) / 2., true);
}