diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-09 11:15:18 +1100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-02-08 18:22:30 -0800 |
commit | 926fcef2a1e83b58c37c948a3f1a904aa0be0d0e (patch) | |
tree | 7f759284b78c77beecb2a11bae25649122f2690a /dive.c | |
parent | b286ea638c8ce468cf9c1a1b5037867acb5d6fe4 (diff) | |
download | subsurface-926fcef2a1e83b58c37c948a3f1a904aa0be0d0e.tar.gz |
Do more dive fixup for each dive computer
In commit b6c9301e5847 ("Move more dive computer filled data to the
divecomputer structure") we moved the fields that get filled in by the
dive computers to be per-divecomputer data structures.
This patch re-creates some of those fields back in the "struct dive",
but now the fields are initialized to be a reasonable average from the
dive computer data. We already did some of this for the temperature
min/max fields for the statistics, so this just continues that trend.
The goal is to make it easy to look at "dive values" without having to
iterate over dive computers every time you do. Just do it once in
"fixup_dive()" instead.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 55 |
1 files changed, 34 insertions, 21 deletions
@@ -230,27 +230,6 @@ int get_duration_in_sec(struct dive *dive) return duration; } -int get_surface_pressure_in_mbar(const struct dive *dive, gboolean non_null) -{ - unsigned int count = 0, sum = 0; - const struct divecomputer *dc = &dive->dc; - - do { - if (!dc->surface_pressure.mbar) - continue; - sum += dc->surface_pressure.mbar; - count++; - } while ((dc = dc->next) != NULL); - - /* Did we have any dive computers with surface pressure information */ - if (count) - return (sum + count/2) / count; - - if (non_null) - return SURFACE_PRESSURE; - return 0; -} - static void update_temperature(temperature_t *temperature, int new) { if (new) { @@ -445,6 +424,36 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event * return previous; } +static void fixup_surface_pressure(struct dive *dive) +{ + struct divecomputer *dc; + int sum, nr; + + for_each_dc(dive, dc) { + if (dc->surface_pressure.mbar) { + sum += dc->surface_pressure.mbar; + nr++; + } + } + if (nr) + dive->surface_pressure.mbar = (sum + nr/2)/nr; +} + +static void fixup_water_salinity(struct dive *dive) +{ + struct divecomputer *dc; + int sum, nr; + + for_each_dc(dive, dc) { + if (dc->salinity) { + sum += dc->salinity; + nr++; + } + } + if (nr) + dive->salinity = (sum + nr/2)/nr; +} + /* right now this only operates on the first divecomputer */ struct dive *fixup_dive(struct dive *dive) { @@ -466,6 +475,10 @@ struct dive *fixup_dive(struct dive *dive) add_suit(dive->suit); sanitize_cylinder_info(dive); dive->maxcns = dive->cns; + + fixup_water_salinity(dive); + fixup_surface_pressure(dive); + dc = &dive->dc; for (i = 0; i < dc->samples; i++) { struct sample *sample = dc->sample + i; |