SHARE
TWEET

Untitled

a guest Jul 21st, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. index   StartDelivery   Production(intervall)   Quantity    VWAP
  2. 17  2017-01-03 01:00:00 2017-01-02 19:00:00       45       36,56666667
  3. 18  2017-01-03 01:00:00 2017-01-02 19:15:00       1,4      36,01428571
  4. ...
  5. 69  2017-01-03 02:00:00 2017-01-02 22:15:00       8,7      34
  6. 70  2017-01-03 02:00:00 2017-01-02 23:45:00       5,3      33,63773585
  7.    
  8. import mysql.connector
  9. import numpy as np
  10. import pandas as pd
  11. import datetime
  12.  
  13.  
  14.  
  15.  
  16. conn=mysql.connector.connect(user='AriHeck',password='none',host='local',database='DataEvaluation', port=3308)
  17. df = pd.read_sql("select StartOfDelivery,EndOfDelivery,ProdDateTime,PriceEURpMW,QuantityMW, PriceEURpMW*QuantityMW as 'p*Q'  from `Production`
  18. where timestampdiff(hour,StartOfDelivery,EndOfDelivery)=1 AND StartOfDelivery >= '2017-01-03 01:00:00'  AND StartOfDelivery < '2017-01-03 03:00:00'", con=conn)
  19.  
  20. #Delivery Time Loop
  21. dt=datetime.datetime.strptime('2017-01-03 01:00:00', "%Y-%m-%d %H:%M:%S")
  22. end_date=datetime.datetime.strptime('2017-01-05 00:00:00', "%Y-%m-%d %H:%M:%S")
  23.  
  24. #Dummies loops
  25. incr_delivery_loop=datetime.timedelta(hours=1)
  26. incr_production_loop=datetime.timedelta(minutes=15)
  27. delta_start=datetime.timedelta(days=1)
  28. delta_end=datetime.timedelta(minutes=30)
  29.  
  30. #Dummies Data
  31. a=1
  32. delivery_array=[0]*a
  33. production_array=[0]*a
  34. time_remaining_array=[0]*a
  35. VWAP_array=np.zeros(a)
  36. quantity_array=np.zeros(a)
  37.  
  38. #Start Delivery time loop
  39. while (dt <= end_date):
  40.  
  41.     #Production Time Loop:
  42.         #Start Production: 1 Day before delivery 15:00 (3:00 PM), End Production 30 mins before delivery
  43.     prod_time=(dt-delta_start).replace(hour=15)
  44.     end_prod=dt-delta_end
  45.  
  46.     while (prod_time<=end_prod):
  47.  
  48.         quantity=df[(df['StartOfDelivery']==dt)& (df['ProdDateTime']>=prod_time) & (df['ProdDateTime']<(prod_time+incr_production_loop))].QuantityMW.sum()
  49.         if (quantity==0):
  50.             VWAP=0        
  51.         else:  
  52.             #Calculate  Volume Weighted Average Price
  53.             pq_total=df[(df['StartOfDelivery']==dt)& (df['ProdDateTime']>=prod_time) & (df['ProdDateTime']<(prod_time+incr_production_loop))]['p*Q'].sum()
  54.             VWAP=pq_total/quantity
  55.  
  56.         #Save values to  arrays
  57.         VWAP_array=np.append(VWAP_array,VWAP)
  58.         quantity_array=np.append(quantity_array,quantity)
  59.         delivery_array.append(dt)
  60.         production_array.append(prod_time)
  61.  
  62.        #Increments
  63.         prod_time=prod_time+incr_production_loop
  64.  
  65.     dt=dt+incr_delivery_loop
  66. #END LOOPS
  67.  
  68. #Save to Dataframe
  69. WAP_dict={'TimeOfDelivery':delivery_array,
  70.           'ProductionDateTime':production_array,
  71.           'VWAP':VWAP_array,
  72.           'Quantity':quantity_array,}
  73. df_WAP=pd.DataFrame(WAP_dict)
  74. df_WAP=df_WAP[['TimeOfDelivery','ProductionDateTime','Quantity','VWAP']]
  75.  
  76.  
  77. #Output
  78. print(df_WAP.head(50))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top