Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index StartDelivery Production(intervall) Quantity VWAP
- 17 2017-01-03 01:00:00 2017-01-02 19:00:00 45 36,56666667
- 18 2017-01-03 01:00:00 2017-01-02 19:15:00 1,4 36,01428571
- ...
- 69 2017-01-03 02:00:00 2017-01-02 22:15:00 8,7 34
- 70 2017-01-03 02:00:00 2017-01-02 23:45:00 5,3 33,63773585
- import mysql.connector
- import numpy as np
- import pandas as pd
- import datetime
- conn=mysql.connector.connect(user='AriHeck',password='none',host='local',database='DataEvaluation', port=3308)
- df = pd.read_sql("select StartOfDelivery,EndOfDelivery,ProdDateTime,PriceEURpMW,QuantityMW, PriceEURpMW*QuantityMW as 'p*Q' from `Production`
- where timestampdiff(hour,StartOfDelivery,EndOfDelivery)=1 AND StartOfDelivery >= '2017-01-03 01:00:00' AND StartOfDelivery < '2017-01-03 03:00:00'", con=conn)
- #Delivery Time Loop
- dt=datetime.datetime.strptime('2017-01-03 01:00:00', "%Y-%m-%d %H:%M:%S")
- end_date=datetime.datetime.strptime('2017-01-05 00:00:00', "%Y-%m-%d %H:%M:%S")
- #Dummies loops
- incr_delivery_loop=datetime.timedelta(hours=1)
- incr_production_loop=datetime.timedelta(minutes=15)
- delta_start=datetime.timedelta(days=1)
- delta_end=datetime.timedelta(minutes=30)
- #Dummies Data
- a=1
- delivery_array=[0]*a
- production_array=[0]*a
- time_remaining_array=[0]*a
- VWAP_array=np.zeros(a)
- quantity_array=np.zeros(a)
- #Start Delivery time loop
- while (dt <= end_date):
- #Production Time Loop:
- #Start Production: 1 Day before delivery 15:00 (3:00 PM), End Production 30 mins before delivery
- prod_time=(dt-delta_start).replace(hour=15)
- end_prod=dt-delta_end
- while (prod_time<=end_prod):
- quantity=df[(df['StartOfDelivery']==dt)& (df['ProdDateTime']>=prod_time) & (df['ProdDateTime']<(prod_time+incr_production_loop))].QuantityMW.sum()
- if (quantity==0):
- VWAP=0
- else:
- #Calculate Volume Weighted Average Price
- pq_total=df[(df['StartOfDelivery']==dt)& (df['ProdDateTime']>=prod_time) & (df['ProdDateTime']<(prod_time+incr_production_loop))]['p*Q'].sum()
- VWAP=pq_total/quantity
- #Save values to arrays
- VWAP_array=np.append(VWAP_array,VWAP)
- quantity_array=np.append(quantity_array,quantity)
- delivery_array.append(dt)
- production_array.append(prod_time)
- #Increments
- prod_time=prod_time+incr_production_loop
- dt=dt+incr_delivery_loop
- #END LOOPS
- #Save to Dataframe
- WAP_dict={'TimeOfDelivery':delivery_array,
- 'ProductionDateTime':production_array,
- 'VWAP':VWAP_array,
- 'Quantity':quantity_array,}
- df_WAP=pd.DataFrame(WAP_dict)
- df_WAP=df_WAP[['TimeOfDelivery','ProductionDateTime','Quantity','VWAP']]
- #Output
- print(df_WAP.head(50))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement