Skip to content

Commit dc1fecd

Browse files
committed
adding key names
1 parent bf5b15a commit dc1fecd

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

main.go

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,82 +109,100 @@ func main() {
109109
for _, datum := range vehicleData.Data {
110110
fieldName := datum.Key.String() // Get the field name from the enum
111111
value := datum.Value
112-
113-
var numericValue float64
114-
115112
switch v := value.Value.(type) {
116113
case *protos.Value_DoubleValue:
117-
numericValue = v.DoubleValue
114+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(v.DoubleValue)
118115
case *protos.Value_FloatValue:
119-
numericValue = float64(v.FloatValue)
116+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.FloatValue))
120117
case *protos.Value_IntValue:
121-
numericValue = float64(v.IntValue)
118+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.IntValue))
122119
case *protos.Value_LongValue:
123-
numericValue = float64(v.LongValue)
120+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.LongValue))
124121
case *protos.Value_BooleanValue:
122+
var numericValue float64
125123
if v.BooleanValue {
126124
numericValue = 1.0
127125
} else {
128126
numericValue = 0.0
129127
}
128+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(numericValue)
129+
case *protos.Value_LocationValue:
130+
// Handle LocationValue separately
131+
vehicleDataGauge.WithLabelValues("Latitude", vehicleData.Vin).Set(v.LocationValue.Latitude)
132+
vehicleDataGauge.WithLabelValues("Longitude", vehicleData.Vin).Set(v.LocationValue.Longitude)
133+
case *protos.Value_DoorValue:
134+
// Handle Doors by setting individual door states
135+
doors := v.DoorValue
136+
doorFields := map[string]bool{
137+
"DriverFront": doors.DriverFront,
138+
"PassengerFront": doors.PassengerFront,
139+
"DriverRear": doors.DriverRear,
140+
"PassengerRear": doors.PassengerRear,
141+
"TrunkFront": doors.TrunkFront,
142+
"TrunkRear": doors.TrunkRear,
143+
}
144+
for doorName, state := range doorFields {
145+
var numericValue float64
146+
if state {
147+
numericValue = 1.0
148+
} else {
149+
numericValue = 0.0
150+
}
151+
vehicleDataGauge.WithLabelValues(doorName, vehicleData.Vin).Set(numericValue)
152+
}
153+
case *protos.Value_TimeValue:
154+
// Handle TimeValue by converting to seconds since midnight
155+
timeValue := v.TimeValue
156+
totalSeconds := float64(timeValue.Hour*3600 + timeValue.Minute*60 + timeValue.Second)
157+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(totalSeconds)
130158
case *protos.Value_ChargingValue:
131-
numericValue = float64(v.ChargingValue.Number())
159+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ChargingValue.Number()))
132160
case *protos.Value_ShiftStateValue:
133-
numericValue = float64(v.ShiftStateValue.Number())
161+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ShiftStateValue.Number()))
134162
case *protos.Value_LaneAssistLevelValue:
135-
numericValue = float64(v.LaneAssistLevelValue.Number())
163+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.LaneAssistLevelValue.Number()))
136164
case *protos.Value_ScheduledChargingModeValue:
137-
numericValue = float64(v.ScheduledChargingModeValue.Number())
165+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ScheduledChargingModeValue.Number()))
138166
case *protos.Value_SentryModeStateValue:
139-
numericValue = float64(v.SentryModeStateValue.Number())
167+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.SentryModeStateValue.Number()))
140168
case *protos.Value_SpeedAssistLevelValue:
141-
numericValue = float64(v.SpeedAssistLevelValue.Number())
169+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.SpeedAssistLevelValue.Number()))
142170
case *protos.Value_BmsStateValue:
143-
numericValue = float64(v.BmsStateValue.Number())
171+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.BmsStateValue.Number()))
144172
case *protos.Value_BuckleStatusValue:
145-
numericValue = float64(v.BuckleStatusValue.Number())
173+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.BuckleStatusValue.Number()))
146174
case *protos.Value_CarTypeValue:
147-
numericValue = float64(v.CarTypeValue.Number())
175+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.CarTypeValue.Number()))
148176
case *protos.Value_ChargePortValue:
149-
numericValue = float64(v.ChargePortValue.Number())
177+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ChargePortValue.Number()))
150178
case *protos.Value_ChargePortLatchValue:
151-
numericValue = float64(v.ChargePortLatchValue.Number())
179+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ChargePortLatchValue.Number()))
152180
case *protos.Value_CruiseStateValue:
153-
numericValue = float64(v.CruiseStateValue.Number())
181+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.CruiseStateValue.Number()))
154182
case *protos.Value_DriveInverterStateValue:
155-
numericValue = float64(v.DriveInverterStateValue.Number())
183+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.DriveInverterStateValue.Number()))
156184
case *protos.Value_HvilStatusValue:
157-
numericValue = float64(v.HvilStatusValue.Number())
185+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.HvilStatusValue.Number()))
158186
case *protos.Value_WindowStateValue:
159-
numericValue = float64(v.WindowStateValue.Number())
187+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.WindowStateValue.Number()))
160188
case *protos.Value_SeatFoldPositionValue:
161-
numericValue = float64(v.SeatFoldPositionValue.Number())
189+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.SeatFoldPositionValue.Number()))
162190
case *protos.Value_TractorAirStatusValue:
163-
numericValue = float64(v.TractorAirStatusValue.Number())
191+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.TractorAirStatusValue.Number()))
164192
case *protos.Value_FollowDistanceValue:
165-
numericValue = float64(v.FollowDistanceValue.Number())
193+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.FollowDistanceValue.Number()))
166194
case *protos.Value_ForwardCollisionSensitivityValue:
167-
numericValue = float64(v.ForwardCollisionSensitivityValue.Number())
195+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.ForwardCollisionSensitivityValue.Number()))
168196
case *protos.Value_GuestModeMobileAccessValue:
169-
numericValue = float64(v.GuestModeMobileAccessValue.Number())
197+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.GuestModeMobileAccessValue.Number()))
170198
case *protos.Value_TrailerAirStatusValue:
171-
numericValue = float64(v.TrailerAirStatusValue.Number())
199+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.TrailerAirStatusValue.Number()))
172200
case *protos.Value_DetailedChargeStateValue:
173-
numericValue = float64(v.DetailedChargeStateValue.Number())
174-
case *protos.Value_LocationValue:
175-
// Handle LocationValue separately
176-
lat := v.LocationValue.Latitude
177-
lon := v.LocationValue.Longitude
178-
vehicleDataGauge.WithLabelValues("Latitude", vehicleData.Vin).Set(lat)
179-
vehicleDataGauge.WithLabelValues("Longitude", vehicleData.Vin).Set(lon)
180-
continue // Skip the rest since we've handled this case
201+
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(float64(v.DetailedChargeStateValue.Number()))
181202
default:
182-
// Skip non-numeric or unsupported types
203+
// Skip unsupported types
183204
continue
184205
}
185-
186-
// Update the metric
187-
vehicleDataGauge.WithLabelValues(fieldName, vehicleData.Vin).Set(numericValue)
188206
}
189207
}
190208
}

0 commit comments

Comments
 (0)