[Bug] - The indentation of the statement in line 1615 is wrong
In function create_damage_view
the indentation in line 1615 (sql_statement = f"""
) is wrong. The statement is called multiple times for no reason. Also, the SQL code within this statement is wrongly indented.
for damage_state_id, damage_state_level in damage_states:
damage_state_tables += f"""
INNER JOIN (
SELECT damage_probability, assessment_id
FROM Damage
WHERE Damage.damage_state_id = {damage_state_id}
) AS {damage_state_level}
ON {damage_state_level}.assessment_id = Assessment.id
"""
sql_statement = f"""
CREATE VIEW {name} AS
SELECT
Entity.id AS entityid,
Assessment.id AS assessmentid,
{geom_table}.geom AS geometry,
Entity.quadkey,
ST_Area(SumNum.geom, True)/1000000 AS area_in_sqkm,
SumNum.number_buildings,
MostProbable.damage_state_name AS most_probable_damage,
{damage_state_selection}
FROM Entity
{damage_ratio_query}
INNER JOIN Assessment ON Assessment.entity_id = Entity.id
{damage_state_tables}
INNER JOIN (
SELECT MAX(damage_probability), damage_state_id,
DamageState.damage_state_name, assessment_id
FROM Damage
INNER JOIN DamageState
ON Damage.damage_state_id = DamageState.id
GROUP BY assessment_id
) AS MostProbable ON MostProbable.assessment_id = Assessment.id
WHERE Assessment.assessment_source_id = {assessment_source_id}
"""
# Expand view creation sql_statement for tile entities because
# of aggregation of buildings and residuals over quad-keys
if entity_type == "tile":
sql_statement += " GROUP BY Entity.quadkey"
# Creating the view
self.connection.execute(sql_statement)
Edited by Danijel Schorlemmer