/// <inheritdoc/> public void Log(IWeatherObservation observation) { lock (this.syncroot) { this.observations.Add(observation); if ((DateTime.Now - this.lastPublish).TotalMinutes > this.publishIntervalInMinutes) { try { this.logger.LogSystemStart("Simple SQL log"); var cmd = new SqlCommand(this.insert, this.sqlConnection); cmd.Parameters.AddWithValue("@now", DateTime.Now); cmd.Parameters.AddWithValue("@temp", this.observations.Average(p => p.Temperature1)); cmd.Parameters.AddWithValue("@temp2", this.observations.Average(p => p.Temperature2)); cmd.Parameters.AddWithValue("@hum", this.observations.Average(p => p.RelativeHumidity)); cmd.Parameters.AddWithValue("@pres", this.observations.Average(p => p.BarometricPressure)); cmd.Parameters.AddWithValue("@co2", this.observations.Average(p => p.CO2)); cmd.Parameters.AddWithValue("@tvoc", this.observations.Average(p => p.TVOC)); cmd.Parameters.AddWithValue("@windgust", this.observations.Max(p => p.WindGust)); cmd.Parameters.AddWithValue("@windavg", this.observations.Average(p => p.WindAverage)); this.sqlConnection.Open(); cmd.ExecuteNonQuery(); this.sqlConnection.Close(); this.logger.LogSystemSuccess("Simple SQL log"); } catch (Exception ex) { this.logger.LogSystemError($"Simple SQL log failed {ex}"); } } } }
public void GetWindDirLatestDay_Tdd() { _weather = new WeatherObservation(new FakeWeatherObservationRepository()); _windDir = _weather.GetWindDirLatestDay(71190); Assert.IsNotNull(_windDir); }
/// <inheritdoc/> public void Log(IWeatherObservation observation) { this.logger.LogSystemStart($"Prometheus logging: {this.knownMetrics.Length} measures."); StringBuilder body = new StringBuilder(); body.Append($"weather_timestamp {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}\n"); foreach (var label in this.knownMetrics) { // this.weatherObservation[label].Set(GetValue(label, observation)); body.Append($"weather_{label.ToLower()} {GetValue(label, observation):F4}\n"); } string tosend = body.ToString(); var response = Client.PostAsync(this.targeturl, new StringContent(tosend)); var content = response.Result.Content.ReadAsStringAsync().Result; this.logger.LogSystemSuccess($"Prometheus logging: done."); }
public void Init() { _weatherObservation = new WeatherObservation(new FakeWeatherObservationRepository()); _tempObj = _weatherObservation.GetTempLatestHour(65954); }
private static double GetValue(string label, IWeatherObservation observation) { switch (label) { case "Temperature1": return(observation.Temperature1); case "Temperature2": return(observation.Temperature2); case "UvA": return(observation.UvA); case "UvB": return(observation.UvB); case "UvI": return(observation.UvI); case "TVOC": return(observation.TVOC); case "CO2": return(observation.CO2); case "Pressure": return(observation.Pressure); case "BarometricPressure": return(observation.BarometricPressure); case "SealevelPressure": return(observation.SealevelPressure); case "OverIcePressure": return(observation.OverIcePressure); case "OverWaterPressure": return(observation.OverWaterPressure); case "RelativeHumidity": return(observation.RelativeHumidity); case "AbsoluteHumidity": return(observation.AbsoluteHumidity); case "VapourPressure": return(observation.VapourPressure); case "CalculatedAltitude": return(observation.CalculatedAltitude); case "ActualAltitude": return(observation.ActualAltitude); case "HeatIndex": return(observation.HeatIndex); case "DewPoint": return(observation.DewPoint); case "WindGust": return(observation.WindGust); case "WindAverage": return(observation.WindAverage); case "WindDirection": return(observation.WindDirection); case "Precipitation": return(observation.Precipitation); default: break; } return(-1); }
public void Init() { _weather = new WeatherObservation(new FakeWeatherObservationRepository()); _windDir = _weather.GetWindDirLatestHour(71190); }
/// <summary> /// Constructor injection /// </summary> /// <param name="weatherObservation">Object that retrives weather data</param> public WeatherObservation(IWeatherObservation weatherObservation) { _weatherobservationRepository = weatherObservation; }
public void init() { weather = new FakeWeatherObservationRepository(); }
public void Init() { _weatherObservation = new WeatherObservation(new FakeWeatherObservationRepository()); _temp = _weatherObservation.GetMeanTempLatestMonths(56789); }