summaryrefslogtreecommitdiffstats
path: root/dive.h
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 14:09:16 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 14:29:02 +1100
commit635c28923d28335bb7d39f95c17c2edbf16ee2ac (patch)
tree0ae1566c791a505cd8233928c0258629057e83c9 /dive.h
parent8843ee61560fb3c6a66b7ae9f10367f57eddb109 (diff)
downloadsubsurface-635c28923d28335bb7d39f95c17c2edbf16ee2ac.tar.gz
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>
Diffstat (limited to 'dive.h')
-rw-r--r--dive.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/dive.h b/dive.h
index 2f4dcbd9e..e719f2289 100644
--- a/dive.h
+++ b/dive.h
@@ -321,11 +321,19 @@ struct dive {
struct divecomputer dc;
};
-static inline int dive_has_location(struct dive *dive)
+static inline int dive_has_gps_location(struct dive *dive)
{
return dive->latitude.udeg || dive->longitude.udeg;
}
+static inline void copy_gps_location(struct dive *from, struct dive *to)
+{
+ if (from && to) {
+ to->latitude.udeg = from->latitude.udeg;
+ to->longitude.udeg = from->longitude.udeg;
+ }
+}
+
/* Pa = N/m^2 - so we determine the weight (in N) of the mass of 10m
* of water (and use standard salt water at 1.03kg per liter if we don't know salinity)
* and add that to the surface pressure (or to 1013 if that's unknown) */
@@ -433,6 +441,13 @@ extern struct dive_table dive_table;
extern int selected_dive;
#define current_dive (get_dive(selected_dive))
+static inline struct dive *get_gps_location(int nr, struct dive_table *table)
+{
+ if (nr >= table->nr || nr < 0)
+ return NULL;
+ return table->dives[nr];
+}
+
static inline struct dive *get_dive(int nr)
{
if (nr >= dive_table.nr || nr < 0)
@@ -450,6 +465,9 @@ static inline struct dive *get_dive(int nr)
#define for_each_dive(_i,_x) \
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
+#define for_each_gps_location(_i,_x) \
+ for ((_i) = 0; ((_x) = get_gps_location(_i, &gps_location_table)) != NULL; (_i)++)
+
static inline struct dive *get_dive_by_diveid(int diveid, int deviceid)
{
int i;
@@ -464,6 +482,9 @@ static inline struct dive *get_dive_by_diveid(int diveid, int deviceid)
}
return NULL;
}
+extern struct dive *find_dive_including(timestamp_t when);
+extern gboolean dive_within_time_range(struct dive *dive, timestamp_t when, timestamp_t offset);
+struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset);
/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */
extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
@@ -504,6 +525,7 @@ extern void record_dive(struct dive *dive);
extern struct sample *prepare_sample(struct divecomputer *dc);
extern void finish_sample(struct divecomputer *dc);
+extern void sort_table(struct dive_table *table);
extern void report_dives(gboolean imported, gboolean prefer_imported);
extern struct dive *fixup_dive(struct dive *dive);
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean prefer_downloaded);