From c7efcb23a9a838f88c6691cb7b278126ae639c4b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 9 Feb 2013 06:50:53 -0800 Subject: Add a meandepth to the dive structure This is currently only used in one place (in statistics.c), but it certainly is consistent with the other recent changes to avoid using only the first divecomputer when trying to make statements about a dive. Signed-off-by: Dirk Hohndel --- dive.c | 16 ++++++++++++++++ dive.h | 2 +- statistics.c | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dive.c b/dive.c index fb9d1e84e..ef05c51fe 100644 --- a/dive.c +++ b/dive.c @@ -454,6 +454,21 @@ static void fixup_water_salinity(struct dive *dive) dive->salinity = (sum + nr/2)/nr; } +static void fixup_meandepth(struct dive *dive) +{ + struct divecomputer *dc; + int sum = 0, nr = 0; + + for_each_dc(dive, dc) { + if (dc->meandepth.mm) { + sum += dc->meandepth.mm; + nr++; + } + } + if (nr) + dive->meandepth.mm = (sum + nr / 2) / nr; +} + /* * events are stored as a linked list, so the concept of * "consecutive, identical events" is somewhat hard to @@ -645,6 +660,7 @@ struct dive *fixup_dive(struct dive *dive) fixup_water_salinity(dive); fixup_surface_pressure(dive); + fixup_meandepth(dive); for_each_dc(dive, dc) fixup_dive_dc(dive, dc); diff --git a/dive.h b/dive.h index 14fd29917..830fcce7d 100644 --- a/dive.h +++ b/dive.h @@ -321,7 +321,7 @@ struct dive { /* Calculated based on dive computer data */ temperature_t mintemp, maxtemp; - depth_t maxdepth; + depth_t maxdepth, meandepth; pressure_t surface_pressure; int salinity; // kg per 10000 l diff --git a/statistics.c b/statistics.c index 33789a93d..43e12efed 100644 --- a/statistics.c +++ b/statistics.c @@ -146,7 +146,7 @@ static void process_dive(struct dive *dp, stats_t *stats) if (!duration) return; stats->avg_depth.mm = (1.0 * old_tt * stats->avg_depth.mm + - duration * dp->dc.meandepth.mm) / stats->total_time.seconds; + duration * dp->meandepth.mm) / stats->total_time.seconds; if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */ sac_time = stats->total_sac_time + duration; stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter + -- cgit v1.2.3-70-g09d2