Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0592bdc1 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

fix: use cultureinvariant parse for environmental conditions map and...

fix: use cultureinvariant parse for environmental conditions map and pneumatics compressor map, adapt exception in testcase due to changes in parsing
parent 578b8550
No related branches found
No related tags found
No related merge requests found
...@@ -14,429 +14,426 @@ Imports System.Globalization ...@@ -14,429 +14,426 @@ Imports System.Globalization
Namespace Electrics Namespace Electrics
Public Class CombinedAlternator
Implements IAlternatorMap, ICombinedAlternator
Public Class CombinedAlternator Private map As New List(Of ICombinedAlternatorMapRow)
Implements IAlternatorMap, ICombinedAlternator Public Property Alternators As New List(Of IAlternator) Implements ICombinedAlternator.Alternators
Private OriginalAlternators As New List(Of IAlternator)
Private FilePath As String
Private altSignals As ICombinedAlternatorSignals
Private Signals As ISignals
Private AverageAlternatorsEfficiency As AlternatorMapValues
Private map As New List(Of ICombinedAlternatorMapRow) 'Interface Implementation
Public Property Alternators As New List(Of IAlternator) Implements ICombinedAlternator.Alternators Public Function GetEfficiency(ByVal CrankRPM As Single, ByVal Amps As Single) As AlternatorMapValues _
Private OriginalAlternators As New List(Of IAlternator) Implements IAlternatorMap.GetEfficiency
Private FilePath As String
Private altSignals As ICombinedAlternatorSignals
Private Signals As ISignals
Private AverageAlternatorsEfficiency As AlternatorMapValues
'Interface Implementation altSignals.CrankRPM = CrankRPM
Public Function GetEfficiency(ByVal CrankRPM As Single, ByVal Amps As Single) As AlternatorMapValues Implements IAlternatorMap.GetEfficiency altSignals.CurrentDemandAmps = Amps / Alternators.Count
altSignals.CrankRPM = CrankRPM Dim alternatorMapValues As AlternatorMapValues = Nothing
altSignals.CurrentDemandAmps = Amps / Alternators.Count
Dim alternatorMapValues As AlternatorMapValues = Nothing If Signals Is Nothing OrElse Signals.RunningCalc Then
'If running calc cycle get efficiency from interpolation function
alternatorMapValues = New AlternatorMapValues(Convert.ToSingle(Alternators.Average(Function(a) a.Efficiency) / 100))
Else
'If running Pre calc cycle get an average of inputs
alternatorMapValues = AverageAlternatorsEfficiency
End If
If Signals Is Nothing OrElse Signals.RunningCalc Then If alternatorMapValues.Efficiency <= 0 Then
'If running calc cycle get efficiency from interpolation function alternatorMapValues = New AlternatorMapValues(0.01)
alternatorMapValues = New AlternatorMapValues(Convert.ToSingle(Alternators.Average(Function(a) a.Efficiency) / 100)) End If
Else
'If running Pre calc cycle get an average of inputs
alternatorMapValues = AverageAlternatorsEfficiency
End If
If alternatorMapValues.Efficiency <= 0 Then Return alternatorMapValues
alternatorMapValues = New AlternatorMapValues(0.01) End Function
End If
Return alternatorMapValues Public Function Initialise() As Boolean Implements IAlternatorMap.Initialise
End Function 'From the map we construct this CombinedAlternator object and original CombinedAlternator Object
Public Function Initialise() As Boolean Implements IAlternatorMap.Initialise
'From the map we construct this CombinedAlternator object and original CombinedAlternator Object Alternators.Clear()
OriginalAlternators.Clear()
Alternators.Clear()
OriginalAlternators.Clear()
For Each alt As IEnumerable(Of ICombinedAlternatorMapRow) In map.GroupBy(Function(g) g.AlternatorName)
For Each alt As IEnumerable(Of ICombinedAlternatorMapRow) In map.GroupBy(Function(g) g.AlternatorName) Dim altName As String = alt.First().AlternatorName
Dim pulleyRatio As Single = alt.First().PulleyRatio
Dim altName As String = alt.First().AlternatorName
Dim pulleyRatio As Single = alt.First().PulleyRatio
Dim alternator As IAlternator = New Alternator(altSignals, alt.ToList())
Dim alternator As IAlternator = New Alternator(altSignals, alt.ToList()) Alternators.Add(alternator)
Alternators.Add(alternator)
Next
Next Return True
End Function
Return True 'Constructors
Public Sub New(filePath As String, Optional signals As ISignals = Nothing)
End Function Dim feedback As String = String.Empty
Me.Signals = signals
'Constructors If Not FilePathUtils.ValidateFilePath(filePath, ".aalt", feedback) Then
Public Sub New(filePath As String, Optional signals As ISignals = Nothing) Throw New ArgumentException(String.Format("Combined Alternator requires a valid .AALT filename. : {0}", feedback))
Else
Me.FilePath = filePath
End If
Dim feedback As String = String.Empty
Me.Signals = signals
If Not FilePathUtils.ValidateFilePath(filePath, ".aalt", feedback) Then Me.altSignals = New CombinedAlternatorSignals()
Throw New ArgumentException(String.Format("Combined Alternator requires a valid .AALT filename. : {0}", feedback))
Else
Me.FilePath = filePath
End If
Me.altSignals = New CombinedAlternatorSignals() 'IF file exists then read it otherwise create a default.
If File.Exists(filePath) AndAlso InitialiseMap(filePath) Then
Initialise()
Else
'Create Default Map
CreateDefaultMap()
Initialise()
End If
'IF file exists then read it otherwise create a default. ' Calculate alternators average which is used only in the pre-run
Dim efficiencySum As Single
Dim efficiencyAverage As Single
If File.Exists(filePath) AndAlso InitialiseMap(filePath) Then For Each alt As IAlternator In Alternators
Initialise() efficiencySum += alt.InputTable2000.ElementAt(1).Eff
Else efficiencySum += alt.InputTable2000.ElementAt(2).Eff
'Create Default Map efficiencySum += alt.InputTable2000.ElementAt(3).Eff
CreateDefaultMap()
Initialise()
End If
' Calculate alternators average which is used only in the pre-run efficiencySum += alt.InputTable4000.ElementAt(1).Eff
Dim efficiencySum As Single efficiencySum += alt.InputTable4000.ElementAt(2).Eff
Dim efficiencyAverage As Single efficiencySum += alt.InputTable4000.ElementAt(3).Eff
For Each alt As IAlternator In Alternators efficiencySum += alt.InputTable6000.ElementAt(1).Eff
efficiencySum += alt.InputTable2000.ElementAt(1).Eff efficiencySum += alt.InputTable6000.ElementAt(2).Eff
efficiencySum += alt.InputTable2000.ElementAt(2).Eff efficiencySum += alt.InputTable6000.ElementAt(3).Eff
efficiencySum += alt.InputTable2000.ElementAt(3).Eff Next
efficiencySum += alt.InputTable4000.ElementAt(1).Eff efficiencyAverage = efficiencySum / (Alternators.Count * 9)
efficiencySum += alt.InputTable4000.ElementAt(2).Eff AverageAlternatorsEfficiency = New AlternatorMapValues(efficiencyAverage / 100)
efficiencySum += alt.InputTable4000.ElementAt(3).Eff End Sub
efficiencySum += alt.InputTable6000.ElementAt(1).Eff 'Helpers
efficiencySum += alt.InputTable6000.ElementAt(2).Eff Private Sub CreateDefaultMap()
efficiencySum += alt.InputTable6000.ElementAt(3).Eff
Next
efficiencyAverage = efficiencySum / (Alternators.Count * 9) map.Clear()
AverageAlternatorsEfficiency = New AlternatorMapValues(efficiencyAverage / 100)
End Sub map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 10, 62, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 27, 70, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 53, 30, 3.6))
'Helpers map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 10, 64, 3.6))
Private Sub CreateDefaultMap() map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 63, 74, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 125, 68, 3.6))
map.Clear() map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 10, 53, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 68, 70, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 136, 62, 3.6))
map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 10, 62, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 10, 62, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 27, 70, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 27, 70, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 2000, 53, 30, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 53, 30, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 10, 64, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 10, 64, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 63, 74, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 63, 74, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 4000, 125, 68, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 125, 68, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 10, 53, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 68, 70, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3))
map.Add(New CombinedAlternatorMapRow("Alt1", 6000, 136, 62, 3.6)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3))
End Sub
map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 10, 62, 3)) 'Grid Management
map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 27, 70, 3)) Private Function AddNewAlternator(list As List(Of ICombinedAlternatorMapRow), ByRef feeback As String) As Boolean
map.Add(New CombinedAlternatorMapRow("Alt2", 2000, 53, 30, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 10, 64, 3)) Dim returnValue As Boolean = True
map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 63, 74, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 4000, 125, 68, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3)) Dim altName As String = list.First().AlternatorName
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3)) Dim pulleyRatio As Single = list.First().PulleyRatio
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3))
'Check alt does not already exist in list
If Alternators.Where(Function(w) w.AlternatorName = altName).Count > 0 Then
feeback = "This alternator already exists in in the list, operation not completed."
Return False
End If
End Sub Dim alternator As IAlternator = New Alternator(altSignals, list.ToList())
'Grid Management Alternators.Add(alternator)
Private Function AddNewAlternator(list As List(Of ICombinedAlternatorMapRow), ByRef feeback As String) As Boolean
Dim returnValue As Boolean = True
Dim altName As String = list.First().AlternatorName Return returnValue
Dim pulleyRatio As Single = list.First().PulleyRatio End Function
'Check alt does not already exist in list Public Function AddAlternator(rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
If Alternators.Where(Function(w) w.AlternatorName = altName).Count > 0 Then
feeback = "This alternator already exists in in the list, operation not completed."
Return False
End If
Dim alternator As IAlternator = New Alternator(altSignals, list.ToList()) If Not AddNewAlternator(rows, feedback) Then
feedback = String.Format("Unable to add new alternator : {0}", feedback)
Return False
End If
Alternators.Add(alternator) Return True
End Function
Public Function DeleteAlternator(alternatorName As String, ByRef feedback As String, CountValidation As Boolean) _
As Boolean
Return returnValue 'Is this the last alternator, if so deny the user the right to remove it.
If CountValidation AndAlso Alternators.Count < 2 Then
feedback = "There must be at least one alternator remaining, operation aborted."
Return False
End If
End Function If Alternators.Where(Function(w) w.AlternatorName = alternatorName).Count = 0 Then
Public Function AddAlternator(rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean feedback = "This alternator does not exist"
Return False
End If
If Not AddNewAlternator(rows, feedback) Then Dim altToRemove As IAlternator = Alternators.First(Function(w) w.AlternatorName = alternatorName)
feedback = String.Format("Unable to add new alternator : {0}", feedback) Dim numAlternators As Integer = Alternators.Count
Return False
End If
Return True Alternators.Remove(altToRemove)
End Function If Alternators.Count = numAlternators - 1 Then
Public Function DeleteAlternator(alternatorName As String, ByRef feedback As String, CountValidation As Boolean) As Boolean Return True
Else
feedback = String.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback)
Return False
End If
End Function
'Public Function UpdateAlternator( gridIndex As Integer, rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
'Is this the last alternator, if so deny the user the right to remove it. ' Dim altName As String = rows.First.AlternatorName
If CountValidation AndAlso Alternators.Count < 2 Then ' Dim altToUpd As IAlternator = Alternators.First(Function(w) w.AlternatorName = altName)
feedback = "There must be at least one alternator remaining, operation aborted."
Return False
End If
If Alternators.Where(Function(w) w.AlternatorName = alternatorName).Count = 0 Then ' If Not DeleteAlternator(altName, feedback) Then
feedback = "This alternator does not exist" ' feedback = feedback
Return False ' Return False
End If
Dim altToRemove As IAlternator = Alternators.First(Function(w) w.AlternatorName = alternatorName) ' End If
Dim numAlternators As Integer = Alternators.Count
Alternators.Remove(altToRemove) ' 'Re.create alternator.
If Alternators.Count = numAlternators - 1 Then ' Dim replacementAlt As New Alternator(altSignals, rows)
Return True ' Alternators.Add(replacementAlt)
Else
feedback = String.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback)
Return False
End If
End Function ' Return True
'Public Function UpdateAlternator( gridIndex As Integer, rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
' Dim altName As String = rows.First.AlternatorName
' Dim altToUpd As IAlternator = Alternators.First(Function(w) w.AlternatorName = altName)
' If Not DeleteAlternator(altName, feedback) Then 'End Function
' feedback = feedback
' Return False
' End If 'Persistance Functions
Public Function Save(aaltPath As String) As Boolean
' 'Re.create alternator.
' Dim replacementAlt As New Alternator(altSignals, rows) Dim returnValue As Boolean = True
' Alternators.Add(replacementAlt) Dim sb As New StringBuilder()
Dim row As Integer = 0
Dim amps, eff As Single
' Return True 'write headers
sb.AppendLine("[AlternatorName],[RPM],[Amps],[Efficiency],[PulleyRatio]")
'write details
For Each alt As IAlternator In Alternators.OrderBy(Function(o) o.AlternatorName)
'End Function
'Persistance Functions '2000 - IE Alt1,2000,10,50,3
Public Function Save(aaltPath As String) As Boolean For row = 1 To 3
amps = alt.InputTable2000(row).Amps
eff = alt.InputTable2000(row).Eff
sb.Append(
alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("")
Next
'4000 - IE Alt1,2000,10,50,3
For row = 1 To 3
amps = alt.InputTable4000(row).Amps
eff = alt.InputTable4000(row).Eff
sb.Append(
alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("")
Next
Dim returnValue As Boolean = True '6000 - IE Alt1,2000,10,50,3
Dim sb As New StringBuilder() For row = 1 To 3
Dim row As Integer = 0 amps = alt.InputTable6000(row).Amps
Dim amps, eff As Single eff = alt.InputTable6000(row).Eff
sb.Append(
alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("")
Next
'write headers
sb.AppendLine("[AlternatorName],[RPM],[Amps],[Efficiency],[PulleyRatio]")
'write details Next
For Each alt As IAlternator In Alternators.OrderBy(Function(o) o.AlternatorName)
'Add Model Source
sb.AppendLine("[MODELSOURCE]")
sb.Append(Me.ToString())
'2000 - IE Alt1,2000,10,50,3 ' Write the stream cotnents to a new file named "AllTxtFiles.txt"
For row = 1 To 3 Using outfile As New StreamWriter(aaltPath)
amps = alt.InputTable2000(row).Amps : eff = alt.InputTable2000(row).Eff outfile.Write(sb.ToString())
sb.Append(alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000")) End Using
sb.AppendLine("")
Next
'4000 - IE Alt1,2000,10,50,3 Return returnValue
For row = 1 To 3 End Function
amps = alt.InputTable4000(row).Amps : eff = alt.InputTable4000(row).Eff
sb.Append(alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("")
Next
'6000 - IE Alt1,2000,10,50,3 Private Function Load() As Boolean
For row = 1 To 3
amps = alt.InputTable6000(row).Amps : eff = alt.InputTable6000(row).Eff
sb.Append(alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("")
Next
If Not InitialiseMap(FilePath) Then Return False
Next
'Add Model Source Return True
sb.AppendLine("[MODELSOURCE]") End Function
sb.Append(Me.ToString())
' Write the stream cotnents to a new file named "AllTxtFiles.txt" 'Initialises the map, only valid when loadingUI for first time in edit mode or always in operational mode.
Using outfile As New StreamWriter(aaltPath) Private Function InitialiseMap(filePath As String) As Boolean
outfile.Write(sb.ToString())
End Using
Return returnValue Dim returnValue As Boolean = False
Dim elements As String()
End Function If File.Exists(filePath) Then
Private Function Load() As Boolean Using sr As StreamReader = New StreamReader(filePath)
'get array og lines fron csv
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()),
StringSplitOptions.RemoveEmptyEntries)
If Not InitialiseMap(FilePath) Then Return False 'Must have at least 2 entries in map to make it usable [dont forget the header row]
If (lines.Count() < 10) Then
Throw New ArgumentException("Insufficient rows in csv to build a usable map")
End If
map = New List(Of ICombinedAlternatorMapRow)
Return True Dim firstline As Boolean = True
End Function For Each line As String In lines
If Not firstline Then
'Initialises the map, only valid when loadingUI for first time in edit mode or always in operational mode. 'Advanced Alternator Source Check.
Private Function InitialiseMap(filePath As String) As Boolean If line.Contains("[MODELSOURCE") Then Exit For
Dim returnValue As Boolean = False 'split the line
Dim elements As String() elements = line.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
'3 entries per line required
If (elements.Length <> 5) Then
Throw New ArgumentException("Incorrect number of values in csv file")
End If
'add values to map
If File.Exists(filePath) Then map.Add(New CombinedAlternatorMapRow(elements(0), Single.Parse(elements(1), CultureInfo.InvariantCulture),
Using sr As StreamReader = New StreamReader(filePath) Single.Parse(elements(2), CultureInfo.InvariantCulture),
'get array og lines fron csv Single.Parse(elements(3), CultureInfo.InvariantCulture),
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()), StringSplitOptions.RemoveEmptyEntries) Single.Parse(elements(4), CultureInfo.InvariantCulture)))
'Must have at least 2 entries in map to make it usable [dont forget the header row] Else
If (lines.Count() < 10) Then firstline = False
Throw New ArgumentException("Insufficient rows in csv to build a usable map") End If
End If Next line
End Using
Return True
Else
Throw New ArgumentException("Supplied input file does not exist")
End If
map = New List(Of ICombinedAlternatorMapRow) Return returnValue
End Function
Dim firstline As Boolean = True 'Can be used to send messages to Vecto.
Public Event AuxiliaryEvent(ByRef sender As Object, message As String, messageType As AdvancedAuxiliaryMessageType) _
Implements IAuxiliaryEvent.AuxiliaryEvent
For Each line As String In lines 'This is used to generate a diagnostics output which enables the user to
If Not firstline Then 'Determine if they beleive the resulting map is what is expected
'Basically it is a check against the model/Spreadsheet
Public Overrides Function ToString() As String
'Advanced Alternator Source Check. Dim sb As New StringBuilder()
If line.Contains("[MODELSOURCE") Then Exit For Dim a1, a2, a3, e1, e2, e3 As String
'split the line
elements = line.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
'3 entries per line required
If (elements.Length <> 5) Then
Throw New ArgumentException("Incorrect number of values in csv file")
End If
'add values to map
map.Add(New CombinedAlternatorMapRow(elements(0), CType(elements(1), Single), CType(elements(2), Single), CType(elements(3), Single), CType(elements(4), Single))) For Each alt As Alternator In Alternators.OrderBy(Function(o) o.AlternatorName)
sb.AppendLine("")
sb.AppendFormat("** {0} ** , PulleyRatio {1}", alt.AlternatorName, alt.PulleyRatio)
sb.AppendLine("")
sb.AppendLine("******************************************************************")
sb.AppendLine("")
Else Dim i As Integer = 1
firstline = False sb.AppendLine("Table 1 (2000)" + vbTab + "Table 2 (4000)" + vbTab + "Table 3 (6000)")
End If sb.AppendLine("Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab)
Next line sb.AppendLine("")
End Using For i = 1 To 3
Return True
Else
Throw New ArgumentException("Supplied input file does not exist")
End If
Return returnValue a1 = alt.InputTable2000(i).Amps.ToString("0")
e1 = alt.InputTable2000(i).Eff.ToString("0.000")
a2 = alt.InputTable4000(i).Amps.ToString("0")
e2 = alt.InputTable4000(i).Eff.ToString("0.000")
a3 = alt.InputTable6000(i).Amps.ToString("0")
e3 = alt.InputTable6000(i).Eff.ToString("0.000")
sb.AppendLine(a1 + vbTab + e1 + vbTab + a2 + vbTab + e2 + vbTab + a3 + vbTab + e3 + vbTab)
Next
End Function
'Can be used to send messages to Vecto. Next
Public Event AuxiliaryEvent(ByRef sender As Object, message As String, messageType As AdvancedAuxiliaryMessageType) Implements IAuxiliaryEvent.AuxiliaryEvent
'This is used to generate a diagnostics output which enables the user to 'sb.AppendLine("")
'Determine if they beleive the resulting map is what is expected 'sb.AppendLine("********* COMBINED EFFICIENCY VALUES **************")
'Basically it is a check against the model/Spreadsheet 'sb.AppendLine("")
Public Overrides Function ToString() As String 'sb.AppendLine(vbTab + "RPM VALUES")
'sb.AppendLine("AMPS" + vbTab + "500" + vbTab + "1500" + vbTab + "2500" + vbTab + "3500" + vbTab + "4500" + vbTab + "5500" + vbTab + "6500" + vbTab + "7500")
'For a As Single = 1 To Alternators.Count * 50
Dim sb As New StringBuilder() ' sb.Append(a.ToString("0") + vbTab)
Dim a1, a2, a3, e1, e2, e3 As String ' For Each r As Single In {500, 1500, 2500, 3500, 4500, 5500, 6500, 7500}
' Dim eff As Single = GetEfficiency(r, a).Efficiency
For Each alt As Alternator In Alternators.OrderBy(Function(o) o.AlternatorName) ' sb.Append(eff.ToString("0.000") + vbTab)
sb.AppendLine("")
sb.AppendFormat("** {0} ** , PulleyRatio {1}", alt.AlternatorName, alt.PulleyRatio)
sb.AppendLine("")
sb.AppendLine("******************************************************************")
sb.AppendLine("")
Dim i As Integer = 1 ' Next
sb.AppendLine("Table 1 (2000)" + vbTab + "Table 2 (4000)" + vbTab + "Table 3 (6000)") ' sb.AppendLine("")
sb.AppendLine("Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab)
sb.AppendLine("")
For i = 1 To 3
a1 = alt.InputTable2000(i).Amps.ToString("0") 'Next
e1 = alt.InputTable2000(i).Eff.ToString("0.000")
a2 = alt.InputTable4000(i).Amps.ToString("0")
e2 = alt.InputTable4000(i).Eff.ToString("0.000")
a3 = alt.InputTable6000(i).Amps.ToString("0")
e3 = alt.InputTable6000(i).Eff.ToString("0.000")
sb.AppendLine(a1 + vbTab + e1 + vbTab + a2 + vbTab + e2 + vbTab + a3 + vbTab + e3 + vbTab)
Next
Return sb.ToString()
End Function
Next
'sb.AppendLine("") 'Equality
'sb.AppendLine("********* COMBINED EFFICIENCY VALUES **************") Public Function IsEqualTo(other As ICombinedAlternator) As Boolean Implements ICombinedAlternator.IsEqualTo
'sb.AppendLine("")
'sb.AppendLine(vbTab + "RPM VALUES")
'sb.AppendLine("AMPS" + vbTab + "500" + vbTab + "1500" + vbTab + "2500" + vbTab + "3500" + vbTab + "4500" + vbTab + "5500" + vbTab + "6500" + vbTab + "7500")
'For a As Single = 1 To Alternators.Count * 50
' sb.Append(a.ToString("0") + vbTab) 'Count Check.
' For Each r As Single In {500, 1500, 2500, 3500, 4500, 5500, 6500, 7500} If Me.Alternators.Count <> other.Alternators.Count Then Return False
' Dim eff As Single = GetEfficiency(r, a).Efficiency For Each alt As IAlternator In Me.Alternators
' sb.Append(eff.ToString("0.000") + vbTab) 'Can we find the same alternatorName in other
If other.Alternators.Where(Function(f) f.AlternatorName = alt.AlternatorName).Count() <> 1 Then Return False
' Next 'get the alternator to compare and compare it.
' sb.AppendLine("") If Not alt.IsEqualTo(other.Alternators.first(Function(f) f.AlternatorName = alt.AlternatorName)) Then Return False
'Next
Return sb.ToString()
End Function
'Equality
Public Function IsEqualTo(other As ICombinedAlternator) As Boolean Implements ICombinedAlternator.IsEqualTo
'Count Check.
If Me.Alternators.Count <> other.Alternators.Count Then Return False
For Each alt As IAlternator In Me.Alternators
'Can we find the same alternatorName in other
If other.Alternators.Where(Function(f) f.AlternatorName = alt.AlternatorName).Count() <> 1 Then Return False
'get the alternator to compare and compare it.
If Not alt.IsEqualTo(other.Alternators.first(Function(f) f.AlternatorName = alt.AlternatorName)) Then Return False
Next
Return True
End Function
End Class
Next
Return True
End Function
End Class
End Namespace End Namespace
Imports System.IO Imports System.Globalization
Imports System.IO
Namespace Hvac Namespace Hvac
Public Class EnvironmentalConditionsMap
Implements IEnvironmentalConditionsMap
Public Class EnvironmentalConditionsMap Private filePath As String
Implements IEnvironmentalConditionsMap Private vectoDirectory As String
Private filePath As String Private _map As New List(Of IEnvironmentalCondition)
Private vectoDirectory As String
Private _map As New List(Of IEnvironmentalCondition) Public Sub New(filepath As String, vectoDirectory As String)
Public Sub New(filepath As String, vectoDirectory As String) Me.filePath = filepath
Me.vectoDirectory = vectoDirectory
Me.filePath = filepath Initialise()
Me.vectoDirectory = vectoDirectory End Sub
Initialise() Public Function Initialise() As Boolean Implements IEnvironmentalConditionsMap.Initialise
End Sub If (Not String.IsNullOrWhiteSpace(filePath)) Then
Public Function Initialise() As Boolean Implements IEnvironmentalConditionsMap.Initialise filePath = FilePathUtils.ResolveFilePath(vectoDirectory, filePath)
If (Not String.IsNullOrWhiteSpace(filePath)) Then If File.Exists(filePath) Then
Using sr As StreamReader = New StreamReader(filePath)
filePath = FilePathUtils.ResolveFilePath(vectoDirectory, filePath) 'get array og lines fron csv
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()),
StringSplitOptions.RemoveEmptyEntries)
If File.Exists(filePath) Then 'Must have at least 1 entries to make it usable [dont forget the header row]
Using sr As StreamReader = New StreamReader(filePath) If (lines.Count() < 2) Then
Return False
End If
'get array og lines fron csv Dim firstline As Boolean = True
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()), StringSplitOptions.RemoveEmptyEntries)
'Must have at least 1 entries to make it usable [dont forget the header row] For Each line As String In lines
If (lines.Count() < 2) Then If Not firstline Then
Return False
End If
Dim firstline As Boolean = True 'split the line
Dim elements() As String = line.Split(New Char() {","}, StringSplitOptions.RemoveEmptyEntries)
For Each line As String In lines '3 entries per line required
If Not firstline Then If (elements.Length <> 4) Then
Return False
End If
'split the line 'Add environment condition
Dim elements() As String = line.Split(New Char() {","}, StringSplitOptions.RemoveEmptyEntries) Dim newCondition As EnvironmentalCondition = New EnvironmentalCondition(
Double.Parse(elements(1), CultureInfo.InvariantCulture),
Double.Parse(elements(2), CultureInfo.InvariantCulture),
Double.Parse(elements(3), CultureInfo.InvariantCulture))
'3 entries per line required _map.Add(newCondition)
If (elements.Length <> 4) Then
Return False
End If
'Add environment condition Else
Dim newCondition As EnvironmentalCondition = New EnvironmentalCondition(elements(1), elements(2), elements(3)) firstline = False
End If
Next line
End Using
_map.Add(newCondition) Else
Return False
End If
End If
Else Return True
firstline = False End Function
End If
Next line
End Using
Else Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) _
Return False Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions
End If
End If
Return True
End Function
Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions
Return _map
End Function
End Class
Return _map
End Function
End Class
End Namespace End Namespace
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
' '
' See the LICENSE.txt for the specific language governing permissions and limitations. ' See the LICENSE.txt for the specific language governing permissions and limitations.
Imports System.Globalization
Imports System.IO Imports System.IO
Namespace Pneumatics Namespace Pneumatics
...@@ -76,7 +77,10 @@ Namespace Pneumatics ...@@ -76,7 +77,10 @@ Namespace Pneumatics
'4 entries per line required '4 entries per line required
If (elements.Length <> 4) Then Throw New ArgumentException("Incorrect number of values in csv file") If (elements.Length <> 4) Then Throw New ArgumentException("Incorrect number of values in csv file")
'add values to map 'add values to map
map.Add(elements(0), New CompressorMapValues(elements(1), elements(2), elements(3))) map.Add(Integer.Parse(elements(0)),
New CompressorMapValues(Single.Parse(elements(1), CultureInfo.InvariantCulture),
Single.Parse(elements(2), CultureInfo.InvariantCulture),
Single.Parse(elements(3), CultureInfo.InvariantCulture)))
Else Else
firstline = False firstline = False
End If End If
......
...@@ -2,152 +2,140 @@ ...@@ -2,152 +2,140 @@
Imports VectoAuxiliaries.Pneumatics Imports VectoAuxiliaries.Pneumatics
Namespace UnitTests Namespace UnitTests
<TestFixture()>
<TestFixture()> Public Class CompressorMapTests
Public Class CompressorMapTests Private Const GOODMAP As String = "TestFiles\testCompressorMap.acmp"
Private Const INVALIDPOWERCOMPRESSORONMAP As String = "TestFiles\testCompressorMapInvalidOnPower.acmp"
Private Const GOODMAP As String = "TestFiles\testCompressorMap.acmp" Private Const INVALIDPOWERCOMPRESSOROFFMAP As String = "TestFiles\testCompressorMapInvalidOffPower.acmp"
Private Const INVALIDPOWERCOMPRESSORONMAP As String = "TestFiles\testCompressorMapInvalidOnPower.acmp" Private Const INVALIDFLOWRATEMAP As String = "TestFiles\testCompressorMapInvalidFlow.acmp"
Private Const INVALIDPOWERCOMPRESSOROFFMAP As String = "TestFiles\testCompressorMapInvalidOffPower.acmp" Private Const INSSUFICIENTROWSMAP As String = "TestFiles\testCompressorMapNotEnoughRows.acmp"
Private Const INVALIDFLOWRATEMAP As String = "TestFiles\testCompressorMapInvalidFlow.acmp" Private Const INVALIDRPMMAP As String = "TestFiles\testCompressorMapInvalidRpm.acmp"
Private Const INSSUFICIENTROWSMAP As String = "TestFiles\testCompressorMapNotEnoughRows.acmp" Private Const INVALIDNUMBEROFCOLUMNS As String = "TestFiles\testCompressorMapWrongNumberOfColumns.acmp"
Private Const INVALIDRPMMAP As String = "TestFiles\testCompressorMapInvalidRpm.acmp"
Private Const INVALIDNUMBEROFCOLUMNS As String = "TestFiles\testCompressorMapWrongNumberOfColumns.acmp"
#Region "Helpers" #Region "Helpers"
Private Function GetInitialiseMap() As CompressorMap Private Function GetInitialiseMap() As CompressorMap
Dim target As CompressorMap = GetMap() Dim target As CompressorMap = GetMap()
target.Initialise() target.Initialise()
Return target Return target
End Function End Function
Private Function GetMap() As CompressorMap Private Function GetMap() As CompressorMap
Dim path As String = GOODMAP Dim path As String = GOODMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
Return target Return target
End Function End Function
#End Region #End Region
<Test()> <Test()>
Public Sub CreateNewCompressorMapInstanceTest() Public Sub CreateNewCompressorMapInstanceTest()
Dim pat As String = "test" Dim pat As String = "test"
Dim target As CompressorMap = New CompressorMap(pat) Dim target As CompressorMap = New CompressorMap(pat)
End Sub End Sub
<Test()> <Test()>
Public Sub InitialisationTest() Public Sub InitialisationTest()
Dim target As CompressorMap = GetMap() Dim target As CompressorMap = GetMap()
Assert.IsTrue(target.Initialise()) Assert.IsTrue(target.Initialise())
End Sub End Sub
<Test(), ExpectedException("System.ArgumentException")> <Test(), ExpectedException("System.ArgumentException")>
Public Sub InitialisationNoFileSuppliedThrowsExceptionTest() Public Sub InitialisationNoFileSuppliedThrowsExceptionTest()
Dim path As String = "" Dim path As String = ""
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
Assert.IsTrue(target.Initialise()) Assert.IsTrue(target.Initialise())
End Sub End Sub
<Test(), ExpectedException("System.ArgumentException")> <Test(), ExpectedException("System.ArgumentException")>
Public Sub InitialisationWrongNumberOfColumnsThrowsExceptionTest() Public Sub InitialisationWrongNumberOfColumnsThrowsExceptionTest()
Dim path As String = INVALIDNUMBEROFCOLUMNS Dim path As String = INVALIDNUMBEROFCOLUMNS
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidRpmThrowsExceptionTest() Public Sub InitialisationInvalidRpmThrowsExceptionTest()
Dim path As String = INVALIDRPMMAP Dim path As String = INVALIDRPMMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidFlowRateThrowsExceptionTest() Public Sub InitialisationInvalidFlowRateThrowsExceptionTest()
Dim path As String = INVALIDFLOWRATEMAP Dim path As String = INVALIDFLOWRATEMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOnThrowsExceptionTest() Public Sub InitialisationInvalidPowerCompressorOnThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSORONMAP Dim path As String = INVALIDPOWERCOMPRESSORONMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOffThrowsExceptionTest() Public Sub InitialisationInvalidPowerCompressorOffThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSOROFFMAP Dim path As String = INVALIDPOWERCOMPRESSOROFFMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.ArgumentException")> <Test(), ExpectedException("System.ArgumentException")>
Public Sub InitialisationInsufficientRowsThrowsExceptionTest() Public Sub InitialisationInsufficientRowsThrowsExceptionTest()
Dim path As String = INSSUFICIENTROWSMAP Dim path As String = INSSUFICIENTROWSMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test()> <Test()>
Public Sub GetFlowRateKeyPassedTest() Public Sub GetFlowRateKeyPassedTest()
Dim target As CompressorMap = GetInitialiseMap() Dim target As CompressorMap = GetInitialiseMap()
Dim expected As Single = 400 Dim expected As Single = 400
Dim value As Single = target.GetFlowRate(2000) Dim value As Single = target.GetFlowRate(2000)
Assert.AreEqual(expected, value) Assert.AreEqual(expected, value)
End Sub End Sub
<Test()> <Test()>
Public Sub GetFlowRateInterpolaitionTest() Public Sub GetFlowRateInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap() Dim target As CompressorMap = GetInitialiseMap()
Dim expected As Single = 500 Dim expected As Single = 500
Dim value As Single = target.GetFlowRate(2500) Dim value As Single = target.GetFlowRate(2500)
Assert.AreEqual(expected, value) Assert.AreEqual(expected, value)
End Sub End Sub
<Test()>
Public Sub GetPowerCompressorOnInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap()
<Test()> Dim expected As Single = 5000
Public Sub GetPowerCompressorOnInterpolaitionTest() Dim value As Single = target.GetPowerCompressorOn(2500)
Dim target As CompressorMap = GetInitialiseMap() Assert.AreEqual(expected, value)
Dim expected As Single = 5000 End Sub
Dim value As Single = target.GetPowerCompressorOn(2500)
Assert.AreEqual(expected, value)
End Sub <Test()>
Public Sub GetPowerCompressorOffInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap()
Dim expected As Single = 2500
Dim value As Single = target.GetPowerCompressorOff(2500)
<Test()> Assert.AreEqual(expected, value)
Public Sub GetPowerCompressorOffInterpolaitionTest() End Sub
Dim target As CompressorMap = GetInitialiseMap()
Dim expected As Single = 2500
Dim value As Single = target.GetPowerCompressorOff(2500) <Test()>
Assert.AreEqual(expected, value) Public Sub InterpMiddle()
End Sub
Dim target As CompressorMap = New CompressorMap(GOODMAP)
Assert.IsTrue(target.Initialise())
<Test()> Dim actual = target.GetFlowRate(1750)
Public Sub InterpMiddle()
Assert.AreEqual(actual, 300)
Dim target As CompressorMap = New CompressorMap(GOODMAP) End Sub
Assert.IsTrue(target.Initialise()) End Class
Dim actual = target.GetFlowRate(1750)
Assert.AreEqual( actual,300)
End Sub
End Class
End Namespace End Namespace
\ No newline at end of file
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