from util import getQuery, pickleQuery, getkwh
import pandas as p
import matplotlib.pyplot as plt
import seaborn as sns

# 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-01-01 00:30:00'::timestamp, '2017-02-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'
#                 AND icp_id LIKE '%%19'
#             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_jan
# ) AS tall_timestamp 
# ON comb.read_time = tall_timestamp.read_time AND comb.icp_id = tall_timestamp.icp_id;
# """
# 
# pickleQuery(query, "../data/jan19s.pkl")

kwhdata = getkwh('2016-04-01', '2018-01-01', '2016-04-01 00:30:00', '2018-01-01 00:00:00', '%%1')

print(kwhdata.info())

print("Pickling")
kwhdata.to_pickle("../data/2016-17-sample.pkl")
