diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-01-15 15:21:56 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-01-15 15:50:16 -0800 |
commit | dfb94e5470565bc5ad1fd2d0678ef427706bed6c (patch) | |
tree | 7d338582b494a328d5f2a3aba135a87aba41faef /statistics.c | |
parent | 788ebc0500b12fb502b82473c1459ccca06345a5 (diff) | |
download | subsurface-dfb94e5470565bc5ad1fd2d0678ef427706bed6c.tar.gz |
Add statistics for longest, shortest, and shallowest dive
I don't really like calling the shallowest dive "min depth", but all other
texts that I could come up with that were reasonably short weren't any
better...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'statistics.c')
-rw-r--r-- | statistics.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/statistics.c b/statistics.c index 5017fe0b2..2669d5302 100644 --- a/statistics.c +++ b/statistics.c @@ -37,7 +37,10 @@ static single_stat_widget_t single_w; typedef struct { GtkWidget *total_time, *avg_time, + *shortest_time, + *longest_time, *max_overall_depth, + *min_overall_depth, *avg_overall_depth, *min_sac, *avg_sac, @@ -49,7 +52,10 @@ static total_stats_widget_t stats_w; typedef struct { duration_t total_time; /* avg_time is simply total_time / nr -- let's not keep this */ + duration_t shortest_time; + duration_t longest_time; depth_t max_depth; + depth_t min_depth; depth_t avg_depth; volume_t max_sac; volume_t min_sac; @@ -66,6 +72,10 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive) *prev_dive = NULL; memset(&stats, 0, sizeof(stats)); + if (dive_table.nr > 0) { + stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds; + stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm; + } /* this relies on the fact that the dives in the dive_table * are in chronological order */ for (idx = 0; idx < dive_table.nr; idx++) { @@ -77,8 +87,14 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive) } old_tt = stats.total_time.seconds; stats.total_time.seconds += dp->duration.seconds; + if (dp->duration.seconds > stats.longest_time.seconds) + stats.longest_time.seconds = dp->duration.seconds; + if (dp->duration.seconds < stats.shortest_time.seconds) + stats.shortest_time.seconds = dp->duration.seconds; if (dp->maxdepth.mm > stats.max_depth.mm) stats.max_depth.mm = dp->maxdepth.mm; + if (dp->maxdepth.mm < stats.min_depth.mm) + stats.min_depth.mm = dp->maxdepth.mm; stats.avg_depth.mm = (1.0 * old_tt * stats.avg_depth.mm + dp->duration.seconds * dp->meandepth.mm) / stats.total_time.seconds; if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */ @@ -206,8 +222,12 @@ static void show_total_dive_stats(struct dive *dive) set_label(stats_w.total_time, get_time_string(stats.total_time.seconds, 0)); set_label(stats_w.avg_time, get_time_string(stats.total_time.seconds / dive_table.nr, 0)); + set_label(stats_w.longest_time, get_time_string(stats.longest_time.seconds, 0)); + set_label(stats_w.shortest_time, get_time_string(stats.shortest_time.seconds, 0)); value = get_depth_units(stats.max_depth.mm, &decimals, &unit); set_label(stats_w.max_overall_depth, "%.*f %s", decimals, value, unit); + value = get_depth_units(stats.min_depth.mm, &decimals, &unit); + set_label(stats_w.min_overall_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(stats.avg_depth.mm, &decimals, &unit); set_label(stats_w.avg_overall_depth, "%.*f %s", decimals, value, unit); value = get_volume_units(stats.max_sac.mliter, &decimals, &unit); @@ -220,6 +240,8 @@ static void show_total_dive_stats(struct dive *dive) void show_dive_stats(struct dive *dive) { + /* they have to be called in this order, as 'total' depends on + * calculations done in 'single' */ show_single_dive_stats(dive); show_total_dive_stats(dive); } @@ -259,10 +281,18 @@ GtkWidget *total_stats_widget(void) stats_w.total_time = new_info_label_in_frame(hbox, "Total Time"); stats_w.avg_time = new_info_label_in_frame(hbox, "Avg Time"); + stats_w.longest_time = new_info_label_in_frame(hbox, "Longest Dive"); + stats_w.shortest_time = new_info_label_in_frame(hbox, "Shortest Dive"); + + /* second row */ + hbox = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3); + stats_w.max_overall_depth = new_info_label_in_frame(hbox, "Max Depth"); + stats_w.min_overall_depth = new_info_label_in_frame(hbox, "Min Depth"); stats_w.avg_overall_depth = new_info_label_in_frame(hbox, "Avg Depth"); - /* second row */ + /* third row */ hbox = gtk_hbox_new(FALSE, 3); gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3); |