Skip to content

Commit

Permalink
Merge pull request #455 from global-healthy-liveable-cities/enhancements
Browse files Browse the repository at this point in the history
Enhancements
  • Loading branch information
carlhiggs authored Jun 19, 2024
2 parents aafe9eb + 806f3fe commit 0b4b4c1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .ghsci_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.5.2
4.5.3
6 changes: 3 additions & 3 deletions process/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def export_indicators(r, gpkg=True, csv=True):
r.tables = r.get_tables()
if r.tables == []:
sys.exit(
f"\nResults don't appear to have been processed Please ensure that the analysis process has been run for this study region successfully and then try again. The specific error raised was:\n{e}\n",
f"\nResults don't appear to have been processed for {r.codename}.\n\nPlease ensure that the analysis process has been run for this study region successfully and then try again.",
)
print('\nData files')
tables_not_in_database = [x for x in tables if x not in r.tables]
if len(tables_not_in_database) > 0:
print(
Expand Down Expand Up @@ -68,7 +69,7 @@ def export_indicators(r, gpkg=True, csv=True):

def generate(r):
"""List resources that have been generated for this study region."""
if type(r) == str:
if type(r) is str:
codename = r
r = Region(codename)
else:
Expand All @@ -88,7 +89,6 @@ def generate(r):
if os.path.exists(r.log):
print('\nAnalysis log text file')
print(os.path.basename(r.log))
print('\nData files')
export_indicators(r)
# Generate data dictionary
print('\nData dictionaries')
Expand Down
16 changes: 11 additions & 5 deletions process/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,10 @@ async def get_map_tooltip():
## Title
with ui.column().props('style="max-width: 900px; margin-top: 20px;"'):
with ui.row().classes('fixed').style(
'top: 0px; left: 50%;transform: translateX(-50%);',
).style('max-width: 900px;'):
'top: 0px; left: 50%; transform: translateX(-50%); max-width: 900px',
):
ui.label('Global Healthy and Sustainable City Indicators').style(
'color: #6E93D6; font-size: 200%; font-weight: 300; margin-top: 20px;',
'color: #6E93D6; font-size: 200%; font-weight: 300; margin-top: 20px',
)
ui.button().props('icon=logout outline round ').classes(
'shadow-lg',
Expand All @@ -1108,7 +1108,7 @@ async def get_map_tooltip():
## Body
map = (
leaflet()
.style('width:100%;height:25rem')
.style('width:100%;height:20rem')
.on('click', get_map_tooltip)
)
# map.set_no_location(default_location, default_zoom)
Expand Down Expand Up @@ -1160,7 +1160,7 @@ async def get_map_tooltip():
)
# define and design the panels for the six tabs
with ui.tab_panels(tabs, value='Study regions').style(
'width:100%',
'width:100%; max-height:80%',
):
with ui.tab_panel('Study regions'):
region_ui(map, selection)
Expand All @@ -1179,10 +1179,16 @@ async def get_map_tooltip():


# NOTE on windows reload must be disabled to make asyncio.create_subprocess_exec work (see https://github.com/zauberzeug/nicegui/issues/486)
app.on_startup(
lambda: print(
'GHSCI app launched for viewing in your web browser at: http://localhost:8080\nPlease wait a few moments for the app to load.',
),
)
ui.run(
# reload=platform.system() != 'Windows',
reload=False,
title='GHSCI',
show=False,
favicon=r'configuration/assets/favicon.ico',
show_welcome_message=False,
)
3 changes: 2 additions & 1 deletion process/subprocesses/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,8 @@ def update_value_if_key_in_template(
f'{heading} blurb'
].format(**phrases)
else:
template[f'{heading}'] = ''
if phrases[f'{heading} blurb'] == '':
template[f'{heading}'] = ''
return template


