69
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
List<Observation> observations = new List<Observation>
10
{
11
new Observation { ID = 1, Location = "CityA", ObservationDate = new DateTime(2023, 01, 15), Temperature = 10, Precipitation = 5 },
12
new Observation { ID = 2, Location = "CityA", ObservationDate = new DateTime(2023, 01, 16), Temperature = 12, Precipitation = 7 },
13
new Observation { ID = 3, Location = "CityB", ObservationDate = new DateTime(2023, 02, 15), Temperature = 15, Precipitation = 4 },
14
new Observation { ID = 4, Location = "CityB", ObservationDate = new DateTime(2023, 02, 16), Temperature = 17, Precipitation = 2 }
15
// Add more observations as needed
16
};
17
18
// Step 1: Calculate average temperature and total precipitation for each location for each month
19
var monthlyStats = observations
20
.GroupBy(o => new { o.Location, Month = o.ObservationDate.Month })
21
.Select(g => new
22
{
23
Location = g.Key.Location,
24
Month = g.Key.Month,
Cached Result