diff --git a/VECTOAux/VectoAuxiliaries/Electrics/Alternator.vb b/VECTOAux/VectoAuxiliaries/Electrics/Alternator.vb index 49fbe79219b89fcb92712cfdd6b753a5bad4971b..f61e73e5046e57699e539f66689e0a22062626b8 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/Alternator.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/Alternator.vb @@ -2,6 +2,23 @@ Namespace Electrics +Public Class Table4Row + + Public RPM As Single + Public Efficiency As Single + + Public Sub new ( rpm As single, eff As single) + + Me.rpm= rpm + Me.Efficiency = eff + + + End Sub + + +End Class + + Public Class Alternator Implements IAlternator @@ -11,47 +28,37 @@ Public Class Alternator Public Property InputTable2000 As New List(Of AltUserInput) Implements IAlternator.InputTable2000 Public Property InputTable4000 As New List(Of AltUserInput) Implements IAlternator.InputTable4000 Public Property InputTable6000 As New List(Of AltUserInput) Implements IAlternator.InputTable6000 - Public Property RangeTable As New List(Of AltUserInput) Implements IAlternator.RangeTable + Public Property RangeTable As New List(Of Table4Row) Implements IAlternator.RangeTable Private signals As ICombinedAlternatorSignals Public Sub Clone( other As IAlternator) Implements IAlternator.Clone - Me.PulleyRatio = other.PulleyRatio - Me.AlternatorName= other.AlternatorName - - InputTable2000.Clear() - InputTable4000.Clear() - InputTable6000.Clear() - RangeTable .Clear() - - For Each entry As AltUserInput In other.InputTable2000 - InputTable2000.Add(New AltUserInput( entry.Amps, entry.Eff)) - Next - - For Each entry As AltUserInput In other.InputTable4000 - InputTable4000.Add(New AltUserInput( entry.Amps, entry.Eff)) - Next - - For Each entry As AltUserInput In other.InputTable6000 - InputTable6000.Add(New AltUserInput( entry.Amps, entry.Eff)) - Next - - For Each entry As AltUserInput In other.RangeTable - RangeTable.Add(New AltUserInput( entry.Amps, entry.Eff)) - Next End Sub Public ReadOnly Property Efficiency As Double Implements IAlternator.Efficiency + + Get + 'First build RangeTable, table 4 + + InitialiseRangeTable() + CalculateRangeTable() + + 'TODO: Calculate Efficiency + 'Calculate ( Interpolate ) Efficiency + End Get + + + End Property Public ReadOnly Property SpindleSpeed As Double Implements IAlternator.SpindleSpeed Get - + Return signals.CrankRPM * PulleyRatio End Get End Property @@ -79,9 +86,83 @@ Public Class Alternator BuildInputTable( values6k, InputTable6000) + CreateRangeTable() + InitialiseRangeTable() + + End Sub + Private Function Iterpolate( values As List(Of AltUserInput), x As single) As Single + + Dim lowestX As single = values.Min( Function(m) m.Amps) + Dim highestX As Single = values.Max( Function(m) m.Amps) + Dim lastX, nextX ,lastEff,NextEff As single + Dim deltaX As single + Dim slope As single + + 'Out of range, returns efficiency for lowest + If x< lowestX then Return values.First( Function(f) f.Amps= lowestX).Eff + 'Out of range, efficiency for highest + If x> highestX then Return values.First( Function(f) f.Amps= highestX).Eff + + 'On Bounds check + If values.Where( Function(w) w.Amps=x).Count=1 then Return values.First( Function(w) w.Amps=x).Eff + + + 'OK, we need to interpolate. + lastX = values.Last( Function(l) l.Amps < x).Amps + nextX = values.First( Function(l) l.Amps > x).Amps + lastEff = values.First( Function(f) f.Amps=lastX).Eff + nextEff = values.First( Function(f) f.Amps=nextX).Eff + + + deltaX = nextX-lastX + slope = NextEff/lastEff + + Return lastEff + ( NextEff * slope) + + + + End Function + + + Private Sub CalculateRangeTable() + + 'TODO: CALCULATE RANGE TABLE + + + End Sub + + + Private sub InitialiseRangeTable() + + RangeTable(0).RPM=0:RangeTable(0).Efficiency=0 + RangeTable(1).RPM=0:RangeTable(0).Efficiency=0 + RangeTable(2).RPM=2000:RangeTable(0).Efficiency=0 + RangeTable(3).RPM=4000:RangeTable(0).Efficiency=0 + RangeTable(4).RPM=6000:RangeTable(0).Efficiency=0 + RangeTable(5).RPM=0:RangeTable(0).Efficiency=0 + RangeTable(6).RPM=0:RangeTable(0).Efficiency=0 + + End Sub + + + Private Sub CreateRangeTable() + + + RangeTable.Clear() + + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + RangeTable.Add( New Table4Row(0,0)) + + + End Sub public Sub BuildInputTable( inputs As Dictionary(of Single, single), targetTable As List (Of AltUserInput )) diff --git a/VECTOAux/VectoAuxiliaries/Electrics/CombinedAlternator.vb b/VECTOAux/VectoAuxiliaries/Electrics/CombinedAlternator.vb index f8096f306bf7dd3571fea0830c179b5f83598118..e50265364d65ef19ed844eb14299901e12d52ac3 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/CombinedAlternator.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/CombinedAlternator.vb @@ -25,6 +25,16 @@ Public Class CombinedAlternator Private altSignals As ICombinedAlternatorSignals + + Public Function GetEfficiency( CrankRPM As Single , AmpsDemand As Single ) As Single + + altSignals.CrankRPM = CrankRPM + altSignals.CurrentDemandAmps = AmpsDemand + + Return Alternators.Average( Function(a) a.Efficiency) + + End Function + 'Constructors public sub new( filePath as String, altSignals As ICombinedAlternatorSignals) @@ -192,28 +202,31 @@ Public Class CombinedAlternator Public Function UpdateAlternator( 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 + feedback= feedback + Return false - End Function + End If - 'Validation Helpers - Function PanelisValid( forAdd As Boolean, ByRef feedback As string ) As Boolean + 'Re.create alternator. - Dim returnValue As Boolean = true + Dim replacementAlt As New Alternator( altSignals, rows ) + Alternators.Add( replacementAlt) + Return true - Return returnValue + End Function + 'Validation Helpers - End Function 'Persistance Functions - Public Function Save(filePath As String) As Boolean + Public Function Save(filePath As String) As Boolean Dim returnValue As Boolean = True @@ -237,14 +250,14 @@ Public Class CombinedAlternator Return returnValue End Function - private Function Load() As Boolean + private Function Load() As Boolean If Not InitialiseMap(filePath) then Return False Return true - End Function + End Function 'Initialises the map. Public Function InitialiseMap(filePath As string) As Boolean @@ -299,7 +312,7 @@ End Function -End Class + End Class End Namespace diff --git a/VECTOAux/VectoAuxiliaries/Electrics/IAlternator.vb b/VECTOAux/VectoAuxiliaries/Electrics/IAlternator.vb index 28db61ac6adb69edc201535769b78226426a0f97..261b4d86b04e2a9bb95cb5d5c9ba411784c62657 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/IAlternator.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/IAlternator.vb @@ -16,7 +16,7 @@ Namespace Electrics Property InputTable2000 AS List(Of AltUserInput) Property InputTable4000 AS List(Of AltUserInput) Property InputTable6000 AS List(Of AltUserInput) - Property RangeTable AS List(Of AltUserInput) + Property RangeTable AS List(Of Table4Row) diff --git a/VECTOAux/VectoAuxiliaries/Electrics/InterpAltUserInputs.vb b/VECTOAux/VectoAuxiliaries/Electrics/InterpAltUserInputs.vb new file mode 100644 index 0000000000000000000000000000000000000000..2d830531ce812a564f98eb0c5f94b739cca71f52 --- /dev/null +++ b/VECTOAux/VectoAuxiliaries/Electrics/InterpAltUserInputs.vb @@ -0,0 +1,50 @@ + + +Namespace Electrics + +Public Class InterpAltUserInputs + + Public shared Function Iterpolate( values As List(Of AltUserInput), x As single) As Single + + Dim lowestX As single = values.Min( Function(m) m.Amps) + Dim highestX As Single = values.Max( Function(m) m.Amps) + Dim preKey, postKey ,preEff,postEff, xSlope, EffSlope As single + Dim deltaX , deltaEff As single + Dim slope As single + + 'Out of range, returns efficiency for lowest + If x< lowestX then Return values.First( Function(f) f.Amps= lowestX).Eff + + 'Out of range, efficiency for highest + If x> highestX then Return values.First( Function(f) f.Amps= highestX).Eff + + 'On Bounds check + If values.Where( Function(w) w.Amps=x).Count=1 then Return values.First( Function(w) w.Amps=x).Eff + + + 'OK, we need to interpolate. + preKey = values.Last( Function(l) l.Amps < x).Amps + postKey = values.First( Function(l) l.Amps > x).Amps + preEff = values.First( Function(f) f.Amps=preKey).Eff + postEff = values.First( Function(f) f.Amps=postKey).Eff + + + deltaX = postKey-preKey + deltaEff = postEff-preEff + + 'slopes + effSlope = deltaEff/deltaX + + + Dim retVal As Single = ((x - preKey) * effSlope) + preEff + + Return retVal + + End Function + +End Class + + +End Namespace + + diff --git a/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.Designer.vb b/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.Designer.vb index 16ce1675d15677e1dd68816db82365df4791519e..663ab58cf52e2216b73ed3dc3a8a85bfe243accc 100644 --- a/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.Designer.vb +++ b/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.Designer.vb @@ -54,6 +54,8 @@ Partial Class frmCombinedAlternators Me.Label16 = New System.Windows.Forms.Label() Me.TabControl1 = New System.Windows.Forms.TabControl() Me.tabInputs = New System.Windows.Forms.TabPage() + Me.txtAlternatorName = New System.Windows.Forms.TextBox() + Me.lblAlternatorName = New System.Windows.Forms.Label() Me.btnClearForm = New System.Windows.Forms.Button() Me.gvAlternators = New System.Windows.Forms.DataGridView() Me.Label18 = New System.Windows.Forms.Label() @@ -64,8 +66,6 @@ Partial Class frmCombinedAlternators Me.btnSave = New System.Windows.Forms.Button() Me.btnCancel = New System.Windows.Forms.Button() Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider(Me.components) - Me.lblAlternatorName = New System.Windows.Forms.Label() - Me.txtAlternatorName = New System.Windows.Forms.TextBox() Me.grpTable2000PRM.SuspendLayout Me.grpTable4000PRM.SuspendLayout Me.grpTable6000PRM.SuspendLayout @@ -383,6 +383,7 @@ Partial Class frmCombinedAlternators ' 'tabInputs ' + Me.tabInputs.CausesValidation = false Me.tabInputs.Controls.Add(Me.txtAlternatorName) Me.tabInputs.Controls.Add(Me.lblAlternatorName) Me.tabInputs.Controls.Add(Me.btnClearForm) @@ -404,6 +405,22 @@ Partial Class frmCombinedAlternators Me.tabInputs.Text = " Inputs " Me.tabInputs.UseVisualStyleBackColor = true ' + 'txtAlternatorName + ' + Me.txtAlternatorName.Location = New System.Drawing.Point(242, 22) + Me.txtAlternatorName.Name = "txtAlternatorName" + Me.txtAlternatorName.Size = New System.Drawing.Size(160, 20) + Me.txtAlternatorName.TabIndex = 41 + ' + 'lblAlternatorName + ' + Me.lblAlternatorName.AutoSize = true + Me.lblAlternatorName.Location = New System.Drawing.Point(156, 25) + Me.lblAlternatorName.Name = "lblAlternatorName" + Me.lblAlternatorName.Size = New System.Drawing.Size(80, 13) + Me.lblAlternatorName.TabIndex = 40 + Me.lblAlternatorName.Text = "AlternatorName" + ' 'btnClearForm ' Me.btnClearForm.Location = New System.Drawing.Point(589, 140) @@ -462,7 +479,7 @@ Partial Class frmCombinedAlternators Me.tabDiagnostics.Location = New System.Drawing.Point(4, 22) Me.tabDiagnostics.Name = "tabDiagnostics" Me.tabDiagnostics.Padding = New System.Windows.Forms.Padding(3) - Me.tabDiagnostics.Size = New System.Drawing.Size(813, 451) + Me.tabDiagnostics.Size = New System.Drawing.Size(692, 451) Me.tabDiagnostics.TabIndex = 1 Me.tabDiagnostics.Text = " Diagnostics" Me.tabDiagnostics.UseVisualStyleBackColor = true @@ -489,22 +506,6 @@ Partial Class frmCombinedAlternators ' Me.ErrorProvider1.ContainerControl = Me ' - 'lblAlternatorName - ' - Me.lblAlternatorName.AutoSize = true - Me.lblAlternatorName.Location = New System.Drawing.Point(156, 25) - Me.lblAlternatorName.Name = "lblAlternatorName" - Me.lblAlternatorName.Size = New System.Drawing.Size(80, 13) - Me.lblAlternatorName.TabIndex = 40 - Me.lblAlternatorName.Text = "AlternatorName" - ' - 'txtAlternatorName - ' - Me.txtAlternatorName.Location = New System.Drawing.Point(242, 22) - Me.txtAlternatorName.Name = "txtAlternatorName" - Me.txtAlternatorName.Size = New System.Drawing.Size(160, 20) - Me.txtAlternatorName.TabIndex = 41 - ' 'frmCombinedAlternators ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!) diff --git a/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.vb b/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.vb index 48ff835dca34948f139a0938098040c093481d6d..1d75678e57bc0bc6523280e4e6eb8b6560515b0b 100644 --- a/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.vb +++ b/VECTOAux/VectoAuxiliaries/UI/frmCombinedAlternators.vb @@ -33,7 +33,7 @@ Public Class frmCombinedAlternators 'General Helpders Private Sub BindGrid() - gvAlternators.DataSource = New BindingList(Of IAlternator)( combinedAlt.Alternators ) + gvAlternators.DataSource = New BindingList(Of IAlternator)( combinedAlt.Alternators.OrderBy( Function(o) o.AlternatorName ).ToList()) End Sub Private Sub SetupControls() @@ -166,11 +166,11 @@ End Function ErrorProvider1.SetError(txtBox,"Please enter a number") return false else - + ErrorProvider1.SetError(txtBox,"") End If - Return False + Dim number As Single = 0 @@ -261,7 +261,6 @@ End Function End Sub - 'Grid Events Private Sub gvAlternators_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles gvAlternators.CellClick @@ -389,6 +388,19 @@ End Sub txtPulleyRatio .Text = string.Empty + ErrorProvider1.SetError(txtAlternatorName , String.empty) + ErrorProvider1.SetError(txt2K10Efficiency , String.empty) + ErrorProvider1.SetError(txt2K40Efficiency , String.empty) + ErrorProvider1.SetError(txt2K60Efficiency , String.empty) + ErrorProvider1.SetError(txt4K10Efficiency , String.empty) + ErrorProvider1.SetError(txt4K40Efficiency , String.empty) + ErrorProvider1.SetError(txt4K60Efficiency , String.empty) + ErrorProvider1.SetError(txt6K10Efficiency , String.empty) + ErrorProvider1.SetError(txt6K40Efficiency , String.empty) + ErrorProvider1.SetError(txt6K60Efficiency , String.empty) + + ErrorProvider1.SetError(txtPulleyRatio , String.empty) + End Sub @@ -488,6 +500,17 @@ End Sub +Private Sub Validating( sender As Object, e As CancelEventArgs) Handles txtAlternatorName.Validating, txtPulleyRatio.Validating, txt6K60Efficiency.Validating, txt6K40Efficiency.Validating, txt6K10Efficiency.Validating, txt4K60Efficiency.Validating, txt4K40Efficiency.Validating, txt4K10Efficiency.Validating, txt2K60Efficiency.Validating, txt2K40Efficiency.Validating, txt2K10Efficiency.Validating + + If Not Validate_UpdatePanel then + + e.Cancel=true + + End If + +End Sub + + End Class diff --git a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj index 9ae6c54f890d4571b183cc5fe6e6abfc06557fb7..6e61b5900e44cffdad3bbd40295cee4e991d65c1 100644 --- a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj +++ b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj @@ -125,6 +125,7 @@ <Compile Include="Electrics\IM2_AverageElectricalLoadDemand.vb" /> <Compile Include="Electrics\IM5_SmartAlternatorSetGeneration.vb" /> <Compile Include="Electrics\IncDecValuePair.vb" /> + <Compile Include="Electrics\InterpAltUserInputs.vb" /> <Compile Include="Electrics\IResultCard.vb" /> <Compile Include="Electrics\M0_5_SmartAlternatorSetEfficiency.vb" /> <Compile Include="Electrics\M0_NonSmart_AlternatorsSetEfficiency.vb" /> diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/CombinedAlternatorTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/CombinedAlternatorTests.vb index 47e629824e238349cea003ee959c5ff081e0e68d..70987a93c9ab5763437b25e59b76772ccf180654 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/CombinedAlternatorTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/CombinedAlternatorTests.vb @@ -142,6 +142,86 @@ Namespace UnitTests + End Sub + + <Test()> _ + <TestCase(1,2,50f)> _ + <TestCase(1,4,70)> _ + <TestCase(1,6,60)> _ + <TestCase(2,2,80)> _ + <TestCase(2,4,40)> _ + <TestCase(2,6,60)> _ + <TestCase(3,2,55)> _ + <TestCase(3,4,7.75f)> _ + <TestCase(3,6,76.875f)> _ + <TestCase(4,2,47.75f)> _ + <TestCase(4,4,37)> _ + <TestCase(4,6,63)> + Public Sub Interpolate4Table4( alt As Integer, rpmK As integer, expected As single) + + Dim interpValue As Single + + Select Case alt + + Case 1 + + Select Case rpmK + + Case 2 + interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable2000,42.5) + Case 4 + interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable4000,42.5) + Case 6 + interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable6000,42.5) + + End Select + + + Case 2 + + Select Case rpmK + + Case 2 + interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable2000,42.5) + Case 4 + interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable4000,42.5) + Case 6 + interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable6000,42.5) + + End Select + + Case 3 + + Select Case rpmK + + Case 2 + interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable2000,42.5) + Case 4 + interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable4000,42.5) + Case 6 + interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable6000,42.5) + + End Select + + Case 4 + + Select Case rpmK + + Case 2 + interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable2000,42.5) + Case 4 + interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable4000,42.5) + Case 6 + interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable6000,42.5) + + End Select + + End Select + + + Assert.AreEqual( interpValue, expected) + + End Sub