mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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 <dirk@hohndel.org> Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
1c00f9f233
commit
acd385048a
4 changed files with 17 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
19
core/dive.c
19
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue