# from os import path
#
# import pandas as pd
# import requests
# import json
# import gzip
# from main import df
#
#
# import openpyxl
#
# kairosdb_server = "http://192.168.0.220:8080"
# url = 'http://192.168.0.220:8080/api/v1/datapoints/query'
# # Simple test [without compression]
# data = [
#     {
#         "name": "bana",
#         "datapoints": df[['Datetime', 'RH']].values.tolist(),
#         "tags": {"project": "kairos"}
#     }
# ]
#
# response = requests.post(kairosdb_server + "/api/v1/datapoints", json.dumps(data))
# print("Simple test [without compression]: \t %d (status code)" % response.status_code)
#
#
# def minm(query):
#     if query == "months":
#
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "min",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "months"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json()
#     elif query == "weeks":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "min",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "weeks"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     elif query == "days":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "min",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "days"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     else:
#         return ("failed")
#
# def maxm(query):
#     if query == "months":
#
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "max",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "months"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json()
#     elif query == "weeks":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "max",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "weeks"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     elif query == "days":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "max",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "days"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     else:
#         return ("failed")
#
# def avg(query):
#     if query == "months":
#
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "avg",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "months"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json()
#     elif query == "weeks":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "avg",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "weeks"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     elif query == "days":
#         payload = json.dumps({
#             "metrics": [
#                 {
#                     "tags": {},
#                     "name": "bana",
#                     "aggregators": [
#                         {
#                             "name": "avg",
#                             "sampling": {
#                                 "value": "1",
#                                 "unit": "days"
#                             }
#                         }
#                     ]
#                 }
#             ],
#             "plugins": [],
#             "cache_time": 0,
#             "start_absolute": 1096741800000,
#             "end_absolute": 1112553000000
#         })
#         headers = {
#             'Content-Type': 'application/json'
#         }
#
#         response = requests.request("POST", url, headers=headers, data=payload)
#
#         return response.json
#     else:
#         return ("failed")
# def monthlytempdata():
#     MINM = minm("months")['queries'][0]['results'][0]['values']
#
#     df2 = pd.DataFrame(MINM, columns=["Updated_Date", "minm"])
#     MAXM = minm("months")['queries'][0]['results'][0]['values']
#
#     df3 = pd.DataFrame(MAXM, columns=["Updated_Date", "maxm"])
#
#     AVG = minm("months")['queries'][0]['results'][0]['values']
#     df4 = pd.DataFrame(AVG, columns=["Updated_Date", "avg"])
#
#
#     a = pd.merge(df2, df3, on="Updated_Date")
#     b = pd.merge(a, df4, on="Updated_Date")
#     b["Updated date"] = pd.to_datetime(b["Updated Date"], unit='ms')
#     b.to_excel("scripts/Data/monthreport.xlsx", index=None)
#     fpath = 'scripts/Data/'
#     fname = 'monthreport.xlsx'
#     filepath = fpath + fname
#     return filepath, fname
# def dailytempdata():
#     MINM = minm("daily")['queries'][0]['results'][0]['values']
#
#     df2 = pd.DataFrame(MINM, columns=["Updated_Date", "minm"])
#     MAXM = maxm("daily")['queries'][0]['results'][0]['values']
#
#     df3 = pd.DataFrame(MAXM, columns=["Updated_Date", "maxm"])
#
#     AVG = avg("daily")['queries'][0]['results'][0]['values']
#     df4 = pd.DataFrame(AVG, columns=["Updated_Date", "avg"])
#
#
#     a = pd.merge(df2, df3, on="Updated_Date")
#     b = pd.merge(a, df4, on="Updated_Date")
#     b["Updated date"] = pd.to_datetime(b["Updated Date"], unit='ms')
#     b.to_excel("scripts/Data/dailyreport.xlsx", index=None)
#     fpath = 'scripts/Data/'
#     fname = 'dailyreport.xlsx'
#     filepath = fpath + fname
#     return filepath, fname
# def weeklytempdata():
#     MINM = minm("weeks")['queries'][0]['results'][0]['values']
#
#     df2 = pd.DataFrame(MINM, columns=["Updated_Date", "minm"])
#     MAXM = maxm("weeks")['queries'][0]['results'][0]['values']
#
#     df3 = pd.DataFrame(MAXM, columns=["Updated_Date", "maxm"])
#
#     AVG = avg("weeks")['queries'][0]['results'][0]['values']
#     df4 = pd.DataFrame(AVG, columns=["Updated_Date", "avg"])
#
#
#     a = pd.merge(df2, df3, on="Updated_Date")
#     b = pd.merge(a, df4, on="Updated_Date")
#     b["Updated date"] = pd.to_datetime(b["Updated Date"], unit='ms')
#     b.to_excel("scripts/Data/weekreport.xlsx", index=None)
#     fpath = 'scripts/Data/'
#     fname = 'weekreport.xlsx'
#     filepath = fpath + fname
#     return filepath, fname
#     # def yearlytempdata():
# #     MAX_temp= maxtemp("years")['queries'][0]['results'][0]['values']
# #     MIN_temp= mintemp("years")['queries'][0]['results'][0]['values']
# #     AVG_temp=avgtemp("years")['queries'][0]['results'][0]['values']
# #
# #     df1=pd.DataFrame(MAX_temp,columns=["Updated_Date","maxtemp"])
# #     df2=pd.DataFrame(MIN_temp, columns=["Updated_Date", "mintemp"])
# #     df3=pd.DataFrame(AVG_temp, columns=["Updated_Date", "avgtemp"])
#
#     # a=pd.merge(df2,df3,on="Updated_Date")
#     # b=pd.merge(a,df4,on="Updated_Date")
#     # b["Updated date"]=pd.to_datetime(b["Updated Date"], unit='ms')
#     # b.to_excel("scripts/Data/weekreport.xlsx")
#     # b.to_excel("scripts/Data/dailyreport.xlsx", index=None)
#     # b.to_excel("scripts/Data/weekreport.xlsx", index=None)
#     # path='scripts/Data/'
#     # fname='monthlyreport.xlsx'
#     # filepath=fpath+fname
#     # return filepath,fname