added file loader
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace BatteryCostAnalysis.Models
|
namespace BattSim.Models
|
||||||
{
|
{
|
||||||
public class BatteryDayResult
|
public class BatteryDayResult
|
||||||
{
|
{
|
||||||
public DateTime Date { get; set; }
|
public DateOnly Date { get; set; }
|
||||||
public double ChargedEnergy { get; set; }
|
public double ChargedEnergy { get; set; }
|
||||||
public double UsedEnergy { get; set; }
|
public double UsedEnergy { get; set; }
|
||||||
public double RemainingEnergy { get; set; }
|
public double RemainingEnergy { get; set; }
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace BatteryCostAnalysis.Models
|
namespace BattSim.Models
|
||||||
{
|
{
|
||||||
public class EnergyData
|
public class EnergyData
|
||||||
{
|
{
|
||||||
public DateTime Date { get; set; }
|
public DateOnly Date { get; set; }
|
||||||
public double DayConsumption { get; set; }
|
public double DayConsumption { get; set; }
|
||||||
public double NightConsumption { get; set; }
|
public double NightConsumption { get; set; }
|
||||||
public double DayProduction { get; set; }
|
public double DayProduction { get; set; }
|
||||||
|
|||||||
114
Pages/Home.razor
114
Pages/Home.razor
@@ -1,96 +1,50 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using Radzen
|
@using BattSim.Models
|
||||||
@using Radzen.Blazor
|
@using BattSim.Services
|
||||||
@using System.Globalization
|
|
||||||
|
|
||||||
|
<PageTitle>BattSim</PageTitle>
|
||||||
|
|
||||||
<PageTitle>Home</PageTitle>
|
<h1>BattSim</h1>
|
||||||
|
|
||||||
<h1>Hello, world!</h1>
|
|
||||||
|
|
||||||
Welcome to your new app.
|
|
||||||
|
|
||||||
<h2>A Radzen chart:</h2>
|
|
||||||
|
|
||||||
<RadzenChart SeriesClick=@OnSeriesClick style="height: 400px">
|
|
||||||
<RadzenBarSeries Data="@revenue2024" CategoryProperty="Quarter" Title="2024" LineType="LineType.Dashed" ValueProperty="Revenue">
|
|
||||||
<RadzenSeriesDataLabels Visible="@showDataLabels" />
|
|
||||||
</RadzenBarSeries>
|
|
||||||
<RadzenBarSeries Data="@revenue2023" CategoryProperty="Quarter" Title="2023" ValueProperty="Revenue">
|
|
||||||
<RadzenSeriesDataLabels Visible="@showDataLabels" />
|
|
||||||
</RadzenBarSeries>
|
|
||||||
<RadzenValueAxis Formatter="@FormatAsUSD">
|
|
||||||
<RadzenGridLines Visible="true" />
|
|
||||||
<RadzenAxisTitle Text="Revenue in USD" />
|
|
||||||
</RadzenValueAxis>
|
|
||||||
<RadzenBarOptions Radius="5" />
|
|
||||||
</RadzenChart>
|
|
||||||
|
|
||||||
|
<p>Upload your fluvius daily csv file here.</p>
|
||||||
|
<InputFile OnChange="LoadCsvFile" accept=".csv"/>
|
||||||
|
@if (_isLoading){ <p>Loading...</p> }
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
bool showDataLabels = false;
|
EnergyData[] EnergyData = [];
|
||||||
|
(int, BatteryDayResult[])[] SimulationData = [];
|
||||||
|
|
||||||
void OnSeriesClick(SeriesClickEventArgs args)
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
private async Task LoadCsvFile(InputFileChangeEventArgs e)
|
||||||
{
|
{
|
||||||
|
_isLoading = true;
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
var file = e.File;
|
||||||
|
if (file.ContentType != "text/csv")
|
||||||
|
{
|
||||||
|
Console.WriteLine("Only CSV files are allowed!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataItem
|
try
|
||||||
{
|
{
|
||||||
public string Quarter { get; set; }
|
var loadingTask = DataLoader.LoadAndProcessData(file);
|
||||||
public double Revenue { get; set; }
|
var energyData = await loadingTask;
|
||||||
|
|
||||||
|
EnergyData = energyData.ToArray();
|
||||||
|
_isLoading = false;
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
foreach (var data in EnergyData)
|
||||||
|
{
|
||||||
|
Console.WriteLine(data.Date.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
string FormatAsUSD(object value)
|
|
||||||
{
|
|
||||||
return ((double)value).ToString("C0", CultureInfo.CreateSpecificCulture("en-US"));
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
DataItem[] revenue2023 = new DataItem[]
|
|
||||||
{
|
{
|
||||||
new DataItem
|
Console.WriteLine($"Error loading file: {ex.Message}");
|
||||||
{
|
}
|
||||||
Quarter = "Q1",
|
}
|
||||||
Revenue = 234000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q2",
|
|
||||||
Revenue = 284000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q3",
|
|
||||||
Revenue = 274000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q4",
|
|
||||||
Revenue = 294000
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
DataItem[] revenue2024 = new DataItem[] {
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q1",
|
|
||||||
Revenue = 254000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q2",
|
|
||||||
Revenue = 324000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q3",
|
|
||||||
Revenue = 354000
|
|
||||||
},
|
|
||||||
new DataItem
|
|
||||||
{
|
|
||||||
Quarter = "Q4",
|
|
||||||
Revenue = 394000
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
96
Pages/Test.razor
Normal file
96
Pages/Test.razor
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
@page "/Test"
|
||||||
|
@using Radzen
|
||||||
|
@using Radzen.Blazor
|
||||||
|
@using System.Globalization
|
||||||
|
|
||||||
|
|
||||||
|
<PageTitle>Home</PageTitle>
|
||||||
|
|
||||||
|
<h1>Hello, world!</h1>
|
||||||
|
|
||||||
|
Welcome to your new app.
|
||||||
|
|
||||||
|
<h2>A Radzen chart:</h2>
|
||||||
|
|
||||||
|
<RadzenChart SeriesClick=@OnSeriesClick style="height: 400px">
|
||||||
|
<RadzenBarSeries Data="@revenue2024" CategoryProperty="Quarter" Title="2024" LineType="LineType.Dashed" ValueProperty="Revenue">
|
||||||
|
<RadzenSeriesDataLabels Visible="@showDataLabels" />
|
||||||
|
</RadzenBarSeries>
|
||||||
|
<RadzenBarSeries Data="@revenue2023" CategoryProperty="Quarter" Title="2023" ValueProperty="Revenue">
|
||||||
|
<RadzenSeriesDataLabels Visible="@showDataLabels" />
|
||||||
|
</RadzenBarSeries>
|
||||||
|
<RadzenValueAxis Formatter="@FormatAsUSD">
|
||||||
|
<RadzenGridLines Visible="true" />
|
||||||
|
<RadzenAxisTitle Text="Revenue in USD" />
|
||||||
|
</RadzenValueAxis>
|
||||||
|
<RadzenBarOptions Radius="5" />
|
||||||
|
</RadzenChart>
|
||||||
|
|
||||||
|
|
||||||
|
@code {
|
||||||
|
bool showDataLabels = false;
|
||||||
|
|
||||||
|
void OnSeriesClick(SeriesClickEventArgs args)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DataItem
|
||||||
|
{
|
||||||
|
public string Quarter { get; set; }
|
||||||
|
public double Revenue { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
string FormatAsUSD(object value)
|
||||||
|
{
|
||||||
|
return ((double)value).ToString("C0", CultureInfo.CreateSpecificCulture("en-US"));
|
||||||
|
}
|
||||||
|
|
||||||
|
DataItem[] revenue2023 = new DataItem[]
|
||||||
|
{
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q1",
|
||||||
|
Revenue = 234000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q2",
|
||||||
|
Revenue = 284000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q3",
|
||||||
|
Revenue = 274000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q4",
|
||||||
|
Revenue = 294000
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
DataItem[] revenue2024 = new DataItem[] {
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q1",
|
||||||
|
Revenue = 254000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q2",
|
||||||
|
Revenue = 324000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q3",
|
||||||
|
Revenue = 354000
|
||||||
|
},
|
||||||
|
new DataItem
|
||||||
|
{
|
||||||
|
Quarter = "Q4",
|
||||||
|
Revenue = 394000
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
using BattSim;
|
using BattSim;
|
||||||
|
using BattSim.Models;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Setup Frontend
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||||
builder.RootComponents.Add<App>("#app");
|
builder.RootComponents.Add<App>("#app");
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using BatteryCostAnalysis.Models;
|
using BattSim.Models;
|
||||||
|
|
||||||
namespace BatteryCostAnalysis.Services
|
namespace BattSim.Services
|
||||||
{
|
{
|
||||||
public class BatterySimulator
|
public class BatterySimulator
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,26 +3,41 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BatteryCostAnalysis.Models;
|
using System.Threading.Tasks;
|
||||||
|
using BattSim.Models;
|
||||||
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
|
|
||||||
namespace BatteryCostAnalysis.Services
|
namespace BattSim.Services
|
||||||
{
|
{
|
||||||
public class DataLoader
|
public static class DataLoader
|
||||||
{
|
{
|
||||||
public static List<EnergyData> LoadAndProcessData(string filePath)
|
public static async Task<List<EnergyData>> LoadAndProcessData(IBrowserFile file)
|
||||||
{
|
{
|
||||||
var energyData = new List<EnergyData>();
|
var energyData = new List<EnergyData>();
|
||||||
var lines = File.ReadAllLines(filePath).Skip(1); // Skip header
|
await using var stream = file.OpenReadStream();
|
||||||
|
using var reader = new StreamReader(stream);
|
||||||
|
|
||||||
foreach (var line in lines)
|
// Skip header
|
||||||
|
await reader.ReadLineAsync();
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while ((line = await reader.ReadLineAsync()) != null)
|
||||||
{
|
{
|
||||||
var parts = line.Split(';');
|
var parts = line.Split(';');
|
||||||
if (parts.Length < 9) continue;
|
if (parts.Length < 9)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Skipping malformed line: {line}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var date = DateTime.Parse(parts[0], new CultureInfo("nl-BE"));
|
try
|
||||||
|
{
|
||||||
|
var date = DateOnly.ParseExact(parts[0].Length == 10 ? parts[0] : "0"+parts[0], "dd/MM/yyyy", CultureInfo.InvariantCulture);
|
||||||
var register = parts[7].Trim();
|
var register = parts[7].Trim();
|
||||||
var volumeStr = parts[8].Trim();
|
var volumeStr = parts[8].Trim();
|
||||||
var volume = string.IsNullOrEmpty(volumeStr) ? 0 : double.Parse(volumeStr.Replace(",", "."), CultureInfo.InvariantCulture);
|
var volume = string.IsNullOrEmpty(volumeStr)
|
||||||
|
? 0
|
||||||
|
: double.Parse(volumeStr.Replace(",", "."), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
var existing = energyData.FirstOrDefault(e => e.Date == date);
|
var existing = energyData.FirstOrDefault(e => e.Date == date);
|
||||||
if (existing == null)
|
if (existing == null)
|
||||||
@@ -47,8 +62,12 @@ namespace BatteryCostAnalysis.Services
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error parsing line: {line}. Exception: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
return energyData;
|
return energyData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BatteryCostAnalysis.Models;
|
using BattSim.Models;
|
||||||
|
|
||||||
namespace BatteryCostAnalysis.Services
|
namespace BattSim.Services
|
||||||
{
|
{
|
||||||
public class ReportGenerator
|
public class ReportGenerator
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user