Revert "fix: 오차 계산 방법 고정 방식으로 수정"

This reverts commit 085aec7b6c9ddcc14f1e280c0d7083116f4342af.
This commit is contained in:
kje97 2025-06-12 08:49:05 +09:00
parent 085aec7b6c
commit 53bd4fd889

View File

@ -18,13 +18,13 @@ Public Class weightForm
Private weight(2)
'Dim weights As New List(Of Double)() ' 실측 측정값 저장용
'Dim avg As Double = 0.0 ' 평균
'Dim stdDev As Double = 0.0 ' 표준편차
'Dim k As Double = 2.0 ' 오차 계수
'Dim errorRate As Double = 0.0 ' 허용 오차 비율
'Dim weightErrorPlus As Double = 0.0 ' 허용 오차 상한
'Dim weightErrorMinus As Double = 0.0 ' 허용 오차 하한
Dim weights As New List(Of Double)() ' 실측 측정값 저장용
Dim avg As Double = 0.0 ' 평균
Dim stdDev As Double = 0.0 ' 표준편차
Dim k As Double = 2.0 ' 오차 계수
Dim errorRate As Double = 0.0 ' 허용 오차 비율
Dim weightErrorPlus As Double = 0.0 ' 허용 오차 상한
Dim weightErrorMinus As Double = 0.0 ' 허용 오차 하한
Private Sub weightForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ZeroTimer.Enabled = True
@ -157,31 +157,19 @@ Public Class weightForm
End Try
End Sub
'Private Sub UpdateErrorRange()
' If mainForm.rdbWeightAuto.Checked = True Then
' ' 자동 모드: 오차 계수(k) 오차 범위 산출
' Dim autoErrorRate As Double = 0.02 ' : 2% 오차
' weightErrorPlus = weightSum * autoErrorRate
' weightErrorMinus = weightSum * autoErrorRate
Private Sub UpdateErrorRange()
If weights.Count >= 2 Then
avg = weights.Average()
stdDev = Math.Sqrt(weights.Select(Function(x) (x - avg) ^ 2).Average())
errorRate = (k * stdDev) / avg
' 'If lbNowWeight.Text >= weightSum - weightErrorMinus And
' ' lbNowWeight.Text <= weightSum + weightErrorPlus Then
' 'End If
weightErrorPlus = weightSum * errorRate
weightErrorMinus = weightSum * errorRate
' Else
' ' 수동 모드: 평균, 표준편차 기반 오차 범위 산출
' If weights.Count >= 2 Then
' avg = weights.Average()
' stdDev = Math.Sqrt(weights.Select(Function(x) (x - avg) ^ 2).Average())
' errorRate = (k * stdDev) / avg
' weightErrorPlus = weightSum * errorRate
' weightErrorMinus = weightSum * errorRate
' '폼에 오차 범위 표시
' lbError.Text = "(오차: +" & weightErrorPlus.ToString() & ", -" & weightErrorMinus.ToString() & ")"
' End If
' End If
'End Sub
' 폼에 오차 범위 표시
lbError.Text = "(오차: +" & weightErrorPlus.ToString() & ", -" & weightErrorMinus.ToString() & ")"
End If
End Sub
'Private Function weight_compare() As Boolean
' If lbNowWeight.Text >= weightSum - weightErrorMinus And lbNowWeight.Text <= weightSum + weightErrorPlus Then
@ -191,22 +179,18 @@ Public Class weightForm
' End If
'End Function
Private Function weight_compare() As Boolean
Dim nowWeight As Double = Double.Parse(lbNowWeight.Text)
Dim autoErrorRate As Double = 0.02 ' : 2% 오차
Dim weightError As Double = weightSum * autoErrorRate
Dim upperBound As Double = weightSum + weightError
Dim lowerBound As Double = weightSum - weightError
' 폼에 오차 범위 표시
lbError.Text = "(오차: ±" & weightError.ToString("F2") & ", 허용구간: " & lowerBound.ToString("F2") & " ~ " & upperBound.ToString("F2") & ")"
' 기준 무게 기반 허용 오차 범위 계산 완료된 상태에서 비교
Dim upperBound As Double = weightSum + weightErrorPlus
Dim lowerBound As Double = weightSum - weightErrorMinus
Return (nowWeight >= lowerBound) AndAlso (nowWeight <= upperBound)
End Function
Public Sub delay(ByVal milliSecond As Double)
Dim delayTime As Date = Now.AddSeconds(milliSecond / 1000)
Do Until Now > delayTime
@ -230,9 +214,9 @@ Public Class weightForm
Next
Loop
'weights.Add(Double.Parse(weight(0)))
'weights.Add(Double.Parse(weight(1)))
'UpdateErrorRange()
weights.Add(Double.Parse(weight(0)))
weights.Add(Double.Parse(weight(1)))
UpdateErrorRange()
If weight(0) - weight(1) < 10 And weight(0) - weight(1) > -10 Then
Return True