mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[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:
committed by
Émilie Feral
parent
e2a6edd78f
commit
2b59509fdd
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<uint8_t>(m_country)].availableExamModes; }
|
||||
I18n::MethodForQuartiles methodForQuartiles() const { return I18n::CountryPreferencesArray[static_cast<uint8_t>(m_country)].methodForQuartiles; }
|
||||
Poincare::Preferences::UnitFormat unitFormat() const { return I18n::CountryPreferencesArray[static_cast<uint8_t>(m_country)].unitFormat; }
|
||||
bool isInExamMode() const { return (int8_t)examMode() > 0; }
|
||||
ExamMode examMode() const;
|
||||
void setExamMode(ExamMode examMode);
|
||||
|
||||
35
apps/i18n.py
35
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 <escher.h>\n\n")
|
||||
f.write("#include <escher.h>\n")
|
||||
f.write("#include <poincare/preferences.h>\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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user