summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2016-01-17 21:18:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-02-26 09:16:55 +0100
commit403d6dcfb016a5886a9e6baab34c9868dad2aaf0 (patch)
treeb5885cb37239a17fdf2ae30366d4c1056d4977ff
parentb73f56bc43dac5d43d3d8fe16c9d40ed5987ab1d (diff)
downloadsubsurface-403d6dcfb016a5886a9e6baab34c9868dad2aaf0.tar.gz
Add dive type to statistics window
This adds dive type based division to the "yearly statistics" window. Thus people can see the stats from individually from OC, CCR, PSCR and freedive. See #949 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-models/yearlystatisticsmodel.cpp14
-rw-r--r--statistics.c26
-rw-r--r--statistics.h1
3 files changed, 40 insertions, 1 deletions
diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp
index 47d9891f2..1cc5a9087 100644
--- a/qt-models/yearlystatisticsmodel.cpp
+++ b/qt-models/yearlystatisticsmodel.cpp
@@ -202,4 +202,18 @@ void YearlyStatisticsModel::update_yearly_stats()
rootItem->children.append(item);
item->parent = rootItem;
}
+
+ /* Show the statistic sorted by dive type */
+ if (stats_by_type != NULL && stats_by_type[0].selection_size) {
+ YearStatisticsItem *item = new YearStatisticsItem(stats_by_type[0]);
+ for (i = 1; i <= sizeof(dive_comp_type) + 1; ++i) {
+ if (stats_by_type[i].selection_size == 0)
+ continue;
+ YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_type[i]);
+ item->children.append(iChild);
+ iChild->parent = item;
+ }
+ rootItem->children.append(item);
+ item->parent = rootItem;
+ }
}
diff --git a/statistics.c b/statistics.c
index 19fd350eb..ab0aaac3f 100644
--- a/statistics.c
+++ b/statistics.c
@@ -20,6 +20,7 @@ stats_t stats_selection;
stats_t *stats_monthly = NULL;
stats_t *stats_yearly = NULL;
stats_t *stats_by_trip = NULL;
+stats_t *stats_by_type = NULL;
static void process_temperatures(struct dive *dp, stats_t *stats)
{
@@ -117,18 +118,34 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
free(stats_yearly);
free(stats_monthly);
free(stats_by_trip);
+ free(stats_by_type);
size = sizeof(stats_t) * (dive_table.nr + 1);
stats_yearly = malloc(size);
stats_monthly = malloc(size);
stats_by_trip = malloc(size);
- if (!stats_yearly || !stats_monthly || !stats_by_trip)
+ stats_by_type = malloc(size);
+ if (!stats_yearly || !stats_monthly || !stats_by_trip || !stats_by_type)
return;
memset(stats_yearly, 0, size);
memset(stats_monthly, 0, size);
memset(stats_by_trip, 0, size);
+ memset(stats_by_type, 0, size);
stats_yearly[0].is_year = true;
+ /* Setting the is_trip to true to show the location as first
+ * field in the statistics window */
+ stats_by_type[0].location = strdup("All (by type stats)");
+ stats_by_type[0].is_trip = true;
+ stats_by_type[1].location = strdup("OC");
+ stats_by_type[1].is_trip = true;
+ stats_by_type[2].location = strdup("CCR");
+ stats_by_type[2].is_trip = true;
+ stats_by_type[3].location = strdup("pSCR");
+ stats_by_type[3].is_trip = true;
+ stats_by_type[4].location = strdup("Freedive");
+ stats_by_type[4].is_trip = true;
+
/* this relies on the fact that the dives in the dive_table
* are in chronological order */
for_each_dive (idx, dp) {
@@ -154,6 +171,13 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
stats_yearly[year_iter].selection_size++;
stats_yearly[year_iter].period = current_year;
+ /* stats_by_type[0] is all the dives combined */
+ stats_by_type[0].selection_size++;
+ process_dive(dp, &(stats_by_type[0]));
+
+ process_dive(dp, &(stats_by_type[dp->dc.divemode + 1]));
+ stats_by_type[dp->dc.divemode + 1].selection_size++;
+
if (dp->divetrip != NULL) {
if (trip_ptr != dp->divetrip) {
trip_ptr = dp->divetrip;
diff --git a/statistics.h b/statistics.h
index dbab25761..890e6e53c 100644
--- a/statistics.h
+++ b/statistics.h
@@ -39,6 +39,7 @@ extern stats_t stats_selection;
extern stats_t *stats_yearly;
extern stats_t *stats_monthly;
extern stats_t *stats_by_trip;
+extern stats_t *stats_by_type;
extern char *get_time_string_s(int seconds, int maxdays, bool freediving);
extern char *get_minutes(int seconds);