-
Notifications
You must be signed in to change notification settings - Fork 0
/
Route.cs
65 lines (56 loc) · 1.75 KB
/
Route.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using F23.StringSimilarity;
using Newtonsoft.Json;
namespace ZwiftBot
{
public class Route
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
public string Name { get; set; }
public int Distance { get; set; }
public int Gain { get; set; }
public string World { get; set; }
public int DistanceFromStart { get; set; }
public int MinLevel { get; set; }
public bool EventOnly { get; set; }
public bool HasAward { get; set; }
public Sports AllowedSports { get; set; }
public DateTime? Completed { get; set; }
public override string ToString()
{
return $"{Name} {Distance / 1000}km + {(double)DistanceFromStart / 1000:F1}km ({Gain}m)";
}
}
public class RoutesList : List<Route>
{
public Route FindRoute(string name)
{
var route = this.SingleOrDefault(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
if (route != null)
return route;
var longestCommonSubsequence = new LongestCommonSubsequence();
var distance = double.MaxValue;
Route currentRoute = null;
foreach (var tmp in this)
{
var currentDistance = longestCommonSubsequence.Distance(tmp.Name, name);
if (currentDistance < distance)
{
distance = currentDistance;
currentRoute = tmp;
}
}
return currentRoute;
}
}
[Flags]
public enum Sports
{
None = 0,
Running = 1,
Cycling = 2
}
}