Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

further triangulation

parent 367d8784
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
if (entry.FuelConsumption < 0)
throw new ArgumentOutOfRangeException("FuelConsumption < 0" + data.Rows.IndexOf(row));
fuelConsumptionMap._entries.Add(entry);
fuelConsumptionMap._fuelMap.AddPoints(entry.EngineSpeed, entry.Torque, entry.FuelConsumption);
}
catch (Exception e)
{
......@@ -73,25 +74,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
throw new VectoException(string.Format("File {0}: {1}", fileName, e.Message), e);
}
fuelConsumptionMap.Triangulate();
fuelConsumptionMap._fuelMap.Triangulate();
return fuelConsumptionMap;
}
private void Triangulate()
{
foreach (var entry in _entries)
{
_fuelMap.AddPoints(entry.EngineSpeed, entry.Torque, entry.FuelConsumption);
}
_fuelMap.Triangulate();
}
public double GetFuelConsumption(double engineSpeed, double torque)
{
return _fuelMap.Intpol(engineSpeed, torque);
return _fuelMap.Interpolate(engineSpeed, torque);
}
}
}
......@@ -30,44 +30,51 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// </remarks>
public static DataTable Read(string fileName)
{
var lines = File.ReadAllLines(fileName);
var header = lines.First();
header = Regex.Replace(header, @"\[.*?\]", "");
header = Regex.Replace(header, @"\(.*?\)", "");
header = header.Replace("<", "");
header = header.Replace(">", "");
// or all in one regex (incl. trim):
// Regex.Replace(header, @"\s*\[.*?\]\s*|\s*\(.*?\)\s*|\s*<|>\s*|\s*(?=,)|(?<=,)\s*", "");
var cols = header.Split(Separator);
try
{
var lines = File.ReadAllLines(fileName);
var header = lines.First();
header = Regex.Replace(header, @"\[.*?\]", "");
header = Regex.Replace(header, @"\(.*?\)", "");
header = header.Replace("<", "");
header = header.Replace(">", "");
// or all in one regex (incl. trim):
// Regex.Replace(header, @"\s*\[.*?\]\s*|\s*\(.*?\)\s*|\s*<|>\s*|\s*(?=,)|(?<=,)\s*", "");
var cols = header.Split(Separator);
var table = new DataTable();
foreach (var col in cols)
table.Columns.Add(col.Trim(), typeof(string));
var table = new DataTable();
foreach (var col in cols)
table.Columns.Add(col.Trim(), typeof(string));
// skip header! --> begin with index 1
for (int i = 1; i < lines.Length; i++)
{
string line = lines[i];
//todo: do more sophisticated splitting of csv-columns (or use a good csv library!)
// skip header! --> begin with index 1
for (int i = 1; i < lines.Length; i++)
{
string line = lines[i];
//todo: do more sophisticated splitting of csv-columns (or use a good csv library!)
if (line.Contains(Comment))
line = line.Substring(0, line.IndexOf(Comment));
if (line.Contains(Comment))
line = line.Substring(0, line.IndexOf(Comment));
var cells = line.Split(Separator);
if (cells.Length != cols.Length)
throw new CSVReadException("The number of values is not correct. Line: " + i);
var cells = line.Split(Separator);
if (cells.Length != cols.Length)
throw new CSVReadException(string.Format("Line {0}: The number of values is not correct.", i));
try
{
table.Rows.Add(line.Split(Separator));
}
catch (InvalidCastException e)
{
throw new CSVReadException("The data format of a value is not correct. Line " + i, e);
try
{
table.Rows.Add(line.Split(Separator));
}
catch (InvalidCastException e)
{
throw new CSVReadException(string.Format("Line {0}: The data format of a value is not correct. {1}", i, e.Message), e);
}
}
}
return table;
return table;
}
catch (Exception e)
{
throw new VectoException(string.Format("File {0}: {1}", fileName, e.Message));
}
}
}
}
\ No newline at end of file
This diff is collapsed.
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