Commit 5cb65a4e authored by suryakant's avatar suryakant

Query/Code Update

parent ec94d16c
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -74,6 +74,7 @@ class CustomReportHandler:
temp_data_dict = dict()
append_flag = False
data_list = []
# Iterating each query for each KPI
if input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
......@@ -95,7 +96,8 @@ class CustomReportHandler:
CommonConstants.YEAR_END_DATE])
response = self.postgres_db_obj.fetch_data(query=query)
if response:
if response and "addition" not in input_json[each_blocks]:
if len(response) <= 1:
temp_data_dict.update(dict(response[0]))
append_flag = True
......@@ -104,6 +106,12 @@ class CustomReportHandler:
input_json[each_blocks][CommonConstants.DATA]. \
append(dict(every_data))
elif response and "addition" in input_json[each_blocks] and \
"primary" in input_json[each_blocks]["addition"]:
for each_data in response:
data_list.append(dict(each_data))
append_flag = True
if not temp_data_dict and not append_flag:
# Creating null values if no data
for each_columns in input_json[each_blocks][
......@@ -111,9 +119,29 @@ class CustomReportHandler:
temp_data_dict.update({each_columns: None})
append_flag = True
if append_flag:
if append_flag and temp_data_dict:
input_json[each_blocks][CommonConstants.DATA].append(
temp_data_dict)
if data_list:
temp_json = {}
for item in data_list:
category = item[
input_json[each_blocks]["addition"]["primary"]]
if category not in temp_json:
temp_json[category] = {
input_json[each_blocks]["addition"][
"primary"]: category}
for key in item:
if key != input_json[each_blocks]["addition"][
"primary"]:
temp_json[category][key] = item[key]
for category, values in temp_json.items():
if values not in input_json[each_blocks][
CommonConstants.DATA]:
input_json[each_blocks][CommonConstants.DATA].append(
values)
else:
temp_data_dict = dict()
for each_columns in input_json[each_blocks][
......@@ -146,7 +174,7 @@ class CustomReportHandler:
logger.info("Iterating through each block to create a dataframe")
# Iterate through the categories and concatenate their data
print(input_json)
# print(input_json)
for category, category_data in input_json.items():
data = category_data.get('data', [])
......@@ -172,7 +200,7 @@ class CustomReportHandler:
start_row, col_index, value,
workbook.add_format(
SterliteRefineryTemplate.COLUMN_HEADER_FORMAT)
)
)
logger.info(f"Shape of current data frame is {result_df.shape}")
return result_df.shape, worksheet
......@@ -255,7 +283,9 @@ class CustomReportHandler:
# Setting width to the column
worksheet.set_column(0, total_column,
CommonConstants.OVERALL_COLUMN_WIDTH)
worksheet.set_text_wrap()
# Center alignment of Excel data
workbook.formats[0].set_align('center')
logger.info(f"Report completed for: {each_date_range}")
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