[PATCH] Use actual min and max temperatures in statistics.
subsurface at henrik.synth.no
subsurface at henrik.synth.no
Thu Jan 24 05:08:42 PST 2013
From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
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 at henrik.synth.no>
---
This works, but we might consider structuring this differently (or not):
* Should maxtemp and mintemp be on the dive, and not on the divecomputer?
* Should parsing of min/maxtemp be done somewhere else thanin entry()?
Henrik
dive.h | 2 +-
parse-xml.c | 6 ++++++
statistics.c | 24 +++++++++++++++++-------
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/dive.h b/dive.h
index fc82f5e..16a7caa 100644
--- a/dive.h
+++ b/dive.h
@@ -265,7 +265,7 @@ struct divecomputer {
timestamp_t when;
duration_t duration, surfacetime;
depth_t maxdepth, meandepth;
- temperature_t airtemp, watertemp;
+ temperature_t airtemp, watertemp, mintemp, maxtemp;
pressure_t surface_pressure;
int salinity; // kg per 10000 l
const char *model;
diff --git a/parse-xml.c b/parse-xml.c
index 85b1c53..eb89a56 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1271,6 +1271,12 @@ static void entry(const char *name, char *buf)
}
if (cur_sample) {
try_to_fill_sample(cur_sample, name, buf);
+ if (cur_dive && cur_sample->temperature.mkelvin) {
+ if (cur_dive->dc.maxtemp.mkelvin == 0 || cur_sample->temperature.mkelvin > cur_dive->dc.maxtemp.mkelvin)
+ cur_dive->dc.maxtemp = cur_sample->temperature;
+ if (cur_dive->dc.mintemp.mkelvin == 0 || cur_sample->temperature.mkelvin < cur_dive->dc.mintemp.mkelvin)
+ cur_dive->dc.mintemp = cur_sample->temperature;
+ }
return;
}
if (cur_dc) {
diff --git a/statistics.c b/statistics.c
index 1050b39..77afcef 100644
--- a/statistics.c
+++ b/statistics.c
@@ -109,7 +109,7 @@ static char * get_time_string(int seconds, int maxdays);
static void process_dive(struct dive *dp, stats_t *stats)
{
- int old_tt, sac_time = 0;
+ int old_tt, sac_time, mean_temp = 0;
const char *unit;
old_tt = stats->total_time.seconds;
@@ -122,12 +122,22 @@ 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);
+
+ if (dp->dc.mintemp.mkelvin) {
+ if (stats->min_temp == 0 || dp->dc.mintemp.mkelvin < stats->min_temp)
+ stats->min_temp = dp->dc.mintemp.mkelvin;
+ }
+ if (dp->dc.maxtemp.mkelvin) {
+ if (stats->max_temp == 0 || dp->dc.maxtemp.mkelvin > stats->max_temp)
+ stats->max_temp = dp->dc.maxtemp.mkelvin;
+ }
+ if (dp->dc.mintemp.mkelvin || dp->dc.maxtemp.mkelvin) {
+ mean_temp = dp->dc.mintemp.mkelvin;
+ if (mean_temp)
+ mean_temp = (mean_temp + dp->dc.maxtemp.mkelvin) / 2;
+ else
+ mean_temp = dp->dc.maxtemp.mkelvin;
+ stats->combined_temp += get_temp_units(mean_temp, &unit);
stats->combined_count++;
}
--
1.7.11.5
More information about the subsurface
mailing list