Commit 9f037fcb authored by suryakant's avatar suryakant

Sterlite Custom Report Updates

parent 72c79200
...@@ -69,34 +69,34 @@ class CustomReportHandler: ...@@ -69,34 +69,34 @@ class CustomReportHandler:
if input_json[each_blocks][CommonConstants.QUERY]: if input_json[each_blocks][CommonConstants.QUERY]:
for each_kpi in input_json[each_blocks][CommonConstants.QUERY]: for each_kpi in input_json[each_blocks][CommonConstants.QUERY]:
temp_data_dict = dict() temp_data_dict = dict()
# Iterating each query for each KPI
for each_query in \
input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
query = each_query. \
format(
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],
year_start_date=date_filter[
CommonConstants.YEAR_START_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: # Iterating each query for each KPI
# Creating null values if no data if input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
for each_columns in input_json[each_blocks][ for each_query in \
CommonConstants.DATA_COLUMN]: input_json[each_blocks][CommonConstants.QUERY][each_kpi]:
temp_data_dict.update({each_columns: None}) query = each_query. \
format(
input_json[each_blocks][CommonConstants.DATA].append( day_start_date=date_filter[CommonConstants.DAY_START_DATE],
temp_data_dict) 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],
year_start_date=date_filter[
CommonConstants.YEAR_START_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:
# 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)
else: else:
temp_data_dict = dict() temp_data_dict = dict()
for each_columns in input_json[each_blocks][ for each_columns in input_json[each_blocks][
...@@ -107,6 +107,21 @@ class CustomReportHandler: ...@@ -107,6 +107,21 @@ class CustomReportHandler:
input_json[each_blocks][CommonConstants.DATA].append(temp_data_dict) input_json[each_blocks][CommonConstants.DATA].append(temp_data_dict)
return input_json return input_json
def write_dataframe_to_excel(self, input_json, sheet_name):
"""
:param input_json:
:param sheet_name:
:return:
"""
dataframe_list = []
print(sheet_name)
# for each_blocks in input_json:
# print(each_blocks)
# dataframe = pd.DataFrame(data=input_json[each_blocks]["data"])
# dataframe.columns = input_json[each_blocks]["columns"]
# dataframe_list.append(dataframe)
def custom_report_handler(self, input_json): def custom_report_handler(self, input_json):
""" """
:param input_json: :param input_json:
...@@ -118,18 +133,30 @@ class CustomReportHandler: ...@@ -118,18 +133,30 @@ class CustomReportHandler:
try: try:
# if str(input_json.job_type).lower() == ReportType.REFINERY_REPORT: # if str(input_json.job_type).lower() == ReportType.REFINERY_REPORT:
if str(input_json["job_type"]).lower() == ReportType.REFINERY_REPORT: if str(input_json["job_type"]).lower() == ReportType.REFINERY_REPORT:
# Getting custom date range using start date and end date
date_filter = self.create_custom_date_filter(input_json=input_json) date_filter = self.create_custom_date_filter(input_json=input_json)
# with pd.ExcelWriter(path="testing.xlsx", engine="openpyxl") as excel:
# pass
for each_date_range in date_filter: for each_date_range in date_filter:
# Iterating over sterlite json file # Iterating over sterlite json file
for each_blocks in SterliteRefineryTemplate.REPORT_TEMPLATE: for each_blocks in SterliteRefineryTemplate.REPORT_TEMPLATE:
# Getting the data from queries # Getting the data from queries
each_blocks = self.get_queries_from_db( each_blocks = self.get_queries_from_db(
input_json=each_blocks, date_filter=each_date_range input_json=each_blocks, date_filter=each_date_range
) )
# print(each_blocks) print("=" * 60)
# print("=========================================") print(each_blocks)
print(SterliteRefineryTemplate.REPORT_TEMPLATE) # self.write_dataframe_to_excel(
# input_json=each_blocks,
# sheet_name=each_date_range[CommonConstants.DAY_START_DATE]
# )
break
print("@" * 100)
break break
except GeneralException as err: except GeneralException as err:
......
...@@ -15,12 +15,12 @@ class SterliteRefineryTemplate: ...@@ -15,12 +15,12 @@ class SterliteRefineryTemplate:
], ],
"query": { "query": {
"ANODE_AVAILABILITY": [ "ANODE_AVAILABILITY": [
SterliteRefineryQuery.AnodeAvailability.QUERY_AA, SterliteRefineryQuery.AnodeAvailability.QUERY_1,
SterliteRefineryQuery.AnodeAvailability.QUERY_MTD, SterliteRefineryQuery.AnodeAvailability.QUERY_2,
SterliteRefineryQuery.AnodeAvailability.QUERY_YTD, SterliteRefineryQuery.AnodeAvailability.QUERY_3,
], ],
"DO CELLS IN OPERATION": [ "DO CELLS IN OPERATION": [
SterliteRefineryQuery.DOCellsInOperation.QUERY_AA SterliteRefineryQuery.DOCellsInOperation.QUERY_1
], ],
"Total Cells In Operation": [ "Total Cells In Operation": [
SterliteRefineryQuery.TotalCellsInOperation.QUERY_1, SterliteRefineryQuery.TotalCellsInOperation.QUERY_1,
...@@ -30,19 +30,25 @@ class SterliteRefineryTemplate: ...@@ -30,19 +30,25 @@ class SterliteRefineryTemplate:
}, },
"data": [], "data": [],
"data_column": [ "data_column": [
"anode_availability", "anode_availability", "uom", "norms",
"uom", "on_date", "mtd", "ytd"],
"norms",
"on_date",
"mtd",
"ytd",
],
"description": "", "description": "",
"format": "", "format": "",
}, },
"SAFETY REPORT": { "SAFETY REPORT": {
"columns": ["SAFETY REPORT", "UOM", "NORMS", "ON DATE", "MTD", "YTD"], "columns": ["SAFETY REPORT", "UOM", "NORMS", "ON DATE", "MTD", "YTD"],
"query": [], "query": {
"No. of Near Miss": [
SterliteRefineryQuery.NoOfNearMiss.QUERY_1,
SterliteRefineryQuery.NoOfNearMiss.QUERY_2,
SterliteRefineryQuery.NoOfNearMiss.QUERY_3,
],
"No. of First Aid": [
SterliteRefineryQuery.NoOfFirstAid.QUERY_1,
SterliteRefineryQuery.NoOfFirstAid.QUERY_2,
SterliteRefineryQuery.NoOfFirstAid.QUERY_3,
]
},
"data": [], "data": [],
"data_column": ["safety_report", "uom", "norms", "data_column": ["safety_report", "uom", "norms",
"on_date", "mtd", "ytd"], "on_date", "mtd", "ytd"],
...@@ -61,7 +67,22 @@ class SterliteRefineryTemplate: ...@@ -61,7 +67,22 @@ class SterliteRefineryTemplate:
"MTD", "MTD",
"YTD", "YTD",
], ],
"query": [], "query": {
"Grid Power Availability": [],
"Cir 1 Avg. Rectifier Running Hrs.": [],
"Cir 2 Avg. Rectifier Running Hrs.": [],
"Power Availability to Cir-1": [],
"Power Availability to Cir-2": [],
"Power Availability to Cell House": [],
"Cir-1 40 KA Rectifier Avg. Current": [
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_1,
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_2,
SterliteRefineryQuery.Cir140KARectifierAvgCurrent.QUERY_3,
],
"Cir-2 35 KA Rectifier Avg. Current": [],
"Total Avg. Current": [],
"Current Density": []
},
"data": [], "data": [],
"data_column": ["power_availability", "uom", "data_column": ["power_availability", "uom",
"norms", "on_date", "mtd", "norms", "on_date", "mtd",
......
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