Skip to content

Commit 39e2b06

Browse files
authored
v1.2
Multiple days and multiple files support
2 parents f3f10a1 + 1476281 commit 39e2b06

File tree

6 files changed

+157
-55
lines changed

6 files changed

+157
-55
lines changed

Arc-app-export-converter/BurningCal/BurnMETValuesImporter.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

Arc-app-export-converter/JsonParser.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Day(DateTime date) {
131131

132132

133133
public static class JsonParser {
134-
public static void Parse(List<XmlReader> xml) {
134+
public static void Parse(List<XmlReader> xml, string fileName) {
135135
JsonMoves json = new JsonMoves();
136136
json.day = new JsonMoves.Day[xml.Count];
137137
for (int i = 0; i < xml.Count; i++) {
@@ -150,7 +150,7 @@ public static void Parse(List<XmlReader> xml) {
150150
NullValueHandling = NullValueHandling.Ignore
151151
});
152152
output = CleanUpJson(output);
153-
WriteToFile(output);
153+
WriteToFile(output, fileName);
154154
}
155155

156156

@@ -216,12 +216,12 @@ static string CleanUpJson(string json) {
216216
return json;
217217
}
218218

219-
static void WriteToFile(string json) {
220-
StreamWriter sw = new StreamWriter("file.json");
219+
static void WriteToFile(string json, string fileName) {
220+
StreamWriter sw = new StreamWriter(fileName);
221221
sw.Write(json);
222222
sw.Close();
223223
Console.ForegroundColor = ConsoleColor.DarkGreen;
224-
Console.WriteLine("Json file created!");
224+
Console.WriteLine(string.Format("Json file created!"));
225225
}
226226
}
227227

Arc-app-export-converter/PlacesManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public static void SavePlaces() {
9797
StreamWriter sw = new StreamWriter(placesFileName);
9898
sw.Write(JsonConvert.SerializeObject(new PlacesSave(places, currentId)));
9999
sw.Close();
100+
Console.WriteLine();
101+
Console.ForegroundColor = ConsoleColor.Blue;
100102
Console.WriteLine("Places database saved to file " + placesFileName);
101103
}
102104

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
24

35
class MainClass {
46

57
public static float weight = 83;
68

79
[STAThread]
810
public static void Main() {
9-
if (PlacesManager.Loaded)
11+
if (PlacesManager.Loaded) {
12+
Console.ForegroundColor = ConsoleColor.DarkGray;
1013
Console.WriteLine("Places initialised");
11-
Console.Write("Input your weight (in kg): ");
12-
weight = Convert.ToInt32(Console.ReadLine());
13-
XmlReader xr = new XmlReader();
14-
xr.LoadFile();
15-
xr.ParseToJson();
14+
}
15+
SetupWeight();
16+
17+
foreach (var item in ReturnFilePath()) {
18+
XmlReader xr = new XmlReader(item);
19+
20+
// Split into days
21+
List<XmlReader> daysInXml = XmlReader.Split(xr);
22+
JsonParser.Parse(daysInXml, xr.originalName + ".json");
23+
}
1624

1725
// On finish
1826
PlacesManager.SavePlaces();
1927
}
28+
29+
static void SetupWeight() {
30+
Console.ResetColor();
31+
Console.Write("Input your weight (in kg): ");
32+
weight = Convert.ToInt32(Console.ReadLine());
33+
}
34+
35+
static string[] ReturnFilePath() {
36+
string appDirectory = Directory.GetCurrentDirectory();
37+
string[] files = Directory.GetFiles(appDirectory, "*.gpx");
38+
return files;
39+
}
40+
2041
}

Arc-app-export-converter/XmlReader.cs

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class TimelineItem {
1414
public Place place;
1515
public Activity activity;
1616

17-
public TimelineItem (Place place) {
17+
public TimelineItem(Place place) {
1818
type = TimelineItemType.place;
1919
this.place = place;
2020
}
2121

22-
public TimelineItem (Activity activity) {
22+
public TimelineItem(Activity activity) {
2323
type = TimelineItemType.activity;
2424
this.activity = activity;
2525
}
@@ -30,6 +30,46 @@ public override string ToString() {
3030
else
3131
return place.ToString();
3232
}
33+
34+
//Time
35+
public DateTime ReturnDate() {
36+
DateTime tempDate = new DateTime();
37+
if (type == TimelineItemType.activity)
38+
tempDate = activity.startTime;
39+
else
40+
tempDate = place.startTime.Value;
41+
return new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, 12, 0, 0, tempDate.Kind);
42+
}
43+
44+
public DateTime EndTime {
45+
get {
46+
if (type == TimelineItemType.activity)
47+
return activity.endTime;
48+
else
49+
return place.endTime.Value;
50+
}
51+
set {
52+
if (type == TimelineItemType.activity)
53+
activity.endTime = value;
54+
else
55+
place.endTime = value;
56+
}
57+
}
58+
59+
public DateTime StartTime {
60+
get {
61+
if (type == TimelineItemType.activity)
62+
return activity.startTime;
63+
else
64+
return place.startTime.Value;
65+
}
66+
set {
67+
if (type == TimelineItemType.activity)
68+
activity.startTime = value;
69+
else
70+
place.startTime = value;
71+
}
72+
}
3373
}
3474

3575
public class Coordinates {
@@ -194,9 +234,27 @@ public class XmlReader {
194234
List<XmlTimeline.Activity>[] activitySummary = new List<XmlTimeline.Activity>[10];
195235
public DateTime date;
196236
public ActivitySummary[] summary = new ActivitySummary[10];
237+
public string originalName;
197238

198239
// Activity and places loading
199-
public void LoadFile(string path = "file.gpx") {
240+
public XmlReader(string path) {
241+
Console.ForegroundColor = ConsoleColor.DarkGray;
242+
Console.WriteLine();
243+
Console.WriteLine("Opening file: " + path);
244+
originalName = path.Replace(".gpx", "");
245+
LoadFile(path);
246+
}
247+
public XmlReader(List<XmlTimeline.TimelineItem> timelineItems) {
248+
for (int i = 0; i < 10; i++) {
249+
activitySummary[i] = new List<XmlTimeline.Activity>();
250+
}
251+
this.timelineItems = timelineItems;
252+
//SetStartEnd();
253+
SetSummary();
254+
SetXmlDate();
255+
}
256+
257+
public void LoadFile(string path) {
200258
for (int i = 0; i < 10; i++) {
201259
activitySummary[i] = new List<XmlTimeline.Activity>();
202260
}
@@ -220,8 +278,9 @@ public void LoadFile(string path = "file.gpx") {
220278
sr.Close();
221279
SetStartEnd();
222280
SetSummary();
281+
SetXmlDate();
223282

224-
Display();
283+
//Display();
225284
}
226285
void GetPlace(string line, StreamReader sr) {
227286
XmlTimeline.Coordinates location = HelpMethods.GetLatLon(line);
@@ -267,7 +326,7 @@ void GetMove(StreamReader sr) {
267326
AddTimeToPreviousPlace(newActivity);
268327
timelineItems.Add(new XmlTimeline.TimelineItem(newActivity));
269328
AddTimeToPreviousPlace(newActivity);
270-
activitySummary[(int)type].Add(newActivity);
329+
//activitySummary[(int)type].Add(newActivity);
271330
}
272331
}
273332
sr.ReadLine();
@@ -292,26 +351,42 @@ void AddTimeToPreviousPlace(XmlTimeline.Activity activity) {
292351

293352
// End calculations
294353
void SetStartEnd() {
295-
if (timelineItems.First().type == XmlTimeline.TimelineItemType.place) {
354+
if (timelineItems.First().type == XmlTimeline.TimelineItemType.place && !timelineItems.First().place.startTime.HasValue) {
296355
DateTime time = timelineItems.First().place.endTime.Value;
297356
DateTime newTime = new DateTime(time.Year, time.Month, time.Day, 0, 0, 0, time.Kind);
298357
timelineItems.First().place.startTime = newTime;
299358
}
300359

301-
if (timelineItems.Last().type == XmlTimeline.TimelineItemType.place) {
360+
if (timelineItems.Last().type == XmlTimeline.TimelineItemType.place && !timelineItems.Last().place.endTime.HasValue) {
302361
DateTime time = timelineItems.Last().place.startTime.Value;
303362
DateTime newTime = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59, time.Kind);
304363
timelineItems.Last().place.endTime = newTime;
305364
}
306-
365+
}
366+
void SetXmlDate() {
307367
DateTime tempDate = new DateTime();
308-
if (timelineItems.First().type == XmlTimeline.TimelineItemType.activity) {
309-
tempDate = timelineItems.First().activity.startTime;
310-
} else
311-
tempDate = timelineItems.First().place.startTime.Value;
312-
date = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day);
368+
369+
if (timelineItems.Count > 1) {
370+
tempDate = timelineItems.First().EndTime;
371+
} else {
372+
DateTime tempEndTime = timelineItems[0].EndTime;
373+
if (tempEndTime.Day - timelineItems[0].StartTime.Day == 2) {
374+
tempDate = timelineItems.First().StartTime;
375+
tempDate.AddDays(1);
376+
} else if (tempEndTime.Hour == 23 && tempEndTime.Minute == 59 && tempEndTime.Second == 59)
377+
tempDate = tempEndTime;
378+
else
379+
tempDate = timelineItems[0].StartTime;
380+
}
381+
382+
date = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, 12, 0, 0, tempDate.Kind);
313383
}
314384
void SetSummary() {
385+
foreach (var item in timelineItems) {
386+
if (item.type == XmlTimeline.TimelineItemType.activity) {
387+
activitySummary[(int)item.activity.activity].Add(item.activity);
388+
}
389+
}
315390
for (int i = 0; i < 10; i++) {
316391
summary[i] = new ActivitySummary(activitySummary[i], i);
317392
}
@@ -337,6 +412,39 @@ public void ParseToJson() {
337412
List<XmlReader> tempList = new List<XmlReader> {
338413
this
339414
};
340-
JsonParser.Parse(tempList);
415+
JsonParser.Parse(tempList, originalName + ".json");
416+
}
417+
418+
// Split xml file
419+
public static List<XmlReader> Split(XmlReader xml) {
420+
List<XmlTimeline.TimelineItem> timelineItems = xml.timelineItems;
421+
422+
DateTime? currentDate = null;
423+
List<XmlReader> output = new List<XmlReader>();
424+
List<XmlTimeline.TimelineItem> tempList = new List<XmlTimeline.TimelineItem>();
425+
XmlTimeline.TimelineItem lastItem = timelineItems[0];
426+
427+
foreach (var item in timelineItems) {
428+
if (!currentDate.HasValue) {
429+
currentDate = item.ReturnDate();
430+
}
431+
432+
if (currentDate == item.ReturnDate()) {
433+
tempList.Add(item);
434+
lastItem = item;
435+
} else {
436+
XmlReader tempXml = new XmlReader(tempList .ToArray().ToList()); // stupid workaround to clone
437+
output.Add(tempXml);
438+
tempList.Clear();
439+
currentDate = item.ReturnDate();
440+
tempList.Add(lastItem);
441+
tempList.Add(item);
442+
lastItem = item;
443+
}
444+
}
445+
output.Add(new XmlReader(tempList.ToArray().ToList()));
446+
tempList.Clear();
447+
448+
return output;
341449
}
342450
}

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ Converter generates all information used by Moves developers:
1111

1212
### Usage:
1313
1. Download [newest release][2]
14-
2. Generate GPX in Arc App and place file named „file.gpx” in the same folder with .exe
14+
2. Generate GPX in Arc App and place file in the same folder with .exe (app support both single-day and month GPX files, make sure they end with *.gpx*. You can also place many GPX files at once)
1515
3. Run app, input weight - json file will be generated in the same folder
1616

1717
### Notes:
1818
- Step counts and Calories idle are not present in final export
19-
- For now you can convert only one-day gpx into one-day storyline json
2019
- All places are marked as „user”. I hope in future updates Arc GPX will also include Foursquare id
2120

22-
### TODO:
23-
- Export many files/month file into a single json
24-
2521
[1]: https://itunes.apple.com/app/arc-app-location-activity-tracker/id1063151918?mt=8
2622
[2]: https://github.com/bionicl/Arc-app-export-converter/releases/
2723

0 commit comments

Comments
 (0)