Daniel-FD commited on
Commit
cdbe1c5
·
1 Parent(s): d511965

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import datetime
5
+ import gradio as gr
6
+
7
+
8
+ def plot_e_pricing(EIC_code,start_date,end_date,tomorrow_rate):
9
+ #
10
+ list_of_EIC_codes = ["10Y1001A1001A46L","10YDK-1--------W","10YES-REE------0","10YFR-RTE------C"]
11
+ #
12
+ if tomorrow_rate == True:
13
+ now = datetime.datetime.utcnow()
14
+ tomorrow = now + datetime.timedelta(days=1)
15
+ now = now.replace(microsecond=0).isoformat() + 'Z'
16
+ tomorrow = tomorrow.replace(microsecond=0).isoformat() + 'Z'
17
+ #
18
+ start_date = now
19
+ end_date = tomorrow
20
+ #
21
+ url = "https://electri.p.rapidapi.com/api/v1/day-ahead-prices"
22
+ querystring = {"to":end_date,"from":start_date,"eic":EIC_code}
23
+ headers = {
24
+ "X-RapidAPI-Key": "7ad267cb53mshf4f5255c38f192ap19f964jsnc7abc0be43eb",
25
+ "X-RapidAPI-Host": "electri.p.rapidapi.com"
26
+ }
27
+ data = requests.request("GET", url, headers=headers, params=querystring).json()
28
+ df = pd.json_normalize(data['data']['series'])
29
+ df['time'] = pd.to_datetime(df['time'])
30
+ #
31
+ df_metadata = pd.json_normalize(data)
32
+ currency = df_metadata['data.currency'].iloc[0]
33
+ power_unit = df_metadata['data.unit'].iloc[0]
34
+ eic = df_metadata['data.eic'].iloc[0]
35
+ #
36
+ fig, ax = plt.subplots(figsize=(8, 6))
37
+ ax.plot(df['time'], df['price']);
38
+ plt.title('Electrical prices '+ str(eic))
39
+ plt.xlabel('Time')
40
+ plt.ylabel('Price [' + str(currency) + '/' + str(power_unit) + ']')
41
+ fig.autofmt_xdate()
42
+ #
43
+ #
44
+ return fig
45
+
46
+
47
+ inputs = [
48
+ gr.Dropdown(list_of_EIC_codes, label="Electrical Provider EIC"),
49
+ gr.Textbox(label="Start Date [YYYY-MM-DDTHH:MMZ]"),
50
+ gr.Textbox(label="End Date [YYYY-MM-DDTHH:MMZ]"),
51
+ gr.Checkbox(label="Tomorrow's rates?",default='False'),
52
+ ]
53
+ outputs = gr.Plot()
54
+
55
+ demo = gr.Interface(
56
+ fn=plot_e_pricing,
57
+ inputs=inputs,
58
+ outputs=outputs,
59
+ examples=[
60
+ ["10Y1001A1001A46L","2022-04-05T22:00Z","2022-05-05T22:00Z",False],
61
+ ["10YDK-1--------W","2022-08-05T22:00Z","2022-08-06T22:00Z",False],
62
+ ["10YDK-1--------W"," "," ",True],
63
+
64
+ ],
65
+ cache_examples=True,
66
+ )
67
+
68
+ if __name__ == "__main__":
69
+ demo.launch()
70
+
71
+ # Requirements
72
+ # pipreqs .
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.7
2
+ matplotlib==3.5.1
3
+ pandas==1.4.2
4
+ requests==2.27.1