Skip to content

Commit

Permalink
tr/echarging-ocpi: add origin as prefix to stationcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
clezag committed Nov 14, 2024
1 parent 26e6779 commit 64860d0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions transformers/echarging-ocpi/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
go HandleQueue(pushMQ, func(r *raw[EVSERaw]) error {
plugData := b.CreateDataMap()

plugData.AddRecord(r.Rawdata.Params.Evse_uid, dtPlugStatus.Name, bdplib.CreateRecord(r.Timestamp.UnixMilli(), r.Rawdata.Body.Status, period))
plugData.AddRecord(stationId(r.Rawdata.Params.Evse_uid, b.Origin), dtPlugStatus.Name, bdplib.CreateRecord(r.Timestamp.UnixMilli(), r.Rawdata.Body.Status, period))
if err := b.PushData(stationTypePlug, plugData); err != nil {
return fmt.Errorf("error pushing plug data: %w", err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func main() {

numAvailable := len(res.Data)
recs := b.CreateDataMap()
recs.AddRecord(r.Rawdata.Params.Location_id, dtNumberAvailable.Name, bdplib.CreateRecord(r.Timestamp.UnixMilli(), numAvailable, period))
recs.AddRecord(stationId(r.Rawdata.Params.Location_id, b.Origin), dtNumberAvailable.Name, bdplib.CreateRecord(r.Timestamp.UnixMilli(), numAvailable, period))
if err := b.PushData(stationTypePlug, plugData); err != nil {
slog.Error("error pushing location data", "err", err)
}
Expand All @@ -148,7 +148,7 @@ func main() {
lat, _ := strconv.ParseFloat(loc.Coordinates.Latitude, 64)
lon, _ := strconv.ParseFloat(loc.Coordinates.Longitude, 64)
station := bdplib.CreateStation(
loc.ID,
stationId(loc.ID, b.Origin),
loc.Name,
stationTypeLocation,
lat,
Expand All @@ -174,7 +174,7 @@ func main() {

for _, evse := range loc.Evses {
plug := bdplib.CreateStation(
evse.UID,
stationId(evse.UID, b.Origin),
evse.EvseID,
stationTypePlug,
station.Latitude,
Expand Down Expand Up @@ -241,3 +241,7 @@ func failOnError(err error, msg string) {
panic(err)
}
}

func stationId(id string, origin string) string {
return fmt.Sprintf("%s:%s", origin, id)
}

0 comments on commit 64860d0

Please sign in to comment.