summaryrefslogtreecommitdiffstats
path: root/stats/statsvariables.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-10 21:29:45 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-10 13:42:48 -0800
commitde62638b73e91520096d93ed155a627a05a6b005 (patch)
treef147701fca15c4dcde7ac660c42a2f533aeec3a9 /stats/statsvariables.cpp
parent2d864c3e9da1ad38a86ca80ca0b1811c983fbe7c (diff)
downloadsubsurface-de62638b73e91520096d93ed155a627a05a6b005.tar.gz
statistics: add tags variable
Trivially a copy of the "buddies" code. Suggested-by: Peter Zaal <peter.zaal@gmail.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsvariables.cpp')
-rw-r--r--stats/statsvariables.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp
index ea8f33211..f9d75854b 100644
--- a/stats/statsvariables.cpp
+++ b/stats/statsvariables.cpp
@@ -8,6 +8,7 @@
#include "core/pref.h"
#include "core/qthelper.h" // for get_depth_unit() et al.
#include "core/string-format.h"
+#include "core/tag.h"
#include "core/subsurface-time.h"
#include <cmath>
#include <limits>
@@ -1449,6 +1450,30 @@ struct BuddyVariable : public StatsVariableTemplate<StatsVariable::Type::Discret
}
};
+// ============ Tags ============
+
+struct TagBinner : public StringBinner<TagBinner, StringBin> {
+ std::vector<QString> to_bin_values(const dive *d) const {
+ std::vector<QString> tags;
+ for (const tag_entry *tag = d->tag_list; tag; tag = tag->next)
+ tags.push_back(QString(tag->tag->name).trimmed());
+ return tags;
+ }
+};
+
+static TagBinner tag_binner;
+struct TagVariable : public StatsVariableTemplate<StatsVariable::Type::Discrete> {
+ QString name() const override {
+ return StatsTranslations::tr("Tags");
+ }
+ QString diveCategories(const dive *d) const override {
+ return get_taglist_string(d->tag_list);
+ }
+ std::vector<const StatsBinner *> binners() const override {
+ return { &tag_binner };
+ }
+};
+
// ============ Gas type, in 2%, 5%, 10% and 20% steps ============
// This is a bit convoluted: We differentiate between four types: air, pure oxygen, EAN and trimix
// The latter two are binned in x% steps. The problem is that we can't use the "simple binner",
@@ -1865,6 +1890,7 @@ static WeightVariable weight_variable;
static DiveNrVariable dive_nr_variable;
static DiveModeVariable dive_mode_variable;
static BuddyVariable buddy_variable;
+static TagVariable tag_variable;
static GasTypeVariable gas_type_variable;
static GasContentO2Variable gas_content_o2_variable;
static GasContentO2HeMaxVariable gas_content_o2_he_max_variable;
@@ -1881,7 +1907,7 @@ const std::vector<const StatsVariable *> 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, &gas_type_variable, &suit_variable,
+ &dive_mode_variable, &buddy_variable, &tag_variable, &gas_type_variable, &suit_variable,
&weightsystem_variable, &cylinder_type_variable, &location_variable, &day_of_week_variable,
&rating_variable, &visibility_variable
};