4using System.Collections.Generic;
5using System.Globalization;
8using System.Threading.Tasks;
9using System.Reflection;
17 public Helpers
Helper =
new Helpers();
49 List<double> Velocity,
50 List<double> Gradient,
51 out List<VehicleResult> VehicleResultsOrg,
52 bool fleetMix =
false,
54 string CommentPref =
"c")
59 List<VehicleResult> _VehicleResult =
new List<VehicleResult>();
65 Helper.CommentPrefix = CommentPref;
68 for (i = 0; i < DataFiles.Count; i++)
70 if ((DataFiles[i].LastIndexOf(
@"\")) >= 0)
77 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
78 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
79 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
97 VehicleResultsOrg =
null;
103 VehicleResultsOrg =
null;
113 VehicleResultsOrg =
null;
123 VehicleResultsOrg =
null;
129 for (i = 1; i <= Time.Count - 1; i++)
132 acc = (Velocity[i] - Velocity[i - 1]) / (Time[i] - Time[i - 1]);
143 VehicleResultsOrg =
null;
147 VehicleResultsOrg = _VehicleResult;
157 out List<VehicleResult> VehicleResultsOrg,
158 bool fleetMix =
false,
160 string CommentPref =
"c")
163 List<VehicleResult> _VehicleResult =
new List<VehicleResult>();
164 VehicleResultsOrg = _VehicleResult;
167 Helper.CommentPrefix = CommentPref;
170 for (
int i = 0; i < DataFiles.Count; i++)
172 if ((DataFiles[i].LastIndexOf(
@"\")) >= 0)
179 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
180 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
181 _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(
@"\")));
191 Helper.gClass =
"AggClass_" + DataFiles[0];
199 VehicleResultsOrg =
null;
205 VehicleResultsOrg =
null;
215 VehicleResultsOrg =
null;
225 VehicleResultsOrg =
null;
237 VehicleResultsOrg = _VehicleResult;
243 private Dictionary<string, cErgEntry>
ErgEntries =
new Dictionary<string, cErgEntry>();
247 private void AddToErg(
string IDstring,
string Head,
string Unit)
251 ErgEntries.Add(IDstring,
new cErgEntry(Head, Unit));
260 StringBuilder s =
new StringBuilder();
266 key = key_loopVariable;
280 StringBuilder s =
new StringBuilder();
286 key = key_loopVariable;
298 private void OutSeq(VehicleResult _VehicleResult,
bool STA =
false,
bool add =
false)
301 List<string> OutSeqStr =
new List<string> {
"FC",
"FC_EL",
"CO2",
"NOX",
"CO",
"HC",
"PM",
"PN" };
303 if (STA) Unit =
"/h";
311 AddToErg(
"FC",
"FC",
"[g" + Unit +
"]");
312 AddToErg(
"FC_EL",
"Engine Power",
"[kWh" + Unit +
"]");
313 AddToErg(
"CO2",
"CO2",
"[g" + Unit +
"]");
314 AddToErg(
"NOX",
"NOx",
"[g" + Unit +
"]");
315 AddToErg(
"CO",
"CO",
"[g" + Unit +
"]");
316 AddToErg(
"HC",
"HC",
"[g" + Unit +
"]");
317 AddToErg(
"PM",
"PM",
"[g" + Unit +
"]");
318 AddToErg(
"PN",
"PN",
"[#" + Unit +
"]");
320 foreach (
string id in _VehicleResult.EmissionData.Emi.Keys)
322 if (!OutSeqStr.Contains(
id))
AddToErg(
id.ToUpper(),
id,
"[g" + Unit +
"]");
327 foreach (
string id in _VehicleResult.EmissionData.Emi.Keys)
329 if (!
ErgEntries.ContainsKey(
id.ToUpper()))
AddToErg(
id.ToUpper(),
id,
"[g" + Unit +
"]");
335 public bool ExportData(
string path, List<VehicleResult> _VehicleResult)
337 if (path ==
null || _VehicleResult ==
null || _VehicleResult.Count == 0)
return false;
340 StringBuilder allLines =
new StringBuilder();
341 string lineEnding =
"\r\n";
344 OutSeq(_VehicleResult[0],
true);
347 allLines.AppendLine(
"Vehicletype: ," + _VehicleResult[0].
Vehicle);
350 allLines.AppendLine(
"Time, Speed, Gradient, Accelaration, Engine power raw, P_pos, P_norm_rated, P_norm_drive," +
ErgHead());
351 allLines.AppendLine(
"[s], [m/s], [%], [m/s^2], [kW], [kW], [-], [-]," +
ErgUnits());
354 foreach (VehicleResult Result
in _VehicleResult)
356 allLines.Append(Result.Time.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
357 allLines.Append(Result.Speed.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
358 allLines.Append(Result.Grad.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
359 allLines.Append(Result.Accelaration.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
360 allLines.Append(Result.Power.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
361 allLines.Append(Result.PPos.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
362 allLines.Append(Result.PNormRated.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
363 allLines.Append(Result.PNormDrive.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
366 if (Result.EmissionData.Emi.ContainsKey(
id))
367 allLines.Append(Result.EmissionData.Emi[
id].ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
369 allLines.Append(
"-,");
371 allLines.Append(lineEnding);
375 if (path.IndexOf(
".", 0) < 0)
377 path = path +
".sta";
381 StreamWriter file =
new StreamWriter(path);
382 file.WriteLine(allLines);
395 if (path ==
null || _VehicleResult ==
null)
return false;
396 StringBuilder allLines =
new StringBuilder();
398 if (path.IndexOf(
".", 0) < 0)
400 path = path +
".erg";
404 OutSeq(_VehicleResult[0],
false);
405 foreach (VehicleResult Result
in _VehicleResult)
407 OutSeq(Result,
false,
true);
410 if (!File.Exists(path))
413 allLines.AppendLine(
"PHEMLight Results");
414 allLines.AppendLine(
"");
415 allLines.AppendLine(
"Vehicle, Cycle, Time, Speed, Gradient, Accelaration, Engine power raw, P_pos, P_norm_rated, P_norm_drive," +
ErgHead());
416 allLines.AppendLine(
"[-], [-], [s], [km/h], [%], [m/s^2], [kW], [kW], [-], [-]," +
ErgUnits());
420 foreach (VehicleResult Result
in _VehicleResult)
422 allLines.Append(Result.Vehicle +
",");
423 allLines.Append(Result.Cycle +
",");
424 allLines.Append(Result.Time.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
425 allLines.Append(Result.Speed.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
426 allLines.Append(Result.Grad.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
427 allLines.Append(Result.Accelaration.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
428 allLines.Append(Result.Power.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
429 allLines.Append(Result.PPos.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
430 allLines.Append(Result.PNormRated.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
431 allLines.Append(Result.PNormDrive.ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
434 if (Result.EmissionData.Emi.ContainsKey(
id))
435 allLines.Append(Result.EmissionData.Emi[
id].ToString(
"0.0000", CultureInfo.InvariantCulture) +
",");
437 allLines.Append(
"-,");
439 allLines.Append(
"\r\n");
444 StreamWriter file =
new StreamWriter(path,
true);
445 file.WriteLine(allLines);
461 double sum_speed = 0;
463 double sum_power = 0;
465 double sum_pNormRated = 0;
466 double sum_pNormDrive = 0;
468 Dictionary<string, double> sum_Emi =
new Dictionary<string, double>();
470 if (_VehicleResult ==
null || _VehicleResult.Count == 0)
return new VehicleResult(
"",
"", 0, 0, 0, 0, 0, 0, 0, 0, sum_Emi);
473 vehicle = _VehicleResult[0].Vehicle;
474 cycle = _VehicleResult[0].Cycle;
477 foreach (VehicleResult Result
in _VehicleResult)
479 sum_speed += Result.Speed * 3.6;
480 sum_power += Result.Power;
481 if (Result.PPos > 0) { sum_pPos += Result.PPos; }
482 sum_grad += Result.Grad;
483 sum_pNormRated += Result.PNormRated;
484 sum_pNormDrive += Result.PNormDrive;
485 sum_acc += Result.Accelaration;
486 foreach(
string id in Result.EmissionData.Emi.Keys)
488 if (sum_Emi.ContainsKey(
id))
489 sum_Emi[id] += Result.EmissionData.Emi[id];
491 sum_Emi.Add(
id, Result.EmissionData.Emi[
id]);
496 sum_time = _VehicleResult[_VehicleResult.Count - 1].Time - _VehicleResult[0].Time;
497 sum_power /= _VehicleResult.Count;
498 sum_pPos /= _VehicleResult.Count;
499 sum_grad /= _VehicleResult.Count;
500 sum_pNormRated /= _VehicleResult.Count;
501 sum_pNormDrive /= _VehicleResult.Count;
502 sum_acc /= _VehicleResult.Count;
505 foreach (
string id in sum_Emi.Keys.ToList())
507 sum_Emi[id] /= sum_speed;
512 foreach (
string id in sum_Emi.Keys)
517 sum_speed /= _VehicleResult.Count;
519 return new VehicleResult(vehicle,
537 #region CreateVehicleStateData
544 Correction DataCor =
null)
547 double speed = Math.Max(inputSpeed, 0);
555 acc = Math.Min(inputAcc, currCep.GetMaxAccel(speed, Gradient, (Helper.pClass == Constants.strBEV | Helper.uClass == Constants.strHybrid)));
558 double power = currCep.CalcPower(speed, acc, Gradient, (Helper.pClass == Constants.strBEV | Helper.uClass == Constants.strHybrid));
559 double P_eng = currCep.CalcEngPower(power);
561 if (Helper.uClass == Constants.strHybrid) Pwheel = currCep.CalcWheelPower(speed, acc, Gradient);
569 if (Helper.pClass == Constants.strBEV)
571 return new VehicleResult(Helper.gClass,
578 P_eng / currCep.RatedPower,
579 P_eng / currCep.DrivingPower,
581 currCep.GetAllEmission(P_eng, speed, Helper));
585 double decelCoast = currCep.GetDecelCoast(speed, acc, Gradient);
588 if (acc >= decelCoast || speed <= Constants.ZERO_SPEED_ACCURACY)
590 if (Helper.uClass == Constants.strHybrid)
591 return new VehicleResult(Helper.gClass,
598 P_eng / currCep.RatedPower,
599 P_eng / currCep.DrivingPower,
601 currCep.GetAllEmission(Pwheel, speed, Helper));
603 return new VehicleResult(Helper.gClass,
610 P_eng / currCep.RatedPower,
611 P_eng / currCep.DrivingPower,
613 currCep.GetAllEmission(P_eng, speed, Helper));
617 if (Helper.uClass == Constants.strHybrid)
618 return new VehicleResult(Helper.gClass,
625 P_eng / currCep.RatedPower,
626 P_eng / currCep.DrivingPower,
628 currCep.GetAllEmission(Pwheel, speed, Helper,
true));
630 return new VehicleResult(Helper.gClass,
637 P_eng / currCep.RatedPower,
638 P_eng / currCep.DrivingPower,
640 currCep.GetAllEmission(P_eng, speed, Helper,
true));
void AddToErg(string IDstring, string Head, string Unit)
void OutSeq(VehicleResult _VehicleResult, bool STA=false, bool add=false)
List< string > ErgEntryList
Dictionary< string, cErgEntry > ErgEntries
static VehicleResult CreateVehicleStateData(Helpers Helper, CEP currCep, double time, double inputSpeed, double inputAcc, double Gradient=0)
static VehicleResult CreateVehicleStateData(Helpers Helper, CEP currCep, double time, double inputSpeed, double inputAcc, double Gradient=0, Correction DataCor=null)
Dictionary< string, CEP > CEPS
bool GetFleetCEP(string DataPath, string AggClass, Helpers Helper)
bool GetCEP(const std::vector< std::string > &DataPath, Helpers *Helper)
bool setclass(const std::string &VEH)
bool CALC_Array(List< string > DataFiles, List< double > Time, List< double > Velocity, List< double > Gradient, out List< VehicleResult > VehicleResultsOrg, bool fleetMix=false, Correction DataCor=null, string CommentPref="c")
C++ TraCI client API implementation.
bool ExportData(string path, string vehicle, List< VehicleResult > _VehicleResult)
VehicleResult GenerateSumData(List< VehicleResult > _VehicleResult)
bool ExportSumData(string path, string vehicle, string cycle, VehicleResult _VehicleResult)
bool CALC_Single(List< string > DataFiles, double Time, double Velocity, double acc, double Gradient, out List< VehicleResult > VehicleResultsOrg, bool fleetMix=false, string CommentPref="c")