public void ByMonth() { AtomData.Clear(); for (int i = 1; i <= 12; i++) { var data = Db.Table <DataModel>().Where(p => p.Time.Month == i); AtomData.Add(new GraphModel { Line = data.Max(p => p.Temp), Line2 = data.Average(p => p.Temp), Line3 = data.Min(p => p.Temp) }); } }
public void DrawMonth(int year) { AtomData.Clear(); SoilData.Clear(); SoilData.Add(new PieModel { title = "", value = 0 }); RainData.Clear(); PmData.Clear(); var data = Db.Table <DataModel>().ToList().Where(p => p.Time.Year == year); for (int i = 1; i <= 12; i++) { var temp = data.Where(p => p.Time.Month == i); if (temp.Count() > 0) { AtomData.Add(new GraphModel { Line = temp.Max(p => p.Temp), Line2 = temp.Average(p => p.Temp), Line3 = temp.Min(p => p.Temp) }); } } var count = data.Count(); var soil = (double)data.Count(p => p.Soil == 0) / count; var rain = (double)data.Count(p => p.Rain == 0) / count; var pm = (double)data.Count(p => p.Pm25 == 0) / count; SoilData.Add(new PieModel { title = "干燥", value = soil }); SoilData.Add(new PieModel { title = "湿润", value = 1 - soil }); RainData.Add(new PieModel { title = "有雨", value = 1 - rain }); RainData.Add(new PieModel { title = "无雨", value = rain }); PmData.Add(new PieModel { title = "超标", value = 1 - pm }); PmData.Add(new PieModel { title = "良好", value = pm }); }
public void DrawHour(int year, int month, int day) { SoilData.Clear(); RainData.Clear(); PmData.Clear(); AtomData.Clear(); SoilData.Add(new PieModel { title = "", value = 0 }); var list = Db.Table <DataModel>().ToList(); var data = list.Where(p => p.Time.Year == year && p.Time.Month == month && p.Time.Day == day); for (int i = 0; i < 24; i++) { var temp = data.First(p => p.Time.Hour == i); AtomData.Add(new GraphModel { Line = temp.Temp }); } var count = data.Count(); var soil = (double)data.Count(p => p.Soil == 0) / count; var rain = (double)data.Count(p => p.Rain == 0) / count; var pm = (double)data.Count(p => p.Pm25 == 0) / count; SoilData.Add(new PieModel { title = "干燥", value = soil }); SoilData.Add(new PieModel { title = "湿润", value = 1 - soil }); RainData.Add(new PieModel { title = "有雨", value = 1 - rain }); RainData.Add(new PieModel { title = "无雨", value = rain }); PmData.Add(new PieModel { title = "超标", value = 1 - pm }); PmData.Add(new PieModel { title = "良好", value = pm }); }