diff options
author | Robert C. Helling <helling@atdotde.de> | 2021-01-04 22:01:13 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-05 00:34:14 +0100 |
commit | b181c011ccee7525d90bc673ef6ea94af1f8351d (patch) | |
tree | 355671cb0ceeb03bfaaf5a333a4e5e669c3f1351 /stats | |
parent | ce0f64df2ef032d1a6a453569689dce4fe83cb04 (diff) | |
download | subsurface-b181c011ccee7525d90bc673ef6ea94af1f8351d.tar.gz |
Add dive rating and visibility to statistics variables
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'stats')
-rw-r--r-- | stats/statsvariables.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index 9551b5386..3b6d55761 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -1681,6 +1681,58 @@ struct DayOfWeekVariable : public StatsVariableTemplate<StatsVariable::Type::Dis } }; +// ============ Rating ============ +struct RatingBinner : public SimpleBinner<RatingBinner, IntBin> { + QString format(const StatsBin &bin) const override { + return QString("🌟").repeated(derived_bin(bin).value); + } + + int to_bin_value(const dive *d) const { + int res = (int)d->rating; + return res; + } +}; + +static RatingBinner rating_binner; +struct RatingVariable : public StatsVariableTemplate<StatsVariable::Type::Discrete> { + QString name() const override { + return StatsTranslations::tr("Rating"); + } + QString diveCategories(const dive *d) const override { + int rating = (int)d->rating; + return QString("🌟").repeated(rating); + } + std::vector<const StatsBinner *> binners() const override { + return { &rating_binner }; + } +}; + +// ============ Visibility ============ +struct VisibilityBinner : public SimpleBinner<VisibilityBinner, IntBin> { + QString format(const StatsBin &bin) const override { + return QString("🌟").repeated(derived_bin(bin).value); + } + + int to_bin_value(const dive *d) const { + int res = (int)d->visibility; + return res; + } +}; + +static VisibilityBinner visibility_binner; +struct VisibilityVariable : public StatsVariableTemplate<StatsVariable::Type::Discrete> { + QString name() const override { + return StatsTranslations::tr("Visibility"); + } + QString diveCategories(const dive *d) const override { + int viz = (int)d->visibility; + return QString("🌟").repeated(viz); + } + std::vector<const StatsBinner *> binners() const override { + return { &visibility_binner }; + } +}; + static DateVariable date_variable; static DepthVariable depth_variable; static DurationVariable duration_variable; @@ -1699,10 +1751,14 @@ static WeightsystemVariable weightsystem_variable; static CylinderTypeVariable cylinder_type_variable; static LocationVariable location_variable; static DayOfWeekVariable day_of_week_variable; +static RatingVariable rating_variable; +static VisibilityVariable visibility_variable; + const std::vector<const StatsVariable *> stats_variables = { &date_variable, &depth_variable, &duration_variable, &sac_variable, &water_temperature_variable, &air_temperature_variable, &weight_variable, &gas_content_o2_variable, &gas_content_o2_he_max_variable, &gas_content_he_variable, &dive_mode_variable, &buddy_variable, &gas_type_variable, &suit_variable, - &weightsystem_variable, &cylinder_type_variable, &location_variable, &day_of_week_variable + &weightsystem_variable, &cylinder_type_variable, &location_variable, &day_of_week_variable, + &rating_variable, &visibility_variable }; |