Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sterlite_custom_reports
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
suryakant
sterlite_custom_reports
Commits
9f037fcb
Commit
9f037fcb
authored
Oct 06, 2023
by
suryakant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sterlite Custom Report Updates
parent
72c79200
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
313 additions
and
109 deletions
+313
-109
scripts/core/db/postgres/custom_report_query.py
scripts/core/db/postgres/custom_report_query.py
+222
-66
scripts/core/handler/event_handler.py
scripts/core/handler/event_handler.py
+57
-30
scripts/template/sterlite_report_template.py
scripts/template/sterlite_report_template.py
+34
-13
No files found.
scripts/core/db/postgres/custom_report_query.py
View file @
9f037fcb
This diff is collapsed.
Click to expand it.
scripts/core/handler/event_handler.py
View file @
9f037fcb
...
@@ -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
:
...
...
scripts/template/sterlite_report_template.py
View file @
9f037fcb
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment