Skip to content

Commit bfb9399

Browse files
committed
Remove GeoCoordinate package and related code
1 parent 469dd66 commit bfb9399

9 files changed

Lines changed: 2 additions & 227 deletions

File tree

src/Tracked/Models/Model.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@ public async Task SaveRide(Ride ride) {
5454
await storage.SaveObject(ride.Id.Value, ride);
5555
}
5656

57-
public async Task CompareSegments(Ride ride) {
58-
foreach (var segment in Segments) {
59-
SegmentAttempt result = ride.MatchesSegment(segment);
60-
61-
if (result != null) {
62-
await SaveSegmentAttempt(result);
63-
}
64-
}
65-
}
66-
6757
public async Task RemoveRide(Ride ride) {
6858
var attempts = SegmentAttempts
6959
.Where(i => i.RideId == ride.Id)
@@ -86,16 +76,6 @@ public async Task SaveSegment(Segment segment) {
8676
await storage.SaveObject(segment.Id.Value, segment);
8777
}
8878

89-
public async Task AnalyseExistingRides(Segment segment) {
90-
foreach (var ride in Rides.OrderBy(i => i.Start)) {
91-
SegmentAttempt result = ride.MatchesSegment(segment);
92-
93-
if (result != null) {
94-
await SaveSegmentAttempt(result);
95-
}
96-
}
97-
}
98-
9979
public async Task RemoveSegment(Segment segment) {
10080
var attempts = SegmentAttempts
10181
.Where(i => i.SegmentId == segment.Id)

src/Tracked/Models/Ride.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using Newtonsoft.Json;
55
using Shared;
6-
using Tracked.Utilities;
76

87
namespace Tracked.Models {
98
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
@@ -49,59 +48,5 @@ public Ride() {
4948
Jumps = new List<Jump>();
5049
AccelerometerReadings = new List<AccelerometerReading>();
5150
}
52-
53-
public SegmentAttempt MatchesSegment(Segment segment) {
54-
List<LatLng> locationLatLngs = MovingLocations
55-
.Select(i => i.Point)
56-
.ToList();
57-
58-
var result = PolyUtils.LocationsMatch(segment, locationLatLngs);
59-
60-
if (!result.MatchesSegment) {
61-
return null;
62-
}
63-
64-
SegmentAttempt attempt = new SegmentAttempt {
65-
RideId = Id,
66-
SegmentId = segment.Id,
67-
Start = MovingLocations[result.StartIdx].Timestamp,
68-
End = MovingLocations[result.EndIdx].Timestamp,
69-
};
70-
71-
attempt.Medal = GetMedal(attempt.Time, segment.Id.Value);
72-
73-
return attempt;
74-
}
75-
76-
private Medal GetMedal(TimeSpan time, Guid segmentId) {
77-
var existingAttempts = Model.Instance.SegmentAttempts
78-
.Where(i => i.Ride.Start < Start)
79-
.Where(i => i.SegmentId == segmentId)
80-
.OrderBy(i => i.Time)
81-
.Select(i => i.Time)
82-
.ToList();
83-
84-
if (!existingAttempts.Any()) {
85-
return Medal.None;
86-
}
87-
88-
if (existingAttempts.Count == 1) {
89-
return time < existingAttempts[0] ? Medal.Gold : Medal.Silver;
90-
}
91-
92-
if (existingAttempts.Count == 2) {
93-
return time < existingAttempts[0] ? Medal.Gold : time < existingAttempts[1] ? Medal.Silver : Medal.Bronze;
94-
}
95-
96-
if (time < existingAttempts.FirstOrDefault()) {
97-
return Medal.Gold;
98-
} else if (time < existingAttempts.Skip(1).FirstOrDefault()) {
99-
return Medal.Silver;
100-
} else if (time < existingAttempts.Skip(2).FirstOrDefault()) {
101-
return Medal.Bronze;
102-
}
103-
104-
return Medal.None;
105-
}
10651
}
10752
}

src/Tracked/Models/Segment.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
5-
using System.Text;
6-
using Tracked.Utilities;
74
using Newtonsoft.Json;
8-
using Xamarin.Essentials;
95

106
namespace Tracked.Models {
117
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
@@ -25,45 +21,5 @@ public class Segment {
2521
public Segment() {
2622
Points = new List<SegmentLocation>();
2723
}
28-
29-
public LatLng GetClosestStartPoint(IList<LatLng> locations) {
30-
return GetClosestPoint(locations, Start.Point);
31-
}
32-
33-
public LatLng GetClosestEndPoint(IList<LatLng> locations) {
34-
return GetClosestPoint(locations, End.Point);
35-
}
36-
37-
private LatLng GetClosestPoint(IList<LatLng> locations, LatLng point) {
38-
LatLng closestLocation = null;
39-
double lastDistance = double.MaxValue;
40-
41-
foreach (var location in locations) {
42-
double distance = location.CalculateDistance(point);
43-
44-
if (distance < lastDistance) {
45-
lastDistance = distance;
46-
closestLocation = location;
47-
}
48-
}
49-
50-
return closestLocation;
51-
}
52-
53-
public ShareFile GetLocationFile() {
54-
StringBuilder sb = new StringBuilder();
55-
56-
foreach (var point in Points) {
57-
sb.AppendLine($"S,{point.Point.Latitude},{point.Point.Longitude},E");
58-
}
59-
60-
sb.AppendLine();
61-
62-
string fileName = "Segment Data.txt";
63-
string filePath = Path.Combine(FileSystem.CacheDirectory, fileName);
64-
File.WriteAllText(filePath, sb.ToString());
65-
66-
return new ShareFile(filePath);
67-
}
6824
}
6925
}

src/Tracked/Models/SegmentAttempt.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Tracked.Utilities;
54
using Newtonsoft.Json;
65
using Shared;
76

@@ -54,7 +53,7 @@ public class SegmentAttempt : IRide {
5453

5554
public string FormattedTime => Time.ToString(@"mm\:ss");
5655

57-
public double Distance => Locations.CalculateDistanceKm();
56+
public double Distance => 0; // Locations.CalculateDistanceKm();
5857

5958
public double AverageSpeed => Locations.Average(i => i.Mph);
6059

src/Tracked/Screens/Review/RideReviewScreenViewModel.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Tracked.Controls;
66
using Tracked.Models;
77
using Tracked.Utilities;
8-
using Xamarin.Forms;
98

109
namespace Tracked.Screens.Review {
1110
public class RideReviewScreenViewModel : ViewModelBase {
@@ -46,16 +45,7 @@ public double MaxSpeed {
4645
}
4746
}
4847

49-
public double Distance {
50-
get {
51-
if (!Ride.Locations.Any()) {
52-
return 0;
53-
}
54-
55-
return Ride.Locations.CalculateDistanceMi();
56-
}
57-
}
58-
48+
public double Distance => 0;
5949
public string Time => (Ride.End - Ride.Start).ToString(@"mm\:ss");
6050
public int JumpCount => Ride.Jumps.Count;
6151
public string MaxAirtime => Ride.Jumps.Count == 0 ? "-" : $"{Ride.Jumps.Max(i => i.Airtime)}s";

src/Tracked/Screens/Segments/CreateSegmentScreenViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public void Save(INavigation nav) {
7272

7373
await Model.Instance.SaveSegment(segment);
7474

75-
await Model.Instance.AnalyseExistingRides(segment);
76-
7775
await nav.PopAsync();
7876
});
7977
}

src/Tracked/Tracked.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="akavache" Version="6.9.10" />
16-
<PackageReference Include="GeoCoordinate" Version="1.1.0" />
1716
<PackageReference Include="Google.Apis.Oauth2.v2" Version="1.43.0.1602" />
1817
<PackageReference Include="OxyPlot.Xamarin.Forms" Version="1.0.0" />
1918
<PackageReference Include="Plugin.Permissions" Version="3.0.0.12" />

src/Tracked/Utilities/PolyUtils.cs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using GeoCoordinatePortable;
54
using Tracked.Models;
65

76
namespace Tracked.Utilities {
87
public static class PolyUtils {
9-
public static bool HasPointOnLine(this IList<LatLng> path, LatLng point, int toleranceInMetres = 25) {
10-
return path.Any(i => i.CalculateDistance(point) * 1000 <= toleranceInMetres);
11-
}
12-
13-
public static double CalculateDistanceKm(this IList<LatLng> path) {
14-
double totalKm = 0;
15-
16-
for (int i = 0; i < path.Count - 1; i++) {
17-
var pin1 = GetGeoModel(path[i]);
18-
var pin2 = GetGeoModel(path[i + 1]);
19-
20-
var km = pin2.GetDistanceTo(pin1) / 1000;
21-
totalKm += km;
22-
}
23-
24-
return totalKm;
25-
}
26-
27-
public static double CalculateDistanceKm(this IList<Location> path) {
28-
return path.Select(i => i.Point)
29-
.ToList()
30-
.CalculateDistanceKm();
31-
}
32-
33-
public static double CalculateDistanceMi(this IList<LatLng> path) {
34-
return path.CalculateDistanceKm() * 0.621371192;
35-
}
36-
37-
public static double CalculateDistanceMi(this IList<Location> path) {
38-
return path.CalculateDistanceKm() * 0.621371192;
39-
}
40-
41-
private static GeoCoordinate GetGeoModel(LatLng model) {
42-
return new GeoCoordinate(model.Latitude, model.Longitude);
43-
}
44-
45-
public static double CalculateDistance(this LatLng latLong1, LatLng latLong2) {
46-
return new List<LatLng>() {
47-
latLong1,
48-
latLong2,
49-
}.CalculateDistanceKm();
50-
}
51-
52-
public static LocationMatchResult LocationsMatch(Segment segment, IList<LatLng> rideLocations) {
53-
bool matchesStart = rideLocations
54-
.HasPointOnLine(segment.Start.Point);
55-
56-
bool matchesEnd = rideLocations
57-
.HasPointOnLine(segment.End.Point);
58-
59-
if (!matchesStart || !matchesEnd) {
60-
return new LocationMatchResult {
61-
MatchesSegment = false,
62-
};
63-
};
64-
65-
var closestPointToSegmentStart = segment.GetClosestStartPoint(rideLocations);
66-
var closestPointToSegmentEnd = segment.GetClosestEndPoint(rideLocations);
67-
68-
if (closestPointToSegmentStart == null || closestPointToSegmentEnd == null) {
69-
return new LocationMatchResult {
70-
MatchesSegment = false,
71-
};
72-
}
73-
74-
int startIdx = rideLocations.IndexOf(closestPointToSegmentStart);
75-
int endIdx = rideLocations.IndexOf(closestPointToSegmentEnd);
76-
77-
var filteredRideLocations = rideLocations.ToList().GetRange(startIdx, (endIdx - startIdx) + 1);
78-
79-
int matchedPointCount = 0;
80-
int missedPointCount = 0;
81-
82-
foreach (var segmentLocation in segment.Points) {
83-
if (filteredRideLocations.HasPointOnLine(segmentLocation.Point)) {
84-
matchedPointCount++;
85-
} else {
86-
missedPointCount++;
87-
}
88-
}
89-
90-
// return true if 90% of the segment points match the ride
91-
return new LocationMatchResult {
92-
MatchesSegment = matchedPointCount >= segment.Points.Count * 0.9,
93-
StartIdx = startIdx,
94-
EndIdx = endIdx,
95-
};
96-
}
97-
988
public static IList<MapLocation> GetMapLocations(IRide ride) {
999
var locations = ride.Locations
10010
.OrderBy(i => i.Timestamp)

src/Tracked/Utilities/RideRecorder.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public async Task StopRide() {
4848
}
4949

5050
await Model.Instance.SaveRide(Ride);
51-
52-
await Model.Instance.CompareSegments(Ride);
5351
}
5452

5553
private void AccelerometerUtility_AccelerometerChanged(AccelerometerChangedEventArgs e) {

0 commit comments

Comments
 (0)