Spaces:
Runtime error
Runtime error
Merge pull request #94 from TomorrowsCities/ui_extended_labels
Browse files- tomorrowcities/pages/engine.py +46 -32
- tomorrowcities/pages/utilities.py +69 -0
tomorrowcities/pages/engine.py
CHANGED
|
@@ -28,7 +28,8 @@ from .settings import threshold_flood, threshold_flood_distance, threshold_road_
|
|
| 28 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics, generate_exposure, \
|
| 29 |
create_tally, generate_metrics
|
| 30 |
from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile, read_gem_xml, read_gem_xml_fragility, read_gem_xml_vulnerability, getText
|
| 31 |
-
from .utilities import S3FileBrowser, extension_list, extension_list_w_dots, PowerFragilityDisplayer, FragilityFunctionDisplayer
|
|
|
|
| 32 |
from ..components.file_drop import FileDropMultiple
|
| 33 |
from .docs import data_import_help
|
| 34 |
import ipywidgets
|
|
@@ -942,52 +943,65 @@ def FilterPanel():
|
|
| 942 |
# for filter_col in ['zoneid']:
|
| 943 |
# solara.CrossFilterSelect(df, filter_col, multiple=True)
|
| 944 |
# filters[layer_name], _ = solara.use_cross_filter(id(df), "dataframe")
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
with solara.Row(): #spacer
|
| 950 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 951 |
btn = solara.Button("BUILDING FILTERS")
|
| 952 |
with solara.Column(align="stretch"):
|
| 953 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 954 |
-
solara.CrossFilterReport(
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
solara.CrossFilterSelect(building, "nhouse", multiple=True)
|
| 958 |
-
solara.CrossFilterSelect(building, "residents", multiple=True)
|
| 959 |
-
solara.CrossFilterSelect(building, "occupancy", multiple=True)
|
| 960 |
-
solara.CrossFilterSelect(building, "storeys", multiple=True)
|
| 961 |
-
solara.CrossFilterSelect(building, "code_level", multiple=True)
|
| 962 |
-
solara.CrossFilterSelect(building, "material", multiple=True)
|
| 963 |
-
solara.CrossFilterSelect(building, "zoneid", multiple=True)
|
| 964 |
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
|
|
|
| 968 |
with solara.Row(): #spacer
|
| 969 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 970 |
btn = solara.Button("LANDUSE FILTERS")
|
| 971 |
with solara.Column(align="stretch"):
|
| 972 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 973 |
-
solara.CrossFilterReport(
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
tally_filter.value, _ = solara.use_cross_filter(id(tally_minimal), "tally_filter")
|
| 982 |
-
if tally_minimal is not None:
|
| 983 |
with solara.Row(): #spacer
|
| 984 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 985 |
btn = solara.Button("METRIC FILTERS")
|
| 986 |
with solara.Column(align="stretch"):
|
| 987 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 988 |
-
solara.CrossFilterReport(
|
| 989 |
-
for col in
|
| 990 |
-
solara.CrossFilterSelect(
|
| 991 |
|
| 992 |
@solara.component
|
| 993 |
def LayerDisplayer():
|
|
@@ -1458,7 +1472,7 @@ def ExecutePanel():
|
|
| 1458 |
|
| 1459 |
store_in_session_storage('tally', tally)
|
| 1460 |
store_in_session_storage('tally_geo', tally_geo)
|
| 1461 |
-
store_in_session_storage('tally_minimal', tally[
|
| 1462 |
store_info_to_session()
|
| 1463 |
layers.value['tally_is_available'].value = True
|
| 1464 |
tally_counter.value += 1
|
|
|
|
| 28 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics, generate_exposure, \
|
| 29 |
create_tally, generate_metrics
|
| 30 |
from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile, read_gem_xml, read_gem_xml_fragility, read_gem_xml_vulnerability, getText
|
| 31 |
+
from .utilities import S3FileBrowser, extension_list, extension_list_w_dots, PowerFragilityDisplayer, FragilityFunctionDisplayer, \
|
| 32 |
+
convert_data_for_filter_view, lbl_2_str
|
| 33 |
from ..components.file_drop import FileDropMultiple
|
| 34 |
from .docs import data_import_help
|
| 35 |
import ipywidgets
|
|
|
|
| 943 |
# for filter_col in ['zoneid']:
|
| 944 |
# solara.CrossFilterSelect(df, filter_col, multiple=True)
|
| 945 |
# filters[layer_name], _ = solara.use_cross_filter(id(df), "dataframe")
|
| 946 |
+
building_filter_view, set_building_filter_view = solara.use_state(None)
|
| 947 |
+
landuse_filter_view, set_landuse_filter_view = solara.use_state(None)
|
| 948 |
+
tally_minimal_filter_view, set_tally_minimal_filter_view = solara.use_state(None)
|
| 949 |
+
|
| 950 |
+
def create_building_filter_view():
|
| 951 |
+
data = layers.value['layers']['building']['df'].value
|
| 952 |
+
df = convert_data_for_filter_view(data, 'building')
|
| 953 |
+
set_building_filter_view(df)
|
| 954 |
+
|
| 955 |
+
def create_landuse_filter_view():
|
| 956 |
+
data = layers.value['layers']['landuse']['df'].value
|
| 957 |
+
df = convert_data_for_filter_view(data, 'landuse')
|
| 958 |
+
set_landuse_filter_view(df)
|
| 959 |
+
|
| 960 |
+
def create_tally_minimal_filter_view():
|
| 961 |
+
print('create_tally_minimal_filter_view triggered')
|
| 962 |
+
data = read_from_session_storage('tally_minimal')
|
| 963 |
+
df = convert_data_for_filter_view(data, 'tally_minimal')
|
| 964 |
+
print(df)
|
| 965 |
+
set_tally_minimal_filter_view(df)
|
| 966 |
+
|
| 967 |
+
# Building
|
| 968 |
+
solara.use_memo(create_building_filter_view, [layers.value['layers']['building']['df'].value])
|
| 969 |
+
building_filter.value, _ = solara.use_cross_filter(id(building_filter_view), "building_filter")
|
| 970 |
+
if building_filter_view is not None:
|
| 971 |
with solara.Row(): #spacer
|
| 972 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 973 |
btn = solara.Button("BUILDING FILTERS")
|
| 974 |
with solara.Column(align="stretch"):
|
| 975 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 976 |
+
solara.CrossFilterReport(building_filter_view)
|
| 977 |
+
for col, colinfo in lbl_2_str['building'].items():
|
| 978 |
+
solara.CrossFilterSelect(building_filter_view, colinfo['name'], multiple=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 979 |
|
| 980 |
+
# Landuse
|
| 981 |
+
solara.use_memo(create_landuse_filter_view, [layers.value['layers']['landuse']['df'].value])
|
| 982 |
+
landuse_filter.value, _ = solara.use_cross_filter(id(landuse_filter_view), "landuse_filter")
|
| 983 |
+
if landuse_filter_view is not None:
|
| 984 |
with solara.Row(): #spacer
|
| 985 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 986 |
btn = solara.Button("LANDUSE FILTERS")
|
| 987 |
with solara.Column(align="stretch"):
|
| 988 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 989 |
+
solara.CrossFilterReport(landuse_filter_view)
|
| 990 |
+
for col, colinfo in lbl_2_str['landuse'].items():
|
| 991 |
+
solara.CrossFilterSelect(landuse_filter_view, colinfo['name'], multiple=True)
|
| 992 |
+
|
| 993 |
+
# Tally minimal
|
| 994 |
+
solara.use_memo(create_tally_minimal_filter_view, [tally_counter.value])
|
| 995 |
+
tally_filter.value, _ = solara.use_cross_filter(id(tally_minimal_filter_view), "tally_filter")
|
| 996 |
+
if tally_minimal_filter_view is not None:
|
|
|
|
|
|
|
| 997 |
with solara.Row(): #spacer
|
| 998 |
solara.Markdown('''<h5 style=""></h5>''')
|
| 999 |
btn = solara.Button("METRIC FILTERS")
|
| 1000 |
with solara.Column(align="stretch"):
|
| 1001 |
with solara.lab.Menu(activator=btn, close_on_content_click=False, style={"width":"35vh", "align":"stretch"}): #"height":"60vh"
|
| 1002 |
+
solara.CrossFilterReport(tally_minimal_filter_view)
|
| 1003 |
+
for col, colinfo in lbl_2_str['tally_minimal'].items():
|
| 1004 |
+
solara.CrossFilterSelect(tally_minimal_filter_view, colinfo['name'], multiple=True)
|
| 1005 |
|
| 1006 |
@solara.component
|
| 1007 |
def LayerDisplayer():
|
|
|
|
| 1472 |
|
| 1473 |
store_in_session_storage('tally', tally)
|
| 1474 |
store_in_session_storage('tally_geo', tally_geo)
|
| 1475 |
+
store_in_session_storage('tally_minimal', tally[lbl_2_str['tally_minimal'].keys()])
|
| 1476 |
store_info_to_session()
|
| 1477 |
layers.value['tally_is_available'].value = True
|
| 1478 |
tally_counter.value += 1
|
tomorrowcities/pages/utilities.py
CHANGED
|
@@ -496,3 +496,72 @@ def PowerFragilityDisplayer(data, items_per_page=5):
|
|
| 496 |
on_value=set_vuln_string)
|
| 497 |
|
| 498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
on_value=set_vuln_string)
|
| 497 |
|
| 498 |
|
| 499 |
+
lbl_2_str = {
|
| 500 |
+
'landuse': {
|
| 501 |
+
'luf': {'name': 'Land Use Type',
|
| 502 |
+
'mapping': {}},
|
| 503 |
+
'avgincome': {'name': 'Average Income',
|
| 504 |
+
'mapping': {}},
|
| 505 |
+
},
|
| 506 |
+
'building': {
|
| 507 |
+
'ds': {'name': 'Damage State',
|
| 508 |
+
'mapping': {0: 'No',1: 'Slight', 2:'Moderate',3:'Extensive',4:'Complete'}},
|
| 509 |
+
'specialfac': {'name': 'Special Facility',
|
| 510 |
+
'mapping': {0: 'Residential', 1: 'Educational', 2:'Health'}},
|
| 511 |
+
'nhouse': {'name': 'Number of Households',
|
| 512 |
+
'mapping': {}},
|
| 513 |
+
'residents': {'name': 'Number of Residents',
|
| 514 |
+
'mapping': {}},
|
| 515 |
+
'occupancy': {'name': 'Occupancy',
|
| 516 |
+
'mapping': {'Com': 'Commercial','Res': 'Residential'}},
|
| 517 |
+
'storeys': {'name': 'Storeys',
|
| 518 |
+
'mapping': {}},
|
| 519 |
+
'code_level': {'name': 'Code Level',
|
| 520 |
+
'mapping': {}},
|
| 521 |
+
'material': {'name': 'Material',
|
| 522 |
+
'mapping': {}},
|
| 523 |
+
'zoneid': {'name': 'Zone ID',
|
| 524 |
+
'mapping': {}},
|
| 525 |
+
},
|
| 526 |
+
'tally_minimal': {
|
| 527 |
+
'ds': {'name': 'Damage State',
|
| 528 |
+
'mapping': {0: 'No',1: 'Slight', 2:'Moderate',3:'Extensive',4:'Complete'}},
|
| 529 |
+
'income': {'name': 'Income Level',
|
| 530 |
+
'mapping': {'highIncome': 'High Income', 'lowIncomeA': 'Low Income A'}},
|
| 531 |
+
'material': {'name': 'Material',
|
| 532 |
+
'mapping': {}},
|
| 533 |
+
'gender': {'name': 'Gender',
|
| 534 |
+
'mapping': {}},
|
| 535 |
+
'age': {'name': 'Age',
|
| 536 |
+
'mapping': {}},
|
| 537 |
+
'head': {'name': 'Head',
|
| 538 |
+
'mapping': {}},
|
| 539 |
+
'eduattstat': {'name': 'Education Status',
|
| 540 |
+
'mapping': {}},
|
| 541 |
+
'luf': {'name': 'Land Use',
|
| 542 |
+
'mapping': {}},
|
| 543 |
+
'occupancy': {'name': 'Occupancy',
|
| 544 |
+
'mapping': {'Com': 'Commercial','Res': 'Residential'}},
|
| 545 |
+
},
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
|
| 549 |
+
def convert_data_for_filter_view(data, layer_name):
|
| 550 |
+
if data is None:
|
| 551 |
+
return None
|
| 552 |
+
|
| 553 |
+
if layer_name not in lbl_2_str.keys():
|
| 554 |
+
return data
|
| 555 |
+
|
| 556 |
+
# Take the columns
|
| 557 |
+
df = data[lbl_2_str[layer_name].keys()]
|
| 558 |
+
|
| 559 |
+
for col, colinfo in lbl_2_str[layer_name].items():
|
| 560 |
+
if len(colinfo['mapping']) > 0:
|
| 561 |
+
df.replace({col: colinfo['mapping']}, inplace=True)
|
| 562 |
+
|
| 563 |
+
renaming = {col: colinfo['name'] for col, colinfo in lbl_2_str[layer_name].items()}
|
| 564 |
+
df.rename(columns=renaming, inplace=True)
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
return df
|