import pandas as pd import numpy as np # 设置随机种子以重现结果 np.random.seed(43) def simulate_sunlight(hour, month): # 假设最大日照强度在正午,根据月份调整最大日照强度 max_intensity = 1.0 # 夏季最大日照强度 if month in [12, 1, 2]: # 冬季 max_intensity = 0.6 elif month in [3, 4, 10, 11]: # 春秋 max_intensity = 0.8 # 计算日照强度,模拟早晚日照弱,中午日照强 intensity = max_intensity * np.sin(np.pi * (hour - 6) / 12)**2 if 6 <= hour <= 18 else 0 return intensity def simulate_factory_demand(hour, day_of_week): # 周末工厂需求可能减少 if day_of_week in [5, 6]: # 周六和周日 base_demand = 3000 else: base_demand = 6000 # 日常波动 if 8 <= hour <= 20: return base_demand + np.random.randint(100, 200) # 白天需求量大 else: return base_demand - np.random.randint(0, 100) # 夜间需求量小 def generate_data(days=10): records = [] month_demand = 0 for day in range(days): month = (day % 365) // 30 + 1 day_of_week = day % 7 day_demand = 0 for hour in range(24): for minute in [0, 10, 20, 30, 40, 50]: time = f'{hour:02d}:{minute:02d}' sunlight = simulate_sunlight(hour, month) demand = simulate_factory_demand(hour, day_of_week) day_demand+=demand records.append({'time': time, 'sunlight': sunlight, 'demand': demand}) print(f"day:{day}, day_demand: {day_demand}") month_demand += day_demand if day%30 == 0: print(f"month:{month}, month_demand:{month_demand}") month_demand = 0 return pd.DataFrame(records) # 生成数据 data = generate_data(365) # 模拟一年的数据 data.to_csv('simulation_data.csv', index=False) print("Data generated and saved to simulation_data.csv.")