File size: 4,400 Bytes
3f046ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
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()