public MyMeasurements GetAverageMeasurementsFromLocation(string location, params string[] pars) { MyMeasurements m = new MyMeasurements(); if (m_MeasurementPublishers.ContainsKey(location)) { if (pars[0].Equals("temp") || pars[0].Equals("both")) { List <TemperatureMeasurement> ms = MyDbContext.TemperatureMeasurements.ToList(); double sum = 0.0f; Action <TemperatureMeasurement> addToSum = (measurement) => { sum += measurement.Value; }; ms.ForEach(addToSum); m.MyAverageTemperature = (float)sum / (float)ms.Count; } if (pars[0].Equals("humid") || pars[0].Equals("both")) { List <HumidityMeasurement> ms = MyDbContext.HumidityMeasurements.ToList(); double sum = 0.0f; Action <HumidityMeasurement> addToSum = (measurement) => { sum += measurement.Value; }; ms.ForEach(addToSum); m.MyAverageHumidity = (float)sum / (float)ms.Count; } } return(m); }
public MyMeasurements GetAllMeasuremensWithLimit(float limit, params string[] pars) { MyMeasurements m = new MyMeasurements(); List <TemperatureMeasurement> tlist = new List <TemperatureMeasurement>(); List <HumidityMeasurement> hlist = new List <HumidityMeasurement>(); if (pars[1].Equals("humid") || pars[1].Equals("both")) { if (pars[0].Equals("above")) { hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.Value > limit).ToList(); } else if (pars[0].Equals("under")) { hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.Value < limit).ToList(); } Action <HumidityMeasurement> toSendList = (item) => { var item2 = new MyHumidityMeasurement(); item2.MyDateTime = item.DateTime; item2.MyRMUnitName = item.RMUnit.Name; item2.MyValue = (float)item.Value; item2.MyLocationName = item.LocationName; m.MyHumMeasurements.Add(item2); }; hlist.ForEach(toSendList); } if (pars[1].Equals("temp") || pars[1].Equals("both")) { if (pars[0].Equals("above")) { tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.Value > limit).ToList(); } else if (pars[0].Equals("under")) { tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.Value < limit).ToList(); } Action <TemperatureMeasurement> toSendList = (item) => { var item2 = new MyTemperatureMeasurement(); item2.MyDateTime = item.DateTime; item2.MyRMUnitName = item.RMUnit.Name; item2.MyLocationName = item.LocationName; item2.MyValue = (float)item.Value; m.MyTempMeasurements.Add(item2); }; tlist.ForEach(toSendList); } return(m); }
public MyMeasurements GetAllMeasurementsFromLocationDateToDate(DateTime from, DateTime todate, params string[] pars) { MyMeasurements m = new MyMeasurements(); List <TemperatureMeasurement> tlist = new List <TemperatureMeasurement>(); List <HumidityMeasurement> hlist = new List <HumidityMeasurement>(); string location = pars[0]; string measurement = pars[1]; if (pars[0].Equals("all")) { hlist = MyDbContext.HumidityMeasurements.ToList(); tlist = MyDbContext.TemperatureMeasurements.ToList(); } else { hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.LocationName.Equals(location)).ToList(); tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.LocationName.Equals(location)).ToList(); } if (pars[1].Equals("humid") || pars[1].Equals("both")) { hlist = hlist.Where(r => r.DateTime > from).ToList(); hlist = hlist.Where(r => r.DateTime < todate).ToList(); Action <HumidityMeasurement> toSendList = (item) => { var item2 = new MyHumidityMeasurement(); item2.MyDateTime = item.DateTime; item2.MyRMUnitName = item.RMUnit.Name; item2.MyLocationName = item.LocationName; item2.MyValue = (float)item.Value; m.MyHumMeasurements.Add(item2); }; hlist.ForEach(toSendList); } if (pars[1].Equals("temp") || pars[1].Equals("both")) { tlist = tlist.Where(r => r.DateTime > from).ToList(); tlist = tlist.Where(r => r.DateTime < todate).ToList(); Action <TemperatureMeasurement> toSendList = (item) => { var item2 = new MyTemperatureMeasurement(); item2.MyDateTime = item.DateTime; item2.MyRMUnitName = item.RMUnit.Name; item2.MyLocationName = item.LocationName; item2.MyValue = (float)item.Value; m.MyTempMeasurements.Add(item2); }; tlist.ForEach(toSendList); } return(m); }