63
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<SolarProduction> solarProductions = new List<SolarProduction>
10
{
11
new SolarProduction { DataID = 1, LocationID = 101, Timestamp = new DateTime(2023, 3, 10), Production = 500.5, SunlightDuration = 5.5 },
12
new SolarProduction { DataID = 2, LocationID = 102, Timestamp = new DateTime(2023, 3, 11), Production = 600.0, SunlightDuration = 6.0 },
13
new SolarProduction { DataID = 3, LocationID = 101, Timestamp = new DateTime(2023, 3, 12), Production = 550.0, SunlightDuration = 6.5 },
14
new SolarProduction { DataID = 4, LocationID = 103, Timestamp = new DateTime(2023, 3, 13), Production = 620.0, SunlightDuration = 7.0 },
15
new SolarProduction { DataID = 5, LocationID = 101, Timestamp = new DateTime(2023, 3, 14), Production = 560.0, SunlightDuration = 5.8 },
16
// Add more solar production entries as needed
17
};
18
19
// Step 1: Calculate the total energy production and average sunlight duration for each location
20
var productionByLocation = solarProductions
21
.GroupBy(sp => sp.LocationID)
22
.Select(g => new
23
{
24
LocationID = g.Key,
Cached Result