public async Task <bool> HandleObservationRecord(string message) { _Round = await _LoadSaveRepo.LoadSingleRoundAsync(message); _Station = await _LoadSaveRepo.LoadStationAsync(_Round.StationId); ProcessNewObs(_Round, _Station); if (_Station.ReferenceRound != _Round._id) { _RefRound = await _LoadSaveRepo.LoadSingleRoundAsync(_Station.ReferenceRound); string[] keys = new string[_Station.TerrestrialRounds.Count]; _Station.TerrestrialRounds.Keys.CopyTo(keys, 0); _PreviRound = await _LoadSaveRepo.LoadSingleRoundAsync(keys[Array.IndexOf(keys, _Round._id) - 1]); ProcessNewObsTime(_Round, _PreviRound, _RefRound); if (IsInteger(message)) { ProcessStationTargets(_Round, _Station); await _LoadSaveRepo.UpdateTargetsAsync(_Station._id, _Station.Targets); } } await _LoadSaveRepo.SaveIntegrityData(_Round.IntegrityData, _Round._id); await _LoadSaveRepo.UpdateTerrestrialRound(_Station._id, _Station.TerrestrialRounds[_Round._id]); return(true); }
private bool ProcessStationTargets(TerrestrialRound round, Station station) { Console.WriteLine("Start Station Taget processing: " + round._id); Console.WriteLine("Integ data: true, roundid: " + round._id); foreach (var target in round.Observations) { if (!station.TerrestrialRounds[round._id].FlaggedObs.Contains(target.Key)) { if (!station.Targets.ContainsKey(target.Key)) { Console.WriteLine("Adding new Target: " + target.Key); station.Targets.Add(target.Key, _Features.GetNewTargetParams(round, target.Key)); } else { if (station.Targets[target.Key].RoundProcessed != round._id) { Console.WriteLine("Updating Target: " + target.Key); station.Targets[target.Key] = _Features.UpdateTargetParams(station.Targets[target.Key], round, target.Key); } } } } _Station.Targets = station.Targets; return(true); }
private async Task <bool> FixMean(TerrestrialRound round) { foreach (var obs in round.Observations) { if (obs.Value.MeanF1F2 == null) { if (obs.Value.Face1 != null) { if (obs.Value.Face1.EdmDistance != null) { TerrestrialObservation mean = obs.Value.Face1; mean.ObservationType = "MeanF1"; await _LoadSaveRepo.SaveMeanAsync(mean, obs.Key); } } if (obs.Value.Face2 != null) { if (obs.Value.Face2.EdmDistance != null) { TerrestrialObservation mean = obs.Value.Face2; mean.ObservationType = "MeanF2"; await _LoadSaveRepo.SaveMeanAsync(mean, obs.Key); } } } } return(true); }
public ObservationIntegrityTime GetObservationIntegrityTime(TerrestrialRound currentRound, TerrestrialRound referenceRound, TerrestrialRound comparativelyRounds, TargetParams targetParams, string targetId) { if (currentRound.IntegrityData.ObservationIntegrity[targetId].Flag == true) { return(null); } ObservationIntegrityTime obstime = new ObservationIntegrityTime() { PointId = targetId, Face = "MeanF1F2", }; if (referenceRound.Results.LocalCoordinates.ContainsKey(targetId)) { obstime.DistToRef = Get2dDist(currentRound.Results.LocalCoordinates[targetId], referenceRound.Results.LocalCoordinates[targetId]); } else { var task = _LoadSaveRepo.SaveLocalCoords(currentRound.Results.LocalCoordinates[targetId], referenceRound._id); var result = task.Result; referenceRound.Results.LocalCoordinates.Add(targetId, currentRound.Results.LocalCoordinates[targetId]); obstime.DistToRef = Get2dDist(currentRound.Results.LocalCoordinates[targetId], referenceRound.Results.LocalCoordinates[targetId]); } if (comparativelyRounds.Results.LocalCoordinates.ContainsKey(targetId)) { obstime.DistToLast = Get2dDist(currentRound.Results.LocalCoordinates[targetId], comparativelyRounds.Results.LocalCoordinates[targetId]); } if (targetParams != null) { obstime.DistToAllTimeMean = Get2dDist(currentRound.Results.LocalCoordinates[targetParams.ID], targetParams.AllTimeMean.Position); int obstemp = Convert.ToInt32(currentRound.Observations[targetParams.ID].MeanF1F2.Temperature); if (targetParams.TempMean.ContainsKey(obstemp.ToString())) { obstime.DistToTempMean = Get2dDist(currentRound.Results.LocalCoordinates[targetParams.ID], targetParams.TempMean[obstemp.ToString()].Position); } else { string point = "0"; int minDeltaTemp = 1000; int deltaTemp = 0; foreach (var temp in targetParams.TempMean) { deltaTemp = Math.Abs(temp.Value.Temperature - obstemp); if (minDeltaTemp > deltaTemp) { minDeltaTemp = deltaTemp; point = temp.Key; } } obstime.DistToTempMean = Get2dDist(currentRound.Results.LocalCoordinates[targetParams.ID], targetParams.TempMean[point].Position); } } return(obstime); }
public async Task <string> UpdateRoundEnd(TerrestrialRound round) { var filter = Builders <Station> .Filter.Eq(s => s._id, round.StationId); var update = Builders <Station> .Update.Set(u => u.TerrestrialRounds[round._id].RoundEndUtc, round.RoundEndUtc); await _MongoCollectionStations.UpdateOneAsync(filter, update); return(round._id); }
public async Task <bool> ProcessRoundEnd(string roundId) { TerrestrialRound round = await _LoadSaveRepo.LoadSingleRoundAsync(roundId); await FixMean(round); await _LoadSaveRepo.UpdateRoundEnd(round); Console.WriteLine("Set stationRoundEnd: " + round.RoundEndUtc); _MessageSender.NewObservation(roundId); return(true); }
public async Task <bool> ProcessStationRecord(string stationId, string roundId) { var station = await _LoadSaveRepo.LoadStationAsync(stationId); if (station == null) { var rounds = await _LoadSaveRepo.LoadRoundsByStationIdAsync(stationId); Station nstation = new Station() { _id = stationId, PointId = rounds[0].Station.PointId, Position = rounds[0].Station.Position, ReferenceRound = roundId, TerrestrialRounds = new Dictionary <string, RoundParams>(), Targets = new Dictionary <string, TargetParams>() }; foreach (var round in rounds) { RoundParams roundParams = new RoundParams() { ID = round._id, RoundStartUtc = round.RoundStartUtc, RoundEndUtc = round.RoundEndUtc, FlaggedObs = new List <string>() }; nstation.TerrestrialRounds.Add(round._id, roundParams); } await _LoadSaveRepo.SaveNewStationAsync(nstation); } else { if (!station.TerrestrialRounds.ContainsKey(roundId)) { TerrestrialRound round = await _LoadSaveRepo.LoadSingleRoundAsync(roundId); RoundParams roundParams = new RoundParams() { ID = roundId, RoundStartUtc = round.RoundStartUtc, RoundEndUtc = round.RoundEndUtc, FlaggedObs = new List <string>() }; station.TerrestrialRounds.Add(roundId, roundParams); await _LoadSaveRepo.UpdateStationRoundListAsync(station._id, station.TerrestrialRounds); } } return(true); }
public async Task <string> SaveStationRecordAsync(TerrestrialRoundMessage message) { var filter = Builders <TerrestrialRound> .Filter.Eq(s => s._id, message.RoundId); if (!(await _MongoCollectionRounds.CountDocumentsAsync(filter) > 0)) { TerrestrialRound document = new TerrestrialRound { }; document = MapRound(message); await _MongoCollectionRounds.InsertOneAsync(document); return(message.RoundId); } return(null); }
private bool ProcessNewObs(TerrestrialRound round, Station station) { Console.WriteLine("Process single round: " + round._id); foreach (var point in round.Observations) { if (round.Observations[point.Key].Face1 != null && round.Observations[point.Key].Face2 != null) { Console.WriteLine("Process new Obs: " + point.Key); if (round.IntegrityData == null) { round.IntegrityData = new IntegrityData() { ObservationIntegrity = new Dictionary <string, ObservationIntegrity>() }; round.IntegrityData.ObservationIntegrity.Add(point.Key, _Features.GetObservationIntegrity(round.Observations[point.Key].Face1, round.Observations[point.Key].Face2)); if (round.IntegrityData.ObservationIntegrity[point.Key].Flag == true) { station.TerrestrialRounds[round._id].FlaggedObs.Add(point.Key); } } else { if (!round.IntegrityData.ObservationIntegrity.ContainsKey(point.Key)) { round.IntegrityData.ObservationIntegrity.Add(point.Key, _Features.GetObservationIntegrity(round.Observations[point.Key].Face1, round.Observations[point.Key].Face2)); if (round.IntegrityData.ObservationIntegrity[point.Key].Flag == true) { station.TerrestrialRounds[round._id].FlaggedObs.Add(point.Key); } } } } else { station.TerrestrialRounds[round._id].FlaggedObs.Add(point.Key); } } if (station.TerrestrialRounds[round._id].FlaggedObs.Count != 0) { station.TerrestrialRounds[round._id].Flagged = true; } _Round.IntegrityData = round.IntegrityData; _Station.TerrestrialRounds = station.TerrestrialRounds; Console.WriteLine("saved round"); return(true); }
private TerrestrialRound MapRound(TerrestrialRoundMessage message) { TerrestrialRound round = new TerrestrialRound { _id = message.RoundId, DeviceId = message.DeviceId, StationId = message.StationId, RoundStartUtc = message.RoundStartUtc, RoundEndUtc = message.RoundEndUtc, Station = message.Station }; round.Results = new Results() { LocalCoordinates = new Dictionary <string, LocalPoint>(), ProjectCoordinates = new Dictionary <string, ProjectCoordinates>(), }; return(round); }
// When looking at the code keep in mind that a lot of the code is there to handle incomplete data public async Task <bool> ProcessNewObs(string roundId) { TerrestrialRound round = await _LoadSaveRepo.LoadSingleRoundAsync(roundId); foreach (var point in round.Observations) { if (round.Observations[point.Key].Face1 != null && round.Observations[point.Key].Face2 != null && round.Observations[point.Key].MeanF1F2 == null) { if (round.Observations[point.Key].Face1.EdmDistance != null && round.Observations[point.Key].Face2.EdmDistance != null) { TerrestrialObservation mean = _GeodeticCalc.MeanObservations(round.Observations[point.Key].Face1, round.Observations[point.Key].Face2); mean.EdmDistance = _ObservationCorrectionService.GetCorrectedDistance(round.Station, mean); await _LoadSaveRepo.SaveMeanAsync(mean, roundId); await _LoadSaveRepo.SaveLocalCoords(_GeodeticCalc.GetLocalPoint(mean), roundId); } } } return(true); }
public TargetParams GetNewTargetParams(TerrestrialRound terrestrialRound, string targetId) { TargetParams targetParams = new TargetParams() { ID = targetId, RoundProcessed = terrestrialRound._id, AllTimeMean = new AllTimeMean() { count = 1, Position = terrestrialRound.Results.LocalCoordinates[targetId], }, TempMean = new Dictionary <string, TempMean>(), }; int temp = Convert.ToInt32(terrestrialRound.Observations[targetId].MeanF1F2.Temperature); targetParams.TempMean.Add(temp.ToString(), new TempMean() { Temperature = temp, count = 1, Position = terrestrialRound.Results.LocalCoordinates[targetId] }); return(targetParams); }
public TargetParams UpdateTargetParams(TargetParams targetParams, TerrestrialRound terrestrialRound, string targetId) { targetParams.RoundProcessed = terrestrialRound._id; targetParams.AllTimeMean.Position = MeanWeightedLocalPoint(targetParams.AllTimeMean.Position, terrestrialRound.Results.LocalCoordinates[targetId], targetParams.AllTimeMean.count); targetParams.AllTimeMean.count++; string temp = (Convert.ToInt32(terrestrialRound.Observations[targetId].MeanF1F2.Temperature)).ToString(); if (targetParams.TempMean.ContainsKey(temp)) { targetParams.TempMean[temp].Position = MeanWeightedLocalPoint(targetParams.TempMean[temp].Position, terrestrialRound.Results.LocalCoordinates[targetId], targetParams.TempMean[temp].count); targetParams.TempMean[temp].count++; } else { targetParams.TempMean.Add(temp, new TempMean() { Temperature = Convert.ToInt32(temp), count = 1, Position = terrestrialRound.Results.LocalCoordinates[targetId] }); } return(targetParams); }
private bool ProcessNewObsTime(TerrestrialRound lastRound, TerrestrialRound previRound, TerrestrialRound refRound) { Console.WriteLine("Process 2 rounds: " + lastRound._id + "and: " + previRound._id); foreach (var obs in lastRound.Observations) { if (!_Station.TerrestrialRounds[lastRound._id].FlaggedObs.Contains(obs.Key) && !_Station.TerrestrialRounds[previRound._id].FlaggedObs.Contains(obs.Key))//lastRound.Observations[obs.Key].MeanF1F2 != null) { Console.WriteLine("Process new Obs: " + obs.Key); if (lastRound.IntegrityData.ObservationIntegrityTime == null) { lastRound.IntegrityData.ObservationIntegrityTime = new Dictionary <string, ObservationIntegrityTime>(); } if (!lastRound.IntegrityData.ObservationIntegrityTime.ContainsKey(obs.Key)) { TargetParams targetParams = new TargetParams(); targetParams = _Station.Targets.ContainsKey(obs.Key) ? _Station.Targets[obs.Key] : null; lastRound.IntegrityData.ObservationIntegrityTime.Add(obs.Key, _Features.GetObservationIntegrityTime(lastRound, refRound, previRound, targetParams, obs.Key)); } } } _Round.IntegrityData = lastRound.IntegrityData; Console.WriteLine("saved round"); return(true); }
public async Task <string> SaveObservationAsync(TerrestrialRoundMessage message) { var filter = Builders <TerrestrialRound> .Filter.Eq(s => s._id, message.RoundId); TerrestrialRound round = await _MongoCollectionRounds.Find(filter).SingleAsync(); foreach (var obj in message.Observations) { if (round.Observations == null) { Dictionary <string, Target> dict = new Dictionary <string, Target>(); Target target = new Target { }; dict.Add(obj.PointId, target); switch (obj.ObservationType) { case "Face1": if (obj.EdmDistance != 0) { dict[obj.PointId].Face1 = obj; } else { dict[obj.PointId].Face1 = null; } break; case "Face2": if (obj.EdmDistance != 0) { dict[obj.PointId].Face2 = obj; } else { dict[obj.PointId].Face2 = null; } break; default: Console.WriteLine("unknown ObservationType: " + obj.ObservationType); break; } round.Observations = dict; } else { if (round.Observations.ContainsKey(obj.PointId)) { switch (obj.ObservationType) { case "Face1": round.Observations[obj.PointId].Face1 = obj; break; case "Face2": round.Observations[obj.PointId].Face2 = obj; break; default: Console.WriteLine("unknown ObservationType: " + obj.ObservationType); break; } round.Observations[obj.PointId].MeanF1F2 = null; } else { Target target = new Target { }; round.Observations.Add(obj.PointId, target); switch (obj.ObservationType) { case "Face1": round.Observations[obj.PointId].Face1 = obj; break; case "Face2": round.Observations[obj.PointId].Face2 = obj; break; default: Console.WriteLine("unknown ObservationType: " + obj.ObservationType); break; } } } } var update = Builders <TerrestrialRound> .Update.Set(s => s.Observations, round.Observations); await _MongoCollectionRounds.UpdateOneAsync(filter, update); return(message.RoundId); }