File size: 4,046 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
"""
Weather Data Generator
Generate sample weather data for testing
"""

import random
from datetime import datetime, timedelta
from weather_data import WeatherData
from globals import DEFAULT_LOCATIONS

class DataGenerator:
    def __init__(self):
        self.locations = list(DEFAULT_LOCATIONS.keys())
    
    def generate_temperature(self, base_temp=20):
        """
        Generate realistic temperature
        """
        variation = random.uniform(-10, 10)
        return base_temp + variation
    
    def generate_humidity(self):
        """
        Generate humidity percentage
        """
        return random.uniform(30, 90)
    
    def generate_pressure(self):
        """
        Generate atmospheric pressure
        """
        return random.uniform(990, 1030)
    
    def generate_wind_speed(self):
        """
        Generate wind speed
        """
        return random.uniform(0, 60)
    
    def generate_wind_direction(self):
        """
        Generate wind direction
        """
        directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
        return random.choice(directions)
    
    def generate_precipitation(self):
        """
        Generate precipitation amount
        """
        if random.random() < 0.7:
            return 0
        return random.uniform(0, 30)
    
    def generate_conditions(self, temp, precip):
        """
        Generate weather conditions description
        """
        if precip > 10:
            return "Rainy"
        elif precip > 0:
            return "Light Rain"
        elif temp < 0:
            return "Freezing"
        elif temp > 30:
            return "Hot"
        elif random.random() < 0.3:
            return "Cloudy"
        else:
            return "Clear"
    
    def generate_single_reading(self, location, timestamp):
        """
        Generate a single weather reading
        """
        weather = WeatherData(timestamp, location)
        
        # Generate base temperature based on location
        if location in ['Phoenix', 'Los Angeles']:
            base_temp = 25
        elif location in ['Chicago', 'New York']:
            base_temp = 15
        else:
            base_temp = 20
        
        temp = self.generate_temperature(base_temp)
        humidity = self.generate_humidity()
        pressure = self.generate_pressure()
        wind_speed = self.generate_wind_speed()
        wind_dir = self.generate_wind_direction()
        precip = self.generate_precipitation()
        
        weather.set_temperature(temp)
        weather.set_humidity(humidity)
        weather.set_pressure(pressure)
        weather.set_wind(wind_speed, wind_dir)
        weather.set_precipitation(precip)
        weather.conditions = self.generate_conditions(temp, precip)
        
        return weather
    
    def generate_dataset(self, days=7, readings_per_day=4):
        """
        Generate a dataset of weather readings
        """
        dataset = []
        start_date = datetime.now() - timedelta(days=days)
        
        for day in range(days):
            for reading in range(readings_per_day):
                timestamp = start_date + timedelta(days=day, hours=reading*6)
                location = random.choice(self.locations)
                
                weather = self.generate_single_reading(location, timestamp)
                dataset.append(weather)
        
        return dataset
    
    def generate_location_dataset(self, location, days=7):
        """
        Generate dataset for specific location
        """
        if location not in self.locations:
            raise ValueError(f"Unknown location: {location}")
        
        dataset = []
        start_date = datetime.now() - timedelta(days=days)
        
        for day in range(days):
            for hour in range(0, 24, 6):
                timestamp = start_date + timedelta(days=day, hours=hour)
                weather = self.generate_single_reading(location, timestamp)
                dataset.append(weather)
        
        return dataset