From 256b2d777e310f7cc8cfff5141b82a94d804da8f Mon Sep 17 00:00:00 2001 From: Maciej Maj Date: Wed, 3 Apr 2019 20:26:28 +0200 Subject: [PATCH 1/4] Added timer, before XML library --- Arc-app-export-converter/Program.cs | 3 ++- ConverterLibrary/ConverterLibrary.csproj | 1 + ConverterLibrary/ElevationCalculator.cs | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 ConverterLibrary/ElevationCalculator.cs diff --git a/Arc-app-export-converter/Program.cs b/Arc-app-export-converter/Program.cs index 32a8894..4f4d97a 100644 --- a/Arc-app-export-converter/Program.cs +++ b/Arc-app-export-converter/Program.cs @@ -13,7 +13,7 @@ public static void Main() { Console.WriteLine("Places initialised"); } SetupWeight(); - + DateTime startTime = DateTime.Now; foreach (var item in ReturnFilePath()) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(); @@ -28,6 +28,7 @@ public static void Main() { // On finish PlacesManager.SavePlaces(); + Console.WriteLine(DateTime.Now - startTime); } static void SetupWeight() { diff --git a/ConverterLibrary/ConverterLibrary.csproj b/ConverterLibrary/ConverterLibrary.csproj index 646adfc..a36c1a6 100644 --- a/ConverterLibrary/ConverterLibrary.csproj +++ b/ConverterLibrary/ConverterLibrary.csproj @@ -40,6 +40,7 @@ + diff --git a/ConverterLibrary/ElevationCalculator.cs b/ConverterLibrary/ElevationCalculator.cs new file mode 100644 index 0000000..176cf19 --- /dev/null +++ b/ConverterLibrary/ElevationCalculator.cs @@ -0,0 +1,4 @@ +using System; +public class ElevationCalculator { + +} From 6cbd528fd1b481a0e791d673c863c36123d2cc5d Mon Sep 17 00:00:00 2001 From: Maciej Maj Date: Wed, 3 Apr 2019 22:18:40 +0200 Subject: [PATCH 2/4] New library implementation --- Arc-app-export-converter/Program.cs | 6 ++--- ConverterLibrary/ConverterLibrary.csproj | 5 +++- ConverterLibrary/XmlReader.cs | 34 ++++++++++++++++++++---- ConverterLibrary/packages.config | 3 ++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Arc-app-export-converter/Program.cs b/Arc-app-export-converter/Program.cs index 4f4d97a..2ae6557 100644 --- a/Arc-app-export-converter/Program.cs +++ b/Arc-app-export-converter/Program.cs @@ -21,9 +21,9 @@ public static void Main() { XmlReader xr = new XmlReader(item, true, weight); - // Split into days - List daysInXml = XmlReader.Split(xr); - JsonParser.Parse(daysInXml, xr.originalName + ".json", true); + //// Split into days + //List daysInXml = XmlReader.Split(xr); + //JsonParser.Parse(daysInXml, xr.originalName + ".json", true); } // On finish diff --git a/ConverterLibrary/ConverterLibrary.csproj b/ConverterLibrary/ConverterLibrary.csproj index a36c1a6..ab2c57c 100644 --- a/ConverterLibrary/ConverterLibrary.csproj +++ b/ConverterLibrary/ConverterLibrary.csproj @@ -29,7 +29,10 @@ - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\GpxTools.macharius40.1.0.2\lib\netstandard2.0\GpxTools.dll diff --git a/ConverterLibrary/XmlReader.cs b/ConverterLibrary/XmlReader.cs index daa8c48..5d839a6 100644 --- a/ConverterLibrary/XmlReader.cs +++ b/ConverterLibrary/XmlReader.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using GpxTools; public class XmlTimeline { @@ -245,12 +246,35 @@ public class XmlReader { // Activity and places loading public XmlReader(string path, bool isPath, float weight) { this.weight = weight; - if (isPath) { - originalName = path.Replace(".gpx", ""); - LoadFile(path); - } else { - LoadString(path); + string allText = File.ReadAllText(path); + byte[] byteArray = Encoding.UTF8.GetBytes(allText); + MemoryStream stream = new MemoryStream(byteArray); + GpxReader gpxReader = new GpxReader(stream); + while (gpxReader.Read()) { + switch (gpxReader.ObjectType) { + case GpxObjectType.Metadata: + //gpxReader.Metadata; + break; + case GpxObjectType.WayPoint: + //gpxReader.WayPoint; + break; + case GpxObjectType.Route: + //gpxReader.Route; + break; + case GpxObjectType.Track: + //gpxReader.Track; + break; + } } + GpxAnalyser analyser = new GpxAnalyser(gpxReader); + Console.WriteLine(gpxReader.Read()); + + //if (isPath) { + // originalName = path.Replace(".gpx", ""); + // LoadFile(path); + //} else { + // LoadString(path); + //} } public XmlReader(List timelineItems) { for (int i = 0; i < 10; i++) { diff --git a/ConverterLibrary/packages.config b/ConverterLibrary/packages.config index 5762754..a8a6430 100644 --- a/ConverterLibrary/packages.config +++ b/ConverterLibrary/packages.config @@ -1,4 +1,5 @@  - + + \ No newline at end of file From f3989f741ed648a9234e747ab6aae9105f8e0fa1 Mon Sep 17 00:00:00 2001 From: Maciej Maj Date: Wed, 3 Apr 2019 23:34:39 +0200 Subject: [PATCH 3/4] Working migration --- Arc-app-export-converter/Program.cs | 4 +- ConverterLibrary/JsonParser.cs | 2 +- ConverterLibrary/XmlReader.cs | 179 ++++++++-------------------- 3 files changed, 55 insertions(+), 130 deletions(-) diff --git a/Arc-app-export-converter/Program.cs b/Arc-app-export-converter/Program.cs index 2ae6557..1e493e5 100644 --- a/Arc-app-export-converter/Program.cs +++ b/Arc-app-export-converter/Program.cs @@ -22,8 +22,8 @@ public static void Main() { //// Split into days - //List daysInXml = XmlReader.Split(xr); - //JsonParser.Parse(daysInXml, xr.originalName + ".json", true); + List daysInXml = XmlReader.Split(xr); + JsonParser.Parse(daysInXml, xr.originalName + ".json", true); } // On finish diff --git a/ConverterLibrary/JsonParser.cs b/ConverterLibrary/JsonParser.cs index aefbbe8..815349a 100644 --- a/ConverterLibrary/JsonParser.cs +++ b/ConverterLibrary/JsonParser.cs @@ -238,7 +238,7 @@ static void WriteToFile(string json, string fileName) { sw.Write(json); sw.Close(); Console.ForegroundColor = ConsoleColor.DarkGreen; - Console.WriteLine(string.Format("Json file created!")); + Console.WriteLine(string.Format("Json file created!\n") + fileName); } } diff --git a/ConverterLibrary/XmlReader.cs b/ConverterLibrary/XmlReader.cs index 5d839a6..da2ed4c 100644 --- a/ConverterLibrary/XmlReader.cs +++ b/ConverterLibrary/XmlReader.cs @@ -77,13 +77,19 @@ public DateTime StartTime { public class Coordinates { public double lat; public double lon; - public string ele = null; + public double? ele = null; public DateTime? time = null; public Coordinates(string lat, string lon) { this.lat = Convert.ToDouble(lat); this.lon = Convert.ToDouble(lon); } + public Coordinates(double lat, double lon, double? ele, DateTime? time) { + this.lat = lat; + this.lon = lon; + this.ele = ele; + this.time = time; + } public Coordinates(double lat, double lon) { this.lat = lat; this.lon = lon; @@ -98,7 +104,7 @@ public class Place { public Coordinates position; public DateTime? startTime; public DateTime? endTime; - public string ele; + public double? ele; public string link; public int Duration { @@ -112,10 +118,11 @@ public int Duration { } } - public Place(Coordinates position, string name, DateTime? startTime = null, string ele = null, string link = null) { + public Place(Coordinates position, string name, DateTime? startTime = null, double? ele = null, string link = null) { this.position = position; this.startTime = startTime; this.name = name; + this.ele = ele; this.link = link; } @@ -246,35 +253,16 @@ public class XmlReader { // Activity and places loading public XmlReader(string path, bool isPath, float weight) { this.weight = weight; - string allText = File.ReadAllText(path); + + string allText = ""; + if (isPath) { + allText = File.ReadAllText(path); + originalName = path.Replace(".gpx", ""); + } else + allText = path; byte[] byteArray = Encoding.UTF8.GetBytes(allText); MemoryStream stream = new MemoryStream(byteArray); - GpxReader gpxReader = new GpxReader(stream); - while (gpxReader.Read()) { - switch (gpxReader.ObjectType) { - case GpxObjectType.Metadata: - //gpxReader.Metadata; - break; - case GpxObjectType.WayPoint: - //gpxReader.WayPoint; - break; - case GpxObjectType.Route: - //gpxReader.Route; - break; - case GpxObjectType.Track: - //gpxReader.Track; - break; - } - } - GpxAnalyser analyser = new GpxAnalyser(gpxReader); - Console.WriteLine(gpxReader.Read()); - - //if (isPath) { - // originalName = path.Replace(".gpx", ""); - // LoadFile(path); - //} else { - // LoadString(path); - //} + Load(stream); } public XmlReader(List timelineItems) { for (int i = 0; i < 10; i++) { @@ -286,27 +274,27 @@ public XmlReader(List timelineItems) { SetXmlDate(); } - public void Load(StreamReader sr) { + public void Load(Stream stream) { for (int i = 0; i < 10; i++) { activitySummary[i] = new List(); } - // Ignore first 2 lines - sr.ReadLine(); - sr.ReadLine(); - // Loop timelineItems.Clear(); - while (true) { - string line = sr.ReadLine().Replace("\t", ""); - if (line.StartsWith("")) - return; - XmlTimeline.Coordinates location = HelpMethods.GetLatLon(line); - - // time - DateTime? startTime = null; - + void GetPlace(GpxTools.Gpx.GpxWayPoint waypoint) { + // location + XmlTimeline.Coordinates location = new XmlTimeline.Coordinates(waypoint.Latitude, waypoint.Longitude); // time - string tempLine = sr.ReadLine().Replace("\t", ""); - if (tempLine.StartsWith("