[PATCH] Use actual min and max temperatures in statistics.
subsurface at henrik.synth.no
subsurface at henrik.synth.no
Thu Jan 24 09:53:47 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>
---
Updated patch: this will use the watertemp property if there are no
temperature samples available
Henrik
dive.h | 1 +
parse-xml.c | 11 +++++++++++
statistics.c | 41 +++++++++++++++++++++++++++++++++--------
3 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/dive.h b/dive.h
index fc82f5e..9dd1dae 100644
--- a/dive.h
+++ b/dive.h
@@ -316,6 +316,7 @@ struct dive {
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
char *suit;
int sac, otu, cns, maxcns;
+ temperature_t mintemp, maxtemp;
/* Eventually we'll do multiple dive computers */
struct divecomputer dc;
diff --git a/parse-xml.c b/parse-xml.c
index 85b1c53..6a92908 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1258,6 +1258,16 @@ static void divecomputer_end(void)
cur_dc = NULL;
}
+static void update_min_max_temperatures()
+{
+ if (cur_dive && cur_sample->temperature.mkelvin) {
+ if (!cur_dive->maxtemp.mkelvin || cur_sample->temperature.mkelvin > cur_dive->maxtemp.mkelvin)
+ cur_dive->maxtemp = cur_sample->temperature;
+ if (!cur_dive->mintemp.mkelvin || cur_sample->temperature.mkelvin < cur_dive->mintemp.mkelvin)
+ cur_dive->mintemp = cur_sample->temperature;
+ }
+}
+
static void entry(const char *name, char *buf)
{
if (in_settings) {
@@ -1271,6 +1281,7 @@ static void entry(const char *name, char *buf)
}
if (cur_sample) {
try_to_fill_sample(cur_sample, name, buf);
+ update_min_max_temperatures();
return;
}
if (cur_dc) {
diff --git a/statistics.c b/statistics.c
index 1050b39..0cdbf71 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)
--
1.8.1.1
More information about the subsurface
mailing list