Commit 1b8ff03e authored by suryakant's avatar suryakant

Sterlite Custom Report Updates

parent c74f4592
import copy
import pandas as pd
from datetime import datetime
from scripts.constants import ReportType, CommonConstants
......@@ -69,34 +71,46 @@ class CustomReportHandler:
if input_json[each_blocks][CommonConstants.QUERY]:
for each_kpi in input_json[each_blocks][CommonConstants.QUERY]:
temp_data_dict = dict()
append_flag = False
# Iterating each query for each KPI
if input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
for each_query in \
input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
input_json[each_blocks][CommonConstants.QUERY][
each_kpi]:
query = each_query. \
format(
day_start_date=date_filter[CommonConstants.DAY_START_DATE],
day_start_date=date_filter[
CommonConstants.DAY_START_DATE],
day_end_date=date_filter[CommonConstants.DAY_END_DATE],
month_start_date=date_filter[
CommonConstants.MONTH_START_DATE],
month_end_date=date_filter[CommonConstants.MONTH_END_DATE],
month_end_date=date_filter[
CommonConstants.MONTH_END_DATE],
year_start_date=date_filter[
CommonConstants.YEAR_START_DATE],
year_end_date=date_filter[CommonConstants.YEAR_END_DATE])
year_end_date=date_filter[
CommonConstants.YEAR_END_DATE])
response = self.postgres_db_obj.fetch_data(query=query)
if response:
temp_data_dict.update(dict(response[0]))
if not temp_data_dict:
if len(response) <= 1:
temp_data_dict.update(dict(response[0]))
append_flag = True
else:
for every_data in response:
input_json[each_blocks][CommonConstants.DATA]. \
append(dict(every_data))
if not temp_data_dict and append_flag:
# Creating null values if no data
for each_columns in input_json[each_blocks][
CommonConstants.DATA_COLUMN]:
temp_data_dict.update({each_columns: None})
input_json[each_blocks][CommonConstants.DATA].append(
temp_data_dict)
if append_flag:
input_json[each_blocks][CommonConstants.DATA].append(
temp_data_dict)
else:
temp_data_dict = dict()
for each_columns in input_json[each_blocks][
......@@ -114,8 +128,20 @@ class CustomReportHandler:
:return:
"""
dataframe_list = []
print(input_json)
print(sheet_name)
print(len(input_json))
if len(input_json) >= 2:
print("2 block")
# concatenated_df = pd.concat(
# [dataframes_to_concat[i], dataframes_to_concat[i + 1]],
for each_blocks in input_json:
print(input_json[each_blocks])
else:
print("1 block")
print()
# for each_blocks in input_json:
# print(each_blocks)
# dataframe = pd.DataFrame(data=input_json[each_blocks]["data"])
......@@ -142,21 +168,25 @@ class CustomReportHandler:
for each_date_range in date_filter:
report_template = copy.deepcopy(
SterliteRefineryTemplate.REPORT_TEMPLATE
)
# Iterating over sterlite json file
for each_blocks in SterliteRefineryTemplate.REPORT_TEMPLATE:
for each_blocks in report_template:
# Getting the data from queries
each_blocks = self.get_queries_from_db(
input_json=each_blocks, date_filter=each_date_range
)
print("=" * 60)
print(each_blocks)
# self.write_dataframe_to_excel(
# input_json=each_blocks,
# sheet_name=each_date_range[CommonConstants.DAY_START_DATE]
# )
self.write_dataframe_to_excel(
input_json=each_blocks,
sheet_name=each_date_range[CommonConstants.DAY_START_DATE]
)
break
print("@" * 100)
print(report_template)
break
except GeneralException as err:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment