Skip to content

Commit 8c3f26d

Browse files
author
Pierre Segonne
committed
feat: add config and models for data centers
1 parent 9b7b529 commit 8c3f26d

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

config/data_centers/aws.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"aws-us-east-1": {
3+
"displayName": "us-east-1 (Virginia)",
4+
"lonlat": [37.3382, -76.7483],
5+
"provider": "Amazon Web Services",
6+
"region": "us-east-1",
7+
"zoneKey": "US-MIDA-PJM"
8+
},
9+
"aws-us-east-2": {
10+
"displayName": "us-east-2 (Ohio)",
11+
"lonlat": [39.9526, -82.9959],
12+
"provider": "Amazon Web Services",
13+
"region": "us-east-2",
14+
"zoneKey": "US-MIDW-MISO"
15+
}
16+
}

config/data_centers/gcp.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"gcp-europe-west1": {
3+
"displayName": "europe-west1 (Belgium)",
4+
"lonlat": [50.8503, 4.3517],
5+
"provider": "Google Cloud Platform",
6+
"region": "europe-west1",
7+
"zoneKey": "BE"
8+
},
9+
"gcp-us-central1": {
10+
"displayName": "us-central1 (Iowa)",
11+
"lonlat": [41.5908, -93.6208],
12+
"provider": "Google Cloud Platform",
13+
"region": "us-central1",
14+
"zoneKey": "US-MIDW-MISO"
15+
}
16+
}

electricitymap/contrib/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from electricitymap.contrib.config.co2eq_parameters import generate_co2eq_parameters
88
from electricitymap.contrib.config.reading import (
9+
read_data_centers_config,
910
read_defaults,
1011
read_exchanges_config,
1112
read_zones_config,
@@ -24,6 +25,7 @@
2425
ZONES_CONFIG = read_zones_config(CONFIG_DIR)
2526
RETIRED_ZONES_CONFIG = read_zones_config(CONFIG_DIR, retired=True)
2627
EXCHANGES_CONFIG = read_exchanges_config(CONFIG_DIR)
28+
DATA_CENTERS_CONFIG = read_data_centers_config(CONFIG_DIR)
2729

2830
EU_ZONES = [
2931
"AT",

electricitymap/contrib/config/model.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
EXCHANGES_CONFIG,
1818
ZONE_NEIGHBOURS,
1919
ZONES_CONFIG,
20+
DATA_CENTERS_CONFIG,
2021
)
2122
from electricitymap.contrib.config.types import Point
2223
from electricitymap.contrib.lib.types import ZoneKey
@@ -340,3 +341,23 @@ def _load_config_model() -> ConfigModel:
340341
CO2EQ_CONFIG_MODEL = CO2eqConfigModel(
341342
direct=CO2EQ_PARAMETERS_DIRECT, lifecycle=CO2EQ_PARAMETERS_LIFECYCLE
342343
)
344+
345+
346+
class DataCenter(StrictBaseModel):
347+
displayName: str
348+
lonlat: tuple[float, float] | None
349+
provider: str
350+
region: str
351+
status: str
352+
zoneKey: ZoneKey
353+
354+
355+
class DataCenters(StrictBaseModel):
356+
dataCenters: dict[str, DataCenter]
357+
358+
359+
DATA_CENTERS_CONFIG_MODEL = DataCenters(dataCenters=DATA_CENTERS_CONFIG)
360+
361+
362+
if __name__ == "__main__":
363+
print(DATA_CENTERS_CONFIG_MODEL)

electricitymap/contrib/config/reading.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any
2+
import json
23

34
from ruamel.yaml import YAML
45

@@ -38,3 +39,10 @@ def read_exchanges_config(config_dir) -> dict[ZoneKey, Any]:
3839
with open(exchange_path, encoding="utf-8") as file:
3940
exchanges_config[exchange_key] = yaml.load(file)
4041
return exchanges_config
42+
43+
def read_data_centers_config(config_dir) -> dict[str, Any]:
44+
data_centers_config = {}
45+
for data_center_path in config_dir.joinpath("data_centers").glob("*.json"):
46+
with open(data_center_path, encoding="utf-8") as file:
47+
data_centers_config[data_center_path.stem] = json.load(file)
48+
return data_centers_config

0 commit comments

Comments
 (0)