mirror of
https://github.com/ckaczor/WeatherService.git
synced 2026-02-16 18:48:46 -05:00
Initial support for custom reporting
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using WeatherService.Data;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
using WeatherService.Devices;
|
using WeatherService.Devices;
|
||||||
|
using WeatherService.Reporting;
|
||||||
|
|
||||||
namespace WeatherService.Remote
|
namespace WeatherService.Remote
|
||||||
{
|
{
|
||||||
@@ -100,5 +103,36 @@ namespace WeatherService.Remote
|
|||||||
|
|
||||||
return grouped;
|
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
13
Reporting/DailySummary.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.AspNet.SignalR;
|
using Microsoft.AspNet.SignalR;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WeatherService.Devices;
|
using WeatherService.Devices;
|
||||||
using WeatherService.Remote;
|
using WeatherService.Remote;
|
||||||
|
using WeatherService.Reporting;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.SignalR
|
namespace WeatherService.SignalR
|
||||||
@@ -38,5 +40,10 @@ namespace WeatherService.SignalR
|
|||||||
{
|
{
|
||||||
return WeatherServiceCommon.GetWindDirectionHistory().ToList();
|
return WeatherServiceCommon.GetWindDirectionHistory().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DailySummary> GetDailySummary(int deviceId, int valueType, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
return WeatherServiceCommon.GetDailySummary(deviceId, valueType, startDate, endDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,6 +157,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Remote\WeatherServiceCommon.cs" />
|
<Compile Include="Remote\WeatherServiceCommon.cs" />
|
||||||
<Compile Include="Remote\WeatherServiceDuplex.cs" />
|
<Compile Include="Remote\WeatherServiceDuplex.cs" />
|
||||||
|
<Compile Include="Reporting\DailySummary.cs" />
|
||||||
<Compile Include="ServiceImplementation.cs" />
|
<Compile Include="ServiceImplementation.cs" />
|
||||||
<Compile Include="Session.cs" />
|
<Compile Include="Session.cs" />
|
||||||
<Compile Include="Settings.Designer.cs">
|
<Compile Include="Settings.Designer.cs">
|
||||||
|
|||||||
Reference in New Issue
Block a user