From b181c011ccee7525d90bc673ef6ea94af1f8351d Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 4 Jan 2021 22:01:13 +0100 Subject: Add dive rating and visibility to statistics variables Signed-off-by: Robert C. Helling --- stats/statsvariables.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) 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 { + 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 { + 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 binners() const override { + return { &rating_binner }; + } +}; + +// ============ Visibility ============ +struct VisibilityBinner : public SimpleBinner { + 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 { + 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 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 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 }; -- cgit v1.2.3-70-g09d2