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
exposure-japan
Commits
7afb795e
Commit
7afb795e
authored
Jan 27, 2022
by
Danijel Schorlemmer
Browse files
Simplified the SQL query and optimized for processing speed
parent
bd4bfec8
Pipeline
#37870
passed with stage
in 1 minute and 31 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
exposurejapan/database.py
View file @
7afb795e
...
...
@@ -1065,16 +1065,13 @@ class JapanDatabase(SpatialiteDatabase):
# Calculate the population_density with the boundary area from Districts table
# and update the PopulationDistribution table
sql_statement
=
(
"WITH updates(ID, population_density) "
"AS (SELECT PopulationDistribution.district_id, PopulationDistribution.total/ "
"District.area_size "
"FROM PopulationDistribution "
"INNER JOIN District ON District.id = PopulationDistribution.district_id) "
)
sql_statement
+=
(
"UPDATE PopulationDistribution "
"SET population_density = (SELECT population_density FROM updates "
"WHERE PopulationDistribution.district_id = ID)"
"SET population_density = Q.density FROM "
"(SELECT PopulationDistribution.total/District.area_size AS density, "
"PopulationDistribution.district_id AS id "
"FROM PopulationDistribution INNER JOIN District "
"ON District.id = PopulationDistribution.district_id) AS Q "
"WHERE PopulationDistribution.district_id = Q.id"
)
logger
.
debug
(
sql_statement
)
self
.
cursor
.
execute
(
sql_statement
)
...
...
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