68
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<SensorReading> sensorReadings = new List<SensorReading>
10
{
11
new SensorReading { ReadingID = 1, SensorID = 1, Location = "CityA", Timestamp = DateTime.Now.AddDays(-8), PM2_5 = 12, PM10 = 20 },
12
new SensorReading { ReadingID = 2, SensorID = 1, Location = "CityA", Timestamp = DateTime.Now.AddDays(-7), PM2_5 = 15, PM10 = 22 },
13
new SensorReading { ReadingID = 3, SensorID = 2, Location = "CityB", Timestamp = DateTime.Now.AddDays(-6), PM2_5 = 20, PM10 = 25 },
14
new SensorReading { ReadingID = 4, SensorID = 2, Location = "CityB", Timestamp = DateTime.Now.AddDays(-5), PM2_5 = 25, PM10 = 30 },
15
new SensorReading { ReadingID = 5, SensorID = 1, Location = "CityA", Timestamp = DateTime.Now.AddDays(-4), PM2_5 = 10, PM10 = 21 },
16
new SensorReading { ReadingID = 6, SensorID = 1, Location = "CityA", Timestamp = DateTime.Now.AddDays(-3), PM2_5 = 14, PM10 = 20 },
17
new SensorReading { ReadingID = 7, SensorID = 2, Location = "CityB", Timestamp = DateTime.Now.AddDays(-2), PM2_5 = 18, PM10 = 28 },
18
new SensorReading { ReadingID = 8, SensorID = 2, Location = "CityB", Timestamp = DateTime.Now.AddDays(-1), PM2_5 = 22, PM10 = 27 },
19
// Add more sensor reading entries as needed
20
};
21
22
// Step 1: Calculate the average PM2.5 and PM10 levels for each location
23
var averagesByLocation = sensorReadings
24
.GroupBy(sr => sr.Location)
Cached Result
True
False
False
False
False