Blazor webassembly with radzen setup
This commit is contained in:
54
Services/DataLoader.cs
Normal file
54
Services/DataLoader.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BatteryCostAnalysis.Models;
|
||||
|
||||
namespace BatteryCostAnalysis.Services
|
||||
{
|
||||
public class DataLoader
|
||||
{
|
||||
public static List<EnergyData> LoadAndProcessData(string filePath)
|
||||
{
|
||||
var energyData = new List<EnergyData>();
|
||||
var lines = File.ReadAllLines(filePath).Skip(1); // Skip header
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var parts = line.Split(';');
|
||||
if (parts.Length < 9) continue;
|
||||
|
||||
var date = DateTime.Parse(parts[0], new CultureInfo("nl-BE"));
|
||||
var register = parts[7].Trim();
|
||||
var volumeStr = parts[8].Trim();
|
||||
var volume = string.IsNullOrEmpty(volumeStr) ? 0 : double.Parse(volumeStr.Replace(",", "."), CultureInfo.InvariantCulture);
|
||||
|
||||
var existing = energyData.FirstOrDefault(e => e.Date == date);
|
||||
if (existing == null)
|
||||
{
|
||||
existing = new EnergyData { Date = date };
|
||||
energyData.Add(existing);
|
||||
}
|
||||
|
||||
switch (register)
|
||||
{
|
||||
case "Afname Dag":
|
||||
existing.DayConsumption = volume;
|
||||
break;
|
||||
case "Afname Nacht":
|
||||
existing.NightConsumption = volume;
|
||||
break;
|
||||
case "Injectie Dag":
|
||||
existing.DayProduction = volume;
|
||||
break;
|
||||
case "Injectie Nacht":
|
||||
existing.NightProduction = volume;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return energyData;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user