Skip to content

Commit 8a13d0c

Browse files
committed
Smart places grouping
1 parent 2956c7a commit 8a13d0c

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

Arc-app-export-converter/HelpMethods.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
public static class HelpMethods {
44

5-
// Copied from
6-
// https://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates
7-
5+
// Distance measure
86
public static float DistanceTo(XmlTimeline.Coordinates wp1, XmlTimeline.Coordinates wp2, char unit = 'K') {
7+
// Copied from
8+
// https://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates
9+
10+
911
double rlat1 = Math.PI * wp1.lat / 180;
12+
1013
double rlat2 = Math.PI * wp2.lat / 180;
1114
double theta = wp1.lon - wp2.lon;
1215
double rtheta = Math.PI * theta / 180;
@@ -30,11 +33,23 @@ public static float DistanceTo(XmlTimeline.Coordinates wp1, XmlTimeline.Coordina
3033

3134
return distF;
3235
}
36+
public static float DistanceTo(JsonMoves.Day.Segment.Place.Location jwp1, JsonMoves.Day.Segment.Place.Location jwp2, char unit = 'K') {
37+
XmlTimeline.Coordinates wp1 = new XmlTimeline.Coordinates(jwp1.lat, jwp1.lon);
38+
XmlTimeline.Coordinates wp2 = new XmlTimeline.Coordinates(jwp2.lat, jwp2.lon);
39+
return DistanceTo(wp1, wp2, unit);
40+
}
3341

42+
// Time conversations
3443
public static DateTime ParseIso8601(string iso8601Time) {
3544
return DateTime.Parse(iso8601Time, null, System.Globalization.DateTimeStyles.RoundtripKind);
3645
}
46+
public static string ConvertToIso1601(DateTime time) {
47+
string output = time.ToString(Iso1601Format);
48+
return output.Replace(":", "");
49+
}
50+
public static string Iso1601Format = "yyyyMMddTHHmmsszzz";
3751

52+
// GPX conversion
3853
public static XmlTimeline.Coordinates GetLatLon(string line) {
3954
string lat = "";
4055
string lon = "";
@@ -63,12 +78,7 @@ public static string LeaveCenterFromString(string text, string removeLeft, strin
6378
return temp;
6479
}
6580

66-
public static string ConvertToIso1601(DateTime time) {
67-
string output = time.ToString(Iso1601Format);
68-
return output.Replace(":", "");
69-
}
70-
public static string Iso1601Format = "yyyyMMddTHHmmsszzz";
71-
81+
// To Json conversion
7282
public static JsonMoves.ActivityGroup ReturnGroup(ActivityType type) {
7383
switch (type) {
7484
case ActivityType.walking:

Arc-app-export-converter/PlacesManager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ public Place(int id, string name, JsonMoves.Day.Segment.Place.Location location)
2525
}
2626

2727
public void AddVisit(DateTime startTime, DateTime endTime) {
28-
visits.Add(new PlaceVisit(startTime, endTime));
28+
PlaceVisit tempVisit = new PlaceVisit(startTime, endTime);
29+
foreach (var item in visits) {
30+
if (item.startTime == startTime)
31+
return;
32+
}
33+
visits.Add(tempVisit);
2934
}
3035
}
3136

@@ -42,6 +47,7 @@ public PlacesSave(List<Place> places, int currentId) {
4247
public class PlacesManager {
4348
static bool loaded;
4449
static string placesFileName = "places.json";
50+
static float distanceTolerance = 0.07f;
4551

4652
static List<Place> places = new List<Place>();
4753
static int currentId;
@@ -58,7 +64,7 @@ public static bool Loaded {
5864

5965
public static int ReturnPlaceId(JsonMoves.Day.Segment.Place place, DateTime startTime, DateTime endTime) {
6066
foreach (var item in places) {
61-
if (place.name == item.name) {
67+
if (CheckIfSamePlace(item, place)) {
6268
item.AddVisit(startTime, endTime);
6369
return item.id;
6470
}
@@ -68,6 +74,13 @@ public static int ReturnPlaceId(JsonMoves.Day.Segment.Place place, DateTime star
6874
newPlace.AddVisit(startTime, endTime);
6975
return newPlace.id;
7076
}
77+
static bool CheckIfSamePlace(Place place, JsonMoves.Day.Segment.Place jsonPlace) {
78+
if (place.name == jsonPlace.name) {
79+
if (HelpMethods.DistanceTo(place.location, jsonPlace.location) <= distanceTolerance)
80+
return true;
81+
}
82+
return false;
83+
}
7184

7285
// Loading files
7386
static void LoadPlaces() {

Arc-app-export-converter/XmlReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public Coordinates(string lat, string lon) {
4242
this.lat = Convert.ToDouble(lat);
4343
this.lon = Convert.ToDouble(lon);
4444
}
45+
public Coordinates(double lat, double lon) {
46+
this.lat = lat;
47+
this.lon = lon;
48+
}
4549
public override string ToString() {
4650
return string.Format("Lat: {0} Lon: {1} Ele: {2}", lat, lon, ele);
4751
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Convert GPX exported from [Arc App][1] to storyline Json format used by abandome
77
Converter generates all information used by Moves developers:
88
- Calculates burned calories based on movement speed and body weight
99
- Creates summary of all movement types
10+
- Sometimes GPX file can contain two different places with the same name - if those are too far from each other, converter will split it into two different places
1011

1112
### Usage:
1213
1. Download [newest release][2]
@@ -20,7 +21,6 @@ Converter generates all information used by Moves developers:
2021

2122
### TODO:
2223
- Export many files/month file into a single json
23-
- Create place id’s with smart place grouping based on name and coordinates
2424

2525
[1]: https://itunes.apple.com/app/arc-app-location-activity-tracker/id1063151918?mt=8
2626
[2]: https://github.com/bionicl/Arc-app-export-converter/releases/

0 commit comments

Comments
 (0)