Update data/climate_data.py
Browse files- data/climate_data.py +10 -4
data/climate_data.py
CHANGED
|
@@ -77,6 +77,7 @@ class ClimateLocation:
|
|
| 77 |
latitude: float
|
| 78 |
longitude: float
|
| 79 |
elevation: float # meters
|
|
|
|
| 80 |
climate_zone: str
|
| 81 |
heating_degree_days: float # base 18°C
|
| 82 |
cooling_degree_days: float # base 18°C
|
|
@@ -100,6 +101,7 @@ class ClimateLocation:
|
|
| 100 |
self.latitude = kwargs.get("latitude")
|
| 101 |
self.longitude = kwargs.get("longitude")
|
| 102 |
self.elevation = kwargs.get("elevation")
|
|
|
|
| 103 |
self.typical_extreme_periods = typical_extreme_periods
|
| 104 |
self.ground_temperatures = ground_temperatures
|
| 105 |
self.solar_calculations = kwargs.get("solar_calculations", [])
|
|
@@ -186,6 +188,7 @@ class ClimateLocation:
|
|
| 186 |
"latitude": self.latitude,
|
| 187 |
"longitude": self.longitude,
|
| 188 |
"elevation": self.elevation,
|
|
|
|
| 189 |
"climate_zone": self.climate_zone,
|
| 190 |
"heating_degree_days": self.heating_degree_days,
|
| 191 |
"cooling_degree_days": self.cooling_degree_days,
|
|
@@ -242,7 +245,7 @@ class ClimateData:
|
|
| 242 |
def validate_climate_data(data: Dict[str, Any]) -> bool:
|
| 243 |
"""Validate climate data for required fields and ranges."""
|
| 244 |
required_fields = [
|
| 245 |
-
"id", "country", "city", "latitude", "longitude", "elevation",
|
| 246 |
"climate_zone", "heating_degree_days", "cooling_degree_days",
|
| 247 |
"winter_design_temp", "summer_design_temp_db", "summer_design_temp_wb",
|
| 248 |
"summer_daily_range", "wind_speed", "pressure", "hourly_data"
|
|
@@ -259,6 +262,9 @@ class ClimateData:
|
|
| 259 |
if data["elevation"] < 0:
|
| 260 |
st.error("Validation failed: Negative elevation")
|
| 261 |
return False
|
|
|
|
|
|
|
|
|
|
| 262 |
if data["climate_zone"] not in ["0A", "0B", "1A", "1B", "2A", "2B", "3A", "3B", "3C", "4A", "4B", "4C", "5A", "5B", "5C", "6A", "6B", "7", "8"]:
|
| 263 |
st.error(f"Validation failed: Invalid climate zone '{data['climate_zone']}'")
|
| 264 |
return False
|
|
@@ -401,7 +407,7 @@ class ClimateData:
|
|
| 401 |
st.markdown(STYLE, unsafe_allow_html=True)
|
| 402 |
|
| 403 |
# Clear invalid session_state["climate_data"] without warning
|
| 404 |
-
if "climate_data" in session_state and not all(key in session_state["climate_data"] for key in ["id", "country", "city"]):
|
| 405 |
del session_state["climate_data"]
|
| 406 |
|
| 407 |
uploaded_file = st.file_uploader("Upload EPW File", type=["epw"])
|
|
@@ -528,7 +534,7 @@ class ClimateData:
|
|
| 528 |
latitude=latitude,
|
| 529 |
longitude=longitude,
|
| 530 |
elevation=elevation,
|
| 531 |
-
timezone=timezone
|
| 532 |
)
|
| 533 |
self.add_location(location)
|
| 534 |
climate_data_dict = location.to_dict()
|
|
@@ -697,7 +703,7 @@ class ClimateData:
|
|
| 697 |
<li><strong>Latitude:</strong> {location.latitude}°</li>
|
| 698 |
<li><strong>Longitude:</strong> {location.longitude}°</li>
|
| 699 |
<li><strong>Elevation:</strong> {location.elevation} m</li>
|
| 700 |
-
<li><strong>
|
| 701 |
</ul>
|
| 702 |
</div>
|
| 703 |
</div>
|
|
|
|
| 77 |
latitude: float
|
| 78 |
longitude: float
|
| 79 |
elevation: float # meters
|
| 80 |
+
timezone: float # hours from UTC
|
| 81 |
climate_zone: str
|
| 82 |
heating_degree_days: float # base 18°C
|
| 83 |
cooling_degree_days: float # base 18°C
|
|
|
|
| 101 |
self.latitude = kwargs.get("latitude")
|
| 102 |
self.longitude = kwargs.get("longitude")
|
| 103 |
self.elevation = kwargs.get("elevation")
|
| 104 |
+
self.timezone = kwargs.get("timezone")
|
| 105 |
self.typical_extreme_periods = typical_extreme_periods
|
| 106 |
self.ground_temperatures = ground_temperatures
|
| 107 |
self.solar_calculations = kwargs.get("solar_calculations", [])
|
|
|
|
| 188 |
"latitude": self.latitude,
|
| 189 |
"longitude": self.longitude,
|
| 190 |
"elevation": self.elevation,
|
| 191 |
+
"timezone": self.timezone,
|
| 192 |
"climate_zone": self.climate_zone,
|
| 193 |
"heating_degree_days": self.heating_degree_days,
|
| 194 |
"cooling_degree_days": self.cooling_degree_days,
|
|
|
|
| 245 |
def validate_climate_data(data: Dict[str, Any]) -> bool:
|
| 246 |
"""Validate climate data for required fields and ranges."""
|
| 247 |
required_fields = [
|
| 248 |
+
"id", "country", "city", "latitude", "longitude", "elevation", "timezone",
|
| 249 |
"climate_zone", "heating_degree_days", "cooling_degree_days",
|
| 250 |
"winter_design_temp", "summer_design_temp_db", "summer_design_temp_wb",
|
| 251 |
"summer_daily_range", "wind_speed", "pressure", "hourly_data"
|
|
|
|
| 262 |
if data["elevation"] < 0:
|
| 263 |
st.error("Validation failed: Negative elevation")
|
| 264 |
return False
|
| 265 |
+
if not (-24 <= data["timezone"] <= 24):
|
| 266 |
+
st.error(f"Validation failed: Timezone {data['timezone']} outside range")
|
| 267 |
+
return False
|
| 268 |
if data["climate_zone"] not in ["0A", "0B", "1A", "1B", "2A", "2B", "3A", "3B", "3C", "4A", "4B", "4C", "5A", "5B", "5C", "6A", "6B", "7", "8"]:
|
| 269 |
st.error(f"Validation failed: Invalid climate zone '{data['climate_zone']}'")
|
| 270 |
return False
|
|
|
|
| 407 |
st.markdown(STYLE, unsafe_allow_html=True)
|
| 408 |
|
| 409 |
# Clear invalid session_state["climate_data"] without warning
|
| 410 |
+
if "climate_data" in session_state and not all(key in session_state["climate_data"] for key in ["id", "country", "city", "timezone"]):
|
| 411 |
del session_state["climate_data"]
|
| 412 |
|
| 413 |
uploaded_file = st.file_uploader("Upload EPW File", type=["epw"])
|
|
|
|
| 534 |
latitude=latitude,
|
| 535 |
longitude=longitude,
|
| 536 |
elevation=elevation,
|
| 537 |
+
timezone=timezone
|
| 538 |
)
|
| 539 |
self.add_location(location)
|
| 540 |
climate_data_dict = location.to_dict()
|
|
|
|
| 703 |
<li><strong>Latitude:</strong> {location.latitude}°</li>
|
| 704 |
<li><strong>Longitude:</strong> {location.longitude}°</li>
|
| 705 |
<li><strong>Elevation:</strong> {location.elevation} m</li>
|
| 706 |
+
<li><strong>Timezone:</strong> {location.timezone:+.1f} hours</li>
|
| 707 |
</ul>
|
| 708 |
</div>
|
| 709 |
</div>
|