1
|
|
|
""" |
2
|
|
|
DB tables / SQLAlchemy ORM classes for motorized individual travel |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
from sqlalchemy import ( |
6
|
|
|
Boolean, |
7
|
|
|
Column, |
8
|
|
|
DateTime, |
9
|
|
|
Float, |
10
|
|
|
ForeignKey, |
11
|
|
|
Integer, |
12
|
|
|
SmallInteger, |
13
|
|
|
String, |
14
|
|
|
) |
15
|
|
|
from sqlalchemy.dialects.postgresql import REAL |
16
|
|
|
from sqlalchemy.ext.declarative import declarative_base |
17
|
|
|
|
18
|
|
|
from egon.data.datasets.mv_grid_districts import MvGridDistricts |
19
|
|
|
from egon.data.datasets.scenario_parameters import EgonScenario |
20
|
|
|
|
21
|
|
|
# from sqlalchemy.orm import relationship |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
Base = declarative_base() |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class EgonEvPool(Base): |
28
|
|
|
"""Motorized individual travel: EV pool |
29
|
|
|
|
30
|
|
|
Each row is one EV, uniquely defined by either (`ev_id`) or |
31
|
|
|
(`rs7_id`, `type`, `simbev_id`). |
32
|
|
|
|
33
|
|
|
Columns |
34
|
|
|
------- |
35
|
|
|
ev_id: |
36
|
|
|
Unique id of EV |
37
|
|
|
rs7_id: |
38
|
|
|
id of RegioStar7 region |
39
|
|
|
type: |
40
|
|
|
type of EV, one of |
41
|
|
|
* bev_mini |
42
|
|
|
* bev_medium |
43
|
|
|
* bev_luxury |
44
|
|
|
* phev_mini |
45
|
|
|
* phev_medium |
46
|
|
|
* phev_luxury |
47
|
|
|
simbev_ev_id: |
48
|
|
|
id of EV as exported by simBEV |
49
|
|
|
""" |
50
|
|
|
|
51
|
|
|
__tablename__ = "egon_ev_pool" |
52
|
|
|
__table_args__ = {"schema": "demand"} |
53
|
|
|
|
54
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), primary_key=True) |
55
|
|
|
ev_id = Column(Integer, primary_key=True) |
56
|
|
|
rs7_id = Column(SmallInteger) |
57
|
|
|
type = Column(String(11)) |
58
|
|
|
simbev_ev_id = Column(Integer) |
59
|
|
|
|
60
|
|
|
# trips = relationship( |
61
|
|
|
# "EgonEvTrip", cascade="all, delete", back_populates="ev" |
62
|
|
|
# ) |
63
|
|
|
# mvgds = relationship( |
64
|
|
|
# "EgonEvMvGridDistrict", cascade="all, delete", back_populates="ev" |
65
|
|
|
# ) |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
class EgonEvTrip(Base): |
69
|
|
|
"""Motorized individual travel: EVs' trips |
70
|
|
|
|
71
|
|
|
Each row is one event of a specific electric vehicle which is |
72
|
|
|
uniquely defined by `rs7_id`, `ev_id` and `event_id`. |
73
|
|
|
|
74
|
|
|
Columns |
75
|
|
|
------- |
76
|
|
|
scenario: |
77
|
|
|
Scenario |
78
|
|
|
event_id: |
79
|
|
|
Unique id of EV event |
80
|
|
|
egon_ev_pool_ev_id: |
81
|
|
|
id of EV, references EgonEvPool.ev_id |
82
|
|
|
simbev_event_id: |
83
|
|
|
id of EV event, unique within a specific EV dataset |
84
|
|
|
location: |
85
|
|
|
Location of EV event, one of |
86
|
|
|
* "0_work" |
87
|
|
|
* "1_business" |
88
|
|
|
* "2_school" |
89
|
|
|
* "3_shopping" |
90
|
|
|
* "4_private/ridesharing" |
91
|
|
|
* "5_leisure" |
92
|
|
|
* "6_home" |
93
|
|
|
* "7_charging_hub" |
94
|
|
|
* "driving" |
95
|
|
|
use_case: |
96
|
|
|
Use case of EV event, one of |
97
|
|
|
* "public" (public charging) |
98
|
|
|
* "home" (private charging at 6_home) |
99
|
|
|
* "work" (private charging at 0_work) |
100
|
|
|
* <empty> (driving events) |
101
|
|
|
charging_capacity_nominal: |
102
|
|
|
Nominal charging capacity in kW |
103
|
|
|
charging_capacity_grid: |
104
|
|
|
Charging capacity at grid side in kW, |
105
|
|
|
includes efficiency of charging infrastructure |
106
|
|
|
charging_capacity_battery: |
107
|
|
|
Charging capacity at battery side in kW, |
108
|
|
|
includes efficiency of car charger |
109
|
|
|
soc_start: |
110
|
|
|
State of charge at start of event |
111
|
|
|
soc_start: |
112
|
|
|
State of charge at end of event |
113
|
|
|
charging_demand: |
114
|
|
|
Energy demand during parking/charging event in kWh. |
115
|
|
|
0 if no charging takes place. |
116
|
|
|
park_start: |
117
|
|
|
Start timestep of parking event (15min interval, e.g. 4 = 1h) |
118
|
|
|
park_end: |
119
|
|
|
End timestep of parking event (15min interval) |
120
|
|
|
drive_start: |
121
|
|
|
Start timestep of driving event (15min interval) |
122
|
|
|
drive_end: |
123
|
|
|
End timestep of driving event (15min interval) |
124
|
|
|
consumption: |
125
|
|
|
Energy demand during driving event in kWh |
126
|
|
|
|
127
|
|
|
Notes |
128
|
|
|
----- |
129
|
|
|
pgSQL's REAL is sufficient for floats as simBEV rounds output to 4 digits. |
130
|
|
|
""" |
131
|
|
|
|
132
|
|
|
__tablename__ = "egon_ev_trip" |
133
|
|
|
__table_args__ = {"schema": "demand"} |
134
|
|
|
|
135
|
|
|
# scenario = Column( |
136
|
|
|
# String, ForeignKey(EgonEvPool.scenario), primary_key=True |
137
|
|
|
# ) |
138
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), primary_key=True) |
139
|
|
|
event_id = Column(Integer, primary_key=True) |
140
|
|
|
# egon_ev_pool_ev_id = Column( |
141
|
|
|
# Integer, ForeignKey(EgonEvPool.ev_id), nullable=False, index=True |
142
|
|
|
# ) |
143
|
|
|
egon_ev_pool_ev_id = Column(Integer, nullable=False, index=True) |
144
|
|
|
simbev_event_id = Column(Integer) |
145
|
|
|
location = Column(String(21)) |
146
|
|
|
use_case = Column(String(8)) |
147
|
|
|
charging_capacity_nominal = Column(REAL) |
148
|
|
|
charging_capacity_grid = Column(REAL) |
149
|
|
|
charging_capacity_battery = Column(REAL) |
150
|
|
|
soc_start = Column(REAL) |
151
|
|
|
soc_end = Column(REAL) |
152
|
|
|
charging_demand = Column(REAL) |
153
|
|
|
park_start = Column(Integer) |
154
|
|
|
park_end = Column(Integer) |
155
|
|
|
drive_start = Column(Integer) |
156
|
|
|
drive_end = Column(Integer) |
157
|
|
|
consumption = Column(REAL) |
158
|
|
|
|
159
|
|
|
# __table_args__ = ( |
160
|
|
|
# ForeignKeyConstraint([scenario, egon_ev_pool_ev_id], |
161
|
|
|
# [EgonEvPool.scenario, EgonEvPool.ev_id]), |
162
|
|
|
# {"schema": "demand"}, |
163
|
|
|
# ) |
164
|
|
|
|
165
|
|
|
# ev = relationship("EgonEvPool", back_populates="trips") |
166
|
|
|
|
167
|
|
|
|
168
|
|
View Code Duplication |
class EgonEvCountRegistrationDistrict(Base): |
|
|
|
|
169
|
|
|
"""Electric vehicle counts per registration district""" |
170
|
|
|
|
171
|
|
|
__tablename__ = "egon_ev_count_registration_district" |
172
|
|
|
__table_args__ = {"schema": "demand"} |
173
|
|
|
|
174
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), primary_key=True) |
175
|
|
|
scenario_variation = Column(String, primary_key=True) |
176
|
|
|
ags_reg_district = Column(Integer, primary_key=True) |
177
|
|
|
reg_district = Column(String) |
178
|
|
|
bev_mini = Column(Integer) |
179
|
|
|
bev_medium = Column(Integer) |
180
|
|
|
bev_luxury = Column(Integer) |
181
|
|
|
phev_mini = Column(Integer) |
182
|
|
|
phev_medium = Column(Integer) |
183
|
|
|
phev_luxury = Column(Integer) |
184
|
|
|
|
185
|
|
|
|
186
|
|
View Code Duplication |
class EgonEvCountMunicipality(Base): |
|
|
|
|
187
|
|
|
"""Electric vehicle counts per municipality""" |
188
|
|
|
|
189
|
|
|
__tablename__ = "egon_ev_count_municipality" |
190
|
|
|
__table_args__ = {"schema": "demand"} |
191
|
|
|
|
192
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), primary_key=True) |
193
|
|
|
scenario_variation = Column(String, primary_key=True) |
194
|
|
|
ags = Column(Integer, primary_key=True) |
195
|
|
|
bev_mini = Column(Integer) |
196
|
|
|
bev_medium = Column(Integer) |
197
|
|
|
bev_luxury = Column(Integer) |
198
|
|
|
phev_mini = Column(Integer) |
199
|
|
|
phev_medium = Column(Integer) |
200
|
|
|
phev_luxury = Column(Integer) |
201
|
|
|
rs7_id = Column(SmallInteger) |
202
|
|
|
|
203
|
|
|
|
204
|
|
View Code Duplication |
class EgonEvCountMvGridDistrict(Base): |
|
|
|
|
205
|
|
|
"""Electric vehicle counts per MV grid district""" |
206
|
|
|
|
207
|
|
|
__tablename__ = "egon_ev_count_mv_grid_district" |
208
|
|
|
__table_args__ = {"schema": "demand"} |
209
|
|
|
|
210
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), primary_key=True) |
211
|
|
|
scenario_variation = Column(String, primary_key=True) |
212
|
|
|
bus_id = Column( |
213
|
|
|
Integer, ForeignKey(MvGridDistricts.bus_id), primary_key=True |
214
|
|
|
) |
215
|
|
|
bev_mini = Column(Integer) |
216
|
|
|
bev_medium = Column(Integer) |
217
|
|
|
bev_luxury = Column(Integer) |
218
|
|
|
phev_mini = Column(Integer) |
219
|
|
|
phev_medium = Column(Integer) |
220
|
|
|
phev_luxury = Column(Integer) |
221
|
|
|
rs7_id = Column(SmallInteger) |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
class EgonEvMvGridDistrict(Base): |
225
|
|
|
"""List of electric vehicles per MV grid district""" |
226
|
|
|
|
227
|
|
|
__tablename__ = "egon_ev_mv_grid_district" |
228
|
|
|
__table_args__ = {"schema": "demand"} |
229
|
|
|
|
230
|
|
|
id = Column(Integer, primary_key=True) |
231
|
|
|
scenario = Column(String, ForeignKey(EgonScenario.name), index=True) |
232
|
|
|
scenario_variation = Column(String, index=True) |
233
|
|
|
bus_id = Column(Integer, ForeignKey(MvGridDistricts.bus_id), index=True) |
234
|
|
|
# egon_ev_pool_ev_id = Column(Integer, ForeignKey(EgonEvPool.ev_id)) |
235
|
|
|
egon_ev_pool_ev_id = Column(Integer, nullable=False) |
236
|
|
|
|
237
|
|
|
# ev = relationship("EgonEvPool", back_populates="mvgds") |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
class EgonEvMetadata(Base): |
241
|
|
|
"""List of EV Pool Metadata""" |
242
|
|
|
|
243
|
|
|
__tablename__ = "egon_ev_metadata" |
244
|
|
|
__table_args__ = {"schema": "demand"} |
245
|
|
|
|
246
|
|
|
scenario = Column(String, primary_key=True) |
247
|
|
|
eta_cp = Column(Float) |
248
|
|
|
stepsize = Column(Integer) |
249
|
|
|
start_date = Column(DateTime) |
250
|
|
|
end_date = Column(DateTime) |
251
|
|
|
soc_min = Column(Float) |
252
|
|
|
grid_timeseries = Column(Boolean) |
253
|
|
|
grid_timeseries_by_usecase = Column(Boolean) |
254
|
|
|
|