4 using System.Collections.Generic;
5 using System.Globalization;
8 using System.Threading.Tasks;
9 using 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>();
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;
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(
@"\")));
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)
260 StringBuilder s =
new StringBuilder();
266 key = key_loopVariable;
280 StringBuilder s =
new StringBuilder();
286 key = key_loopVariable;
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 +
"]");
322 if (!OutSeqStr.Contains(
id))
AddToErg(
id.ToUpper(),
id,
"[g" + Unit +
"]");
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());
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) +
",");
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);
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());
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) +
",");
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;
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;
488 if (sum_Emi.ContainsKey(
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;
537 #region CreateVehicleStateData
547 double speed = Math.Max(inputSpeed, 0);
585 double decelCoast = currCep.
GetDecelCoast(speed, acc, Gradient);
bool ReadFleetShares(string DataPath, Helpers Helper)
Dictionary< string, CEP > CEPS
bool GetFleetCEP(string DataPath, string AggClass, Helpers Helper)
bool GetCEP(const std::vector< std::string > &DataPath, Helpers *Helper)
Dictionary< string, double > GetAllEmission(double power, double speed, Helpers VehicleClass, bool SetZero=false)
double GetMaxAccel(double speed, double gradient)
double CalcWheelPower(double speed, double acc, double gradient)
double CalcEngPower(double power)
double CalcPower(double speed, double acc, double gradient)
double GetDecelCoast(double speed, double acc, double gradient)
static const std::string strBEV
static const double ZERO_SPEED_ACCURACY
static const std::string strHybrid
Dictionary< string, double > Emi
bool setclass(const std::string &VEH)
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)
bool CALC_Single(List< string > DataFiles, double Time, double Velocity, double acc, double Gradient, out List< VehicleResult > VehicleResultsOrg, bool fleetMix=false, Correction DataCor=null, string CommentPref="c")
Dictionary< string, cErgEntry > ErgEntries
List< string > ErgEntryList
void OutSeq(VehicleResult _VehicleResult, bool STA=false, bool add=false)
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")
void AddToErg(string IDstring, string Head, string Unit)
VehicleResult GenerateSumData(List< VehicleResult > _VehicleResult)
bool ExportSumData(string path, List< VehicleResult > _VehicleResult)
bool ExportData(string path, List< VehicleResult > _VehicleResult)
EmissionData EmissionData
C++ TraCI client API implementation.