public GpsTrackStatistics CalculateStatistics () { GpsTrackStatistics stat = new GpsTrackStatistics (); foreach (TrackPoint w in waypoints) { stat.Bounds.ExtendToCover (w.Location); if (w.Elevation.HasValue) { stat.MinElevation = Math.Min (stat.MinElevation, w.Elevation.Value); stat.MaxElevation = Math.Min (stat.MaxElevation, w.Elevation.Value); } if (w.Time.HasValue) { stat.StartTime = stat.StartTime <= w.Time.Value ? stat.StartTime : w.Time.Value; stat.EndTime = stat.EndTime >= w.Time.Value ? stat.EndTime : w.Time.Value; } } foreach (Track r in routes) { GpsTrackStatistics childStat = GpsUtilities.CalculateTrackStatistics (r); stat.Union (childStat); } foreach (Track t in tracks) { GpsTrackStatistics childStat = GpsUtilities.CalculateTrackStatistics (t); stat.Union (childStat); } return stat; }
private async Task <PositionRecord> CreateOrUpdatePositionRecord() { var location = GpsUtilities.GetLocation(); var memberId = _members.Random().Id; var record = await _repository.GetById <PositionRecord>(memberId); if (null == record) { record = new PositionRecord(memberId, location.Latitude, location.Longitude); _loggerFactory.LogInformation($"New Position Record [{memberId}] [{location.Longitude}/{location.Latitude}]"); } else { record.Update(new PositionRecordUpdatedEvent(record.MemberId, location.Latitude, location.Longitude)); _loggerFactory.LogInformation($"Update Position Record [{memberId}] [{location.Longitude}/{location.Latitude}]"); } return(record); }
public void Start() { _cache.GetOutputStream().Subscribe(obs => { if (obs.PositionRecords.Count > 0) { foreach (var record in obs.PositionRecords) { var memberOne = record.MemberId; var memberOnePosition = _cache.CacheState.State[memberOne]; lock (_gateKeeper) { _proximities.RemoveAll((proximity) => proximity.HasMember(memberOne)); foreach (var member in _cache.CacheState.State) { if (member.Key == record.MemberId) { continue; } var memberTwo = member.Key; var memberTwoPosition = member.Value; var proximity = GpsUtilities.DistanceBetweenPoints(memberOnePosition, memberTwoPosition); if (proximity < proximityThreshold) { _proximities.Add(new ProximityEvent(memberOne, memberTwo, proximity)); _logger.LogInformation($"Proximity - [{memberOne}] [{memberTwo}] | {proximity}"); } } } } } }); }