weather-analyzer / main.py
Amanda Torres
initial commit
3f046ba
"""
Weather Data Analyzer - Main Program
"""
from data_generator import DataGenerator
from analyzer import WeatherAnalyzer
from globals import APPLICATION_NAME, APPLICATION_VERSION
def print_separator(char='=', length=70):
"""
Print separator line
"""
print(char * length)
def display_statistics(analyzer):
"""
Display statistical analysis
"""
print_separator()
print("Temperature Statistics")
print_separator()
temp_stats = analyzer.get_temperature_stats()
if temp_stats:
print(f"Count: {temp_stats['count']} readings")
print(f"Mean: {temp_stats['mean']} C")
print(f"Median: {temp_stats['median']} C")
print(f"Min: {temp_stats['min']} C")
print(f"Max: {temp_stats['max']} C")
if 'stdev' in temp_stats:
print(f"Standard Deviation: {temp_stats['stdev']} C")
print("")
print_separator()
print("Humidity Statistics")
print_separator()
humidity_stats = analyzer.get_humidity_stats()
if humidity_stats:
print(f"Mean: {humidity_stats['mean']}%")
print(f"Median: {humidity_stats['median']}%")
print(f"Min: {humidity_stats['min']}%")
print(f"Max: {humidity_stats['max']}%")
print("")
def display_distribution(analyzer):
"""
Display weather distribution
"""
print_separator()
print("Temperature Distribution")
print_separator()
distribution = analyzer.get_weather_distribution()
total = sum(distribution.values())
for category, count in distribution.items():
percentage = (count / total * 100) if total > 0 else 0
print(f"{category}: {count} readings ({percentage:.1f}%)")
print("")
def display_location_averages(analyzer):
"""
Display average temperatures by location
"""
print_separator()
print("Average Temperature by Location")
print_separator()
averages = analyzer.get_average_by_location()
for location, avg_temp in sorted(averages.items(), key=lambda x: x[1], reverse=True):
print(f"{location}: {avg_temp} C")
print("")
def display_extreme_weather(analyzer):
"""
Display extreme weather events
"""
print_separator()
print("Extreme Weather Events")
print_separator()
extreme_days = analyzer.find_extreme_days()
if not extreme_days:
print("No extreme weather detected")
else:
print(f"Found {len(extreme_days)} extreme weather events:")
for weather in extreme_days[:5]:
print(f" {weather.timestamp.strftime('%Y-%m-%d %H:%M')} - {weather.location}")
print(f" Temperature: {weather.temperature} C")
if weather.wind_speed and weather.wind_speed > 80:
print(f" Wind: {weather.wind_speed} km/h")
if weather.precipitation and weather.precipitation > 50:
print(f" Precipitation: {weather.precipitation} mm")
print("")
def main():
"""
Main program execution
"""
print_separator()
print(f"{APPLICATION_NAME} v{APPLICATION_VERSION}")
print_separator()
print("")
# Generate sample data
print("Generating sample weather data...")
generator = DataGenerator()
dataset = generator.generate_dataset(days=14, readings_per_day=4)
print(f"Generated {len(dataset)} weather readings")
print("")
# Create analyzer and add data
analyzer = WeatherAnalyzer()
for data in dataset:
analyzer.add_data(data)
# Display analysis results
display_statistics(analyzer)
display_distribution(analyzer)
display_location_averages(analyzer)
display_extreme_weather(analyzer)
# Display trend
print_separator()
print("Temperature Trend Analysis")
print_separator()
trend = analyzer.detect_trend()
print(f"Overall trend: {trend}")
print("")
# Sample data details
print_separator()
print("Sample Weather Readings")
print_separator()
for i, weather in enumerate(dataset[:5], 1):
print(f"{i}. {weather.location} - {weather.timestamp.strftime('%Y-%m-%d %H:%M')}")
print(f" Temperature: {weather.temperature} C")
print(f" Humidity: {weather.humidity}%")
print(f" Conditions: {weather.conditions}")
print("")
if __name__ == "__main__":
main()