From 233e686b92e172d4d29357b5e02d440144595130 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 11 Jan 2021 00:12:22 +0100 Subject: statistics: split people binner The people binner (called "buddies") is too coarse. Split into buddies, dive guide and people (the old "buddies", which is a combination of buddies and dive guide). Reported-by: Peter Zaal Reported-by: Rick Walsh Signed-off-by: Berthold Stoeger --- stats/statsvariables.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'stats') diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index 923fe4c86..8b2dc9bc3 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -1420,9 +1420,9 @@ struct DiveModeVariable : public StatsVariableTemplate { +struct PeopleBinner : public StringBinner { std::vector to_bin_values(const dive *d) const { std::vector dive_people; for (const QString &s: QString(d->buddy).split(",", SKIP_EMPTY)) @@ -1433,10 +1433,10 @@ struct BuddyBinner : public StringBinner { } }; -static BuddyBinner buddy_binner; -struct BuddyVariable : public StatsVariableTemplate { +static PeopleBinner people_binner; +struct PeopleVariable : public StatsVariableTemplate { QString name() const override { - return StatsTranslations::tr("Buddies"); + return StatsTranslations::tr("People"); } QString diveCategories(const dive *d) const override { QString buddy = QString(d->buddy).trimmed(); @@ -1445,11 +1445,55 @@ struct BuddyVariable : public StatsVariableTemplate binners() const override { + return { &people_binner }; + } +}; + +struct BuddyBinner : public StringBinner { + std::vector to_bin_values(const dive *d) const { + std::vector buddies; + for (const QString &s: QString(d->buddy).split(",", SKIP_EMPTY)) + buddies.push_back(s.trimmed()); + return buddies; + } +}; + +static BuddyBinner buddy_binner; +struct BuddyVariable : public StatsVariableTemplate { + QString name() const override { + return StatsTranslations::tr("Buddies"); + } + QString diveCategories(const dive *d) const override { + return QString(d->buddy).trimmed(); + } std::vector binners() const override { return { &buddy_binner }; } }; +struct DiveGuideBinner : public StringBinner { + std::vector to_bin_values(const dive *d) const { + std::vector dive_guides; + for (const QString &s: QString(d->divemaster).split(",", SKIP_EMPTY)) + dive_guides.push_back(s.trimmed()); + return dive_guides; + } +}; + +static DiveGuideBinner dive_guide_binner; +struct DiveGuideVariable : public StatsVariableTemplate { + QString name() const override { + return StatsTranslations::tr("Dive guides"); + } + QString diveCategories(const dive *d) const override { + return QString(d->divemaster).trimmed(); + } + std::vector binners() const override { + return { &dive_guide_binner }; + } +}; + // ============ Tags ============ struct TagBinner : public StringBinner { @@ -1889,7 +1933,9 @@ static AirTemperatureVariable air_temperature_variable; static WeightVariable weight_variable; static DiveNrVariable dive_nr_variable; static DiveModeVariable dive_mode_variable; +static PeopleVariable people_variable; static BuddyVariable buddy_variable; +static DiveGuideVariable dive_guide_variable; static TagVariable tag_variable; static GasTypeVariable gas_type_variable; static GasContentO2Variable gas_content_o2_variable; @@ -1907,7 +1953,8 @@ const std::vector stats_variables = { &date_variable, &max_depth_variable, &mean_depth_variable, &duration_variable, &sac_variable, &water_temperature_variable, &air_temperature_variable, &weight_variable, &dive_nr_variable, &gas_content_o2_variable, &gas_content_o2_he_max_variable, &gas_content_he_variable, - &dive_mode_variable, &buddy_variable, &tag_variable, &gas_type_variable, &suit_variable, + &dive_mode_variable, &people_variable, &buddy_variable, &dive_guide_variable, &tag_variable, + &gas_type_variable, &suit_variable, &weightsystem_variable, &cylinder_type_variable, &location_variable, &day_of_week_variable, &rating_variable, &visibility_variable }; -- cgit v1.2.3-70-g09d2