Пример #1
0
 public JObject GetBatteryWeek()
 {
     try
     {
         var context          = new DatabaseContext();
         var batteryWeekStart = DataCruncher.BatteryWeekStart();
         var batteries        = context.Batteries.Where(x => x.DateTime > batteryWeekStart).ToList();
         var batteryWeek      = DataCruncher.CrunchLastWeekBatteryData(batteries);
         return(JObject.FromObject(batteryWeek));
     }
     catch (Exception e)
     {
         var value = "{ \"response\": \"error " + e.Message + "\" }";
         return(JObject.Parse(value));
     }
 }
Пример #2
0
 public JObject GetStatus()
 {
     try
     {
         Status  completeStatus;
         var     context            = new DatabaseContext();
         var     dataWeekStart      = DataCruncher.DataWeekStart();
         var     amounts            = context.Amounts.Where(x => x.DateTime > dataWeekStart).ToList();
         var     dataWeek           = DataCruncher.CrunchLastWeekData(amounts);
         var     batteryWeekStart   = DataCruncher.BatteryWeekStart();
         var     batteries          = context.Batteries.Where(x => x.DateTime > batteryWeekStart).ToList();
         var     batteryWeek        = DataCruncher.CrunchLastWeekBatteryData(batteries);
         Average lastUpdatedAverage = context.Averages.OrderByDescending(x => x.DateTime).FirstOrDefault();
         if (lastUpdatedAverage == null)
         {
             completeStatus = new Status {
                 Avg = new UpDown {
                     Up = 0, Down = 0
                 }, BatteryWeek = batteryWeek, DataWeek = dataWeek
             };
         }
         else
         {
             completeStatus = new Status {
                 Avg = new UpDown {
                     Up = lastUpdatedAverage.Up, Down = lastUpdatedAverage.Down
                 }, BatteryWeek = batteryWeek, DataWeek = dataWeek
             };
         }
         return(JObject.FromObject(completeStatus));
     }
     catch (Exception e)
     {
         var value = "{ \"response\": \"error " + e.Message + "\" }";
         return(JObject.Parse(value));
     }
 }