""" Weather Data Class Represents weather measurements and data """ from datetime import datetime class WeatherData: def __init__(self, timestamp, location): self.timestamp = timestamp self.location = location self.temperature = None self.humidity = None self.pressure = None self.wind_speed = None self.wind_direction = None self.precipitation = None self.conditions = None def set_temperature(self, temp_celsius): """ Set temperature in Celsius """ if temp_celsius < -100 or temp_celsius > 60: raise ValueError("Temperature out of valid range") self.temperature = temp_celsius def get_temperature_fahrenheit(self): """ Get temperature in Fahrenheit """ if self.temperature is None: return None return (self.temperature * 9/5) + 32 def set_humidity(self, humidity_percent): """ Set humidity percentage """ if humidity_percent < 0 or humidity_percent > 100: raise ValueError("Humidity must be between 0 and 100") self.humidity = humidity_percent def set_pressure(self, pressure_hpa): """ Set atmospheric pressure in hPa """ if pressure_hpa < 800 or pressure_hpa > 1100: raise ValueError("Pressure out of valid range") self.pressure = pressure_hpa def set_wind(self, speed_kmh, direction): """ Set wind speed and direction """ if speed_kmh < 0: raise ValueError("Wind speed cannot be negative") self.wind_speed = speed_kmh self.wind_direction = direction def set_precipitation(self, precip_mm): """ Set precipitation in millimeters """ if precip_mm < 0: raise ValueError("Precipitation cannot be negative") self.precipitation = precip_mm def is_extreme_weather(self): """ Check if conditions are extreme """ extreme = False if self.temperature and (self.temperature < -20 or self.temperature > 40): extreme = True if self.wind_speed and self.wind_speed > 80: extreme = True if self.precipitation and self.precipitation > 50: extreme = True return extreme def to_dict(self): """ Convert to dictionary """ return { 'timestamp': str(self.timestamp), 'location': self.location, 'temperature_c': self.temperature, 'temperature_f': self.get_temperature_fahrenheit(), 'humidity': self.humidity, 'pressure': self.pressure, 'wind_speed': self.wind_speed, 'wind_direction': self.wind_direction, 'precipitation': self.precipitation, 'conditions': self.conditions, 'extreme': self.is_extreme_weather() } def __str__(self): return f"Weather at {self.location} on {self.timestamp}: {self.temperature}C, {self.humidity}% humidity"