Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

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

corrected AuxModData Test (works now with SI units in moddata)

parent 3eaf08af
Branches
Tags
No related merge requests found
...@@ -46,49 +46,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -46,49 +46,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public static class ModalDataWriterExtensions public static class ModalDataWriterExtensions
{ {
public static double? Max(this IModalDataWriter data, ModalResultField field) public static SI Max(this IModalDataWriter data, ModalResultField field)
{ {
var val = data.GetValues<SI>(field).Max(); return data.GetValues<SI>(field).Max();
if (val != null) {
return val.Value();
}
return null;
} }
public static double? Average(this IModalDataWriter data, ModalResultField field, Func<SI, bool> filter = null) public static SI Average(this IModalDataWriter data, ModalResultField field, Func<SI, bool> filter = null)
{ {
var val = data.GetValues<SI>(field).Where(filter ?? (x => x != null)).ToList(); return data.GetValues<SI>(field).Average(filter);
if (val.Any()) {
return val.ToDouble().Average();
}
return null;
} }
public static double? Sum(this IModalDataWriter data, ModalResultField field, Func<SI, bool> filter = null) public static SI Sum(this IModalDataWriter data, ModalResultField field, Func<SI, bool> filter = null)
{ {
var val = data.GetValues<SI>(field).Where(filter ?? (x => x != null)).ToList(); return data.GetValues<SI>(field).Where(filter ?? (x => x != null)).Sum();
if (val.Any()) {
return val.ToDouble().Sum();
}
return null;
} }
public static double? Sum(this IModalDataWriter data, DataColumn col, Func<SI, bool> filter = null) public static SI Sum(this IModalDataWriter data, DataColumn col, Func<SI, bool> filter = null)
{ {
var val = data.GetValues<SI>(col).Where(filter ?? (x => x != null)).ToList(); return data.GetValues<SI>(col).Where(filter ?? (x => x != null)).Sum();
if (val.Any()) {
return val.ToDouble().Sum();
}
return null;
} }
public static double? Average(this IEnumerable<SI> self, Func<SI, bool> filter = null) public static SI Average(this IEnumerable<SI> self, Func<SI, bool> filter = null)
{ {
var val = self.Where(filter ?? (x => x != null)).ToList(); var values = self.Where(filter ?? (x => x != null)).ToList();
if (val.Any()) { return values.Any() ? values.Sum() / values.Count : null;
return val.ToDouble().Average();
}
return null;
} }
public static object DefaultIfNull(this object self) public static object DefaultIfNull(this object self)
......
...@@ -82,11 +82,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -82,11 +82,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
_table.Columns.AddRange(new[] { _table.Columns.AddRange(new[] {
TIME, DISTANCE, SPEED, ALTITUDE, PPOS, PNEG, FCMAP, FCMAPKM, FCAUXC, FCAUXCKM, FCWHTCC, FCWHTCCKM, PWHEELPOS, PBRAKE, TIME, DISTANCE, SPEED, ALTITUDE, PPOS, PNEG, FCMAP, FCMAPKM, FCAUXC, FCAUXCKM, FCWHTCC, FCWHTCCKM, PWHEELPOS, PBRAKE,
EPOSICE, EPOSICE, ENEGICE, EAIR, EROLL, EGRAD, EACC, EAUX, EBRAKE, ETRANSM, ERETARDER, MASS, LOADING, A, APOS, ANEG, PACC,
ENEGICE, EAIR, EROLL, EGRAD, EACC, EAUX, EBRAKE, ETRANSM, ERETARDER, MASS, LOADING, A, APOS, ANEG, PACC, PDEC, PDEC, PCRUISE, PSTOP, ETORQUECONV, CO2, CO2T, FCFINAL, FCFINAL_LITER, FCFINAL_LITERPER100TKM, ACCNOISE
PCRUISE, PSTOP, ETORQUECONV, CO2, }.Select(x => new DataColumn(x, typeof(SI))).ToArray());
CO2T, FCFINAL, FCFINAL_LITER, FCFINAL_LITERPER100TKM, ACCNOISE
}.Select(x => new DataColumn(x, typeof(double))).ToArray());
} }
protected internal void WriteEngineOnly(IModalDataWriter data, string jobFileName, string jobName, protected internal void WriteEngineOnly(IModalDataWriter data, string jobFileName, string jobName,
...@@ -97,11 +95,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -97,11 +95,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
row[INPUTFILE] = jobFileName; row[INPUTFILE] = jobFileName;
row[CYCLE] = cycleFileName; row[CYCLE] = cycleFileName;
row[TIME] = data.GetValues<SI>(ModalResultField.time).Max(); row[TIME] = data.GetValues<SI>(ModalResultField.time).Max();
row[PPOS] = data.GetValues<SI>(ModalResultField.Pe_eng).Where(x => x > 0).ToDouble().Average(); row[PPOS] = data.GetValues<SI>(ModalResultField.Pe_eng).Where(x => x > 0).Average();
row[PNEG] = data.GetValues<SI>(ModalResultField.Pe_eng).Where(x => x < 0).ToDouble().Average(); row[PNEG] = data.GetValues<SI>(ModalResultField.Pe_eng).Where(x => x < 0).Average();
row[FCMAP] = data.GetValues<SI>(ModalResultField.FCMap).ToDouble().Average(); row[FCMAP] = data.GetValues<SI>(ModalResultField.FCMap).Average();
row[FCAUXC] = data.GetValues<SI>(ModalResultField.FCAUXc).ToDouble().Average(); row[FCAUXC] = data.GetValues<SI>(ModalResultField.FCAUXc).Average();
row[FCWHTCC] = data.GetValues<SI>(ModalResultField.FCWHTCc).ToDouble().Average(); row[FCWHTCC] = data.GetValues<SI>(ModalResultField.FCWHTCc).Average();
WriteAuxiliaries(data, row); WriteAuxiliaries(data, row);
...@@ -112,11 +110,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -112,11 +110,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
{ {
_auxColumns = _auxColumns.Union(data.Auxiliaries.Select(kv => "Eaux_" + kv.Key + " [kwh]")).ToList(); _auxColumns = _auxColumns.Union(data.Auxiliaries.Select(kv => "Eaux_" + kv.Key + " [kwh]")).ToList();
double? sum = 0.0; var sum = 0.SI<Watt>();
foreach (var aux in data.Auxiliaries) { foreach (var aux in data.Auxiliaries) {
var colName = "Eaux_" + aux.Key + " [kWh]"; var colName = "Eaux_" + aux.Key + " [kWh]";
if (!_table.Columns.Contains(colName)) { if (!_table.Columns.Contains(colName)) {
_table.Columns.Add(colName, typeof(double)); _table.Columns.Add(colName, typeof(SI));
} }
var currentSum = data.Sum(aux.Value); var currentSum = data.Sum(aux.Value);
...@@ -153,9 +151,19 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -153,9 +151,19 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
row[EGRAD] = data.Sum(ModalResultField.Pgrad).DefaultIfNull(); row[EGRAD] = data.Sum(ModalResultField.Pgrad).DefaultIfNull();
row[EAUX] = data.Sum(ModalResultField.Paux).DefaultIfNull(); row[EAUX] = data.Sum(ModalResultField.Paux).DefaultIfNull();
row[EBRAKE] = data.Sum(ModalResultField.Pbrake).DefaultIfNull(); row[EBRAKE] = data.Sum(ModalResultField.Pbrake).DefaultIfNull();
row[ETRANSM] = (data.Sum(ModalResultField.PlossDiff) + data.Sum(ModalResultField.PlossGB)).DefaultIfNull();
var plossdiff = data.Sum(ModalResultField.PlossDiff);
var plossgb = data.Sum(ModalResultField.PlossGB);
if ((plossdiff ?? plossgb) != null) {
row[ETRANSM] = plossdiff ?? 0.SI() + plossgb ?? 0.SI();
}
row[ERETARDER] = data.Sum(ModalResultField.PlossRetarder).DefaultIfNull(); row[ERETARDER] = data.Sum(ModalResultField.PlossRetarder).DefaultIfNull();
row[EACC] = (data.Sum(ModalResultField.PaEng) + data.Sum(ModalResultField.PaGB)).DefaultIfNull();
var paeng = data.Sum(ModalResultField.PaEng);
var pagb = data.Sum(ModalResultField.PaGB);
if ((paeng ?? pagb) != null) {
row[EACC] = paeng ?? 0.SI() + pagb ?? 0.SI();
}
//todo altitude - calculate when reading the cycle file, add column for altitude //todo altitude - calculate when reading the cycle file, add column for altitude
//row["∆altitude [m]"] = Data.Rows[Data.Rows.Count - 1].Field<double>("altitude") - //row["∆altitude [m]"] = Data.Rows[Data.Rows.Count - 1].Field<double>("altitude") -
...@@ -164,30 +172,35 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -164,30 +172,35 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
WriteAuxiliaries(data, row); WriteAuxiliaries(data, row);
//todo get data from vehicle file //todo get data from vehicle file
row[MASS] = vehicleMass == null ? "" : vehicleMass.Value().ToString(CultureInfo.InvariantCulture); if (vehicleMass != null) {
row[LOADING] = vehicleLoading == null ? "" : vehicleLoading.Value().ToString(CultureInfo.InvariantCulture); row[MASS] = vehicleMass;
}
if (vehicleLoading != null) {
row[LOADING] = vehicleLoading;
}
var dtValues = data.GetValues<SI>(ModalResultField.simulationInterval).ToList(); var dtValues = data.GetValues<SI>(ModalResultField.simulationInterval).ToList();
var accValues = data.GetValues<SI>(ModalResultField.acc); var accValues = data.GetValues<SI>(ModalResultField.acc);
var accelerations = CalculateAverageOverSeconds(dtValues, accValues).ToList(); var accelerations = CalculateAverageOverSeconds(dtValues, accValues).ToList();
if (accelerations.Any()) { if (accelerations.Any()) {
row[A] = accelerations.ToDouble().Average(); row[A] = accelerations.Average();
} }
var acceleration3SecondAverage = Calculate3SecondAverage(accelerations).ToList(); var acceleration3SecondAverage = Calculate3SecondAverage(accelerations).ToList();
if (acceleration3SecondAverage.Any()) {
row[APOS] = acceleration3SecondAverage.Average(x => x > 0.125).DefaultIfNull(); row[APOS] = acceleration3SecondAverage.Average(x => x > 0.125).DefaultIfNull();
row[ANEG] = acceleration3SecondAverage.Average(x => x < -0.125).DefaultIfNull(); row[ANEG] = acceleration3SecondAverage.Average(x => x < -0.125).DefaultIfNull();
row[PACC] = 100.0 * acceleration3SecondAverage.Count(x => x > 0.125) / acceleration3SecondAverage.Count; row[PACC] = 100.SI() * acceleration3SecondAverage.Count(x => x > 0.125) / acceleration3SecondAverage.Count;
row[PDEC] = 100.0 * acceleration3SecondAverage.Count(x => x < -0.125) / acceleration3SecondAverage.Count; row[PDEC] = 100.SI() * acceleration3SecondAverage.Count(x => x < -0.125) / acceleration3SecondAverage.Count;
row[PCRUISE] = 100.0 * acceleration3SecondAverage.Count(x => x < 0.125 && x > -0.125) / row[PCRUISE] = 100.SI() * acceleration3SecondAverage.Count(x => x < 0.125 && x > -0.125) /
acceleration3SecondAverage.Count; acceleration3SecondAverage.Count;
}
var pStopTime = data.GetValues<SI>(ModalResultField.v_act) var pStopTime = data.GetValues<SI>(ModalResultField.v_act)
.Zip(dtValues, (velocity, dt) => new { velocity, dt }) .Zip(dtValues, (velocity, dt) => new { velocity, dt })
.Where(x => x.velocity < 0.1) .Where(x => x.velocity < 0.1)
.Sum(x => x.dt.Value()); .Sum(x => x.dt.Value());
row[PSTOP] = 100.0 * pStopTime / dtValues.ToDouble().Sum(); row[PSTOP] = 100 * pStopTime / dtValues.Sum();
_table.Rows.Add(row); _table.Rows.Add(row);
} }
......
...@@ -143,7 +143,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -143,7 +143,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} catch (VectoException ex) { } catch (VectoException ex) {
Log.WarnFormat("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime, ex.Message, Log.WarnFormat("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime, ex.Message,
_currentState.EngineSpeed, _currentState.EngineTorque); _currentState.EngineSpeed, _currentState.EngineTorque);
writer[ModalResultField.FCMap] = double.NaN; writer[ModalResultField.FCMap] = double.NaN.SI();
} }
} }
......
using System; using System;
using System.Collections.Generic;
using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Connector.Ports.Impl;
...@@ -17,10 +18,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -17,10 +18,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{ {
protected DrivingCycleData Data; protected DrivingCycleData Data;
private ITnOutPort _outPort; private ITnOutPort _outPort;
private IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSample { get; set; }
private IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSample { get; set; }
public EngineOnlySimulation(IVehicleContainer container, DrivingCycleData cycle) : base(container) public EngineOnlySimulation(IVehicleContainer container, DrivingCycleData cycle) : base(container)
{ {
Data = cycle; Data = cycle;
LeftSample = Data.Entries.GetEnumerator();
LeftSample.MoveNext();
RightSample = Data.Entries.GetEnumerator();
RightSample.MoveNext();
RightSample.MoveNext();
} }
#region ITnInProvider #region ITnInProvider
...@@ -79,14 +89,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -79,14 +89,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected override void DoWriteModalResults(IModalDataWriter writer) {} protected override void DoWriteModalResults(IModalDataWriter writer) {}
protected override void DoCommitSimulationStep() {} protected override void DoCommitSimulationStep()
{
LeftSample.MoveNext();
RightSample.MoveNext();
}
#endregion #endregion
public CycleData CycleData() public CycleData CycleData()
{ {
//todo EngineOnlyDrivingCycle.CycleData return new CycleData {
throw new NotImplementedException(); AbsTime = LeftSample.Current.Time,
AbsDistance = null,
LeftSample = LeftSample.Current,
RightSample = RightSample.Current,
};
} }
} }
} }
\ No newline at end of file
...@@ -42,9 +42,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -42,9 +42,10 @@ namespace TUGraz.VectoCore.Utils
} }
} }
public static T Sum<T>(this IEnumerable<T> list) where T : SIBase<T> public static SI Sum(this IEnumerable<SI> values)
{ {
return list.Aggregate((sum, current) => sum + current); var valueList = values.ToList();
return valueList.Any() ? valueList.Aggregate((sum, current) => sum + current) : null;
} }
public static Func<bool> Once() public static Func<bool> Once()
......
...@@ -47,10 +47,12 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation ...@@ -47,10 +47,12 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var speed = 1400.RPMtoRad(); var speed = 1400.RPMtoRad();
var torque = 500.SI<NewtonMeter>(); var torque = 500.SI<NewtonMeter>();
var t = 0.SI<Second>(); var t = 0.SI<Second>();
var dt = 1.SI<Second>();
for (var i = 0; i < data.Entries.Count; i++) { for (var i = 0; i < data.Entries.Count; i++) {
aux.OutPort().Request(t, t, torque, speed); aux.OutPort().Request(t, t, torque, speed);
container.CommitSimulationStep(t, t); container.CommitSimulationStep(t, dt);
t += dt;
} }
container.FinishSimulation(); container.FinishSimulation();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment