Enhance Battery and Motor Diagnostics: Add standard deviation calculation and motor diagnostics functionality

This commit is contained in:
alkadienePhoton
2025-12-07 16:57:28 -06:00
parent e00b6f1b2c
commit e4e9ef988b
3 changed files with 113 additions and 5 deletions

View File

@@ -39,13 +39,16 @@ class BatteryDiagnostics:
print("Current deviation:", self.stdev(currentList))
def stdev(self, vals):
data = vals
if len(data) < 2:
return 0
# Calculate the mean
mean = sum(data) / len(data)
# Calculate the variance (sum of squared differences from the mean, divided by n-1 for sample standard deviation)
variance = sum([(x - mean) ** 2 for x in data]) / (len(data) - 1)
variance = sum([(x - mean) ** 2 for x in data]) / float(len(data) - 1)
# Calculate the standard deviation (square root of the variance)
std_dev_manual = umath.sqrt(variance)
return (std_dev_manual)