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<TrafficData> trafficData = new List<TrafficData>
10
{
11
new TrafficData { DataID = 1, IntersectionID = 101, Timestamp = new DateTime(2023, 3, 10, 8, 0, 0), VehicleCount = 150, AverageSpeed = 40 },
12
new TrafficData { DataID = 2, IntersectionID = 101, Timestamp = new DateTime(2023, 3, 10, 10, 0, 0), VehicleCount = 200, AverageSpeed = 35 },
13
new TrafficData { DataID = 3, IntersectionID = 102, Timestamp = new DateTime(2023, 3, 10, 8, 0, 0), VehicleCount = 100, AverageSpeed = 45 },
14
new TrafficData { DataID = 4, IntersectionID = 102, Timestamp = new DateTime(2023, 3, 10, 17, 30, 0), VehicleCount = 180, AverageSpeed = 30 },
15
// Simulating a scenario with no peak hour data for Intersection 101
16
new TrafficData { DataID = 5, IntersectionID = 101, Timestamp = new DateTime(2023, 3, 10, 11, 0, 0), VehicleCount = 180, AverageSpeed = 25 },
17
};
18
19
// Step 1: Calculate the total vehicle count and the average speed for each intersection
20
var statsByIntersection = trafficData
21
.GroupBy(td => td.IntersectionID)
22
.Select(g => new
23
{
24
IntersectionID = g.Key,
Cached Result
El formato es valido: 13:00
El formato es valido: 13:00
El formato no es valido
El formato es valido: 13:00
El formato no es valido