From 7f1b3805d741d93f412e93b0392931b463f985fa Mon Sep 17 00:00:00 2001 From: Kira-Liu00 Date: Wed, 8 Oct 2025 15:42:02 +1100 Subject: [PATCH 1/3] fix: implement fixed heatmap legend range for issue #224 --- pages/lib/extract_df.py | 12 +++++++++++- pages/lib/template_graphs.py | 1 + pages/natural_ventilation.py | 13 ++++++++----- tests/node/cypress/e2e/spec.cy.js | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pages/lib/extract_df.py b/pages/lib/extract_df.py index ded1c78..37ebde3 100644 --- a/pages/lib/extract_df.py +++ b/pages/lib/extract_df.py @@ -5,6 +5,7 @@ import zipfile from datetime import timedelta from urllib.request import Request, urlopen +from functools import lru_cache import logging import numpy as np @@ -49,6 +50,13 @@ def get_data(source_url): return None +@lru_cache(maxsize=64) +def get_global_temp_range(location: str, col_name: str) -> tuple[float, float]: + df_all = get_data(location) # Take the full-year data + series = df_all[col_name].replace([np.inf, -np.inf], np.nan).dropna() + return float(series.min()), float(series.max()) + + @code_timer def get_location_info(lst, file_name): """Extract and clean the data. Return a pandas data from a url.""" @@ -254,7 +262,9 @@ def create_df(lst, file_name): Variables.MONTH.col_name, Variables.HOUR.col_name, ] - ].astype(int) + ].astype( + int + ) # Add in DOY df_doy = ( diff --git a/pages/lib/template_graphs.py b/pages/lib/template_graphs.py index 0d3bae3..4dcc499 100644 --- a/pages/lib/template_graphs.py +++ b/pages/lib/template_graphs.py @@ -370,6 +370,7 @@ def heatmap_with_filter( invert_month, invert_hour, title, + z_range=None, ): """General function that returns a heatmap.""" variable = VariableInfo.from_col_name(var) diff --git a/pages/natural_ventilation.py b/pages/natural_ventilation.py index 9f18520..fee08e7 100644 --- a/pages/natural_ventilation.py +++ b/pages/natural_ventilation.py @@ -1,5 +1,6 @@ import dash from dash import dcc +from dash import no_update import dash_mantine_components as dmc from dash_extensions.enrich import Output, Input, State, callback @@ -12,7 +13,6 @@ tight_margins, month_lst, ) -from pages.lib.utils import get_max_min_value from pages.lib.template_graphs import filter_df_by_month_and_hour from pages.lib.global_variables import Variables, VariableInfo from pages.lib.global_element_ids import ElementIds @@ -278,6 +278,8 @@ def nv_heatmap( invert_hour, si_ip, ): + if df is None: + return no_update # enable or disable button apply filter DPT dpt_data_filter = enable_dew_point_data_filter(condensation_enabled) @@ -328,11 +330,10 @@ def nv_heatmap( var_color = variable.get_color() - if global_local == "global": - range_z = var_range + if si_ip == UnitSystem.IP: + range_z = [32.0, 86.0] else: - data_max, data_min = get_max_min_value(df[var]) - range_z = [data_min, data_max] + range_z = [0.0, 30.0] title = ( f"Hours when the {var_name} is in the range {min_dbt_val} to" @@ -420,6 +421,7 @@ def nv_heatmap( Input(ElementIds.NV_MONTH_HOUR_FILTER, "n_clicks"), Input(ElementIds.NV_DBT_FILTER, "n_clicks"), Input(ElementIds.NV_DPT_FILTER, "n_clicks"), + Input(ElementIds.ID_NATURAL_VENTILATION_GLOBAL_LOCAL_RADIO_INPUT, "value"), Input(ElementIds.SWITCHES_INPUT, "checked"), Input(ElementIds.ENABLE_CONDENSATION, "value"), ], @@ -441,6 +443,7 @@ def nv_bar_chart( time_filter, dbt_data_filter, click_dpt_filter, + global_local, normalize, condensation_enabled, df, diff --git a/tests/node/cypress/e2e/spec.cy.js b/tests/node/cypress/e2e/spec.cy.js index 38dea4f..3de4a4a 100644 --- a/tests/node/cypress/e2e/spec.cy.js +++ b/tests/node/cypress/e2e/spec.cy.js @@ -22,7 +22,7 @@ function click_tab(name) { } function load_epw() { - cy.get('input[type=file]').selectFile('test.epw', {force: true}); + cy.get('input[type=file]').selectFile('test.epw', { force: true }); } describe('Clima', () => { From c562e2f9523debd894dbdc82b9a3ca27529a354a Mon Sep 17 00:00:00 2001 From: Kira-Liu00 Date: Thu, 9 Oct 2025 15:20:21 +1100 Subject: [PATCH 2/3] fix: remove the unused function --- pages/lib/extract_df.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pages/lib/extract_df.py b/pages/lib/extract_df.py index 37ebde3..3bf724b 100644 --- a/pages/lib/extract_df.py +++ b/pages/lib/extract_df.py @@ -5,7 +5,6 @@ import zipfile from datetime import timedelta from urllib.request import Request, urlopen -from functools import lru_cache import logging import numpy as np @@ -50,13 +49,6 @@ def get_data(source_url): return None -@lru_cache(maxsize=64) -def get_global_temp_range(location: str, col_name: str) -> tuple[float, float]: - df_all = get_data(location) # Take the full-year data - series = df_all[col_name].replace([np.inf, -np.inf], np.nan).dropna() - return float(series.min()), float(series.max()) - - @code_timer def get_location_info(lst, file_name): """Extract and clean the data. Return a pandas data from a url.""" From e46d76211e6fead54bb55703e17b7ac7ec1d748d Mon Sep 17 00:00:00 2001 From: Wenshu Lyu Date: Tue, 14 Oct 2025 18:30:11 +1100 Subject: [PATCH 3/3] fix: format code to pass ruff test. --- pages/lib/extract_df.py | 4 +--- pages/natural_ventilation.py | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pages/lib/extract_df.py b/pages/lib/extract_df.py index 3bf724b..ded1c78 100644 --- a/pages/lib/extract_df.py +++ b/pages/lib/extract_df.py @@ -254,9 +254,7 @@ def create_df(lst, file_name): Variables.MONTH.col_name, Variables.HOUR.col_name, ] - ].astype( - int - ) + ].astype(int) # Add in DOY df_doy = ( diff --git a/pages/natural_ventilation.py b/pages/natural_ventilation.py index fee08e7..a2485bb 100644 --- a/pages/natural_ventilation.py +++ b/pages/natural_ventilation.py @@ -322,8 +322,6 @@ def nv_heatmap( filter_unit = filter.get_unit(si_ip) - var_range = variable.get_range(si_ip) - var_name = variable.get_name() filter_name = filter.get_name()