fix: normalize yutong mqtt mileage units
This commit is contained in:
@@ -69,7 +69,7 @@ func fieldsFromData(data map[string]any) map[string]any {
|
||||
fields[envelope.FieldSpeedKMH] = speed
|
||||
}
|
||||
if mileage, ok := firstFloat(data, "TOTAL_MILEAGE", "totalMileage", "total_mileage_km"); ok {
|
||||
fields[envelope.FieldTotalMileageKM] = mileage
|
||||
fields[envelope.FieldTotalMileageKM] = normalizeTotalMileageKM(mileage)
|
||||
}
|
||||
if soc, ok := firstFloat(data, "BATTERY_CAPACITY_SOC", "soc", "SOC", "soc_percent"); ok {
|
||||
fields[envelope.FieldSOCPercent] = soc
|
||||
@@ -166,6 +166,14 @@ func parseTimeMS(raw string, fallback int64) int64 {
|
||||
if raw == "" {
|
||||
return fallback
|
||||
}
|
||||
for _, layout := range []string{
|
||||
"2006-01-02 15:04:05.000",
|
||||
"2006-01-02 15:04:05",
|
||||
} {
|
||||
if parsed, err := time.ParseInLocation(layout, raw, time.FixedZone("Asia/Shanghai", 8*3600)); err == nil {
|
||||
return parsed.UnixMilli()
|
||||
}
|
||||
}
|
||||
if len(raw) == 14 {
|
||||
if parsed, err := time.ParseInLocation("20060102150405", raw, time.FixedZone("Asia/Shanghai", 8*3600)); err == nil {
|
||||
return parsed.UnixMilli()
|
||||
@@ -187,3 +195,10 @@ func looksLikeVIN(value string) bool {
|
||||
value = strings.TrimSpace(value)
|
||||
return len(value) == 17
|
||||
}
|
||||
|
||||
func normalizeTotalMileageKM(value float64) float64 {
|
||||
if value > 1_000_000 {
|
||||
return value / 1000
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user