From c32e71e64d97016d201aea26f0623de6cd65d74d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 6 Oct 2018 09:21:27 +0200 Subject: Dive information: fix surface interval calculation The old surface interval calculation had fundamental issues: 1) process_all_dives(), which calculates the statistics over *all* dives was used to get the pointer to the previous dive. 2) If two dives in the table had the same time, one of those would have been considered the "previous" dive. 3) If the dive, for which the surface interval is calculated is not yet in the table, no previous dive would be determined. Fix all this by creating a get_surface_interval() function and removing the "get previous dive" functionality of process_all_dives(). Remove the process_all_dives() call from TabDiveInformation::updateData(). Reported-by: Jan Mulder Signed-off-by: Berthold Stoeger --- core/statistics.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'core/statistics.c') diff --git a/core/statistics.c b/core/statistics.c index beeb258a6..b25080a9f 100644 --- a/core/statistics.c +++ b/core/statistics.c @@ -3,7 +3,7 @@ * * core logic for the Info & Stats page - * char *get_minutes(int seconds); - * void process_all_dives(struct dive *dive, struct dive **prev_dive); + * void process_all_dives(); */ #include "gettext.h" #include @@ -91,7 +91,7 @@ char *get_minutes(int seconds) return buf; } -void process_all_dives(struct dive *dive, struct dive **prev_dive) +void process_all_dives() { int idx; struct dive *dp; @@ -105,7 +105,6 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive) dive_trip_t *trip_ptr = 0; unsigned int size, tsize; - *prev_dive = NULL; memset(&stats, 0, sizeof(stats)); if (dive_table.nr > 0) { stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds; @@ -152,11 +151,6 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive) /* this relies on the fact that the dives in the dive_table * are in chronological order */ for_each_dive (idx, dp) { - if (dive && dp->when == dive->when) { - /* that's the one we are showing */ - if (idx > 0) - *prev_dive = dive_table.dives[idx - 1]; - } process_dive(dp, &stats); /* yearly statistics */ -- cgit v1.2.3-70-g09d2