mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
66cdb3689a
commit
ce525bd285
3 changed files with 47 additions and 3 deletions
|
@ -1364,7 +1364,13 @@ QVariant YearStatisticsItem::data(int column, int role) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
switch(column) {
|
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 DIVES: ret = stats_interval.selection_size; break;
|
||||||
case TOTAL_TIME: ret = get_time_string(stats_interval.total_time.seconds, 0); 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;
|
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) {
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
switch(section) {
|
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 DIVES: val = tr("#"); break;
|
||||||
case TOTAL_TIME: val = tr("Duration \n Total"); break;
|
case TOTAL_TIME: val = tr("Duration \n Total"); break;
|
||||||
case AVERAGE_TIME: val = tr("\nAverage"); break;
|
case AVERAGE_TIME: val = tr("\nAverage"); break;
|
||||||
|
@ -1447,6 +1453,18 @@ void YearlyStatisticsModel::update_yearly_stats()
|
||||||
rootItem->children.append(item);
|
rootItem->children.append(item);
|
||||||
item->parent = rootItem;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*#################################################################
|
/*#################################################################
|
||||||
|
|
25
statistics.c
25
statistics.c
|
@ -19,6 +19,7 @@ static stats_t stats;
|
||||||
stats_t stats_selection;
|
stats_t stats_selection;
|
||||||
stats_t *stats_monthly = NULL;
|
stats_t *stats_monthly = NULL;
|
||||||
stats_t *stats_yearly = NULL;
|
stats_t *stats_yearly = NULL;
|
||||||
|
stats_t *stats_by_trip = NULL;
|
||||||
|
|
||||||
static void process_temperatures(struct dive *dp, stats_t *stats)
|
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 year_iter = 0;
|
||||||
int month_iter = 0;
|
int month_iter = 0;
|
||||||
int prev_month = 0, prev_year = 0;
|
int prev_month = 0, prev_year = 0;
|
||||||
|
int trip_iter = 0;
|
||||||
|
dive_trip_t *trip_ptr = 0;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
|
|
||||||
*prev_dive = NULL;
|
*prev_dive = NULL;
|
||||||
|
@ -112,15 +115,19 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
|
||||||
if (stats_yearly != NULL) {
|
if (stats_yearly != NULL) {
|
||||||
free(stats_yearly);
|
free(stats_yearly);
|
||||||
free(stats_monthly);
|
free(stats_monthly);
|
||||||
|
free(stats_by_trip);
|
||||||
}
|
}
|
||||||
size = sizeof(stats_t) * (dive_table.nr + 1);
|
size = sizeof(stats_t) * (dive_table.nr + 1);
|
||||||
stats_yearly = malloc(size);
|
stats_yearly = malloc(size);
|
||||||
stats_monthly = 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;
|
return;
|
||||||
memset(stats_yearly, 0, size);
|
memset(stats_yearly, 0, size);
|
||||||
memset(stats_monthly, 0, size);
|
memset(stats_monthly, 0, size);
|
||||||
|
memset(stats_by_trip, 0, size);
|
||||||
stats_yearly[0].is_year = TRUE;
|
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
|
/* this relies on the fact that the dives in the dive_table
|
||||||
* are in chronological order */
|
* 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].selection_size++;
|
||||||
stats_yearly[year_iter].period = current_year;
|
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 */
|
/* monthly statistics */
|
||||||
if (current_month == 0) {
|
if (current_month == 0) {
|
||||||
current_month = tm.tm_mon + 1;
|
current_month = tm.tm_mon + 1;
|
||||||
|
|
|
@ -31,10 +31,13 @@ typedef struct {
|
||||||
unsigned int selection_size;
|
unsigned int selection_size;
|
||||||
unsigned int total_sac_time;
|
unsigned int total_sac_time;
|
||||||
bool is_year;
|
bool is_year;
|
||||||
|
bool is_trip;
|
||||||
|
char *location;
|
||||||
} stats_t;
|
} stats_t;
|
||||||
extern stats_t stats_selection;
|
extern stats_t stats_selection;
|
||||||
extern stats_t *stats_yearly;
|
extern stats_t *stats_yearly;
|
||||||
extern stats_t *stats_monthly;
|
extern stats_t *stats_monthly;
|
||||||
|
extern stats_t *stats_by_trip;
|
||||||
|
|
||||||
extern char *get_time_string(int seconds, int maxdays);
|
extern char *get_time_string(int seconds, int maxdays);
|
||||||
extern char *get_minutes(int seconds);
|
extern char *get_minutes(int seconds);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue