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
c34dd82d
Commit
c34dd82d
authored
Oct 17, 2023
by
suryakant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table Header Update
parent
9998cd08
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
14 deletions
+137
-14
scripts/core/handler/event_handler.py
scripts/core/handler/event_handler.py
+46
-14
scripts/template/sterlite_report_template.py
scripts/template/sterlite_report_template.py
+91
-0
No files found.
scripts/core/handler/event_handler.py
View file @
c34dd82d
...
...
@@ -178,6 +178,12 @@ class CustomReportHandler:
"""
dataframes_list
=
[]
header_row
=
start_row
border_json
=
dict
()
column_counter
=
0
previous_category_cols
=
0
header_flag
=
False
logger
.
info
(
"Iterating through each block to create a dataframe"
)
# Iterate through the categories and concatenate their data
...
...
@@ -187,6 +193,25 @@ class CustomReportHandler:
data_frame
.
columns
=
category_data
.
get
(
'columns'
,
[])
dataframes_list
.
append
(
data_frame
)
shape
=
data_frame
.
shape
# Checking if merged border in the JSON
if
"addition"
in
category_data
and
"merge_header"
in
category_data
[
"addition"
]:
header_flag
=
True
header_start_col
=
previous_category_cols
header_end_col
=
header_start_col
+
shape
[
1
]
-
1
border_json
[
(
header_row
,
header_start_col
,
header_row
,
header_end_col
)
]
=
\
category_data
[
"addition"
][
"merge_header"
]
column_counter
+=
shape
[
1
]
previous_category_cols
=
column_counter
if
header_flag
:
start_row
+=
1
# Concatenate all DataFrames vertically (along rows)
logger
.
info
(
"Concatenating all dataframes to one"
)
result_df
=
pd
.
concat
(
dataframes_list
,
axis
=
1
,
ignore_index
=
False
)
...
...
@@ -199,6 +224,14 @@ class CustomReportHandler:
# Get the xlsxwriter workbook and worksheet objects.
worksheet
=
writer
.
sheets
[
sheet_name
]
# Generating merged header for each dataframe
for
merge_index
,
border_value
in
border_json
.
items
():
# (Start Rows, Start Column, End Row, End Column, Title, Format)
worksheet
.
merge_range
(
*
merge_index
,
border_value
,
workbook
.
add_format
(
SterliteRefineryTemplate
.
COLUMN_HEADER_FORMAT
)
)
# Write the column headers with the defined format.
for
col_index
,
value
in
enumerate
(
result_df
.
columns
.
values
):
if
value
:
...
...
@@ -215,7 +248,7 @@ class CustomReportHandler:
)
logger
.
info
(
f
"Shape of current data frame is {result_df.shape}"
)
return
result_df
.
shape
,
worksheet
return
result_df
.
shape
,
worksheet
,
header_flag
def
custom_report_handler
(
self
,
input_json
):
"""
...
...
@@ -262,25 +295,24 @@ class CustomReportHandler:
input_json
=
each_blocks
,
date_filter
=
each_date_range
)
logger
.
info
(
f
"start_row: {start_row}"
)
logger
.
info
(
"Writing each block into excel sheet"
)
shape
,
worksheet
=
self
.
write_dataframe_to_excel
(
shape
,
worksheet
,
header_flag
=
\
self
.
write_dataframe_to_excel
(
input_json
=
each_blocks
,
writer
=
writer
,
workbook
=
workbook
,
sheet_name
=
sheet_name
,
start_col
=
start_col
,
start_row
=
start_row
,
)
logger
.
info
(
f
"Last row: {shape[0]}"
)
logger
.
info
(
f
"Last column: {shape[1]}"
)
if
total_column
<
shape
[
1
]:
total_column
=
shape
[
1
]
start_row
+=
shape
[
0
]
+
2
logger
.
info
(
f
"end_row: {start_row}"
)
if
header_flag
:
start_row
+=
1
# Add a header format.
main_header_format
=
workbook
.
add_format
(
...
...
scripts/template/sterlite_report_template.py
View file @
c34dd82d
...
...
@@ -87,6 +87,16 @@ class SterliteRefineryTemplate:
"anode_availability"
,
"uom"
,
"norms"
,
"on_date"
,
"mtd"
,
"ytd"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"SAFETY REPORT"
:
{
"columns"
:
[
"SAFETY REPORT"
,
"UOM"
,
"NORMS"
,
"ON DATE"
,
"MTD"
,
"YTD"
],
"query"
:
{
...
...
@@ -173,6 +183,16 @@ class SterliteRefineryTemplate:
"norms"
,
"on_date"
,
"mtd"
,
"ytd"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"RM ANODE RECEIPT DETAILS"
:
{
"columns"
:
[
"RM ANODE RECEIPT DETAILS"
,
...
...
@@ -229,6 +249,16 @@ class SterliteRefineryTemplate:
"data_column"
:
[
"efficiencies"
,
"uom"
,
"norms"
,
"on_date"
,
"mtd"
,
"ytd"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"BANK / CROP"
:
{
"columns"
:
[
"BANK / CROP"
,
...
...
@@ -271,6 +301,16 @@ class SterliteRefineryTemplate:
"data_column"
:
[
"production"
,
"uom"
,
"norms"
,
"on_date"
,
"mtd"
,
"ytd"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"CIRCULATION"
:
{
"columns"
:
[
"CIRCULATION"
,
"CE
%
"
,
"THEOR. WEIGHT"
,
"ACTUAL WEIGHT"
],
"query"
:
{
...
...
@@ -313,6 +353,16 @@ class SterliteRefineryTemplate:
"data"
:
[],
"data_column"
:
[
"fg_inventory"
,
"on_date"
,
"mtd"
,
"ytd"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"PRODUCTION"
:
{
"columns"
:
[
"PRODUCTION"
,
"ON DATE"
,
"MTD"
,
"YTD"
],
"query"
:
{
...
...
@@ -359,6 +409,16 @@ class SterliteRefineryTemplate:
"data_column"
:
[
"crop"
,
"banks"
,
"total_cells"
,
"cell_voltage"
,
"t_shorts"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"DEPOSIT LOSS (-) / GAIN (+) DETAILS"
:
{
"columns"
:
[
"CATEGORY"
,
...
...
@@ -505,6 +565,16 @@ class SterliteRefineryTemplate:
"primary"
:
"utilities_consumptions"
}
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"SPECIFIC CONSUMPTION"
:
{
"columns"
:
[
"CONSUMABLES"
,
"UOM"
,
"NORMS"
,
"ON DATE"
,
"MTD"
,
"YTD"
],
"query"
:
{
...
...
@@ -549,6 +619,16 @@ class SterliteRefineryTemplate:
"cir_2"
,
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"SUSPENDED SOLIDS 1"
:
{
"columns"
:
[
"SUSPENDED SOLIDS (Cir-1: I/L)"
,
...
...
@@ -636,6 +716,16 @@ class SterliteRefineryTemplate:
"equipment_location"
,
"duration"
,
"production"
,
"cause"
],
},
"BLANK"
:
{
"columns"
:
[
None
],
"data"
:
[],
"query"
:
{},
"data_column"
:
[
None
]
},
"PM COMPLIANCE"
:
{
"columns"
:
[
"PM COMPLIANCE"
,
...
...
@@ -663,3 +753,4 @@ class SterliteRefineryTemplate:
}
},
]
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