summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2013-11-24 03:09:34 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-23 22:07:18 -0800
commitce525bd28518cc3c625b5e005bc7eb5e3c460c29 (patch)
treea8d09fd1b88b9bb8e9e674a9ca70042d59f5e65e
parent66cdb3689a3bac0a56d9d8d38c01379fa4c3fda9 (diff)
downloadsubsurface-ce525bd28518cc3c625b5e005bc7eb5e3c460c29.tar.gz
Adding trip based statistics
This adds trip based statistics to the Yearly Statistics view. Signed-off-by: Miika Turkia <miika.turkia@nixu.fi> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/models.cpp22
-rw-r--r--statistics.c25
-rw-r--r--statistics.h3
3 files changed, 47 insertions, 3 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index ae156cbbc..8dfdb5c1f 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1364,7 +1364,13 @@ QVariant YearStatisticsItem::data(int column, int role) const
return ret;
}
switch(column) {
- case YEAR: ret = stats_interval.period; break;
+ case YEAR:
+ if (stats_interval.is_trip) {
+ ret = stats_interval.location;
+ } else {
+ ret = stats_interval.period;
+ }
+ break;
case DIVES: ret = stats_interval.selection_size; break;
case TOTAL_TIME: ret = get_time_string(stats_interval.total_time.seconds, 0); break;
case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); break;
@@ -1409,7 +1415,7 @@ QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientat
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) {
- case YEAR: val = tr("Year \n > Month"); break;
+ case YEAR: val = tr("Year \n > Month / Trip"); break;
case DIVES: val = tr("#"); break;
case TOTAL_TIME: val = tr("Duration \n Total"); break;
case AVERAGE_TIME: val = tr("\nAverage"); break;
@@ -1447,6 +1453,18 @@ void YearlyStatisticsModel::update_yearly_stats()
rootItem->children.append(item);
item->parent = rootItem;
}
+
+
+ if (stats_by_trip != NULL ) {
+ YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]);
+ for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) {
+ YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]);
+ item->children.append(iChild);
+ iChild->parent = item;
+ }
+ rootItem->children.append(item);
+ item->parent = rootItem;
+ }
}
/*#################################################################
diff --git a/statistics.c b/statistics.c
index a382af5a4..13c50039b 100644
--- a/statistics.c
+++ b/statistics.c
@@ -19,6 +19,7 @@ static stats_t stats;
stats_t stats_selection;
stats_t *stats_monthly = NULL;
stats_t *stats_yearly = NULL;
+stats_t *stats_by_trip = NULL;
static void process_temperatures(struct dive *dp, stats_t *stats)
{
@@ -95,6 +96,8 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
int year_iter = 0;
int month_iter = 0;
int prev_month = 0, prev_year = 0;
+ int trip_iter = 0;
+ dive_trip_t *trip_ptr = 0;
unsigned int size;
*prev_dive = NULL;
@@ -112,15 +115,19 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
if (stats_yearly != NULL) {
free(stats_yearly);
free(stats_monthly);
+ free(stats_by_trip);
}
size = sizeof(stats_t) * (dive_table.nr + 1);
stats_yearly = malloc(size);
stats_monthly = malloc(size);
- if (!stats_yearly || !stats_monthly)
+ stats_by_trip = malloc(size);
+ if (!stats_yearly || !stats_monthly || !stats_by_trip)
return;
memset(stats_yearly, 0, size);
memset(stats_monthly, 0, size);
+ memset(stats_by_trip, 0, size);
stats_yearly[0].is_year = TRUE;
+ stats_by_trip[0].is_trip = TRUE;
/* this relies on the fact that the dives in the dive_table
* are in chronological order */
@@ -148,6 +155,22 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
stats_yearly[year_iter].selection_size++;
stats_yearly[year_iter].period = current_year;
+ if (trip_ptr != dp->divetrip) {
+ trip_ptr = dp->divetrip;
+ trip_iter++;
+ }
+
+ /* stats_by_trip[0] is all the dives combined */
+ stats_by_trip[0].selection_size++;
+ process_dive(dp, &(stats_by_trip[0]));
+ stats_by_trip[0].is_trip = TRUE;
+ stats_by_trip[0].location = strdup("All (by trip stats)");
+
+ process_dive(dp, &(stats_by_trip[trip_iter]));
+ stats_by_trip[trip_iter].selection_size++;
+ stats_by_trip[trip_iter].is_trip = TRUE;
+ stats_by_trip[trip_iter].location = dp->divetrip->location;
+
/* monthly statistics */
if (current_month == 0) {
current_month = tm.tm_mon + 1;
diff --git a/statistics.h b/statistics.h
index 47fd24d3c..5f6e306c4 100644
--- a/statistics.h
+++ b/statistics.h
@@ -31,10 +31,13 @@ typedef struct {
unsigned int selection_size;
unsigned int total_sac_time;
bool is_year;
+ bool is_trip;
+ char *location;
} stats_t;
extern stats_t stats_selection;
extern stats_t *stats_yearly;
extern stats_t *stats_monthly;
+extern stats_t *stats_by_trip;
extern char *get_time_string(int seconds, int maxdays);
extern char *get_minutes(int seconds);