Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JK_Report
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
vaisakh.nair
JK_Report
Commits
207c9e88
Commit
207c9e88
authored
May 11, 2023
by
vaisakh.nair
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added - template and logo changes
parent
723a857c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
16 deletions
+53
-16
config.yml
config.yml
+2
-0
create_report.py
create_report.py
+51
-16
No files found.
config.yml
0 → 100644
View file @
207c9e88
template_file
:
/path/to/template.xlsx
logo_image
:
/path/to/logo.png
create_report.py
View file @
207c9e88
...
@@ -4,14 +4,25 @@ from datetime import datetime, timedelta
...
@@ -4,14 +4,25 @@ from datetime import datetime, timedelta
import
schedule
import
schedule
import
time
import
time
import
os
import
os
from
openpyxl
import
load_workbook
from
openpyxl.drawing.image
import
Image
import
yaml
class
DailyReportGenerator
:
class
DailyReportGenerator
:
def
__init__
(
self
):
def
__init__
(
self
):
# Connect to MongoDB
# Connect to MongoDB
client
=
MongoClient
(
os
.
environ
[
"MONGO_CLIENT"
])
client
=
MongoClient
(
os
.
environ
[
"MONGO_CLIENT"
])
db
=
client
[
os
.
environ
[
"MONGO_DATABASE"
]]
db
=
client
[
os
.
environ
[
"MONGO_DATABASE"
]]
self
.
collection
=
db
[
os
.
environ
[
"MONGO_COLLECTION"
]]
self
.
collection
=
db
[
os
.
environ
[
"MONGO_COLLECTION"
]]
# Load configuration from config.yml
with
open
(
'config.yml'
)
as
config_file
:
config
=
yaml
.
safe_load
(
config_file
)
self
.
template_file
=
config
[
'template_file'
]
self
.
logo_image
=
config
[
'logo_image'
]
def
get_shift_name
(
self
,
timestamp
):
def
get_shift_name
(
self
,
timestamp
):
hour
=
timestamp
.
hour
hour
=
timestamp
.
hour
...
@@ -22,7 +33,6 @@ class DailyReportGenerator:
...
@@ -22,7 +33,6 @@ class DailyReportGenerator:
else
:
else
:
return
'Shift C'
return
'Shift C'
def
map_packer_name
(
self
,
camera_name
):
def
map_packer_name
(
self
,
camera_name
):
packer_mapping
=
{
packer_mapping
=
{
'camera_41'
:
'Packer 1'
,
'camera_41'
:
'Packer 1'
,
...
@@ -57,28 +67,53 @@ class DailyReportGenerator:
...
@@ -57,28 +67,53 @@ class DailyReportGenerator:
def
create_excel_report
(
self
):
def
create_excel_report
(
self
):
data
=
[]
report_file
=
'daily_report.xlsx'
current_time
=
datetime
.
now
()
current_time
=
datetime
.
now
()
start_time
=
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
-
1
,
6
,
0
,
0
)
start_time
=
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
-
1
,
6
,
0
,
0
)
end_time
=
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
6
,
0
,
0
)
end_time
=
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
6
,
0
,
0
)
wb
=
load_workbook
(
self
.
template_file
)
sheet
=
wb
.
active
# Add logos
logo_image
=
Image
(
self
.
logo_image
)
sheet
.
add_image
(
logo_image
,
'A1'
)
sheet
.
merge_cells
(
'A1:C3'
)
# Add headings
sheet
[
'D1'
]
=
'JK CEMENT WORKS, NIMBAHERA RAJASTHAN'
sheet
[
'D1'
]
.
font
=
sheet
[
'D1'
]
.
font
.
copy
(
bold
=
True
)
sheet
[
'D1'
]
.
alignment
=
sheet
[
'D1'
]
.
alignment
.
copy
(
horizontal
=
'center'
)
# Add column headers
sheet
[
'A7'
]
=
'Date'
sheet
[
'B7'
]
=
'Shift Name'
sheet
[
'C7'
]
=
'Packer Name'
sheet
[
'D7'
]
=
'Count'
# Start filling details from row 8
row
=
8
for
camera_name
in
[
'camera_41'
,
'camera_42'
,
'camera_44'
,
'camera_45'
,
'camera_46'
,
'camera_47'
]:
for
camera_name
in
[
'camera_41'
,
'camera_42'
,
'camera_44'
,
'camera_45'
,
'camera_46'
,
'camera_47'
]:
shift_name
=
self
.
get_shift_name
(
start_time
)
shift_name
=
self
.
get_shift_name
(
start_time
)
packer_name
=
self
.
map_packer_name
(
camera_name
)
packer_name
=
self
.
map_packer_name
(
camera_name
)
count
=
self
.
get_count
(
start_time
,
end_time
,
camera_name
)
count
=
self
.
get_count
(
start_time
,
end_time
,
camera_name
)
data
.
append
({
# Fill in the data in respective cells
'Date'
:
start_time
.
date
(),
sheet
[
f
'A{row}'
]
=
start_time
.
date
()
'Shift Name'
:
shift_name
,
sheet
[
f
'B{row}'
]
=
shift_name
'Packer Name'
:
packer_name
,
sheet
[
f
'C{row}'
]
=
packer_name
'Count'
:
count
sheet
[
f
'D{row}'
]
=
count
})
row
+=
1
df
=
pd
.
DataFrame
(
data
)
# Save the report file
writer
=
pd
.
ExcelWriter
(
'daily_report.xlsx'
,
engine
=
'openpyxl'
)
wb
.
save
(
report_file
)
df
.
to_excel
(
writer
,
index
=
False
,
sheet_name
=
'Report'
)
writer
.
save
()
# Return the absolute path of the generated report file
file_path
=
os
.
path
.
abspath
(
report_file
)
return
file_path
def
schedule_report_generation
(
self
):
def
schedule_report_generation
(
self
):
schedule
.
every
()
.
day
.
at
(
'08:00'
)
.
do
(
self
.
create_excel_report
)
schedule
.
every
()
.
day
.
at
(
'08:00'
)
.
do
(
self
.
create_excel_report
)
...
...
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