From acd385048ae61248c7f961318ed99b4aa627928c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 20 Aug 2022 17:24:45 +0200 Subject: [PATCH] Prefer real data over planned When a dive has both real dive computers as well as at least a planned version (which is just another dive computer with a special name), only use the data from real dive computers for aggregate values like maxdepth, dive time, average depth etc in order not to have imagined data on the dive list, statistics etc. Macro-magic-provided-by: Dirk Hohndel Signed-off-by: Robert C. Helling --- .clang-format | 2 +- CHANGELOG.md | 1 + core/dive.c | 19 +++++++++++-------- core/dive.h | 4 ++++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.clang-format b/.clang-format index 81c427805..f590bd1b3 100644 --- a/.clang-format +++ b/.clang-format @@ -10,7 +10,7 @@ ColumnLimit: 0 ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 8 ContinuationIndentWidth: 8 -ForEachMacros: [ 'foreach', 'for_each_dc', 'for_each_dive', 'for_each_line', 'Q_FOREACH', 'BOOST_FOREACH' ] +ForEachMacros: [ 'foreach', 'for_each_dc', 'for_each_relevant_dc', 'for_each_dive', 'for_each_line', 'Q_FOREACH', 'BOOST_FOREACH' ] IndentFunctionDeclarationAfterType: false #personal taste, good for long methods IndentWidth: 8 MaxEmptyLinesToKeep: 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index d996a5ffa..e20c30689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +divelist: do not include planned versions of a dive if there is real data desktop: fix key composition in tag widgets and dive site widget mobile: allow cloud account deletion (Apple app store requirement) diff --git a/core/dive.c b/core/dive.c index 5e6c2c0f1..ffbd16673 100644 --- a/core/dive.c +++ b/core/dive.c @@ -795,7 +795,7 @@ pressure_t calculate_surface_pressure(const struct dive *dive) pressure_t res; int sum = 0, nr = 0; - for_each_dc (dive, dc) { + for_each_relevant_dc(dive, dc) { if (dc->surface_pressure.mbar) { sum += dc->surface_pressure.mbar; nr++; @@ -826,7 +826,7 @@ static void fixup_water_salinity(struct dive *dive) struct divecomputer *dc; int sum = 0, nr = 0; - for_each_dc (dive, dc) { + for_each_relevant_dc (dive, dc) { if (dc->salinity) { if (dc->salinity < 500) dc->salinity += FRESHWATER_SALINITY; @@ -848,12 +848,13 @@ static void fixup_meandepth(struct dive *dive) struct divecomputer *dc; int sum = 0, nr = 0; - for_each_dc (dive, dc) { + for_each_relevant_dc (dive, dc) { if (dc->meandepth.mm) { sum += dc->meandepth.mm; nr++; } } + if (nr) dive->meandepth.mm = (sum + nr / 2) / nr; } @@ -863,9 +864,9 @@ static void fixup_duration(struct dive *dive) struct divecomputer *dc; duration_t duration = { }; - for_each_dc (dive, dc) + for_each_relevant_dc (dive, dc) { duration.seconds = MAX(duration.seconds, dc->duration.seconds); - + } dive->duration.seconds = duration.seconds; } @@ -981,8 +982,9 @@ static void fixup_dc_depths(struct dive *dive, struct divecomputer *dc) } update_depth(&dc->maxdepth, maxdepth); - if (maxdepth > dive->maxdepth.mm) - dive->maxdepth.mm = maxdepth; + if (!has_planned(dive, false) || !is_dc_planner(dc)) + if (maxdepth > dive->maxdepth.mm) + dive->maxdepth.mm = maxdepth; } static void fixup_dc_ndl(struct divecomputer *dc) @@ -2961,7 +2963,7 @@ static inline int dive_totaltime(const struct dive *dive) int time = dive->duration.seconds; const struct divecomputer *dc; - for_each_dc(dive, dc) { + for_each_relevant_dc(dive, dc) { int dc_time = dc_totaltime(dc); if (dc_time > time) time = dc_time; @@ -3118,6 +3120,7 @@ struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number) res->id = dive_getUniqID(); delete_divecomputer(res, dc_number); + force_fixup_dive(res); return res; } diff --git a/core/dive.h b/core/dive.h index f2dad1d56..d1df22193 100644 --- a/core/dive.h +++ b/core/dive.h @@ -143,6 +143,10 @@ void split_divecomputer(const struct dive *src, int num, struct dive **out1, str #define for_each_dc(_dive, _dc) \ for (_dc = &_dive->dc; _dc; _dc = _dc->next) +#define for_each_relevant_dc(_dive, _dc) \ + bool _all_planned = !has_planned(_dive, false); \ + for (_dc = &_dive->dc; _dc; _dc = _dc->next) if (_all_planned || !is_dc_planner(_dc)) + extern struct dive *get_dive_by_uniq_id(int id); extern int get_idx_by_uniq_id(int id); extern bool dive_site_has_gps_location(const struct dive_site *ds);