summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Henrik Brautaset Aronsen <subsurface@henrik.synth.no>2013-01-24 19:58:59 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-24 13:00:03 -0800
commite3088930ab58327fac744e4672906892560dc93e (patch)
treef58167085dab3419256b44a17c3d9beee5a3804d /statistics.c
parentb8efe709a8e6c23a2bf3849a454565634b2a0545 (diff)
downloadsubsurface-e3088930ab58327fac744e4672906892560dc93e.tar.gz
Use actual min and max temperatures in statistics.
The statistics page only used each dive's "watertemp" attribute, regardless of actual higher/lower temperatures in the samples. By finding the actual max/min temperatures, the statistics page utilize more "real" data, and look better even on single dives. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/statistics.c b/statistics.c
index 1050b39ad..0cdbf7146 100644
--- a/statistics.c
+++ b/statistics.c
@@ -107,6 +107,37 @@ enum {
static char * get_time_string(int seconds, int maxdays);
+static void process_temperatures(struct dive *dp, stats_t *stats, const char *unit)
+{
+ int min_temp, mean_temp, max_temp = 0;
+
+ if (dp->maxtemp.mkelvin)
+ max_temp = dp->maxtemp.mkelvin;
+ else
+ max_temp = dp->dc.watertemp.mkelvin;
+
+ if (max_temp && (!stats->max_temp || max_temp > stats->max_temp))
+ stats->max_temp = max_temp;
+
+ if (dp->mintemp.mkelvin)
+ min_temp = dp->mintemp.mkelvin;
+ else
+ min_temp = dp->dc.watertemp.mkelvin;
+
+ if (min_temp && (!stats->min_temp || min_temp < stats->min_temp))
+ stats->min_temp = min_temp;
+
+ if (min_temp || max_temp) {
+ mean_temp = min_temp;
+ if (mean_temp)
+ mean_temp = (mean_temp + max_temp) / 2;
+ else
+ mean_temp = max_temp;
+ stats->combined_temp += get_temp_units(mean_temp, &unit);
+ stats->combined_count++;
+ }
+}
+
static void process_dive(struct dive *dp, stats_t *stats)
{
int old_tt, sac_time = 0;
@@ -122,14 +153,8 @@ static void process_dive(struct dive *dp, stats_t *stats)
stats->max_depth.mm = dp->dc.maxdepth.mm;
if (stats->min_depth.mm == 0 || dp->dc.maxdepth.mm < stats->min_depth.mm)
stats->min_depth.mm = dp->dc.maxdepth.mm;
- if (dp->dc.watertemp.mkelvin) {
- if (stats->min_temp == 0 || dp->dc.watertemp.mkelvin < stats->min_temp)
- stats->min_temp = dp->dc.watertemp.mkelvin;
- if (dp->dc.watertemp.mkelvin > stats->max_temp)
- stats->max_temp = dp->dc.watertemp.mkelvin;
- stats->combined_temp += get_temp_units(dp->dc.watertemp.mkelvin, &unit);
- stats->combined_count++;
- }
+
+ process_temperatures(dp, stats, unit);
/* Maybe we should drop zero-duration dives */
if (!dp->dc.duration.seconds)