From 9f1fbcdd5a05c9d31957e623bb8d0a9e1ca8f6e5 Mon Sep 17 00:00:00 2001 From: douwe Date: Sat, 28 Mar 2026 12:47:03 +0100 Subject: [PATCH] Shart generation after csv files uploaded. --- Models/EnergyData.cs | 2 + Pages/Home.razor | 77 ++++++++++++++++++++++++++++-------- Services/BatterySimulator.cs | 4 +- wwwroot/index.html | 5 +-- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Models/EnergyData.cs b/Models/EnergyData.cs index c93ac7f..901ff8b 100644 --- a/Models/EnergyData.cs +++ b/Models/EnergyData.cs @@ -7,7 +7,9 @@ namespace BattSim.Models public DateOnly Date { get; set; } public double DayConsumption { get; set; } public double NightConsumption { get; set; } + public double TotalConsumption => DayConsumption + NightConsumption; public double DayProduction { get; set; } public double NightProduction { get; set; } + public double TotalProduction => DayProduction + NightProduction; } } \ No newline at end of file diff --git a/Pages/Home.razor b/Pages/Home.razor index 00302e4..d288cfc 100644 --- a/Pages/Home.razor +++ b/Pages/Home.razor @@ -1,4 +1,6 @@ @page "/" +@using Radzen +@using Radzen.Blazor @using BattSim.Models @using BattSim.Services @@ -6,21 +8,43 @@

BattSim

+

Input Data

Upload your fluvius daily csv file here.

-@if (_isLoading){

Loading...

} +@if (_isLoadingFile){

Loading...

} +@if (EnergyData.Length != 0){ + + + + + + + + + + + + + + + +} + + +

Simulate Battery

+

Set the battery capacity

+ + + +

Calculate Cost

+ @code { EnergyData[] EnergyData = []; - (int, BatteryDayResult[])[] SimulationData = []; - - bool _isLoading = false; + bool _isLoadingFile = false; private async Task LoadCsvFile(InputFileChangeEventArgs e) { - _isLoading = true; - StateHasChanged(); - var file = e.File; if (file.ContentType != "text/csv") { @@ -30,21 +54,42 @@ try { - var loadingTask = DataLoader.LoadAndProcessData(file); - var energyData = await loadingTask; - - EnergyData = energyData.ToArray(); - _isLoading = false; + Console.WriteLine("Reading csv file..."); + _isLoadingFile = true; StateHasChanged(); - foreach (var data in EnergyData) - { - Console.WriteLine(data.Date.ToString()); - } + var loadingTask = DataLoader.LoadAndProcessData(file); + var energyData = await loadingTask; + EnergyData = energyData.ToArray(); + + _isLoadingFile = false; + StateHasChanged(); + Console.WriteLine("Done reading csv file!"); } catch (Exception ex) { Console.WriteLine($"Error loading file: {ex.Message}"); } } + + bool _showProduction = true; + bool _showConsumption = true; + + private void OnSeriesClick(){} + private string FormatObject(object value) { + if(value is double d) return $"{value:0.##} kWh"; + if(value is DateOnly date) return (date.Day == 1) ? date.ToString("MM/yyyy") : string.Empty; + else return string.Empty; + } + + double BatteryCapacity = 0.0; + BatteryDayResult[] SimulationData = []; + + + private async Task SimulateBattery(){ + Console.WriteLine("Simulating..."); + SimulationData = BatterySimulator.SimulateBattery(EnergyData, BatteryCapacity).ToArray(); + Console.WriteLine("Done simulating!"); + } + } \ No newline at end of file diff --git a/Services/BatterySimulator.cs b/Services/BatterySimulator.cs index 0247fcd..6867963 100644 --- a/Services/BatterySimulator.cs +++ b/Services/BatterySimulator.cs @@ -3,9 +3,9 @@ using BattSim.Models; namespace BattSim.Services { - public class BatterySimulator + public static class BatterySimulator { - public static List SimulateBattery(List data, double batteryCapacity) + public static List SimulateBattery(EnergyData[] data, double batteryCapacity) { var results = new List(); double remainingEnergy = 0; diff --git a/wwwroot/index.html b/wwwroot/index.html index fd22d75..8d1d176 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -13,10 +13,8 @@ - - - + @@ -35,6 +33,7 @@ +