Skip to content

Commit 552028f

Browse files
authored
Merge pull request #1 from oldrev/dev
time related from long to DateTimeOffset
2 parents 5fa3de2 + f9da091 commit 552028f

File tree

9 files changed

+32
-29
lines changed

9 files changed

+32
-29
lines changed

examples/Sandwych.MapMatchingKit.Examples.HelloWorldApp/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void Main(string[] args)
6060
if (cand.HasTransition)
6161
{
6262
var geom = cand.Transition.Route.ToGeometry(); // path geometry from last matching candidate
63-
Console.WriteLine("RoadID={0}\t\tFraction={1}", roadId, cand.Point.Fraction);
63+
Console.WriteLine("Lng={0}\tLat={1}\tRoadID={2}", coord.X, coord.Y, roadId, cand.Point.Fraction);
6464
}
6565
}
6666

@@ -82,7 +82,7 @@ private static IEnumerable<MatcherSample> ReadSamples()
8282
var timeStr = i.Properties["field_8"].ToString().Substring(0, timeFormat.Length);
8383
var time = DateTimeOffset.ParseExact(timeStr, timeFormat, CultureInfo.InvariantCulture);
8484
var longTime = time.ToUnixTimeMilliseconds();
85-
yield return new MatcherSample(longTime, longTime, coord2D);
85+
yield return new MatcherSample(longTime, time, coord2D);
8686
}
8787
}
8888

src/Sandwych.MapMatchingKit/Markov/ISample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace Sandwych.MapMatchingKit.Markov
66
{
77
public interface ISample
88
{
9-
long Time { get; }
9+
DateTimeOffset Time { get; }
1010
}
1111
}

src/Sandwych.MapMatchingKit/Markov/IStateMemory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface IStateMemory<TCandidate, TTransition, TSample>
4141
/// <summary>
4242
/// Time of the last state update in milliseconds epoch time.
4343
/// </summary>
44-
long Time { get; }
44+
DateTimeOffset Time { get; }
4545

4646

4747
/// <summary>

src/Sandwych.MapMatchingKit/Markov/KState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public TSample Sample
7171
}
7272
}
7373

