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

Skip to content
Snippets Groups Projects
Commit 5d821e02 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

declaration fan

parent 7e5fca0b
No related branches found
No related tags found
No related merge requests found
using System.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
{
......@@ -10,6 +14,7 @@ namespace TUGraz.VectoCore.Models.Declaration
private readonly DeclarationWheels _wheels;
private readonly DeclarationPT1 _pt1;
private readonly ElectricSystem _electricSystem;
private readonly DeclarationFan _fan;
public static DeclarationWheels Wheels
{
......@@ -36,6 +41,11 @@ namespace TUGraz.VectoCore.Models.Declaration
get { return Instance()._electricSystem; }
}
public static DeclarationFan Fan
{
get { return Instance()._fan; }
}
private DeclarationData()
{
_wheels = new DeclarationWheels();
......@@ -43,6 +53,7 @@ namespace TUGraz.VectoCore.Models.Declaration
_segments = new DeclarationSegments();
_pt1 = new DeclarationPT1();
_electricSystem = new ElectricSystem();
_fan = new DeclarationFan();
}
private static DeclarationData Instance()
......@@ -50,4 +61,33 @@ namespace TUGraz.VectoCore.Models.Declaration
return _instance ?? (_instance = new DeclarationData());
}
}
public class DeclarationFan : LookupData<MissionType, string, Watt>
{
private readonly Dictionary<Tuple<MissionType, string>, Watt> _data =
new Dictionary<Tuple<MissionType, string>, Watt>();
protected override string ResourceId
{
get { return "TUGraz.VectoCore.Resources.Declaration.Fan-Tech.csv"; }
}
protected override void ParseData(DataTable table)
{
NormalizeTable(table);
_data.Clear();
foreach (DataRow row in table.Rows) {
foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) {
_data[Tuple.Create(mission, row.Field<string>("Technology"))] =
row.ParseDouble(mission.ToString().ToLower()).SI<Watt>();
}
}
}
public override Watt Lookup(MissionType mission, string technology)
{
return _data[Tuple.Create(mission, technology)];
}
}
}
\ No newline at end of file
......@@ -19,9 +19,7 @@ namespace TUGraz.VectoCore.Models.Declaration
protected override void ParseData(DataTable table)
{
foreach (DataColumn col in table.Columns) {
table.Columns[col.ColumnName].ColumnName = col.ColumnName.ToLower().Replace(" ", "");
}
NormalizeTable(table);
foreach (DataRow row in table.Rows) {
var name = row.Field<string>("Technology");
......
......@@ -18,7 +18,11 @@ namespace TUGraz.VectoCore.Models.Declaration
[NonSerialized] protected ILog Log;
/// <summary>
/// Gets the resource identifier. e.g. "TUGraz.VectoCore.Resources.Declaration.Rims.csv"
/// </summary>
protected abstract string ResourceId { get; }
protected abstract void ParseData(DataTable table);
protected DataTable ReadCsvFile(string resourceId)
......@@ -27,6 +31,13 @@ namespace TUGraz.VectoCore.Models.Declaration
var file = myAssembly.GetManifestResourceStream(resourceId);
return VectoCSVFile.ReadStream(file);
}
protected void NormalizeTable(DataTable table)
{
foreach (DataColumn col in table.Columns) {
table.Columns[col.ColumnName].ColumnName = col.ColumnName.ToLower().Replace(" ", "");
}
}
}
......
......@@ -128,7 +128,7 @@ namespace TUGraz.VectoCore.Tests.Models
{
var fan = DeclarationData.Fan;
var defaultFan = "Crankshaft mounted - Electronically controlled visco clutch (Default)";
const string defaultFan = "Crankshaft mounted - Electronically controlled visco clutch (Default)";
var expected = new Dictionary<string, int[]> {
{
"Crankshaft mounted - Electronically controlled visco clutch (Default)",
......@@ -180,7 +180,7 @@ namespace TUGraz.VectoCore.Tests.Models
for (var i = 0; i < missions.Length; i++) {
// default
Watt defaultValue = fan.Lookup(missions[i], "");
Assert.AreEqual(expected[defaultFan].Value[i], defaultValue.Double(), Tolerance);
Assert.AreEqual(expected[defaultFan][i], defaultValue.Double(), Tolerance);
// all fan techs
foreach (var expect in expected) {
......
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