|
@@ -1,4 +1,4 @@
|
1
|
|
-from util import getQuery
|
|
1
|
+from util import getQuery, pickleQuery
|
2
|
2
|
import pandas as p
|
3
|
3
|
import matplotlib.pyplot as plt
|
4
|
4
|
import seaborn as sns
|
|
@@ -12,23 +12,57 @@ import seaborn as sns
|
12
|
12
|
#
|
13
|
13
|
# qparams = ['%%1117', '20/04/2017']
|
14
|
14
|
|
|
15
|
+#query = """
|
|
16
|
+#SELECT read_date, period, AVG(kwh_tot) AS average
|
|
17
|
+#FROM public.coup_tall_april
|
|
18
|
+#GROUP BY read_date, period
|
|
19
|
+#ORDER BY read_date, period;
|
|
20
|
+#"""
|
|
21
|
+#
|
|
22
|
+#qparams = []
|
|
23
|
+#
|
|
24
|
+#df = getQuery(query, qparams)
|
|
25
|
+#
|
|
26
|
+#print(df.info())
|
|
27
|
+#
|
|
28
|
+#sns.set()
|
|
29
|
+#
|
|
30
|
+##sns.lineplot(x = 'read_time', y = 'kwh_tot', hue = 'icp_id', data = df)
|
|
31
|
+#sns.lineplot(x = 'period', y = 'average', hue = 'read_date', data = df)
|
|
32
|
+#
|
|
33
|
+#plt.show()
|
|
34
|
+
|
15
|
35
|
query = """
|
16
|
|
-SELECT read_date, period, AVG(kwh_tot) AS average
|
17
|
|
-FROM public.coup_tall_april
|
18
|
|
-GROUP BY read_date, period
|
19
|
|
-ORDER BY read_date, period;
|
|
36
|
+SELECT comb.icp_id, comb.read_time, COALESCE(kwh_tot, 0) AS kwh_tot
|
|
37
|
+FROM
|
|
38
|
+(
|
|
39
|
+ SELECT read_time, icp_id
|
|
40
|
+ FROM
|
|
41
|
+ (
|
|
42
|
+ SELECT read_time
|
|
43
|
+ FROM GENERATE_SERIES('2017-04-01 00:30:00'::timestamp, '2017-05-01 00:00:00'::timestamp,
|
|
44
|
+ '30 minutes'::interval) read_time
|
|
45
|
+ ) AS tsdata CROSS JOIN
|
|
46
|
+ (
|
|
47
|
+ SELECT *
|
|
48
|
+ FROM
|
|
49
|
+ (
|
|
50
|
+ SELECT icp_id, COUNT(DISTINCT read_date) AS data_days
|
|
51
|
+ FROM coup_prd.coupdatamaster
|
|
52
|
+ WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
|
|
53
|
+ AND read_date < to_date('01/01/2018','dd/mm/yyyy')
|
|
54
|
+ AND content_code = 'UN'
|
|
55
|
+ GROUP BY icp_id
|
|
56
|
+ ) AS cir
|
|
57
|
+ WHERE data_days >= 360
|
|
58
|
+ ) AS qual_icp
|
|
59
|
+) AS comb
|
|
60
|
+LEFT JOIN
|
|
61
|
+(
|
|
62
|
+ SELECT *, read_date + CONCAT(period / 2, ':', period % 2 * 30, ':00')::time AS read_time
|
|
63
|
+ FROM public.coup_tall_april
|
|
64
|
+) AS tall_timestamp
|
|
65
|
+ON comb.read_time = tall_timestamp.read_time AND comb.icp_id = tall_timestamp.icp_id;
|
20
|
66
|
"""
|
21
|
67
|
|
22
|
|
-qparams = []
|
23
|
|
-
|
24
|
|
-df = getQuery(query, qparams)
|
25
|
|
-
|
26
|
|
-print(df.info())
|
27
|
|
-
|
28
|
|
-sns.set()
|
29
|
|
-
|
30
|
|
-#sns.lineplot(x = 'read_time', y = 'kwh_tot', hue = 'icp_id', data = df)
|
31
|
|
-sns.lineplot(x = 'period', y = 'average', hue = 'read_date', data = df)
|
32
|
|
-
|
33
|
|
-plt.show()
|
34
|
|
-
|
|
68
|
+pickleQuery(query, "April.pkl")
|