Added quarter based simulation with efficiency and capacity parameters.
This commit is contained in:
@@ -13,7 +13,7 @@ namespace BattSim.Services
|
||||
{
|
||||
public static class FluviusDataHandler
|
||||
{
|
||||
public static async Task<Dictionary<DateTime, EnergyData>> LoadAndProcessFile(IBrowserFile file)
|
||||
public static async Task<EnergyData[]> LoadAndProcessFile(IBrowserFile file)
|
||||
{
|
||||
var lines = await ReadCsvFile(file);
|
||||
var energyData = new ConcurrentDictionary<DateTime,EnergyData>(); // Thread-safe collection
|
||||
@@ -48,21 +48,22 @@ namespace BattSim.Services
|
||||
Console.WriteLine($"Error parsing line: {line}. Skipping to next line. Exception: {e}");
|
||||
}
|
||||
});
|
||||
return energyData.ToDictionary();
|
||||
var results = energyData.Values.ToArray();
|
||||
results.Sort((a,b)=>a.Time.CompareTo(b.Time));
|
||||
return results;
|
||||
}
|
||||
|
||||
public static Dictionary<DateOnly, EnergyData> GenerateDailyData(Dictionary<DateTime, EnergyData> energyData)
|
||||
public static EnergyData[] GenerateDailyData(EnergyData[] energyData)
|
||||
{
|
||||
var dailyEnergyData = new ConcurrentDictionary<DateOnly, EnergyData>();
|
||||
Parallel.ForEach(energyData, entry =>
|
||||
Parallel.ForEach(energyData, energy =>
|
||||
{
|
||||
var date = DateOnly.FromDateTime(entry.Key);
|
||||
var energy = entry.Value;
|
||||
var date = DateOnly.FromDateTime(energy.Time);
|
||||
|
||||
// Use AddOrUpdate to avoid double lookup
|
||||
dailyEnergyData.AddOrUpdate(
|
||||
date,
|
||||
energy, // If key doesn't exist, add this value
|
||||
new EnergyData(energy), // If key doesn't exist, add this value
|
||||
(_, existing) =>
|
||||
{
|
||||
// If key exists, aggregate the values
|
||||
@@ -72,7 +73,7 @@ namespace BattSim.Services
|
||||
}
|
||||
);
|
||||
});
|
||||
return dailyEnergyData.ToDictionary();
|
||||
return dailyEnergyData.Values.ToArray();
|
||||
}
|
||||
|
||||
private static async Task<List<string>> ReadCsvFile(IBrowserFile file)
|
||||
|
||||
Reference in New Issue
Block a user