This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_schema.py
80 lines (61 loc) · 1.67 KB
/
profile_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from dataclasses import dataclass
from datetime import time
@dataclass
class Location:
latitude: float
longitude: float
@dataclass
class Base:
vp_address: str
category: str
@dataclass
class Streetlight(Base):
@dataclass
class CategoryMeta:
type: str
control_api_endpoint: bool
fixture_installed_power: float
pv_capacity: float
storage_capacity: float
on_time: time
off_time: time
locations: list[Location]
category_meta: CategoryMeta
@classmethod
def fromJson(cls, json: dict[str, any]):
meta = cls.CategoryMeta(**json.pop("category_meta"))
return Streetlight(**json, category_meta=meta)
@dataclass
class _Generation:
technology: str
installed_kw: float
export_price: float
profile: str
@dataclass
class _Load:
profile: str
@dataclass
class _Storage:
technology: str
max_capacity: float
usable_capacity: float
max_charge_rate: float
max_discharge_rate: float
charge_efficiency: float
discharge_efficiency: float
export_price: 10
@dataclass
class Residential(Base):
location: str
generations: list[_Generation]
loads: list[_Load]
storages: list[_Storage]
@classmethod
def fromJson(cls, json: dict[str, any]):
generations = json.pop("generations")
loads = json.pop("loads")
storages = json.pop("storages")
generations = [_Generation(**props) for props in generations]
loads = [_Load(**props) for props in loads]
storages = [_Storage(**props) for props in storages]
return Residential(**json, generations=generations, loads=loads, storages=storages)