mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Better algorithm to merge gps locations & locations names from webservice
This no longer abuses the dive merging code (which would leave stray "dives" behind if a gps fix couldn't be merged with any of the dives) and instead parses the gps fixes into a second table and then walks that table and tries to find matching dives. The code tries to be reasonably smart about this. If we have auto-generated GPS fixes at regular intervals, we look for a fix that is during a dive (that's likely when the boat where the phone is staying dry is more or less above the diver having fun). And if we have named entries (so the user typed in a location name) we try to match them in order to the dives that happened "that day" (where "that day" is about 6h before and after the timestamp of the gps fix). This commit also renames dive_has_location() to dive_has_gps_location() as the difference between if(!dive->location) and if(dives_has_location) is a bit too subtle... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
8843ee6156
commit
635c28923d
7 changed files with 119 additions and 8 deletions
35
dive.c
35
dive.c
|
@ -1519,3 +1519,38 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
|
|||
fixup_dive(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
struct dive *find_dive_including(timestamp_t when)
|
||||
{
|
||||
int i;
|
||||
struct dive *dive;
|
||||
|
||||
/* binary search, anyone? Too lazy for now;
|
||||
* 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 + dive->dc.duration.seconds)
|
||||
return dive;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean dive_within_time_range(struct dive *dive, timestamp_t when, timestamp_t offset)
|
||||
{
|
||||
return when - offset <= dive->when && dive->when + dive->dc.duration.seconds <= when + offset;
|
||||
}
|
||||
|
||||
/* find the n-th dive that is part of a group of dives within the offset around 'when'.
|
||||
* How is that for a vague definition of what this function should do... */
|
||||
struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset)
|
||||
{
|
||||
int i, j = 0;
|
||||
struct dive *dive;
|
||||
|
||||
for_each_dive(i, dive) {
|
||||
if (dive_within_time_range(dive, when, offset))
|
||||
if (++j == n)
|
||||
return dive;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue