private async Task CheckForWarning(Measurement m) { Warning warning = null; // Temperature if (m.MeasurementTypeId == 1) { if (m.Value < -10) { warning = new Warning() { Type = WarningType.LowTemperature, Timestamp = m.TimesStamp, StationId = m.StationId, TypeId = m.MeasurementTypeId }; } else if (m.Value > 38) { warning = new Warning() { Type = WarningType.HighTemperature, Timestamp = m.TimesStamp, StationId = m.StationId, TypeId = m.MeasurementTypeId }; } } else if (m.MeasurementTypeId == 3) { if (m.Value >= 35) { warning = new Warning() { Type = WarningType.HeavyRain, Timestamp = m.TimesStamp, StationId = m.StationId, TypeId = m.MeasurementTypeId }; } } else if (m.MeasurementTypeId == 5) { if (m.Value >= 65) { warning = new Warning() { Type = WarningType.Storm, Timestamp = m.TimesStamp, StationId = m.StationId, TypeId = m.MeasurementTypeId }; } } else if (m.MeasurementTypeId == 4) { if (m.Value >= 45) { warning = new Warning() { Type = WarningType.DryAir, Timestamp = m.TimesStamp, StationId = m.StationId, TypeId = m.MeasurementTypeId }; } } /* Check warning interval */ if (warning != null) { foreach (Warning w in PastWarnings) { /* Remove old warnings */ if (w.Timestamp < DateTime.Now.AddHours(-1)) { PastWarnings.Remove(w); } } /* If there was alredy a warning of this type for this station in the last hour*/ if (PastWarnings.Where(w => w.StationId == m.StationId && w.TypeId == m.MeasurementTypeId).Any()) { return; } PastWarnings.Add(warning); Station station = await stationDao.FindByIdAsync(m.StationId); string prov = (await addressManager.GetProvinceForAddressId(station.AddressId)).Name; this.Tweet("Warning: " + warning.Type.ToString() + " for province '" + prov + "'"); } }