Shart generation after csv files uploaded.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
@page "/"
|
||||
@using Radzen
|
||||
@using Radzen.Blazor
|
||||
@using BattSim.Models
|
||||
@using BattSim.Services
|
||||
|
||||
@@ -6,21 +8,43 @@
|
||||
|
||||
<h1>BattSim</h1>
|
||||
|
||||
<h2>Input Data</h2>
|
||||
<p>Upload your fluvius daily csv file here.</p>
|
||||
<InputFile OnChange="LoadCsvFile" accept=".csv"/>
|
||||
@if (_isLoading){ <p>Loading...</p> }
|
||||
@if (_isLoadingFile){ <p>Loading...</p> }
|
||||
@if (EnergyData.Length != 0){
|
||||
<RadzenChart>
|
||||
<RadzenAreaSeries Smooth=true Data="@EnergyData" CategoryProperty="Date" Title="Consumption" ValueProperty="TotalConsumption">
|
||||
<RadzenChartTooltipOptions Visible="true" />
|
||||
</RadzenAreaSeries>
|
||||
<RadzenAreaSeries Smooth=true Data="@EnergyData" CategoryProperty="Date" Title="Production" ValueProperty="TotalProduction">
|
||||
<RadzenChartTooltipOptions Visible="true" />
|
||||
</RadzenAreaSeries>
|
||||
<RadzenCategoryAxis Formatter="@FormatObject" Padding="20" LabelAutoRotation="-45">
|
||||
<RadzenAxisTitle Text="Time" />
|
||||
</RadzenCategoryAxis>
|
||||
<RadzenValueAxis Formatter="@FormatObject">
|
||||
<RadzenGridLines Visible="true" />
|
||||
<RadzenAxisTitle Text="Energy" />
|
||||
</RadzenValueAxis>
|
||||
</RadzenChart>
|
||||
}
|
||||
|
||||
|
||||
<h2>Simulate Battery</h2>
|
||||
<p>Set the battery capacity</p>
|
||||
<InputNumber @bind-value="BatteryCapacity"/>
|
||||
<Button @onclick="SimulateBattery">Simulate</Button>
|
||||
|
||||
<h2>Calculate Cost</h2>
|
||||
|
||||
|
||||
@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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,9 @@ using BattSim.Models;
|
||||
|
||||
namespace BattSim.Services
|
||||
{
|
||||
public class BatterySimulator
|
||||
public static class BatterySimulator
|
||||
{
|
||||
public static List<BatteryDayResult> SimulateBattery(List<EnergyData> data, double batteryCapacity)
|
||||
public static List<BatteryDayResult> SimulateBattery(EnergyData[] data, double batteryCapacity)
|
||||
{
|
||||
var results = new List<BatteryDayResult>();
|
||||
double remainingEnergy = 0;
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
<link href="manifest.webmanifest" rel="manifest" />
|
||||
<link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
|
||||
<link rel="apple-touch-icon" sizes="192x192" href="icon-192.png" />
|
||||
<script type="importmap"></script>
|
||||
|
||||
<link rel="stylesheet" href="_content/Radzen.Blazor/css/default.css">
|
||||
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
|
||||
<script type="importmap"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -35,6 +33,7 @@
|
||||
</div>
|
||||
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script>
|
||||
<script>navigator.serviceWorker.register('service-worker.js', { updateViaCache: 'none' });</script>
|
||||
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user