Browse Source

Load pickle; reorganise some files

Petra Lamborn 5 years ago
parent
commit
49a3f34448
2 changed files with 61 additions and 52 deletions
  1. 22
    52
      py/clustering.py
  2. 39
    0
      py/downkwh.py

+ 22
- 52
py/clustering.py View File

@@ -12,57 +12,27 @@ 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()
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 34
 
35
-query = """
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;
66
-"""
35
+df = p.read_pickle('../data/April.pkl')
67 36
 
68
-pickleQuery(query, "../data/April.pkl")
37
+print(df)
38
+print(df.info())

+ 39
- 0
py/downkwh.py View File

@@ -0,0 +1,39 @@
1
+from util import getQuery, pickleQuery
2
+import pandas as p
3
+import matplotlib.pyplot as plt
4
+import seaborn as sns
5
+
6
+query = """
7
+SELECT comb.icp_id, comb.read_time, COALESCE(kwh_tot, 0) AS kwh_tot
8
+FROM
9
+(
10
+    SELECT read_time, icp_id
11
+    FROM
12
+    (
13
+        SELECT read_time 
14
+        FROM GENERATE_SERIES('2017-04-01 00:30:00'::timestamp, '2017-05-01 00:00:00'::timestamp, 
15
+            '30 minutes'::interval) read_time
16
+    ) AS tsdata CROSS JOIN
17
+    (
18
+        SELECT *
19
+        FROM
20
+        (
21
+            SELECT icp_id, COUNT(DISTINCT read_date) AS data_days 
22
+            FROM coup_prd.coupdatamaster
23
+            WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
24
+                AND read_date <  to_date('01/01/2018','dd/mm/yyyy')
25
+                AND content_code = 'UN'
26
+            GROUP BY icp_id
27
+        ) AS cir 
28
+        WHERE data_days >= 360
29
+    ) AS qual_icp
30
+) AS comb
31
+LEFT JOIN
32
+(
33
+    SELECT *, read_date + CONCAT(period / 2, ':', period %% 2 * 30, ':00')::time AS read_time
34
+    FROM public.coup_tall_april
35
+) AS tall_timestamp 
36
+ON comb.read_time = tall_timestamp.read_time AND comb.icp_id = tall_timestamp.icp_id;
37
+"""
38
+
39
+pickleQuery(query, "../data/April.pkl")