91 lines
2.7 KiB
Plaintext
91 lines
2.7 KiB
Plaintext
@page "/"
|
|
@using Radzen
|
|
@using Radzen.Blazor
|
|
@using BattSim.Models
|
|
@using BattSim.Services
|
|
|
|
<PageTitle>BattSim</PageTitle>
|
|
|
|
<h1>BattSim</h1>
|
|
|
|
<h2>Input Data</h2>
|
|
<p>Upload your fluvius daily csv file here.</p>
|
|
<InputFile OnChange="LoadCsvFile" accept=".csv"/>
|
|
@if (_isLoadingFile){ <p>Loading...</p> }
|
|
@if (EnergyData.Length != 0){
|
|
<RadzenChart>
|
|
<RadzenAreaSeries Smooth=true Data="@EnergyData" CategoryProperty="Time" Title="Consumption" ValueProperty="Consumption">
|
|
<RadzenChartTooltipOptions Visible="true" />
|
|
</RadzenAreaSeries>
|
|
<RadzenAreaSeries Smooth=true Data="@EnergyData" CategoryProperty="Time" Title="Production" ValueProperty="Production">
|
|
<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>
|
|
}
|
|
|
|
@code{
|
|
EnergyData[] EnergyData = [];
|
|
bool _isLoadingFile = false;
|
|
|
|
private async Task LoadCsvFile(InputFileChangeEventArgs e)
|
|
{
|
|
var file = e.File;
|
|
if (file.ContentType != "text/csv")
|
|
{
|
|
Console.WriteLine("Only CSV files are allowed!");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
Console.WriteLine("Reading csv file...");
|
|
_isLoadingFile = true;
|
|
StateHasChanged();
|
|
|
|
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}");
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
<h2>Simulate Battery</h2>
|
|
<p>Set the battery capacity</p>
|
|
<InputNumber @bind-value="BatteryCapacity"/>
|
|
<Button @onclick="SimulateBattery">Simulate</Button>
|
|
|
|
<h2>Calculate Cost</h2>
|
|
|
|
|
|
@code {
|
|
double BatteryCapacity = 0.0;
|
|
BatteryDayResult[] SimulationData = [];
|
|
|
|
private async Task SimulateBattery(){
|
|
Console.WriteLine("Simulating...");
|
|
SimulationData = BatterySimulator.SimulateBattery(EnergyData, BatteryCapacity).ToArray();
|
|
Console.WriteLine("Done simulating!");
|
|
}
|
|
} |