74-
public long Time
74+
public DateTimeOffset Time
7575
{
7676
get
7777
{
7878
if (_sequence.Count == 0)
7979
{
80-
return -1;
80+
return DateTimeOffset.MaxValue;
8181
}
8282
else
8383
{
@@ -154,7 +154,7 @@ public void Update(ICollection<TCandidate> vector, in TSample sample)
154154

155155
_sequence.AddToBack((vector, sample, kestimate));
156156

157-
while ((_t > 0 && sample.Time - _sequence.PeekFirst().Item2.Time > _t)
157+
while ((_t > 0 && (sample.Time - _sequence.PeekFirst().Item2.Time).TotalMilliseconds > _t)
158158
|| (_k >= 0 && _sequence.Count > _k + 1))
159159
{
160160
var deletes = _sequence.PeekFirst().Item1;

src/Sandwych.MapMatchingKit/Matching/Matcher.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public override IDictionary<MatcherCandidate, IDictionary<MatcherCandidate, Tran
145145

146146
var transitions = new Dictionary<MatcherCandidate, IDictionary<MatcherCandidate, TransitionProbability>>();
147147
var base_ = 1.0 * _spatial.Distance(predecessors.Item1.Coordinate, candidates.Item1.Coordinate) / 60.0;
148-
var bound = Math.Max(1000.0, Math.Min(this.MaxDistance, ((candidates.Item1.Time - predecessors.Item1.Time) / 1000.0) * 100.0));
148+
var bound = Math.Max(1000.0, Math.Min(this.MaxDistance, (candidates.Item1.Time - predecessors.Item1.Time).TotalSeconds * 100.0));
149149

150150
foreach (var predecessor in predecessors.Item2)
151151
{
@@ -165,8 +165,7 @@ public override IDictionary<MatcherCandidate, IDictionary<MatcherCandidate, Tran
165165
// route.length() - dt)) to avoid unnecessary routes in case of u-turns.
166166

167167
var beta = this.Lambda == 0D
168-
? (2.0 * Math.Max(1d,
169-
candidates.Item1.Time - predecessors.Item1.Time) / 1000D)
168+
? (2.0 * Math.Max(1d, (candidates.Item1.Time - predecessors.Item1.Time).TotalMilliseconds) / 1000D)
170169
: 1D / this.Lambda;
171170

172171
var transition = (1D / beta) * Math.Exp(

src/Sandwych.MapMatchingKit/Matching/MatcherSample.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ namespace Sandwych.MapMatchingKit.Matching
1515
public sealed class MatcherSample : ISample
1616
{
1717
public long Id { get; }
18-
public long Time { get; }
18+
public DateTimeOffset Time { get; }
1919
public float Azimuth { get; }
2020
public Coordinate2D Coordinate { get; }
2121
public bool IsNaN => this.Id < 0;
2222

2323
public MatcherSample(long id, long time, double lng, double lat, float azimuth = float.NaN)
2424
{
2525
this.Id = id;
26-
this.Time = time;
26+
this.Time = DateTimeOffset.MinValue.AddMilliseconds(time);
2727
this.Coordinate = new Coordinate2D(lng, lat);
2828
this.Azimuth = NormAzimuth(azimuth);
2929
}
3030

31-
public MatcherSample(long id, long time, Coordinate2D point, float azimuth = float.NaN)
31+
public MatcherSample(long id, long time, in Coordinate2D point, float azimuth = float.NaN)
3232
{
3333
this.Id = id;
34-
this.Time = time;
34+
this.Time = DateTimeOffset.MinValue.AddMilliseconds(time);
3535
this.Coordinate = point;
3636
this.Azimuth = NormAzimuth(azimuth);
3737
}
3838

39-
public MatcherSample(long id, DateTime time, Coordinate2D point, float azimuth = float.NaN)
39+
public MatcherSample(long id, DateTimeOffset time, in Coordinate2D point, float azimuth = float.NaN)
4040
{
4141
this.Id = id;
42-
this.Time = time.ToFileTime();
42+
this.Time = time;
4343
this.Coordinate = point;
4444
this.Azimuth = NormAzimuth(azimuth);
4545
}
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
using System;
22
using System.Linq;
3-
using Sandwych.MapMatchingKit.Topology;
4-
using System.Collections.Generic;
53
using System.Text;
4+
using System.Collections.Generic;
5+
using Sandwych.MapMatchingKit.Topology;
66
using Sandwych.MapMatchingKit.Spatial;
7-
using NetTopologySuite.Geometries;
8-
using GeoAPI.Geometries;
97
using Sandwych.MapMatchingKit.Spatial.Geometries;
108
using Sandwych.MapMatchingKit.Spatial.Index;
119

1210
namespace Sandwych.MapMatchingKit.Roads
1311
{
14-
public class RoadMap : AbstractGraph<Road>
12+
/// Implementation of a road map with (directed) roads, i.e. {@link Road} objects. It provides a road
13+
/// network for routing that is derived from {@link Graph} and spatial search of roads with a
14+
/// {@link SpatialIndex}.
15+
/// <para>
16+
/// <b>Note:</b> Since {@link Road} objects are directed representations of {@link BaseRoad} objects,
17+
/// identifiers have a special mapping, see {@link Road}.
18+
/// </para>
19+
public sealed class RoadMap : AbstractGraph<Road>
1520
{
1621
public ISpatialIndex<RoadInfo> Index { get; }
1722
private readonly ISpatialOperation _spatial;
@@ -26,26 +31,25 @@ public RoadMap(IEnumerable<Road> roads) : this(roads, GeographySpatialOperation.
2631
{
2732
}
2833

29-
private IEnumerable<RoadPoint> Split(IEnumerable<(RoadInfo road, double distance)> points)
34+
private IEnumerable<RoadPoint> Split(IEnumerable<(RoadInfo road, double fraction)> points)
3035
{
3136
/*
3237
* This uses the road
3338
*/
3439
foreach (var point in points)
3540
{
36-
yield return new RoadPoint(this.Edges[point.road.Id * 2], point.Item2, _spatial);
41+
yield return new RoadPoint(this.Edges[point.road.Id * 2], point.fraction, _spatial);
3742

3843
var backwardRoadId = point.road.Id * 2 + 1;
3944
if (this.Edges.TryGetValue(backwardRoadId, out var road))
4045
{
41-
yield return new RoadPoint(road, 1.0 - point.Item2, _spatial);
46+
yield return new RoadPoint(road, 1.0 - point.fraction, _spatial);
4247
}
4348
}
4449
}
4550

46-
public IEnumerable<RoadPoint> Radius(Coordinate2D c, double r) =>
51+
public IEnumerable<RoadPoint> Radius(in Coordinate2D c, double r) =>
4752
this.Split(this.Index.Radius(c, r));
4853

49-
5054
}
5155
}

test/Sandwych.MapMatchingKit.Tests/Markov/MockSample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace Sandwych.MapMatchingKit.Tests.Markov
77
{
88
public sealed class MockSample : ISample
99
{
10-
public long Time { get; }
10+
public DateTimeOffset Time { get; }
1111

1212
public MockSample(long time)
1313
{
14-
this.Time = time;
14+
this.Time = DateTimeOffset.MinValue.AddMilliseconds(time);
1515
}
1616
}
1717
}

test/Sandwych.MapMatchingKit.Tests/Matching/MatcherTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void AssertTransition(in TransitionProbability<MatcherTransition> transi
8383
Assert.Equal(route.StartPoint.Edge.Id, transition.Transition.Route.StartPoint.Edge.Id);
8484
Assert.Equal(route.EndPoint.Edge.Id, transition.Transition.Route.EndPoint.Edge.Id);
8585

86-
double beta = lambda == 0 ? (2.0 * (target.Item2.Time - source.Item2.Time) / 1000)
86+
double beta = lambda == 0 ? (2.0 * (target.Item2.Time - source.Item2.Time).TotalSeconds)
8787
: 1 / lambda;
8888
double @base = 1.0 * _spatial.Distance(source.Item2.Coordinate, target.Item2.Coordinate) / 60;
8989
double p = (1 / beta)

0 commit comments

Comments
 (0)