Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0de047cf authored by Raphael Kalchgruber's avatar Raphael Kalchgruber
Browse files

Read of CSV file, and a testcase to check the contents

parent 612c5cdd
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformationFile.CustomerInformationFile_0_9.CIFWriter;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
{
public sealed class HEVStrategyParameters : LookupData<string, HEVStrategyParameters.Entry>
{
protected override string ResourceId => DeclarationData.DeclarationDataResourcePrefix + ".HEV_Strategy_Parameters_fequiv_40soc_Lorries.csv"; // todo rename csv file...
public override Entry Lookup(string key)
{
return base.Lookup(key.RemoveWhitespace());
}
protected override void ParseData(DataTable table)
{
var vehicleClasses = table.Rows.Cast<DataRow>().Select(row => row.Field<string>("vehiclegroup"));
var cycleEntries = table.Rows.Cast<DataRow>().Select(row => new CycleEntry
{
VehicleGroup = row.Field<string>("vehiclegroup").RemoveWhitespace(),
LongHaul = SplitStringToDoubleTuple(row.Field<string>("longhaul")),
RegionalDelivery = SplitStringToDoubleTuple(row.Field<string>("regionaldelivery")),
UrbanDelivery = SplitStringToDoubleTuple(row.Field<string>("urbandelivery")),
MunicipalUtility = SplitStringToDoubleTuple(row.Field<string>("municipalutility")),
Construction = SplitStringToDoubleTuple(row.Field<string>("construction"))
});
foreach (var cycleEntry in cycleEntries)
{
foreach (string vehClass in cycleEntry.VehicleGroup.Split('/')) {
var newEntry = new Entry {
VehicleGroup = vehClass,
cycleDict = new Dictionary<MissionType, Tuple<double, double>>()
};
newEntry.cycleDict.Add(MissionType.LongHaul, cycleEntry.LongHaul);
newEntry.cycleDict.Add(MissionType.RegionalDelivery, cycleEntry.RegionalDelivery);
newEntry.cycleDict.Add(MissionType.UrbanDelivery, cycleEntry.UrbanDelivery);
newEntry.cycleDict.Add(MissionType.MunicipalUtility, cycleEntry.MunicipalUtility);
newEntry.cycleDict.Add(MissionType.Construction, cycleEntry.Construction);
Data.Add(newEntry.VehicleGroup, newEntry);
}
}
}
public struct CycleEntry
{
public string VehicleGroup;
public Tuple<double, double> LongHaul;
public Tuple<double, double> RegionalDelivery;
public Tuple<double, double> UrbanDelivery;
public Tuple<double, double> MunicipalUtility;
public Tuple<double, double> Construction;
}
public struct Entry
{
public string VehicleGroup;
public Dictionary<MissionType, Tuple<double, double>> cycleDict;
}
private Tuple<double, double> SplitStringToDoubleTuple(string input)
{
var arr = input.Split('/');
return input.IsNullOrEmpty() ? Tuple.Create(0.0,0.0) : Tuple.Create(Convert.ToDouble(arr[0]), Convert.ToDouble(arr[1]));
}
}
}
vehiclegroup , longhaul , regionaldelivery , urbandelivery , municipalutility , construction
53 , , 2.8/2.6 , 2.8/2.7 , ,
54 , , 2.8/2.6 , 2.8/2.7 , ,
1s , , 2.8/2.6 , 2.8/2.7 , ,
1 , , 2.8/2.6 , 2.8/2.7 , ,
2 , 2/2.2 , 2.8/2.6 , 2.8/2.7 , ,
3 , , 2.8/2.6 , 2.8/2.7 , ,
4 , 2/1.8 , 2.4/2.8 , 2.1/2.5 , 2.1/2.1 , 2.1/2.1
5 , 2/1.8 , 2.4/2.8 , 2.1/2.5 , , 2.1/2.1
9 , 2/1.8 , 2.4/2.8 , , 2.1/2.1 , 2.1/2.1
10 , 2/1.8 , 2.4/2.8 , , , 2.1/2.1
11 , 2/1.8 , 2.4/2.8 , , 2.1/2.1 , 2.1/2.1
12 , 2/1.8 , 2.4/2.8 , , , 2.1/2.1
16 , , , , , 2.1/2.1
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.Models.Declaration;
namespace TUGraz.VectoCore.Tests.Models.Declaration
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class HevStrategyParametersTest
{
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
}
private const string HevStrategyParamFile = @"TestData\Cycles\HEV_Strategy_Parameters_fequiv_40soc_Lorries.csv";
[TestCase]
public void TestHevStrategyParametersInput()
{
var lookup = new HEVStrategyParameters();
Assert.IsTrue(lookup.Entries.Count > 0);
}
}
}
vehiclegroup , longhaul , regionaldelivery , urbandelivery , municipalutility , construction
53 , , 2.8/2.6 , 2.8/2.7 , ,
54 , , 2.8/2.6 , 2.8/2.7 , ,
1s , , 2.8/2.6 , 2.8/2.7 , ,
1 , , 2.8/2.6 , 2.8/2.7 , ,
2 , 2/2.2 , 2.8/2.6 , 2.8/2.7 , ,
3 , , 2.8/2.6 , 2.8/2.7 , ,
4 , 2/1.8 , 2.4/2.8 , 2.1/2.5 , 2.1/2.1 , 2.1/2.1
5 , 2/1.8 , 2.4/2.8 , 2.1/2.5 , , 2.1/2.1
9 , 2/1.8 , 2.4/2.8 , , 2.1/2.1 , 2.1/2.1
10 , 2/1.8 , 2.4/2.8 , , , 2.1/2.1
11 , 2/1.8 , 2.4/2.8 , , 2.1/2.1 , 2.1/2.1
12 , 2/1.8 , 2.4/2.8 , , , 2.1/2.1
16 , , , , , 2.1/2.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment