Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart change units should not move #86

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
208 changes: 64 additions & 144 deletions components/show_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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