Skip to content

Commit 1476281

Browse files
committed
Fixed date bug, fixed displaying hours between days
1 parent b95282e commit 1476281

File tree

4 files changed

+71
-19
lines changed

4 files changed

+71
-19
lines changed

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

Arc-app-export-converter/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ class MainClass {
88

99
[STAThread]
1010
public static void Main() {
11-
if (PlacesManager.Loaded)
11+
if (PlacesManager.Loaded) {
12+
Console.ForegroundColor = ConsoleColor.DarkGray;
1213
Console.WriteLine("Places initialised");
14+
}
1315
SetupWeight();
1416

1517
foreach (var item in ReturnFilePath()) {
1618
XmlReader xr = new XmlReader(item);
1719

1820
// Split into days
1921
List<XmlReader> daysInXml = XmlReader.Split(xr);
20-
foreach (var item2 in daysInXml) {
21-
Console.WriteLine("PROGRAM There are segments in this xml: " + item2.timelineItems.Count);
22-
}
23-
JsonParser.Parse(daysInXml, "test.json");
22+
JsonParser.Parse(daysInXml, xr.originalName + ".json");
2423
}
2524

2625
// On finish
2726
PlacesManager.SavePlaces();
2827
}
2928

3029
static void SetupWeight() {
30+
Console.ResetColor();
3131
Console.Write("Input your weight (in kg): ");
3232
weight = Convert.ToInt32(Console.ReadLine());
3333
}

Arc-app-export-converter/XmlReader.cs

Lines changed: 63 additions & 13 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
}
@@ -31,6 +31,7 @@ public override string ToString() {
3131
return place.ToString();
3232
}
3333

34+
//Time
3435
public DateTime ReturnDate() {
3536
DateTime tempDate = new DateTime();
3637
if (type == TimelineItemType.activity)
@@ -39,6 +40,36 @@ public DateTime ReturnDate() {
3940
tempDate = place.startTime.Value;
4041
return new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, 12, 0, 0, tempDate.Kind);
4142
}
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+
}
4273
}
4374

4475
public class Coordinates {
@@ -203,10 +234,13 @@ public class XmlReader {
203234
List<XmlTimeline.Activity>[] activitySummary = new List<XmlTimeline.Activity>[10];
204235
public DateTime date;
205236
public ActivitySummary[] summary = new ActivitySummary[10];
206-
string originalName;
237+
public string originalName;
207238

208239
// Activity and places loading
209240
public XmlReader(string path) {
241+
Console.ForegroundColor = ConsoleColor.DarkGray;
242+
Console.WriteLine();
243+
Console.WriteLine("Opening file: " + path);
210244
originalName = path.Replace(".gpx", "");
211245
LoadFile(path);
212246
}
@@ -215,9 +249,9 @@ public XmlReader(List<XmlTimeline.TimelineItem> timelineItems) {
215249
activitySummary[i] = new List<XmlTimeline.Activity>();
216250
}
217251
this.timelineItems = timelineItems;
218-
Console.WriteLine("Creating with items: " + timelineItems.Count);
219-
SetStartEnd();
252+
//SetStartEnd();
220253
SetSummary();
254+
SetXmlDate();
221255
}
222256

223257
public void LoadFile(string path) {
@@ -244,6 +278,7 @@ public void LoadFile(string path) {
244278
sr.Close();
245279
SetStartEnd();
246280
SetSummary();
281+
SetXmlDate();
247282

248283
//Display();
249284
}
@@ -316,24 +351,35 @@ void AddTimeToPreviousPlace(XmlTimeline.Activity activity) {
316351

317352
// End calculations
318353
void SetStartEnd() {
319-
if (timelineItems.First().type == XmlTimeline.TimelineItemType.place) {
354+
if (timelineItems.First().type == XmlTimeline.TimelineItemType.place && !timelineItems.First().place.startTime.HasValue) {
320355
DateTime time = timelineItems.First().place.endTime.Value;
321356
DateTime newTime = new DateTime(time.Year, time.Month, time.Day, 0, 0, 0, time.Kind);
322357
timelineItems.First().place.startTime = newTime;
323358
}
324359

325-
if (timelineItems.Last().type == XmlTimeline.TimelineItemType.place) {
360+
if (timelineItems.Last().type == XmlTimeline.TimelineItemType.place && !timelineItems.Last().place.endTime.HasValue) {
326361
DateTime time = timelineItems.Last().place.startTime.Value;
327362
DateTime newTime = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59, time.Kind);
328363
timelineItems.Last().place.endTime = newTime;
329364
}
330-
365+
}
366+
void SetXmlDate() {
331367
DateTime tempDate = new DateTime();
332-
if (timelineItems.First().type == XmlTimeline.TimelineItemType.activity) {
333-
tempDate = timelineItems.First().activity.startTime;
334-
} else
335-
tempDate = timelineItems.First().place.startTime.Value;
336-
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);
337383
}
338384
void SetSummary() {
339385
foreach (var item in timelineItems) {
@@ -376,6 +422,7 @@ public static List<XmlReader> Split(XmlReader xml) {
376422
DateTime? currentDate = null;
377423
List<XmlReader> output = new List<XmlReader>();
378424
List<XmlTimeline.TimelineItem> tempList = new List<XmlTimeline.TimelineItem>();
425+
XmlTimeline.TimelineItem lastItem = timelineItems[0];
379426

380427
foreach (var item in timelineItems) {
381428
if (!currentDate.HasValue) {
@@ -384,12 +431,15 @@ public static List<XmlReader> Split(XmlReader xml) {
384431

385432
if (currentDate == item.ReturnDate()) {
386433
tempList.Add(item);
434+
lastItem = item;
387435
} else {
388436
XmlReader tempXml = new XmlReader(tempList .ToArray().ToList()); // stupid workaround to clone
389437
output.Add(tempXml);
390438
tempList.Clear();
391439
currentDate = item.ReturnDate();
440+
tempList.Add(lastItem);
392441
tempList.Add(item);
442+
lastItem = item;
393443
}
394444
}
395445
output.Add(new XmlReader(tempList.ToArray().ToList()));

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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 in the same folder with .exe (app support both single-day and month GPX files, make sure they end with *.gpx*)
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:

0 commit comments

Comments
 (0)