From 929bb7bd66a16eae87a88a3275c423a37a4a0b08 Mon Sep 17 00:00:00 2001 From: Ruixin Wu <524463257@qq.com> Date: Sun, 27 Oct 2024 16:42:52 +1100 Subject: [PATCH 1/4] chart change units should not move --- components/charts.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/charts.py b/components/charts.py index fdb1249..9f52a09 100644 --- a/components/charts.py +++ b/components/charts.py @@ -83,9 +83,9 @@ def adaptive_chart( traces = [] if units == UnitSystem.IP.value: - x_values = np.array([50, 92.3]) if model == "iso" else np.array([50, 92.3]) + x_values = np.array([50, 92.3]) else: - x_values = np.array([10, 30]) if model == "iso" else np.array([10, 33.5]) + x_values = np.array([10, 33.5]) if model == "iso": adaptive_func = adaptive_en @@ -170,7 +170,7 @@ def adaptive_chart( if units == UnitSystem.SI.value else "Prevailing Mean Outdoor Temperature [°F]" ), - range=[10, 30] if model == "iso" else [10, 33.5], + range=[10, 33.5], dtick=2 if units == UnitSystem.SI.value else 5, showgrid=True, gridcolor="lightgray", @@ -186,7 +186,7 @@ def adaptive_chart( if units == UnitSystem.SI.value else "Operative Temperature [°F]" ), - range=[14, 36] if units == UnitSystem.SI.value else [60, 104], + range=[14, 36] if units == UnitSystem.SI.value else [57.2, 97.6], dtick=2 if units == UnitSystem.SI.value else 5, showgrid=True, gridcolor="lightgray", @@ -678,7 +678,7 @@ def function(x): if units == UnitSystem.SI.value else "Dry-bulb Temperature [°F]" ), - range=[10, 36] if units == UnitSystem.SI.value else [50, 100], + range=[10, 36] if units == UnitSystem.SI.value else [50, 96.8], dtick=2 if units == UnitSystem.SI.value else 5, ), showlegend=False, From 4e4c3ad2415a745bd67de02524cf8f45d88a4e30 Mon Sep 17 00:00:00 2001 From: Ruixin Wu <524463257@qq.com> Date: Sun, 27 Oct 2024 17:01:17 +1100 Subject: [PATCH 2/4] change range value in pmv ashare speed chart --- components/charts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/charts.py b/components/charts.py index 9f52a09..68437e9 100644 --- a/components/charts.py +++ b/components/charts.py @@ -1673,7 +1673,7 @@ def function(x): height=500, width=680, xaxis=dict( - range=[20, 34] if units == UnitSystem.SI.value else [68, 94], # x range + range=[20, 34] if units == UnitSystem.SI.value else [68, 93.2], # x range tickmode="linear", tick0=20 if units == UnitSystem.SI.value else 65, dtick=2 if units == UnitSystem.SI.value else 2, From c39e2603555253897933df99e87a80e8e27e85d0 Mon Sep 17 00:00:00 2001 From: ZhouTongworking Date: Sun, 27 Oct 2024 22:19:17 +1100 Subject: [PATCH 3/4] refactor the hover_text function --- components/show_results.py | 208 ++++++++++++------------------------- 1 file changed, 64 insertions(+), 144 deletions(-) diff --git a/components/show_results.py b/components/show_results.py index 9e7881a..6ca108c 100644 --- a/components/show_results.py +++ b/components/show_results.py @@ -3,6 +3,8 @@ from pythermalcomfort.utilities import v_relative, clo_dynamic, mapping from pythermalcomfort.models import adaptive_en, set_tmp, pmv_ppd, cooling_effect from pythermalcomfort.psychrometrics import t_o +from dataclasses import dataclass +from typing import List from utils.get_inputs import get_inputs from utils.my_config_file import ( @@ -421,7 +423,7 @@ def display_results(inputs: dict): ) elif selected_model == Models.Adaptive_EN.name: - results = gain_adaptive_en_hover_text( + results = gain_adaptive_hover_text( tdb=inputs[ElementsIDs.t_db_input.value], tr=inputs[ElementsIDs.t_r_input.value], trm=inputs[ElementsIDs.t_rm_input.value], @@ -430,7 +432,7 @@ def display_results(inputs: dict): ) elif selected_model == Models.Adaptive_ASHRAE.name: - results = gain_adaptive_ashare_hover_text( + results = gain_adaptive_hover_text( tdb=inputs[ElementsIDs.t_db_input.value], tr=inputs[ElementsIDs.t_r_input.value], trm=inputs[ElementsIDs.t_rm_input.value], @@ -453,158 +455,76 @@ def display_results(inputs: dict): ) -def gain_adaptive_en_hover_text(tdb, tr, trm, v, units): - if tdb is None or tr is None or trm is None or v is None: - return "None" - - result = adaptive_en(tdb=tdb, tr=tr, t_running_mean=trm, v=v, units=units) - y = t_o(tdb=tdb, tr=tr, v=v) - if y > result["tmp_cmf_cat_iii_up"] or y < result["tmp_cmf_cat_iii_low"]: - compliance_text = "✘ Does not comply with EN 16798" - compliance_color = "red" - else: - compliance_text = "✔ Complies with EN 16798" - compliance_color = "green" - - if result["tmp_cmf_cat_i_low"] <= y <= result["tmp_cmf_cat_i_up"]: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.COMFORTABLE - elif result["tmp_cmf_cat_i_up"] < y <= result["tmp_cmf_cat_ii_up"]: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.TOO_WARM - elif result["tmp_cmf_cat_ii_up"] < y <= result["tmp_cmf_cat_iii_up"]: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.TOO_WARM - class1_bool = ComfortLevel.TOO_WARM - elif result["tmp_cmf_cat_iii_up"] < y: - class3_bool = ComfortLevel.TOO_WARM - class2_bool = ComfortLevel.TOO_WARM - class1_bool = ComfortLevel.TOO_WARM - elif result["tmp_cmf_cat_i_low"] > y >= result["tmp_cmf_cat_ii_low"]: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.TOO_COOL - elif result["tmp_cmf_cat_ii_low"] > y >= result["tmp_cmf_cat_iii_low"]: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.TOO_COOL - class1_bool = ComfortLevel.TOO_COOL - elif result["tmp_cmf_cat_iii_low"] > y: - class3_bool = ComfortLevel.TOO_COOL - class2_bool = ComfortLevel.TOO_COOL - class1_bool = ComfortLevel.TOO_COOL - else: - class3_bool = ComfortLevel.COMFORTABLE - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.COMFORTABLE - - results = [] - temp_unit = "°F" if units == UnitSystem.IP.value else "°C" - results.append( - dmc.Text( - compliance_text, - c=compliance_color, - ta="center", - size="md", - style={"width": "100%"}, - ) - ) - results.append( - dmc.Center( - dmc.Text( - f"Class III acceptability limits = Operative temperature: {result['tmp_cmf_cat_iii_low']} to {result['tmp_cmf_cat_iii_up']} {temp_unit}" - ) - ) - ) - results.append( - dmc.Center(dmc.Text(f"{class3_bool.description}", fz="xs", c=class3_bool.color)) - ) - results.append( - dmc.Center( - dmc.Text( - f"Class II acceptability limits = Operative temperature: {result['tmp_cmf_cat_ii_low']} to {result['tmp_cmf_cat_ii_up']} {temp_unit}" - ) - ) - ) - results.append( - dmc.Center(dmc.Text(f"{class2_bool.description}", fz="xs", c=class2_bool.color)) - ) - results.append( - dmc.Center( - dmc.Text( - f"Class I acceptability limits = Operative temperature: {result['tmp_cmf_cat_i_low']} to {result['tmp_cmf_cat_i_up']} {temp_unit}" - ) - ) - ) - results.append( - dmc.Center(dmc.Text(f"{class1_bool.description}", fz="xs", c=class1_bool.color)) - ) - return results +@dataclass +class ComfortRange: + low: float + up: float + label: str -def gain_adaptive_ashare_hover_text(tdb, tr, trm, v, units): - if tdb is None or tr is None or trm is None or v is None: - return "None" - - result = adaptive_ashrae(tdb=tdb, tr=tr, t_running_mean=trm, v=v, units=units) +def gain_adaptive_hover_text( + tdb: float, tr: float, trm: float, v: float, units: str, model: Models +) -> List: y = t_o(tdb=tdb, tr=tr, v=v) + temp_unit = "°F" if units == UnitSystem.IP.value else "°C" - if y > result["tmp_cmf_80_up"] or y < result["tmp_cmf_80_low"]: - compliance_text = "✘ Does not comply with ASHRAE 55" - compliance_color = "red" - else: - compliance_text = "✔ Complies with ASHRAE 55" - compliance_color = "green" - - if result["tmp_cmf_90_low"] <= y <= result["tmp_cmf_90_up"]: - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.COMFORTABLE - elif result["tmp_cmf_90_up"] < y <= result["tmp_cmf_80_up"]: - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.TOO_WARM - elif result["tmp_cmf_90_up"] < y: - class2_bool = ComfortLevel.TOO_WARM - class1_bool = ComfortLevel.TOO_WARM - elif result["tmp_cmf_90_low"] > y >= result["tmp_cmf_80_low"]: - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.TOO_COOL - elif result["tmp_cmf_80_low"] > y: - class2_bool = ComfortLevel.TOO_COOL - class1_bool = ComfortLevel.TOO_COOL + if model == Models.Adaptive_EN: + result = adaptive_en(tdb=tdb, tr=tr, t_running_mean=trm, v=v, units=units) + ranges = [ + ComfortRange( + result["tmp_cmf_cat_iii_low"], result["tmp_cmf_cat_iii_up"], "Class III" + ), + ComfortRange( + result["tmp_cmf_cat_ii_low"], result["tmp_cmf_cat_ii_up"], "Class II" + ), + ComfortRange( + result["tmp_cmf_cat_i_low"], result["tmp_cmf_cat_i_up"], "Class I" + ), + ] + standard_text = "EN 16798" + elif model == Models.Adaptive_ASHRAE: + result = adaptive_ashrae(tdb=tdb, tr=tr, t_running_mean=trm, v=v, units=units) + ranges = [ + ComfortRange(result["tmp_cmf_80_low"], result["tmp_cmf_80_up"], "80%"), + ComfortRange(result["tmp_cmf_90_low"], result["tmp_cmf_90_up"], "90%"), + ] + standard_text = "ASHRAE 55" else: - class2_bool = ComfortLevel.COMFORTABLE - class1_bool = ComfortLevel.COMFORTABLE + raise ValueError(f"Unsupported model: {model}") - results = [] - temp_unit = "°F" if units == UnitSystem.IP.value else "°C" - results.append( + main_range = ranges[0] + compliant = main_range.low <= y <= main_range.up + + results = [ dmc.Text( - compliance_text, - c=compliance_color, + f"{'✔' if compliant else '✘'} {'Complies with' if compliant else 'Does not comply with'} {standard_text}", + c="green" if compliant else "red", ta="center", size="md", style={"width": "100%"}, ) - ) - results.append( - dmc.Center( - dmc.Text( - f"80% acceptability limits = Operative temperature: {round(result.tmp_cmf_80_low,1)} to {round(result.tmp_cmf_80_up,1)} {temp_unit}" - ) - ) - ) - results.append( - dmc.Center(dmc.Text(f"{class2_bool.description}", fz="xs", c=class2_bool.color)) - ) - results.append( - dmc.Center( - dmc.Text( - f"90% acceptability limits = Operative temperature: {round(result.tmp_cmf_90_low,1)} to {round(result.tmp_cmf_90_up,1)} {temp_unit}" - ) + ] + + for range_info in ranges: + if range_info.low <= y <= range_info.up: + comfort_level = ComfortLevel.COMFORTABLE + elif y > range_info.up: + comfort_level = ComfortLevel.TOO_WARM + else: + comfort_level = ComfortLevel.TOO_COOL + + results.extend( + [ + dmc.Center( + dmc.Text( + f"{range_info.label} acceptability limits = Operative temperature: " + f"{range_info.low:.1f} to {range_info.up:.1f} {temp_unit}" + ) + ), + dmc.Center( + dmc.Text(comfort_level.description, fz="xs", c=comfort_level.color) + ), + ] ) - ) - results.append( - dmc.Center(dmc.Text(f"{class1_bool.description}", fz="xs", c=class1_bool.color)) - ) + return results From eacf7edcaeb8c9bbbbff34d24000af62275c8597 Mon Sep 17 00:00:00 2001 From: Ruixin Wu <524463257@qq.com> Date: Mon, 28 Oct 2024 12:11:18 +1100 Subject: [PATCH 4/4] fix bugs in gain_hover_text function --- components/show_results.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/show_results.py b/components/show_results.py index 6ca108c..ff31a8c 100644 --- a/components/show_results.py +++ b/components/show_results.py @@ -429,6 +429,7 @@ def display_results(inputs: dict): trm=inputs[ElementsIDs.t_rm_input.value], v=inputs[ElementsIDs.v_input.value], units=units, + model=Models.Adaptive_EN, ) elif selected_model == Models.Adaptive_ASHRAE.name: @@ -438,6 +439,7 @@ def display_results(inputs: dict): trm=inputs[ElementsIDs.t_rm_input.value], v=inputs[ElementsIDs.v_input.value], units=units, + model=Models.Adaptive_ASHRAE, ) if selected_model == Models.PMV_ashrae.name: