-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
348 lines (325 loc) · 12.7 KB
/
database.sql
File metadata and controls
348 lines (325 loc) · 12.7 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
DROP TABLE IF EXISTS building_asset_context;
DROP TABLE IF EXISTS building_consumption;
DROP TABLE IF EXISTS building;
DROP TABLE IF EXISTS building_energy_asset;
DROP TABLE IF EXISTS community_energy_asset;
DROP TABLE IF EXISTS time_serie;
DROP TABLE IF EXISTS multi_time_serie;
DROP TABLE IF EXISTS node;
DROP TABLE IF EXISTS transformation_action;
DROP TABLE IF EXISTS context;
DROP TABLE IF EXISTS building_statistics_profile;
DROP TABLE IF EXISTS demand_profile;
DROP TABLE IF EXISTS building_use;
DROP TABLE IF EXISTS generation_system_profile;
DROP TABLE IF EXISTS generation_system;
DROP TABLE IF EXISTS national_energy_carrier_production;
DROP TABLE IF EXISTS energy_carrier;
DROP TABLE IF EXISTS system_type;
DROP TABLE IF EXISTS country_weather_data;
DROP TABLE IF EXISTS country_statistics;
DROP TABLE IF EXISTS country;
DROP TABLE IF EXISTS climatic_region;
-- DICTIONARIES AND STATIC DATA
CREATE TABLE climatic_region (
id SERIAL NOT NULL CONSTRAINT climatic_region_pk PRIMARY KEY,
name character varying NOT NULL
);
CREATE TABLE country (
id SERIAL NOT NULL CONSTRAINT country_pk PRIMARY KEY,
name character varying NOT NULL,
geom geometry(GEOMETRY,4326) NOT NULL
);
CREATE TABLE country_statistics (
id SERIAL NOT NULL CONSTRAINT country_statistics_pk PRIMARY KEY,
country_id int NOT NULL,
gdp_base float NOT NULL,
gdp_growth float NOT NULL,
population int NOT NULL,
population_growth int NOT NULL,
building_retrofitting_rate int NOT NULL,
e_cars_fleet int NOT NULL,
avg_cars_per_city int NOT NULL,
CONSTRAINT country_statistics_country_fk
FOREIGN key (country_id)
REFERENCES country(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE country_weather_data (
id SERIAL NOT NULL CONSTRAINT country_weather_data_pk PRIMARY KEY,
country_id int NOT NULL,
climatic_region_id int NOT NULL,
hdh float[] NOT NULL,
cdh float[] NOT NULL,
reference_temperature_heating_in_c float NOT NULL,
reference_temperature_cooling_in_c float NOT NULL,
temp_ambient_air_in_c float[] NOT NULL,
temp_mains_water_in_c float[] NOT NULL,
temp_ground_in_c float[] NOT NULL,
humidity_in_percent float[] NOT NULL,
CONSTRAINT country_weather_data_country_fk
FOREIGN key (country_id)
REFERENCES country(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT country_weather_data_climatic_region_fk
FOREIGN key (climatic_region_id)
REFERENCES climatic_region(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE system_type (
id SERIAL NOT NULL CONSTRAINT system_type_pk PRIMARY KEY,
name character varying NOT NULL
);
CREATE TABLE energy_carrier (
id SERIAL NOT NULL CONSTRAINT energy_carrier_pk PRIMARY KEY,
name character varying NOT NULL,
final boolean NOT NULL
);
CREATE TABLE national_energy_carrier_production (
id SERIAL NOT NULL CONSTRAINT national_energy_carrier_production_pk PRIMARY KEY,
energy_carrier_id int NOT NULL,
country_id int NOT NULL,
pef_tot float NOT NULL,
pef_nren float NOT NULL,
pef_ren float NOT NULL,
hourly_price float NOT NULL,
co2_equiv_content float NOT NULL,
CONSTRAINT national_energy_carrier_production_energy_carrier_fk
FOREIGN key (energy_carrier_id)
REFERENCES energy_carrier(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT national_energy_carrier_production_country_fk
FOREIGN key (country_id)
REFERENCES country(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE generation_system (
id SERIAL NOT NULL CONSTRAINT generation_system_pk PRIMARY KEY,
system_type_id int NOT NULL,
name character varying NOT NULL,
fuel_yield float NOT NULL,
energy_carrier_input_1_id int NULL,
energy_carrier_input_2_id int NULL,
energy_carrier_output_1_id int NULL,
energy_carrier_output_2_id int NULL,
CONSTRAINT generation_system_system_type_fk
FOREIGN key (system_type_id)
REFERENCES system_type(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_energy_carrier_input_1_fk
FOREIGN key (energy_carrier_input_1_id)
REFERENCES energy_carrier(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_energy_carrier_input_2_fk
FOREIGN key (energy_carrier_input_2_id)
REFERENCES energy_carrier(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_energy_carrier_output_1_fk
FOREIGN key (energy_carrier_output_1_id)
REFERENCES energy_carrier(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_energy_carrier_output_2_fk
FOREIGN key (energy_carrier_output_2_id)
REFERENCES energy_carrier(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE generation_system_profile (
id SERIAL NOT NULL CONSTRAINT generation_system_profile_pk PRIMARY KEY,
electricity_system_id int NOT NULL,
heating_system_id int NOT NULL,
cooling_system_id int NOT NULL,
dhw_system_id int NOT NULL,
CONSTRAINT generation_system_profile_electricity_system_fk
FOREIGN key (electricity_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_profile_heating_system_fk
FOREIGN key (heating_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_profile_cooling_system_fk
FOREIGN key (cooling_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT generation_system_profile_dhw_system_fk
FOREIGN key (dhw_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE building_use (
id SERIAL NOT NULL CONSTRAINT building_use_pk PRIMARY KEY,
name character varying NOT NULL
);
CREATE TABLE demand_profile (
id SERIAL NOT NULL CONSTRAINT demand_profile_pk PRIMARY KEY,
electricity_demand float[] NOT NULL,
heating_demand float[] NOT NULL,
cooling_demand float[] NOT NULL,
dhw_demand float[] NOT NULL
);
CREATE TABLE building_statistics_profile (
id SERIAL NOT NULL CONSTRAINT building_statistics_profile_pk PRIMARY KEY,
building_use_id int NOT NULL,
demand_profile_id int NOT NULL,
generation_system_profile_id int NULL,
country_id int NOT NULL,
construction_min_year int NULL,
construction_max_year int NULL,
CONSTRAINT building_statistics_profile_building_use_fk
FOREIGN key (building_use_id)
REFERENCES building_use(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_statistics_profile_demand_profile_fk
FOREIGN key (demand_profile_id)
REFERENCES demand_profile(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_statistics_profile_generation_system_profile_fk
FOREIGN key (generation_system_profile_id)
REFERENCES generation_system_profile(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_statistics_profile_country_fk
FOREIGN key (country_id)
REFERENCES country(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- END DICTIONARIES AND STATIC DATA
CREATE TABLE context (
id SERIAL NOT NULL CONSTRAINT context_pk PRIMARY KEY,
context_parent int NULL,
name character varying NOT NULL,
start_date date NOT NULL,
timestep_count int NOT NULL,
timestep_duration int NOT NULL,
author character varying NOT NULL,
creation_date date NOT NULL,
description character varying NOT NULL,
CONSTRAINT context_context_fk
FOREIGN key (context_parent)
REFERENCES context(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE transformation_action (
id SERIAL NOT NULL CONSTRAINT transformation_action_pk PRIMARY KEY,
context_id int,
param1 float NOT NULL,
param2 float NOT NULL,
param3 float NOT NULL,
param4 float NOT NULL,
param5 float NOT NULL,
CONSTRAINT transformation_action_context_fk
FOREIGN key (context_id)
REFERENCES context(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE node (
id SERIAL NOT NULL CONSTRAINT node_pk PRIMARY KEY,
context_id int,
name character varying NOT NULL,
geom geometry(POINT,4326) NOT NULL,
CONSTRAINT node_context_fk
FOREIGN key (context_id)
REFERENCES context(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE multi_time_serie (
id SERIAL NOT NULL CONSTRAINT multi_time_serie_pk PRIMARY KEY,
name character varying NOT NULL
);
CREATE TABLE time_serie (
id SERIAL NOT NULL CONSTRAINT time_serie_pk PRIMARY KEY,
multi_time_serie_id int NOT NULL,
value float[] NOT NULL,
testcase character varying NOT NULL,
CONSTRAINT time_serie_multi_time_serie_fk
FOREIGN key (multi_time_serie_id)
REFERENCES multi_time_serie(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE community_energy_asset (
id SERIAL NOT NULL CONSTRAINT community_energy_asset_pk PRIMARY KEY,
availability_ts_id int NOT NULL,
input_node_id int NOT NULL,
output_node_id int NULL,
generation_system_id int NOT NULL,
pmax_scalar float NOT NULL,
pmaxmin_scalar float NOT NULL,
pmaxmax_scalar float NOT NULL,
CONSTRAINT community_energy_asset_multi_time_serie_fk
FOREIGN key (availability_ts_id)
REFERENCES multi_time_serie(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT community_energy_asset_input_node_fk
FOREIGN key (input_node_id)
REFERENCES node(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT community_energy_asset_output_node_fk
FOREIGN key (output_node_id)
REFERENCES node(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT community_energy_asset_generation_system_fk
FOREIGN key (generation_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE building_energy_asset (
id SERIAL NOT NULL CONSTRAINT building_energy_asset_pk PRIMARY KEY,
availability_ts_id int NOT NULL,
generation_system_id int NOT NULL,
pmax_scalar float NOT NULL,
pmaxmin_scalar float NOT NULL,
pmaxmax_scalar float NOT NULL,
CONSTRAINT building_energy_asset_multi_time_serie_fk
FOREIGN key (availability_ts_id)
REFERENCES multi_time_serie(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_energy_asset_generation_system_fk
FOREIGN key (generation_system_id)
REFERENCES generation_system(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE building (
id SERIAL NOT NULL CONSTRAINT building_pk PRIMARY KEY,
geom geometry(GEOMETRY,4326) NOT NULL,
area float NOT NULL,
height float NOT NULL,
building_statistics_profile_id int NULL,
CONSTRAINT building_building_statistics_profile_fk
FOREIGN key (building_statistics_profile_id)
REFERENCES building_statistics_profile(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE building_consumption (
id SERIAL NOT NULL CONSTRAINT building_consumption_pk PRIMARY KEY,
elec_consumption float[],
heat_consumption float[],
cool_consumption float[],
dhw_consumption float[]
);
CREATE TABLE building_asset_context (
id SERIAL NOT NULL CONSTRAINT building_asset_context_pk PRIMARY KEY,
context_id int NULL,
building_consumption_id int NOT NULL,
generation_system_profile_id int NOT NULL,
building_id int NOT NULL,
building_energy_asset_id int NOT NULL,
CONSTRAINT building_asset_context_context_fk
FOREIGN key (context_id)
REFERENCES context(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_asset_context_building_consumption_fk
FOREIGN key (building_consumption_id)
REFERENCES building_consumption(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_asset_context_generation_system_profile_fk
FOREIGN key (generation_system_profile_id)
REFERENCES generation_system_profile(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_asset_context_building_fk
FOREIGN key (building_id)
REFERENCES building(id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT building_asset_context_building_energy_asset_fk
FOREIGN key (building_energy_asset_id)
REFERENCES building_energy_asset(id)
ON UPDATE NO ACTION ON DELETE NO ACTION
);