diff --git a/VECTO.sln.DotSettings b/VECTO.sln.DotSettings index d35b7aa96aaf9ec5613e6859310011cc46ebb1dd..519ebe2c3f9db225ac68a45e912e6e7854fe41ad 100644 --- a/VECTO.sln.DotSettings +++ b/VECTO.sln.DotSettings @@ -61,11 +61,16 @@ <s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String> <s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String> <s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String> - <s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=881E888B051E884CA3355C69393D8764/@KeyIndexDefined">True</s:Boolean> - <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=881E888B051E884CA3355C69393D8764/AbsolutePath/@EntryValue">C:\Users\Krisper\Documents\vecto-sim\VECTO.sln.DotSettings</s:String> - <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=881E888B051E884CA3355C69393D8764/RelativePath/@EntryValue"></s:String> - <s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File881E888B051E884CA3355C69393D8764/@KeyIndexDefined">True</s:Boolean> - <s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File881E888B051E884CA3355C69393D8764/RelativePriority/@EntryValue">1</s:Double> + + + + <s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=9B8C70A674F95241B1558475C07A6344/@KeyIndexDefined">True</s:Boolean> + <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=9B8C70A674F95241B1558475C07A6344/AbsolutePath/@EntryValue">E:\vecto-sim\VECTO.sln.DotSettings</s:String> + <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=9B8C70A674F95241B1558475C07A6344/RelativePath/@EntryValue"></s:String> + + + <s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File9B8C70A674F95241B1558475C07A6344/@KeyIndexDefined">True</s:Boolean> + <s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File9B8C70A674F95241B1558475C07A6344/RelativePriority/@EntryValue">2</s:Double> diff --git a/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/Models/Declaration/DeclarationData.cs index 801098cd99e25cd8fc2505fca22ce0c7fe458921..d96401b2202067f51c145b095f3e29b5d45921b8 100644 --- a/VectoCore/Models/Declaration/DeclarationData.cs +++ b/VectoCore/Models/Declaration/DeclarationData.cs @@ -1,6 +1,4 @@ -using System.Data; - -namespace TUGraz.VectoCore.Models.Declaration +namespace TUGraz.VectoCore.Models.Declaration { public class DeclarationData { @@ -75,22 +73,4 @@ namespace TUGraz.VectoCore.Models.Declaration return _instance ?? (_instance = new DeclarationData()); } } - - public class WHTCCorrection : LookupData<MissionType, double, double, double, double> - { - public override double Lookup(MissionType key1, double key2, double key3, double key4) - { - throw new System.NotImplementedException(); - } - - protected override string ResourceId - { - get { throw new System.NotImplementedException(); } - } - - protected override void ParseData(DataTable table) - { - throw new System.NotImplementedException(); - } - } } \ No newline at end of file diff --git a/VectoCore/Models/Declaration/LookupData.cs b/VectoCore/Models/Declaration/LookupData.cs index c861c7f413392df7b789ad4f79b3c77be25f6497..f972f96299f7a912dba14059ad158afb61bdbf23 100644 --- a/VectoCore/Models/Declaration/LookupData.cs +++ b/VectoCore/Models/Declaration/LookupData.cs @@ -32,11 +32,12 @@ namespace TUGraz.VectoCore.Models.Declaration return VectoCSVFile.ReadStream(file); } - protected void NormalizeTable(DataTable table) + protected static DataTable NormalizeTable(DataTable table) { foreach (DataColumn col in table.Columns) { table.Columns[col.ColumnName].ColumnName = col.ColumnName.ToLower().Replace(" ", ""); } + return table; } } diff --git a/VectoCore/Models/Declaration/WHTCCorrection.cs b/VectoCore/Models/Declaration/WHTCCorrection.cs new file mode 100644 index 0000000000000000000000000000000000000000..ec7a5e991087425f6d31bb4728e77c57c4094023 --- /dev/null +++ b/VectoCore/Models/Declaration/WHTCCorrection.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public class WHTCCorrection : LookupData<MissionType, double, double, double, double> + { + private Dictionary<MissionType, WHTCCorrectionEntry> _data = new Dictionary<MissionType, WHTCCorrectionEntry>(); + + public override double Lookup(MissionType mission, double rural, double urban, double motorway) + { + var entry = _data[mission]; + return rural * entry.Rural + urban * entry.Urban + motorway * entry.Motorway; + } + + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.WHTC-Weighting-Factors.csv"; } + } + + protected override void ParseData(DataTable table) + { + _data.Clear(); + NormalizeTable(table); + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + var values = table.Columns[mission.ToString().ToLower()].Values<string>().ToDouble().ToArray(); + _data[mission] = new WHTCCorrectionEntry { Rural = values[0], Urban = values[1], Motorway = values[2] }; + } + } + + private class WHTCCorrectionEntry + { + public double Rural { get; set; } + public double Urban { get; set; } + public double Motorway { get; set; } + } + } +} \ No newline at end of file diff --git a/VectoCore/Utils/DataRowExtensionMethods.cs b/VectoCore/Utils/DataTableExtensionMethods.cs similarity index 91% rename from VectoCore/Utils/DataRowExtensionMethods.cs rename to VectoCore/Utils/DataTableExtensionMethods.cs index 5b91b0f7a8e9d52704cf8635aca874d58fdfebcb..e08d00b1329fe9a2e4156371e6d062358298722d 100644 --- a/VectoCore/Utils/DataRowExtensionMethods.cs +++ b/VectoCore/Utils/DataTableExtensionMethods.cs @@ -6,7 +6,7 @@ using TUGraz.VectoCore.Exceptions; namespace TUGraz.VectoCore.Utils { - public static class DataRowExtensionMethods + public static class DataTableExtensionMethods { public static double ParseDoubleOrGetDefault(this DataRow row, string columnName, double defaultValue = default(double)) @@ -53,5 +53,10 @@ namespace TUGraz.VectoCore.Utils throw new VectoException(string.Format("Field {0}: {1}", column, e.Message), e); } } + + public static IEnumerable<T> Values<T>(this DataColumn column) + { + return column.Table.AsEnumerable().Select(r => r.Field<T>(column)); + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index 606b12659b4fc16cfafd2a2333e3af8af13e74f9..37b29bd5eefecc2923da06e6fdc040f286f71cc5 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -126,6 +126,7 @@ <Compile Include="Models\Declaration\HVAC.cs" /> <Compile Include="Models\Declaration\PneumaticSystem.cs" /> <Compile Include="Models\Declaration\SteeringPump.cs" /> + <Compile Include="Models\Declaration\WHTCCorrection.cs" /> <Compile Include="Models\SimulationComponent\Data\AccelerationCurve.cs" /> <Compile Include="Models\Declaration\DeclarationData.cs" /> <Compile Include="Models\Declaration\PT1.cs" /> @@ -213,7 +214,7 @@ <Compile Include="Models\Simulation\Cockpit\IVehicleCockpit.cs" /> <Compile Include="Models\Simulation\IVehicleContainer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="Utils\DataRowExtensionMethods.cs" /> + <Compile Include="Utils\DataTableExtensionMethods.cs" /> <Compile Include="Utils\StringExtensionMethods.cs" /> <Compile Include="Utils\VectoCSVFile.cs" /> <Compile Include="Utils\VectoMath.cs" /> diff --git a/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs b/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs index 7a7bbbadb579358282ce1cc882170a44ab1a3ab5..9aee17b3e68e0407a9d1ea36c074dd080b46e744 100644 --- a/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs +++ b/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs @@ -98,11 +98,9 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var urban = r.NextDouble() * 2; var rural = r.NextDouble() * 2; var motorway = r.NextDouble() * 2; - double whtcValue = whtc.Lookup(missions[i], urban, rural, motorway); + var whtcValue = whtc.Lookup(missions[i], urban, rural, motorway); Assert.AreEqual(urban * factors.urban[i] + rural * factors.rural[i] + motorway * factors.motorway[i], whtcValue); } - - Assert.Inconclusive(); } [TestMethod] diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index 2b918ed8dd88c8bdf460c307819c609f4b9354d1..45350cecd61bd0d73d726f1ed73dc169f8235db5 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -70,7 +70,7 @@ <ItemGroup> <Compile Include="Exceptions\ExceptionTests.cs" /> <Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" /> - <Compile Include="Models\DeclarationData\DeclarationDataTest.cs" /> + <Compile Include="Models\Declaration\DeclarationDataTest.cs" /> <Compile Include="Models\SimulationComponentData\AccelerationCurveTest.cs" /> <Compile Include="Models\SimulationComponentData\FuelConsumptionMapTest.cs" /> <Compile Include="Models\SimulationComponentData\FullLoadCurveTest.cs" />