-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWeatherDataDict.cs
More file actions
36 lines (33 loc) · 918 Bytes
/
WeatherDataDict.cs
File metadata and controls
36 lines (33 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
namespace CreateMissing
{
internal class WeatherDataDict : Dictionary<DateTime, WeatherData>
{
public WeatherData GetAverages(DateTime date)
{
// Get the average values for the specified hour of the day
var dataForHour = this
.Where(kvp => kvp.Key.Date == date.Date && kvp.Key.Hour == date.Hour)
.Select(kvp => kvp.Value)
.ToList();
if (dataForHour.Any())
{
return new WeatherData
{
Temp = dataForHour.Average(d => d.Temp ?? 0),
Humidity = (int?) dataForHour.Average(d => d.Humidity ?? 0),
Pressure = dataForHour.Average(d => d.Pressure ?? 0),
SolarRad = (int?) dataForHour.Average(d => d.SolarRad ?? 0),
SolarMax = (int?) dataForHour.Average(d => d.SolarMax ?? 0),
WindSpeed = dataForHour.Average(d => d.WindSpeed ?? 0)
};
}
else
{
return null;
}
}
}
}