Skip to content

Commit

Permalink
add new fields, available in 2024.44.25 holiday release 🎄
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdemers6 committed Dec 5, 2024
1 parent 7a3be80 commit c6050ed
Show file tree
Hide file tree
Showing 7 changed files with 3,212 additions and 1,175 deletions.
6 changes: 3 additions & 3 deletions datastore/simple/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Producer) ProcessReliableAck(_ *telemetry.Record) {

// Produce sends the data to the logger
func (p *Producer) Produce(entry *telemetry.Record) {
data, err := p.recordToLogMap(entry)
data, err := p.recordToLogMap(entry, entry.Vin)
if err != nil {
p.logger.ErrorLog("record_logging_error", err, logrus.LogInfo{"vin": entry.Vin, "txtype": entry.TxType, "metadata": entry.Metadata()})
return
Expand All @@ -50,10 +50,10 @@ func (p *Producer) ReportError(_ string, _ error, _ logrus.LogInfo) {
}

// recordToLogMap converts the data of a record to a map or slice of maps
func (p *Producer) recordToLogMap(record *telemetry.Record) (interface{}, error) {
func (p *Producer) recordToLogMap(record *telemetry.Record, vin string) (interface{}, error) {
switch payload := record.GetProtoMessage().(type) {
case *protos.Payload:
return transformers.PayloadToMap(payload, p.Config.Verbose, p.logger), nil
return transformers.PayloadToMap(payload, p.Config.Verbose, vin, p.logger), nil
case *protos.VehicleAlerts:
alertMaps := make([]map[string]interface{}, len(payload.Alerts))
for i, alert := range payload.Alerts {
Expand Down
80 changes: 77 additions & 3 deletions datastore/simple/transformers/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import (
"github.com/teslamotors/fleet-telemetry/protos"
)

const (
// SemiModelLetter is the 4th character in VIN representing Tesla semi
SemiModelLetter = "T"
)

// PayloadToMap transforms a Payload into a human readable map for logging purposes
func PayloadToMap(payload *protos.Payload, includeTypes bool, logger *logrus.Logger) map[string]interface{} {
func PayloadToMap(payload *protos.Payload, includeTypes bool, vin string, logger *logrus.Logger) map[string]interface{} {
convertedPayload := make(map[string]interface{}, len(payload.Data)+2)
convertedPayload["Vin"] = payload.Vin
convertedPayload["CreatedAt"] = payload.CreatedAt.AsTime().Format(time.RFC3339)
Expand All @@ -20,7 +25,7 @@ func PayloadToMap(payload *protos.Payload, includeTypes bool, logger *logrus.Log
continue
}
name := protos.Field_name[int32(datum.Key.Number())]
value, ok := transformValue(datum.Value.Value, includeTypes)
value, ok := transformValue(datum.Value.Value, includeTypes, vin)
if !ok {
logger.ActivityLog("unknown_payload_value_data_type", logrus.LogInfo{"name": name, "vin": payload.Vin})
continue
Expand All @@ -31,7 +36,7 @@ func PayloadToMap(payload *protos.Payload, includeTypes bool, logger *logrus.Log
return convertedPayload
}

func transformValue(value interface{}, includeTypes bool) (interface{}, bool) {
func transformValue(value interface{}, includeTypes bool, vin string) (interface{}, bool) {
var outputValue interface{}
var outputType string

Expand Down Expand Up @@ -140,6 +145,71 @@ func transformValue(value interface{}, includeTypes bool) (interface{}, bool) {
case *protos.Value_DetailedChargeStateValue:
outputType = "detailedChargeState"
outputValue = v.DetailedChargeStateValue.String()
case *protos.Value_HvacAutoModeValue:
outputType = "hvacAutoMode"
outputValue = v.HvacAutoModeValue.String()
case *protos.Value_CabinOverheatProtectionModeValue:
outputType = "cabinOverheatProtectionMode"
outputValue = v.CabinOverheatProtectionModeValue.String()
case *protos.Value_CabinOverheatProtectionTemperatureLimitValue:
outputType = "cabinOverheatProtectionTemperatureLimit"
outputValue = v.CabinOverheatProtectionTemperatureLimitValue.String()
case *protos.Value_DefrostModeValue:
outputType = "defrostMode"
outputValue = v.DefrostModeValue.String()
case *protos.Value_ClimateKeeperModeValue:
outputType = "climateKeeperMode"
outputValue = v.ClimateKeeperModeValue.String()
case *protos.Value_HvacPowerValue:
outputType = "hvacPower"
outputValue = v.HvacPowerValue.String()
case *protos.Value_TireLocationValue:
outputType = "tireLocation"
if getModelFromVIN(vin) == SemiModelLetter {
outputValue = map[string]bool{
"FrontLeft": v.TireLocationValue.FrontLeft,
"FrontRight": v.TireLocationValue.FrontRight,
"SemiMiddleAxleLeft": v.TireLocationValue.RearLeft,
"SemiMiddleAxleRight": v.TireLocationValue.RearRight,
"SemiMiddleAxleLeft2": v.TireLocationValue.SemiMiddleAxleLeft_2,
"SemiMiddleAxleRight2": v.TireLocationValue.SemiMiddleAxleRight_2,
"SemiRearAxleLeft": v.TireLocationValue.SemiRearAxleLeft,
"SemiRearAxleRight": v.TireLocationValue.SemiRearAxleRight,
"SemiRearAxleLeft2": v.TireLocationValue.SemiRearAxleLeft_2,
"SemiRearAxleRight2": v.TireLocationValue.SemiRearAxleRight_2,
}
} else {
outputValue = map[string]bool{
"FrontLeft": v.TireLocationValue.FrontLeft,
"FrontRight": v.TireLocationValue.FrontRight,
"RearLeft": v.TireLocationValue.RearLeft,
"RearRight": v.TireLocationValue.RearRight,
}
}
case *protos.Value_FastChargerValue:
outputType = "fastChargerType"
outputValue = v.FastChargerValue.String()
case *protos.Value_CableTypeValue:
outputType = "chargingCableType"
outputValue = v.CableTypeValue.String()
case *protos.Value_TonneauTentModeValue:
outputType = "tonneauTentMode"
outputValue = v.TonneauTentModeValue.String()
case *protos.Value_TonneauPositionValue:
outputType = "tonneauPosition"
outputValue = v.TonneauPositionValue.String()
case *protos.Value_PowershareStateValue:
outputType = "powershareStatus"
outputValue = v.PowershareStateValue.String()
case *protos.Value_PowershareStopReasonValue:
outputType = "powershareStopReason"
outputValue = v.PowershareStopReasonValue.String()
case *protos.Value_PowershareTypeValue:
outputType = "powershareType"
outputValue = v.PowershareTypeValue.String()
case *protos.Value_DisplayStateValue:
outputType = "displayState"
outputValue = v.DisplayStateValue.String()
default:
return nil, false
}
Expand All @@ -150,3 +220,7 @@ func transformValue(value interface{}, includeTypes bool) (interface{}, bool) {

return outputValue, true
}

func getModelFromVIN(vin string) string {
return string(vin[3])
}
6 changes: 3 additions & 3 deletions datastore/simple/transformers/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = Describe("Payload", func() {
Vin: "TEST123",
CreatedAt: now,
}
result := transformers.PayloadToMap(payload, false, logger)
result := transformers.PayloadToMap(payload, false, "", logger)
Expect(result["Vin"]).To(Equal("TEST123"))
Expect(result["CreatedAt"]).To(Equal(now.AsTime().Format(time.RFC3339)))
})
Expand All @@ -46,7 +46,7 @@ var _ = Describe("Payload", func() {
Vin: "TEST123",
CreatedAt: now,
}
result := transformers.PayloadToMap(payload, false, logger)
result := transformers.PayloadToMap(payload, false, "", logger)
Expect(result["Vin"]).To(Equal("TEST123"))
Expect(result["CreatedAt"]).To(Equal(now.AsTime().Format(time.RFC3339)))
Expect(result["BatteryHeaterOn"]).To(Equal(true))
Expand All @@ -59,7 +59,7 @@ var _ = Describe("Payload", func() {
Vin: "TEST123",
CreatedAt: timestamppb.Now(),
}
result := transformers.PayloadToMap(payload, includeTypes, logger)
result := transformers.PayloadToMap(payload, includeTypes, "", logger)
Expect(result[expectedKey]).To(Equal(expectedValue))
},
Entry("String value with types excluded",
Expand Down
136 changes: 83 additions & 53 deletions protos/python/vehicle_data_pb2.py

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion protos/ruby/vehicle_data_pb.rb

Large diffs are not rendered by default.

Loading

0 comments on commit c6050ed

Please sign in to comment.