Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions pkg/emissions/emaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ func NewEMapsProvider(logger *slog.Logger) (Provider, error) {
zones := make(map[string]string, len(zoneData))

for zone, details := range zoneData {
// Check for countryName
var compoundName string
// Build compound name from countryName and zoneName
var parts []string

for _, name := range []string{"countryName", "zoneName"} {
if n, ok := details[name]; ok {
compoundName = fmt.Sprintf("%s %s", compoundName, n)
}
if details.CountryName != "" {
parts = append(parts, details.CountryName)
}

if details.ZoneName != "" {
parts = append(parts, details.ZoneName)
}
// Trim white spaces
compoundName = strings.TrimSpace(compoundName)
zones[zone] = compoundName

zones[zone] = strings.Join(parts, " ")
}

e := &emapsProvider{
Expand Down
2 changes: 1 addition & 1 deletion pkg/emissions/emaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestEMapsDataProviderError(t *testing.T) {

func TestNewEMapsProvider(t *testing.T) {
// Start test server
expected := eMapsZonesResponse{"FR": map[string]string{"zoneName": "France"}}
expected := eMapsZonesResponse{"FR": eMapsZoneDetails{ZoneName: "France"}}

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(&expected)
Expand Down
14 changes: 13 additions & 1 deletion pkg/emissions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,20 @@ type CountryCode struct {
IsoCode []CountryCodeFields `json:"3166-1"`
}

// eMapsZoneDetails represents the details of a zone from the Electricity Maps API.
type eMapsZoneDetails struct {
ZoneName string `json:"zoneName"`
CountryName string `json:"countryName"`
ZoneKey string `json:"zoneKey"`
CountryCode string `json:"countryCode"`
ZoneParentKey *string `json:"zoneParentKey"`
SubZoneKeys []string `json:"subZoneKeys"`
IsCommerciallyAvailable bool `json:"isCommerciallyAvailable"`
Tier *string `json:"tier"`
}

// Electricity Maps zones response signature.
type eMapsZonesResponse map[string]map[string]string
type eMapsZonesResponse map[string]eMapsZoneDetails

// Electricity Maps carbon intensity response signature.
type eMapsCarbonIntensityResponse struct {
Expand Down