Initial support for custom reporting

This commit is contained in:
2015-03-14 21:07:18 -04:00
parent 60fa893205
commit 340a486f95
4 changed files with 56 additions and 1 deletions

View File

@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using WeatherService.Data;
using WeatherService.Values;
using WeatherService.Devices;
using WeatherService.Reporting;
namespace WeatherService.Remote
{
@@ -100,5 +103,36 @@ namespace WeatherService.Remote
return grouped;
}
public static List<DailySummary> GetDailySummary(int deviceId, int valueType, DateTime startDate, DateTime endDate)
{
var summaryList = new List<DailySummary>();
for (var year = startDate.Year; year <= endDate.Year; year++)
{
using (var archiveData = new WeatherArchiveData(year))
{
var groupedReadings = archiveData.Readings
.Where(r => r.ReadTime >= startDate &&
r.ReadTime <= endDate &&
r.DeviceId == deviceId &&
r.Type == valueType)
.GroupBy(r => DbFunctions.TruncateTime(r.ReadTime))
.Select(r => new DailySummary
{
Date = r.Key,
Count = r.Count(),
Minimum = r.Min(v => v.Value),
Maximum = r.Max(v => v.Value),
Average = r.Average(v => v.Value)
})
.OrderBy(d => d.Date);
summaryList.AddRange(groupedReadings);
}
}
return summaryList;
}
}
}

13
Reporting/DailySummary.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
namespace WeatherService.Reporting
{
public class DailySummary
{
public DateTimeOffset? Date { get; set; }
public int Count { get; set; }
public double Minimum { get; set; }
public double Maximum { get; set; }
public double Average { get; set; }
}
}

View File

@@ -1,8 +1,10 @@
using System.Linq;
using System;
using System.Linq;
using Microsoft.AspNet.SignalR;
using System.Collections.Generic;
using WeatherService.Devices;
using WeatherService.Remote;
using WeatherService.Reporting;
using WeatherService.Values;
namespace WeatherService.SignalR
@@ -38,5 +40,10 @@ namespace WeatherService.SignalR
{
return WeatherServiceCommon.GetWindDirectionHistory().ToList();
}
public List<DailySummary> GetDailySummary(int deviceId, int valueType, DateTime startDate, DateTime endDate)
{
return WeatherServiceCommon.GetDailySummary(deviceId, valueType, startDate, endDate);
}
}
}

View File

@@ -157,6 +157,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Remote\WeatherServiceCommon.cs" />
<Compile Include="Remote\WeatherServiceDuplex.cs" />
<Compile Include="Reporting\DailySummary.cs" />
<Compile Include="ServiceImplementation.cs" />
<Compile Include="Session.cs" />
<Compile Include="Settings.Designer.cs">