diff --git a/apps/exam_mode_configuration_official.cpp b/apps/exam_mode_configuration_official.cpp index d13b96bc3..20c89b412 100644 --- a/apps/exam_mode_configuration_official.cpp +++ b/apps/exam_mode_configuration_official.cpp @@ -6,11 +6,12 @@ constexpr Shared::SettingsMessageTree ExamModeConfiguration::s_modelExamChildren[2] = {Shared::SettingsMessageTree(I18n::Message::ActivateExamMode), Shared::SettingsMessageTree(I18n::Message::ActivateDutchExamMode)}; int ExamModeConfiguration::numberOfAvailableExamMode() { - if (GlobalPreferences::sharedGlobalPreferences()->country() != I18n::Country::NL + if (GlobalPreferences::sharedGlobalPreferences()->availableExamModes() == I18n::AvailableExamModes::StandardOnly || GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { return 1; } + assert(GlobalPreferences::sharedGlobalPreferences()->availableExamModes() == I18n::AvailableExamModes::All); return 2; } diff --git a/apps/global_preferences.h b/apps/global_preferences.h index 0001787f8..66996dc46 100644 --- a/apps/global_preferences.h +++ b/apps/global_preferences.h @@ -16,6 +16,9 @@ public: void setLanguage(I18n::Language language) { m_language = language; } I18n::Country country() const { return m_country; } void setCountry(I18n::Country country) { m_country = country; } + I18n::AvailableExamModes availableExamModes() const { return I18n::CountryPreferencesArray[static_cast(m_country)].availableExamModes; } + I18n::MethodForQuartiles methodForQuartiles() const { return I18n::CountryPreferencesArray[static_cast(m_country)].methodForQuartiles; } + Poincare::Preferences::UnitFormat unitFormat() const { return I18n::CountryPreferencesArray[static_cast(m_country)].unitFormat; } bool isInExamMode() const { return (int8_t)examMode() > 0; } ExamMode examMode() const; void setExamMode(ExamMode examMode); diff --git a/apps/i18n.py b/apps/i18n.py index 6f9dddcc9..a5c8437d9 100644 --- a/apps/i18n.py +++ b/apps/i18n.py @@ -120,7 +120,8 @@ def print_header(data, path, locales, countries): f.write("#ifndef APPS_I18N_H\n") f.write("#define APPS_I18N_H\n\n") f.write("// This file is auto-generated by i18n.py\n\n") - f.write("#include \n\n") + f.write("#include \n") + f.write("#include \n\n") f.write("namespace I18n {\n\n") f.write("constexpr static int NumberOfLanguages = %d;\n\n" % len(locales)) f.write("constexpr static int NumberOfCountries = %d;\n\n" % len(countries)) @@ -171,6 +172,38 @@ def print_header(data, path, locales, countries): f.write(" Message::Country" + country.upper() + ",\n") f.write("};\n\n") + # Country preferences + f.write("enum class AvailableExamModes : uint8_t {\n") + f.write(" None,\n") + f.write(" StandardOnly,\n") + f.write(" All\n") + f.write("};\n\n") + f.write("enum class MethodForQuartiles : uint8_t {\n") + f.write(" MedianOfSublist,\n") + f.write(" CumulatedFrequency\n") + f.write("};\n\n") + f.write("struct CountryPreferences {\n") + f.write(" AvailableExamModes availableExamModes;\n") + f.write(" MethodForQuartiles methodForQuartiles;\n") + f.write(" Poincare::Preferences::UnitFormat unitFormat;\n") + f.write("};\n\n") + countryPreferences = { + 'CA':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'DE':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'ES':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'FR':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::CumulatedFrequency, Poincare::Preferences::UnitFormat::Metric}", + 'GB':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'IT':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::CumulatedFrequency, Poincare::Preferences::UnitFormat::Metric}", + 'NL':"CountryPreferences{AvailableExamModes::All, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'PT':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}", + 'US':"CountryPreferences{AvailableExamModes::StandardOnly, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Imperial}", + 'WW':"CountryPreferences{AvailableExamModes::All, MethodForQuartiles::MedianOfSublist, Poincare::Preferences::UnitFormat::Metric}"} + f.write("constexpr static CountryPreferences CountryPreferencesArray[] = {\n") + for country in countries: + key = country if (country in countryPreferences) else 'WW' + f.write(" " + countryPreferences[key] + ",\n") + f.write("};\n\n") + f.write("}\n\n") f.write("#endif\n") f.close() diff --git a/apps/shared/country_controller.cpp b/apps/shared/country_controller.cpp index 911be04bc..7678d23ec 100644 --- a/apps/shared/country_controller.cpp +++ b/apps/shared/country_controller.cpp @@ -136,11 +136,7 @@ bool CountryController::handleEvent(Ion::Events::Event event) { /* FIXME : Changing the unit format should perhaps be done in setCountry.*/ I18n::Country country = CountryAtIndex(selectedRow()); GlobalPreferences::sharedGlobalPreferences()->setCountry(country); - if (country == I18n::Country::US) { - Poincare::Preferences::sharedPreferences()->setUnitFormat(Poincare::Preferences::UnitFormat::Imperial); - } else { - Poincare::Preferences::sharedPreferences()->setUnitFormat(Poincare::Preferences::UnitFormat::Metric); - } + Poincare::Preferences::sharedPreferences()->setUnitFormat(GlobalPreferences::sharedGlobalPreferences()->unitFormat()); return true; } return false; diff --git a/apps/statistics/store.cpp b/apps/statistics/store.cpp index 5c660d36c..6d7465991 100644 --- a/apps/statistics/store.cpp +++ b/apps/statistics/store.cpp @@ -1,6 +1,5 @@ #include "store.h" #include -#include #include #include #include @@ -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); } diff --git a/apps/statistics/test/store.cpp b/apps/statistics/test/store.cpp index 19feeaeaf..e56645160 100644 --- a/apps/statistics/test/store.cpp +++ b/apps/statistics/test/store.cpp @@ -103,7 +103,7 @@ void assert_data_statictics_equal_to( GlobalPreferences::sharedGlobalPreferences()->setCountry(country); quartileRange = store.quartileRange(seriesIndex); quiz_assert(quartileRange >= 0.0); - shouldUseFrequencyMethod = country == I18n::Country::FR || country == I18n::Country::IT; + shouldUseFrequencyMethod = GlobalPreferences::sharedGlobalPreferences()->methodForQuartiles() == I18n::MethodForQuartiles::CumulatedFrequency; assert_value_approximately_equal_to(store.firstQuartile(seriesIndex), shouldUseFrequencyMethod ? trueFirstQuartileFrequencyMethod : trueFirstQuartileSublistMethod, precision, reference); assert_value_approximately_equal_to(store.thirdQuartile(seriesIndex), shouldUseFrequencyMethod ? trueThirdQuartileFrequencyMethod : trueThirdQuartileSublistMethod, precision, reference); assert_value_approximately_equal_to(quartileRange, shouldUseFrequencyMethod ? trueQuartileRangeFrequencyMethod : trueQuartileRangeSublistMethod, 0.0, 0.0);