mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Do more dive fixup for each dive computer
In commit b6c9301e58 ("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>
This commit is contained in:
parent
b286ea638c
commit
926fcef2a1
7 changed files with 86 additions and 51 deletions
55
dive.c
55
dive.c
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue