core: recalculate CNS values on merge

When merging two dives, the higher CNS value was taken. This could
result in inconsistent CNS values if two dives were merged where
one dive's CNS was calculated from a "fake profile", i.e. a dive
without dive-computer profile. In that case, the most conservative
value (all time spent at the bottom) was assumed. The merged dive
then consisted of the dive-computer profile and the conservative
CNS estimate.

This is fixed by setting the CNS value to "0" after merging,
which means "unknown". The correct value will then be recalculated
in "fixup_dive" from the actual sample data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-07-16 21:11:54 +02:00 committed by Dirk Hohndel
parent b18b3119b5
commit 63e1516579

View file

@ -2614,7 +2614,6 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset,
MERGE_MAX(res, a, b, rating); MERGE_MAX(res, a, b, rating);
MERGE_TXT(res, a, b, suit, ", "); MERGE_TXT(res, a, b, suit, ", ");
MERGE_MAX(res, a, b, number); MERGE_MAX(res, a, b, number);
MERGE_NONZERO(res, a, b, cns);
MERGE_NONZERO(res, a, b, visibility); MERGE_NONZERO(res, a, b, visibility);
copy_pictures(a->pictures.nr ? &a->pictures : &b->pictures, &res->pictures); copy_pictures(a->pictures.nr ? &a->pictures : &b->pictures, &res->pictures);
taglist_merge(&res->tag_list, a->tag_list, b->tag_list); taglist_merge(&res->tag_list, a->tag_list, b->tag_list);
@ -2631,6 +2630,9 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset,
else else
join_dive_computers(res, &res->dc, &a->dc, &b->dc, cylinders_map_a, cylinders_map_b, 0); join_dive_computers(res, &res->dc, &a->dc, &b->dc, cylinders_map_a, cylinders_map_b, 0);
/* The CNS values will be recalculated from the sample in fixup_dive() */
res->cns = res->maxcns = 0;
/* we take the first dive site, unless it's empty */ /* we take the first dive site, unless it's empty */
*site = a->dive_site && !dive_site_is_empty(a->dive_site) ? a->dive_site : b->dive_site; *site = a->dive_site && !dive_site_is_empty(a->dive_site) ? a->dive_site : b->dive_site;
fixup_dive(res); fixup_dive(res);