add some old code
This commit is contained in:
parent
88240280ca
commit
ed58e34e7e
19
old/generate_electricity_price.py
Normal file
19
old/generate_electricity_price.py
Normal file
@ -0,0 +1,19 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
start_date = '2023-01-01'
|
||||
end_date = '2024-01-01'
|
||||
|
||||
# 创建时间索引
|
||||
time_index = pd.date_range(start=start_date, end=end_date, freq='15min')
|
||||
|
||||
# 生成电价数据,假设电价在0.28到0.32欧元/kWh之间波动
|
||||
price_data = np.random.uniform(0.28, 0.32, len(time_index))
|
||||
|
||||
# 创建DataFrame
|
||||
price_df = pd.DataFrame(data={'Time': time_index, 'ElectricityPrice': price_data})
|
||||
|
||||
# 保存到CSV文件
|
||||
price_df.to_csv('electricity_price_data.csv', index=False)
|
||||
|
||||
print("Electricity price data generated and saved.")
|
56
old/generatedata.py
Normal file
56
old/generatedata.py
Normal file
@ -0,0 +1,56 @@
|
||||
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.")
|
24
old/generatepriceschedule.py
Normal file
24
old/generatepriceschedule.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def generate_price_schedule():
|
||||
records = []
|
||||
# 假设一天分为三个时段:谷时、平时、峰时
|
||||
times = [('00:00', '06:00', 0.25),
|
||||
('06:00', '18:00', 0.3),
|
||||
('18:00', '24:00', 0.35)]
|
||||
|
||||
# 随机调整每天的电价以增加现实性
|
||||
for time_start, time_end, base_price in times:
|
||||
# 随机浮动5%以内
|
||||
fluctuation = np.random.uniform(-0.005, 0.005)
|
||||
price = round(base_price + fluctuation, 3)
|
||||
records.append({'time_start': time_start, 'time_end': time_end, 'price': price})
|
||||
|
||||
return pd.DataFrame(records)
|
||||
|
||||
# 生成电价计划
|
||||
price_schedule = generate_price_schedule()
|
||||
price_schedule.to_csv('price_schedule.csv', index=False)
|
||||
print("Price schedule generated and saved to price_schedule.csv.")
|
||||
print(price_schedule)
|
4
old/price_schedule.csv
Normal file
4
old/price_schedule.csv
Normal file
@ -0,0 +1,4 @@
|
||||
time_start,time_end,price
|
||||
00:00,06:00,0.247
|
||||
06:00,18:00,0.3
|
||||
18:00,24:00,0.349
|
|
52561
old/simulation_data.csv
Normal file
52561
old/simulation_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user