1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- from util import getQuery, pickleQuery
- import pandas as p
- import matplotlib.pyplot as plt
- import seaborn as sns
-
-
- # query = """
- # SELECT *, read_date + CONCAT(period / 2, ':', period %% 2 * 30, ':00')::time AS read_time
- # FROM public.coup_tall_april WHERE icp_id LIKE (%s) AND read_date = to_date(%s, 'dd/mm/yyyy')
- # ORDER BY icp_id, read_time;
- # """
- #
- # qparams = ['%%1117', '20/04/2017']
-
- #query = """
- #SELECT read_date, period, AVG(kwh_tot) AS average
- #FROM public.coup_tall_april
- #GROUP BY read_date, period
- #ORDER BY read_date, period;
- #"""
- #
- #qparams = []
- #
- #df = getQuery(query, qparams)
- #
- #print(df.info())
- #
- #sns.set()
- #
- ##sns.lineplot(x = 'read_time', y = 'kwh_tot', hue = 'icp_id', data = df)
- #sns.lineplot(x = 'period', y = 'average', hue = 'read_date', data = df)
- #
- #plt.show()
-
- query = """
- SELECT comb.icp_id, comb.read_time, COALESCE(kwh_tot, 0) AS kwh_tot
- FROM
- (
- SELECT read_time, icp_id
- FROM
- (
- SELECT read_time
- FROM GENERATE_SERIES('2017-04-01 00:30:00'::timestamp, '2017-05-01 00:00:00'::timestamp,
- '30 minutes'::interval) read_time
- ) AS tsdata CROSS JOIN
- (
- SELECT *
- FROM
- (
- SELECT icp_id, COUNT(DISTINCT read_date) AS data_days
- FROM coup_prd.coupdatamaster
- WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
- AND read_date < to_date('01/01/2018','dd/mm/yyyy')
- AND content_code = 'UN'
- GROUP BY icp_id
- ) AS cir
- WHERE data_days >= 360
- ) AS qual_icp
- ) AS comb
- LEFT JOIN
- (
- SELECT *, read_date + CONCAT(period / 2, ':', period % 2 * 30, ':00')::time AS read_time
- FROM public.coup_tall_april
- ) AS tall_timestamp
- ON comb.read_time = tall_timestamp.read_time AND comb.icp_id = tall_timestamp.icp_id;
- """
-
- pickleQuery(query, "April.pkl")
|