diff options
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -219,17 +219,6 @@ static void update_duration(duration_t *duration, int new) duration->seconds = new; } -int get_duration_in_sec(struct dive *dive) -{ - int duration = 0; - struct divecomputer *dc = &dive->dc; - do { - duration = MAX(duration, dc->duration.seconds); - dc = dc->next; - } while (dc); - return duration; -} - static void update_temperature(temperature_t *temperature, int new) { if (new) { @@ -469,6 +458,17 @@ static void fixup_meandepth(struct dive *dive) dive->meandepth.mm = (sum + nr / 2) / nr; } +static void fixup_duration(struct dive *dive) +{ + struct divecomputer *dc; + int duration = 0; + + for_each_dc(dive, dc) + duration = MAX(duration, dc->duration.seconds); + + dive->duration.seconds = duration; +} + /* * events are stored as a linked list, so the concept of * "consecutive, identical events" is somewhat hard to @@ -661,6 +661,7 @@ struct dive *fixup_dive(struct dive *dive) fixup_water_salinity(dive); fixup_surface_pressure(dive); fixup_meandepth(dive); + fixup_duration(dive); for_each_dc(dive, dc) fixup_dive_dc(dive, dc); @@ -1302,9 +1303,9 @@ static int likely_same_dive(struct dive *a, struct dive *b) * Do some basic sanity testing of the values we * have filled in during 'fixup_dive()' */ - if (!similar(a->dc.maxdepth.mm, b->dc.maxdepth.mm, 1000) || - !similar(a->dc.meandepth.mm, b->dc.meandepth.mm, 1000) || - !similar(get_duration_in_sec(a), get_duration_in_sec(b), 5*60)) + if (!similar(a->maxdepth.mm, b->maxdepth.mm, 1000) || + !similar(a->meandepth.mm, b->meandepth.mm, 1000) || + !similar(a->duration.seconds, b->duration.seconds, 5*60)) return 0; /* See if we can get an exact match on the dive computer */ @@ -1316,7 +1317,7 @@ static int likely_same_dive(struct dive *a, struct dive *b) * Allow a time difference due to dive computer time * setting etc. Check if they overlap. */ - fuzz = MAX(get_duration_in_sec(a), get_duration_in_sec(b)) / 2; + fuzz = MAX(a->duration.seconds, b->duration.seconds) / 2; if (fuzz < 60) fuzz = 60; @@ -1604,7 +1605,7 @@ struct dive *find_dive_including(timestamp_t when) * also we always use the duration from the first divecomputer * could this ever be a problem? */ for_each_dive(i, dive) { - if (dive->when <= when && when <= dive->when + get_duration_in_sec(dive)) + if (dive->when <= when && when <= dive->when + dive->duration.seconds) return dive; } return NULL; @@ -1612,7 +1613,7 @@ struct dive *find_dive_including(timestamp_t when) gboolean dive_within_time_range(struct dive *dive, timestamp_t when, timestamp_t offset) { - return when - offset <= dive->when && dive->when + get_duration_in_sec(dive) <= when + offset; + return when - offset <= dive->when && dive->when + dive->duration.seconds <= when + offset; } /* find the n-th dive that is part of a group of dives within the offset around 'when'. |