Expand Down
20 changes: 13 additions & 7 deletions process/subprocesses/ghsci.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,12 @@ def _region_dictionary_setup(self, folder_path):
'urban_region',
data_path,
)
if r['urban_region'] is None:
return None
if r['urban_region']['data_dir'].startswith('Not required'):
r['urban_query'] = None
if r['study_region_boundary']['data'] == 'urban_query':
sys.exit(
'Study region has been configured to use the "urban_query" parameter, but urban region data does not appear to have been defined.',
)
r['buffered_urban_study_region'] = buffered_urban_study_region
r['db'] = codename.lower()
r['dbComment'] = (
Expand Down Expand Up @@ -574,6 +578,8 @@ def _region_data_setup(
region = region_config['codename']
else:
region = self.codename
if data not in region_config:
region_config[data] = None
if isinstance(region_config[data], str):
if data not in datasets or datasets[data] is None:
print(
Expand All @@ -592,9 +598,7 @@ def _region_data_setup(
return None
data_dictionary = datasets[data][region_config[data]].copy()
else:
if data == 'urban_region' and (
data not in region_config or region_config[data] is None
):
if data == 'urban_region' and region_config[data] is None:
urban_region_checks = [
self.config['study_region_boundary'][
'ghsl_urban_intersection'
Expand Down Expand Up @@ -634,13 +638,15 @@ def _region_data_setup(
f"{region}.yml error: The 'data_dir' entry for {data} does not appear to have been defined. This parameter is required for analysis of {region}, and is used to locate a required dataset cross-referenced in {region}.yml. Please check the configured settings before proceeding.",
)
return None
if data_path is not None:
if data_path is not None and not data_dictionary[
'data_dir'
].startswith('Not required'):
data_dictionary['data_dir'] = (
f"{data_path}/{data_dictionary['data_dir']}"
)
return data_dictionary
except Exception as e:
sys.exit(e)
sys.exit(f'Data Check error with {data}: {e}')

def _population_data_setup(self, r):
r['population'] = self._region_data_setup(r, 'population', data_path)
Expand Down
79 changes: 50 additions & 29 deletions process/subprocesses/policy_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def get_policy_checklist(xlsx) -> dict:

try:
df = pd.read_excel(
xlsx, sheet_name='Policy Checklist', header=1, usecols='A:N',
xlsx,
sheet_name='Policy Checklist',
header=1,
usecols='A:N',
)
df.columns = [
'Indicators',
Expand Down Expand Up @@ -41,10 +44,12 @@ def get_policy_checklist(xlsx) -> dict:
df.loc[:, 'Indicators'] = df.loc[:, 'Indicators'].ffill()
# Only keep measures associated with indicators, replacing 'see also' reference indicators with NA
df.loc[:, 'Measures'] = df.apply(
lambda x: x['Measures']
if x['Indicators'] in policies['Indicators'].keys()
and x['Measures'] in policies['Indicators'][x['Indicators']]
else pd.NA,
lambda x: (
x['Measures']
if x['Indicators'] in policies['Indicators'].keys()
and x['Measures'] in policies['Indicators'][x['Indicators']]
else pd.NA
),
axis=1,
)
# fill down Measures column values
Expand All @@ -54,13 +59,15 @@ def get_policy_checklist(xlsx) -> dict:
df['qualifier'] = (
df['Principles']
.apply(
lambda x: x.strip()
if (
str(x).strip() == 'No'
or str(x).strip() == 'Yes'
or str(x).strip() == 'Yes, explicit mention of:'
)
else pd.NA,
lambda x: (
x.strip()
if (
str(x).strip() == 'No'
or str(x).strip() == 'Yes'
or str(x).strip() == 'Yes, explicit mention of:'
)
else pd.NA
),
)
.ffill()
.fillna('')
Expand Down Expand Up @@ -101,13 +108,16 @@ def get_policy_setting(xlsx) -> dict:
df.loc[:, 'item'] = df.loc[:, 'item'].ffill()
setting = {}
setting['Person(s)'] = df.loc[
df['item'] == 'Name of person(s) completing checklist:', 'value',
df['item'] == 'Name of person(s) completing checklist:',
'value',
].values[0]
setting['E-mail'] = df.loc[
df['item'] == 'Email address(es):', 'value',
df['item'] == 'Email address(es):',
'value',
].values[0]
setting['Date'] = df.loc[
df['item'] == 'Date completed', 'value',
df['item'] == 'Date completed',
'value',
].values[0]
try:
setting['Date'] = setting['Date'].strftime('%Y-%m-%d')
Expand All @@ -118,7 +128,8 @@ def get_policy_setting(xlsx) -> dict:
0
]
setting['Country'] = df.loc[
df['location'] == 'Country', 'value',
df['location'] == 'Country',
'value',
].values[0]
setting['Levels of Government'] = (
df.loc[
Expand Down Expand Up @@ -155,7 +166,8 @@ def get_policy_setting(xlsx) -> dict:
'value',
].values[0]
setting['Environmental disaster context']['Other'] = df.loc[
df['location'] == 'Other (please specify)', 'value',
df['location'] == 'Other (please specify)',
'value',
].values[0]
setting['Environmental disaster context'] = '\n'.join(
[
Expand Down Expand Up @@ -215,12 +227,16 @@ def header(self):
# Printing title:
self.set_font('helvetica', 'B', 24)
with self.local_context(text_color=(89, 39, 226)):
self.write_html(
f'<br><br><section><h1><font color="#5927E2"><b>{self.location}</b></font></h1></section>',
)
self.write_html(
'<font color="#CCCCCC"><b>Policy report</b></font><br><br>',
self.multi_cell(
w=180,
text=f'\n\n\n{self.location}\nPolicy summary\n',
)
# self.write_html(
# f'<br><br><section><h1><font color="#5927E2"><b>{self.location}</b></font></h1></section>',
# )
# self.write_html(
# '<font color="#CCCCCC"><b>Policy report</b></font><br><br>',
# )
else:
# Rendering logo:
self.image(
Expand All @@ -234,7 +250,10 @@ def header(self):
with self.local_context(text_color=(89, 39, 226)):
self.set_x(38)
self.multi_cell(
w=134, txt=self.location, border=0, align='R',
w=134,
txt=self.location,
border=0,
align='R',
)
self.set_x(0)
self.set_margins(19, 32, 19)
Expand Down Expand Up @@ -298,12 +317,14 @@ def format_policy_checklist(self, df) -> None:
== sections[section]['indicators'][indicator]
]
.apply(
lambda x: x.str.strip()
.replace('&nbsp', ' ')
.replace(' ', '')
if x['Measures']
in policies['Indicators'][x['Indicators']]
else pd.NA,
lambda x: (
x.str.strip()
.replace('&nbsp', ' ')
.replace(' ', '')
if x['Measures']
in policies['Indicators'][x['Indicators']]
else pd.NA
),
axis=1,
)['Measures']
.ffill()
Expand Down

0 comments on commit 0b4b4c1

Please sign in to comment.