// Crayted measurements from coordinates private TerrestrialObservation AddMeasurements(TerrestrialPosition coords, TerrestrialObservation observation) { observation.EdmDistance = Math.Sqrt(Math.Pow(coords.Easting, 2) + Math.Pow(coords.Northing, 2) + Math.Pow(coords.Elevation, 2)); observation.HorizontalCircleReading = Math.Atan2(coords.Easting, coords.Northing); observation.VerticalAngle = Math.Atan2(Math.Sqrt(Math.Pow(coords.Easting, 2) + Math.Pow(coords.Northing, 2)), coords.Elevation); return(observation); }
// Calculates Face2 from Face1 public TerrestrialObservation FlipFace(TerrestrialObservation observation) { observation.HorizontalCircleReading = observation.HorizontalCircleReading + Math.PI; if (observation.HorizontalCircleReading > Math.PI * 2) { observation.HorizontalCircleReading = observation.HorizontalCircleReading - Math.PI * 2; } observation.VerticalAngle = Math.PI * 2 - observation.VerticalAngle; observation.ObservationType = "Face2"; observation.TimeUtc.AddSeconds(30); return(observation); }
public TerrestrialObservation GetTerrestrialObservation(string target, Config config, Random rnd, int step, bool fail) { // create a new observation TerrestrialObservation observation = new TerrestrialObservation { PointId = target, ObservationType = "Face1", // Not used ritght now ... Pressure = 930, PrismConstant = 0, TargetHeight = 0, CompensatorTiltX = 0, CompensatorTiltY = 0, }; _Fail = fail; double j = step * Increment(config.Interval); // Add calculated data to the observation observation.Temperature = Math.Round(config.Temperature + Math.Sin(j * Math.PI) * 0.8, 1); TerrestrialPosition position = GetCoords(config.Targets[target], j, rnd); TerrestrialObservation obsnew = AddMeasurements(position, observation); return(obsnew); }
public Simulator(string config) { // Loads configuration _Config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(config)); // Sets starting parameters Random rnd = new Random(); int i = 0; int tag = 0; int day = 1440 / _Config.Interval - 1; int timeTofail = Convert.ToInt32(day * _Config.Days * _Config.AddOutliers); bool fail = false; List <TerrestrialObservation> observations = new List <TerrestrialObservation>(); Dictionary <string, List <string> > failList = new Dictionary <string, List <string> >(); // Documantation for outliers foreach (var target in _Config.Targets) { failList.Add(target.Key, new List <string>()); } Console.WriteLine("Ready to generate " + (day * _Config.Days).ToString() + " Observations"); Console.ReadLine(); while (i < day * _Config.Days) { i++; // new message TerrestrialRoundMessage message = new TerrestrialRoundMessage { DeviceId = _Config.DeviceId, RoundStartUtc = _Config.StartTime.AddMinutes(i * _Config.Interval), Station = _Config.Station }; message.RoundId = CalcRoundId(_Config.DeviceId, message.RoundStartUtc, _Config.Station); // Send station record _MessageSender.SendStationRecord(message); // Crating observation message foreach (var target in _Config.Targets) { // deciding if the new observation is an outlier if (i > timeTofail) { if (failList[target.Key].Count == 0) { if (rnd.NextDouble() > 0.9) { fail = true; failList[target.Key].Add(i.ToString()); } } else if (i - Convert.ToInt16(failList[target.Key][failList[target.Key].Count - 1]) > 4) // this prevents that there are 2 outliers too close to another { if (rnd.NextDouble() > 0.9) { fail = true; failList[target.Key].Add(i.ToString()); } } } //generating the observation var obs = _DataGenerator.GetTerrestrialObservation(target.Key, _Config, rnd, i, fail); // save observations to the list obs.TimeUtc = message.RoundStartUtc.AddMinutes(tag); observations.Add(obs); TerrestrialObservation face2 = clone(obs); observations.Add(_DataGenerator.FlipFace(face2)); // resetting parameters for next loop fail = false; tag++; } // adding observations to message and sending the message message.Observations = observations.ToArray(); _MessageSender.SendObservationRecord(message); message.Observations = null; message.RoundEndUtc = message.RoundStartUtc.AddMinutes(tag + 1); _MessageSender.SendRoundEnd(message); //Resetting values for next loop tag = 0; observations.Clear(); } foreach (var target in failList) { File.WriteAllLines(_Config.FailSavePath + _Config.DeviceId + target.Key + ".csv", (target.Value.ToArray())); } Console.WriteLine("Finished sending messages"); Console.ReadLine(); }
private TerrestrialObservation clone(TerrestrialObservation terrestrialObservation) { string desi = JsonConvert.SerializeObject(terrestrialObservation); return(JsonConvert.DeserializeObject <TerrestrialObservation>(desi)); }