mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
b8efe709a8
commit
e3088930ab
3 changed files with 47 additions and 8 deletions
13
dive.c
13
dive.c
|
@ -248,6 +248,17 @@ static void fixup_pressure(struct dive *dive, struct sample *sample)
|
||||||
cyl->sample_end.mbar = pressure;
|
cyl->sample_end.mbar = pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_min_max_temperatures(struct dive *dive, struct sample *sample)
|
||||||
|
{
|
||||||
|
if (sample->temperature.mkelvin) {
|
||||||
|
if (!dive->maxtemp.mkelvin || sample->temperature.mkelvin > dive->maxtemp.mkelvin)
|
||||||
|
dive->maxtemp = sample->temperature;
|
||||||
|
if (!dive->mintemp.mkelvin || sample->temperature.mkelvin < dive->mintemp.mkelvin)
|
||||||
|
dive->mintemp = sample->temperature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the cylinder tank pressures are within half a bar
|
* If the cylinder tank pressures are within half a bar
|
||||||
* (about 8 PSI) of the sample pressures, we consider it
|
* (about 8 PSI) of the sample pressures, we consider it
|
||||||
|
@ -479,6 +490,8 @@ struct dive *fixup_dive(struct dive *dive)
|
||||||
if (!mintemp || temp < mintemp)
|
if (!mintemp || temp < mintemp)
|
||||||
mintemp = temp;
|
mintemp = temp;
|
||||||
}
|
}
|
||||||
|
update_min_max_temperatures(dive, sample);
|
||||||
|
|
||||||
depthtime += (time - lasttime) * (lastdepth + depth) / 2;
|
depthtime += (time - lasttime) * (lastdepth + depth) / 2;
|
||||||
lastdepth = depth;
|
lastdepth = depth;
|
||||||
lasttime = time;
|
lasttime = time;
|
||||||
|
|
1
dive.h
1
dive.h
|
@ -316,6 +316,7 @@ struct dive {
|
||||||
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
|
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
|
||||||
char *suit;
|
char *suit;
|
||||||
int sac, otu, cns, maxcns;
|
int sac, otu, cns, maxcns;
|
||||||
|
temperature_t mintemp, maxtemp;
|
||||||
|
|
||||||
/* Eventually we'll do multiple dive computers */
|
/* Eventually we'll do multiple dive computers */
|
||||||
struct divecomputer dc;
|
struct divecomputer dc;
|
||||||
|
|
41
statistics.c
41
statistics.c
|
@ -107,6 +107,37 @@ enum {
|
||||||
|
|
||||||
static char * get_time_string(int seconds, int maxdays);
|
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)
|
static void process_dive(struct dive *dp, stats_t *stats)
|
||||||
{
|
{
|
||||||
int old_tt, sac_time = 0;
|
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;
|
stats->max_depth.mm = dp->dc.maxdepth.mm;
|
||||||
if (stats->min_depth.mm == 0 || dp->dc.maxdepth.mm < stats->min_depth.mm)
|
if (stats->min_depth.mm == 0 || dp->dc.maxdepth.mm < stats->min_depth.mm)
|
||||||
stats->min_depth.mm = dp->dc.maxdepth.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)
|
process_temperatures(dp, stats, unit);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Maybe we should drop zero-duration dives */
|
/* Maybe we should drop zero-duration dives */
|
||||||
if (!dp->dc.duration.seconds)
|
if (!dp->dc.duration.seconds)
|
||||||
|
|
Loading…
Reference in a new issue