Skip to content

Commit e03babe

Browse files
authored
v1.0
2 parents 2d36705 + 9286a32 commit e03babe

File tree

8 files changed

+749
-6
lines changed

8 files changed

+749
-6
lines changed

Arc-app-export-converter/Arc-app-export-converter.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@
3030
</PropertyGroup>
3131
<ItemGroup>
3232
<Reference Include="System" />
33+
<Reference Include="Newtonsoft.Json">
34+
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
35+
</Reference>
3336
</ItemGroup>
3437
<ItemGroup>
3538
<Compile Include="Program.cs" />
3639
<Compile Include="Properties\AssemblyInfo.cs" />
40+
<Compile Include="BurnedCalCalculator.cs" />
41+
<Compile Include="XmlReader.cs" />
42+
<Compile Include="JsonParser.cs" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<None Include="packages.config" />
3746
</ItemGroup>
3847
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
3948
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
4+
5+
[JsonConverter(typeof(StringEnumConverter))]
6+
public enum ActivityType {
7+
walking,
8+
cycling,
9+
running,
10+
car,
11+
transport,
12+
train,
13+
bus,
14+
motorcycle,
15+
airplane,
16+
boat
17+
}
18+
19+
public static class BurnedCalCalculator {
20+
public static float[] activityTypeMultiplayer = { 0.79f, 0.37f, 1.03f };
21+
// multiplayer values based on https://www.topendsports.com/weight-loss/energy-met.htm
22+
// and Moves app data
23+
24+
public static int Calcualate(ActivityType type, float time, float avgSpeed, float weight) {
25+
if ((int)type > 2)
26+
return 0;
27+
float value = activityTypeMultiplayer[(int)type] * time / 3600 * avgSpeed * weight;
28+
return (int)Math.Round(value);
29+
}
30+
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
namespace ArcAppExportConverter.BurningCal {
6+
7+
public class BurnMETValue {
8+
public ActivityType activity;
9+
public float minAvgSpeed; //in km/s
10+
public float metValue;
11+
12+
public BurnMETValue (string activity, float minAvgSpeed, float metValue) {
13+
Enum.TryParse(activity, out this.activity);
14+
this.minAvgSpeed = minAvgSpeed;
15+
this.metValue = metValue;
16+
}
17+
public BurnMETValue(string[] array) : this(array[0], float.Parse(array[1]), float.Parse(array[2])) {
18+
19+
}
20+
}
21+
22+
public class BurnMETValuesImporter {
23+
24+
}
25+
}
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Converters;
6+
7+
public class JsonMoves {
8+
[JsonConverter(typeof(StringEnumConverter))]
9+
public enum SegmentType {
10+
place,
11+
move
12+
}
13+
14+
[JsonConverter(typeof(StringEnumConverter))]
15+
public enum ActivityGroup {
16+
walking,
17+
cycling,
18+
running,
19+
transport
20+
}
21+
22+
public class Day {
23+
public class Summary {
24+
public ActivityType activity;
25+
public ActivityGroup group;
26+
public double duration;
27+
public double distance;
28+
public double? calories;
29+
30+
public Summary(ActivityType activity, float duration, double distance, float calories) {
31+
this.activity = activity;
32+
group = HelpMethods.ReturnGroup(activity);
33+
this.duration = duration;
34+
this.distance = Math.Round(distance * 1000);
35+
if (calories > 0)
36+
this.calories = calories;
37+
}
38+
}
39+
public class Segment {
40+
public class Place {
41+
public class Location {
42+
public double lat;
43+
public double lon;
44+
45+
public Location(double lat, double lon) {
46+
this.lat = lat;
47+
this.lon = lon;
48+
}
49+
}
50+
public long id = 1234567;
51+
public string name;
52+
public string type = "user";
53+
public Location location;
54+
55+
public Place(string name, Location location) {
56+
this.name = name;
57+
this.location = location;
58+
}
59+
60+
}
61+
public class Activity {
62+
public class TrackPoint {
63+
public double lat;
64+
public double lon;
65+
public string time;
66+
67+
public TrackPoint(double lat, double lon, DateTime time) {
68+
this.lat = lat;
69+
this.lon = lon;
70+
this.time = HelpMethods.ConvertToIso1601(time);
71+
}
72+
73+
}
74+
75+
public ActivityType activity;
76+
public ActivityGroup group;
77+
public bool manual = false;
78+
public string startTime;
79+
public string endTime;
80+
public double duration;
81+
public double distance;
82+
public double calories;
83+
public TrackPoint[] trackPoints;
84+
85+
public Activity(ActivityType type, ActivityGroup group, DateTime startTime,
86+
DateTime endTime, double duration, double distance,
87+
double calories, List<TrackPoint> trackpoints) {
88+
activity = type;
89+
this.group = group;
90+
this.startTime = HelpMethods.ConvertToIso1601(startTime);
91+
this.endTime = HelpMethods.ConvertToIso1601(endTime);
92+
this.duration = duration;
93+
this.distance = Math.Round(distance * 1000);
94+
if (calories > 0)
95+
this.calories = calories;
96+
this.trackPoints = trackpoints.ToArray();
97+
}
98+
99+
}
100+
101+
public SegmentType type;
102+
public string startTime;
103+
public string endTime;
104+
public Place place;
105+
public Activity[] activities;
106+
public string lastUpdate;
107+
108+
public Segment(SegmentType type, DateTime startTime, DateTime endTime) {
109+
this.type = type;
110+
this.startTime = HelpMethods.ConvertToIso1601(startTime);
111+
this.endTime = HelpMethods.ConvertToIso1601(endTime);
112+
lastUpdate = HelpMethods.ConvertToIso1601(DateTime.Now);
113+
}
114+
115+
}
116+
public string date;
117+
public Summary[] summary;
118+
public Segment[] segments;
119+
public string caloriesIdle;
120+
public string lastUpdate;
121+
122+
public Day(DateTime date) {
123+
this.date = date.ToString("yyyyMMdd");
124+
lastUpdate = HelpMethods.ConvertToIso1601(DateTime.Now);
125+
}
126+
}
127+
public Day[] day;
128+
}
129+
130+
131+
132+
public static class JsonParser {
133+
public static void Parse(List<XmlReader> xml) {
134+
JsonMoves json = new JsonMoves();
135+
json.day = new JsonMoves.Day[xml.Count];
136+
for (int i = 0; i < xml.Count; i++) {
137+
// Date
138+
json.day[i] = new JsonMoves.Day(xml[i].date);
139+
140+
// Summary
141+
ParseSummary(i, json, xml);
142+
143+
// Segments
144+
ParseSegments(i, json, xml);
145+
}
146+
string output = JsonConvert.SerializeObject(json,
147+
Newtonsoft.Json.Formatting.None,
148+
new JsonSerializerSettings {
149+
NullValueHandling = NullValueHandling.Ignore
150+
});
151+
output = CleanUpJson(output);
152+
WriteToFile(output);
153+
}
154+
155+
156+
static void ParseSummary(int i, JsonMoves json, List<XmlReader> xml) {
157+
List<ActivitySummary> summaries = new List<ActivitySummary>();
158+
for (int o = 0; o < 10; o++) {
159+
if (xml[i].summary[o].duration > 0)
160+
summaries.Add(xml[i].summary[o]);
161+
}
162+
List<JsonMoves.Day.Summary> convertedSummaries = new List<JsonMoves.Day.Summary>();
163+
foreach (var item in summaries) {
164+
convertedSummaries.Add(item.ToMoves());
165+
}
166+
json.day[i].summary = convertedSummaries.ToArray();
167+
}
168+
169+
// Summary parsing
170+
static void ParseSegments(int i, JsonMoves json, List<XmlReader> xml) {
171+
List<JsonMoves.Day.Segment> segments = new List<JsonMoves.Day.Segment>();
172+
foreach (var item in xml[i].timelineItems) {
173+
if (item.type == XmlTimeline.TimelineItemType.place)
174+
segments.Add(SegmentPlace(item.place));
175+
else
176+
segments.Add(SegmentMove(item.activity));
177+
}
178+
json.day[i].segments = segments.ToArray();
179+
}
180+
static JsonMoves.Day.Segment SegmentPlace(XmlTimeline.Place item) {
181+
JsonMoves.Day.Segment output = new JsonMoves.Day.Segment(JsonMoves.SegmentType.place, item.startTime.Value, item.endTime.Value);
182+
output.place = new JsonMoves.Day.Segment.Place(item.name, new JsonMoves.Day.Segment.Place.Location(item.position.lat, item.position.lon));
183+
return output;
184+
}
185+
static JsonMoves.Day.Segment SegmentMove(XmlTimeline.Activity item) {
186+
JsonMoves.Day.Segment output = new JsonMoves.Day.Segment(JsonMoves.SegmentType.move, item.startTime, item.endTime);
187+
188+
// TrackPoints
189+
List<JsonMoves.Day.Segment.Activity.TrackPoint> trackpoints = new List<JsonMoves.Day.Segment.Activity.TrackPoint>();
190+
foreach (var waypoint in item.waypoints) {
191+
trackpoints.Add(new JsonMoves.Day.Segment.Activity.TrackPoint(waypoint.lat, waypoint.lon, waypoint.time.Value));
192+
}
193+
194+
// Setup
195+
List<JsonMoves.Day.Segment.Activity> activity = new List<JsonMoves.Day.Segment.Activity>();
196+
activity.Add(new JsonMoves.Day.Segment.Activity(item.activity,
197+
HelpMethods.ReturnGroup(item.activity),
198+
item.startTime,
199+
item.endTime,
200+
item.Duration,
201+
item.Distance,
202+
item.Calories,
203+
trackpoints));
204+
output.activities = activity.ToArray();
205+
return output;
206+
}
207+
208+
// Clean up to match moves json output
209+
static string CleanUpJson(string json) {
210+
json = json.Substring(7);
211+
json = json.Remove(json.Length - 1);
212+
return json;
213+
}
214+
215+
static void WriteToFile(string json) {
216+
StreamWriter sw = new StreamWriter("file.json");
217+
sw.Write(json);
218+
sw.Close();
219+
Console.ForegroundColor = ConsoleColor.DarkGreen;
220+
Console.Write("Json file created!");
221+
}
222+
}
223+
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
using System;
22

3-
namespace Arcappexportconverter {
4-
class MainClass {
5-
public static void Main(string[] args) {
6-
Console.WriteLine("Hello World!");
7-
}
3+
class MainClass {
4+
5+
public static float weight = 83;
6+
7+
[STAThread]
8+
public static void Main() {
9+
Console.Write("Input your weight (in kg): ");
10+
weight = Convert.ToInt32(Console.ReadLine());
11+
XmlReader xr = new XmlReader();
12+
xr.LoadFile();
13+
xr.ParseToJson();
814
}
915
}

0 commit comments

Comments
 (0)