Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
gde-importer
Commits
f98a2261
Commit
f98a2261
authored
Feb 17, 2022
by
Cecilia Nievas
Browse files
Added feature to store number of storeys to data_units_buildings
parent
648a9073
Pipeline
#39304
passed with stage
in 2 minutes and 25 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
gdeimporter/dataunit.py
View file @
f98a2261
...
...
@@ -194,6 +194,7 @@ class DataUnit:
time of the day).
total_cost_per_building (float):
Total replacement cost per building, including costs of structural and
non-structural components as well as contents.
storeys_min (int):
Minimum number of storeys of the building class.
storeys_max (int):
...
...
@@ -489,9 +490,10 @@ class DataUnit:
sql_commands
[
"insert"
]
=
"INSERT INTO"
sql_commands
[
"insert"
]
+=
" %s(data_unit_id, occupancy_case, aggregated_source_id,"
sql_commands
[
"insert"
]
+=
" building_class_name, settlement_type, occupancy_subtype,"
sql_commands
[
"insert"
]
+=
" exposure_entity, proportions,"
sql_commands
[
"insert"
]
+=
" census_people_per_building, total_cost_per_building)"
sql_commands
[
"insert"
]
+=
" VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');"
sql_commands
[
"insert"
]
+=
" exposure_entity, proportions, census_people_per_building,"
sql_commands
[
"insert"
]
+=
" total_cost_per_building, storeys_min, storeys_max)"
sql_commands
[
"insert"
]
+=
" VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',"
sql_commands
[
"insert"
]
+=
" '%s','%s');"
db_gde_tiles
=
Database
(
**
db_data_units_config
)
db_gde_tiles
.
create_connection_and_cursor
()
...
...
@@ -535,6 +537,8 @@ class DataUnit:
buildings_data
[
"proportions"
].
to_numpy
()[
i
],
buildings_data
[
"census_people_per_building"
].
to_numpy
()[
i
],
buildings_data
[
"total_cost_per_building"
].
to_numpy
()[
i
],
buildings_data
[
"storeys_min"
].
to_numpy
()[
i
],
buildings_data
[
"storeys_max"
].
to_numpy
()[
i
],
)
)
...
...
gdeimporter/tools/buildingtaxonomy.py
View file @
f98a2261
...
...
@@ -86,7 +86,6 @@ class GEMTaxonomy_v3:
num_storeys_max
,
could_not_interpret
,
)
=
GEMTaxonomy_v3
.
_interpret_range_of_storeys
(
building_class
,
"HBET:"
)
else
:
could_not_interpret
=
True
num_storeys_min
=
1
...
...
tests/data/test_database_set_up.sql
View file @
f98a2261
...
...
@@ -161,6 +161,8 @@ CREATE TABLE data_units_buildings
proportions
FLOAT
,
census_people_per_building
FLOAT
,
total_cost_per_building
FLOAT
,
storeys_min
SMALLINT
,
storeys_max
SMALLINT
,
PRIMARY
KEY
(
data_unit_id
,
...
...
@@ -181,9 +183,11 @@ INSERT INTO data_units_buildings(building_class_name,
data_unit_id
,
proportions
,
census_people_per_building
,
total_cost_per_building
)
total_cost_per_building
,
storeys_min
,
storeys_max
)
VALUES
(
'SOMECLASS1'
,
'SOMECLASS1
/H:1
'
,
'urban'
,
'Single'
,
18
,
...
...
@@ -192,9 +196,11 @@ VALUES (
'EN1_Unit_1'
,
0
.
3
,
12
.
7
,
1200000
.
0
1200000
.
0
,
1
,
1
),
(
'SOMECLASS2'
,
(
'SOMECLASS2
/HBET:2-4
'
,
'urban'
,
'Single'
,
18
,
...
...
@@ -203,5 +209,7 @@ VALUES (
'EN1_Unit_1'
,
0
.
7
,
2
.
5
,
500000
.
0
500000
.
0
,
2
,
4
);
tests/test_aggregatedexposuremodel.py
View file @
f98a2261
...
...
@@ -576,6 +576,20 @@ def test_ExposureModelESRM20(test_db):
4
,
)
assert
(
db_queried_proportions_and_properties
[
"storeys_min"
][
which_in_db_query
]
==
expected_results_proportions_and_properties
[
"storeys_min"
].
to_numpy
()[
rows_entity_occupancy
][
rows_data_unit
][
which_in_expected
]
)
assert
(
db_queried_proportions_and_properties
[
"storeys_max"
][
which_in_db_query
]
==
expected_results_proportions_and_properties
[
"storeys_max"
].
to_numpy
()[
rows_entity_occupancy
][
rows_data_unit
][
which_in_expected
]
)
# Test that the data units have been stored correctly
for
row
in
range
(
2
,
11
):
query_result
=
query_data_units
(
...
...
@@ -741,12 +755,16 @@ def query_data_units_buildings(
Number of census-derived people per building of this class.
total_cost_per_building (arr of float):
Total replacement cost of a building of this class.
storeys_min (arr of int):
Minimum number of storeys of the building class.
storeys_max (arr of int):
Maximum number of storeys of the building class.
"""
sql_command
=
(
"SELECT exposure_entity, building_class_name, settlement_type, occupancy_subtype,"
" proportions, census_people_per_building, total_cost_per_building"
" FROM data_units_buildings"
" proportions, census_people_per_building, total_cost_per_building
, storeys_min,
"
"
storeys_max
FROM data_units_buildings"
" WHERE (data_unit_id='%s' AND occupancy_case='%s' AND aggregated_source_id='%s');"
%
(
data_unit_id_full
,
occupancy_case
,
aggregated_source_id
)
)
...
...
@@ -767,5 +785,7 @@ def query_data_units_buildings(
[
result
[
i
][
5
]
for
i
in
range
(
len
(
result
))]
)
results
[
"total_cost_per_building"
]
=
numpy
.
array
([
result
[
i
][
6
]
for
i
in
range
(
len
(
result
))])
results
[
"storeys_min"
]
=
numpy
.
array
([
result
[
i
][
7
]
for
i
in
range
(
len
(
result
))])
results
[
"storeys_max"
]
=
numpy
.
array
([
result
[
i
][
8
]
for
i
in
range
(
len
(
result
))])
return
results
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment