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
f045dfa4
Commit
f045dfa4
authored
May 11, 2023
by
vaisakh.nair
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new changes pertaining to shift
parent
af21ff62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
169 additions
and
1 deletion
+169
-1
create_report.py
create_report.py
+1
-1
new.py
new.py
+168
-0
templates/daily_report_jk_template.xlsx
templates/daily_report_jk_template.xlsx
+0
-0
No files found.
create_report.py
View file @
f045dfa4
...
@@ -73,7 +73,7 @@ class DailyReportGenerator:
...
@@ -73,7 +73,7 @@ class DailyReportGenerator:
report_file
=
f
"daily_report_{report_date}.xlsx"
report_file
=
f
"daily_report_{report_date}.xlsx"
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
,
23
,
59
,
0
)
wb
=
load_workbook
(
self
.
template_file
)
wb
=
load_workbook
(
self
.
template_file
)
sheet
=
wb
.
active
sheet
=
wb
.
active
...
...
new.py
0 → 100644
View file @
f045dfa4
import
pandas
as
pd
from
pymongo
import
MongoClient
from
datetime
import
datetime
,
timedelta
import
os
from
openpyxl
import
load_workbook
from
openpyxl.drawing.image
import
Image
import
yaml
from
dotenv
import
load_dotenv
from
collections
import
defaultdict
load_dotenv
(
dotenv_path
=
'.env'
)
class
DailyReportGenerator
:
def
__init__
(
self
):
# Connect to MongoDB
client
=
MongoClient
(
os
.
environ
[
"MONGO_CLIENT"
])
db
=
client
[
os
.
environ
[
"MONGO_DATABASE"
]]
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
):
hour
=
timestamp
.
hour
if
6
<=
hour
<
14
:
return
'Shift A'
elif
14
<=
hour
<
22
:
return
'Shift B'
else
:
return
'Shift C'
def
map_packer_name
(
self
,
camera_name
):
packer_mapping
=
{
'jk'
:
'Packer 1'
,
'camera_42'
:
'Packer 2'
,
'camera_44'
:
'Packer 4'
,
'camera_45'
:
'Packer 5'
,
'camera_46'
:
'Packer 6'
,
'camera_47'
:
'Packer 7'
}
return
packer_mapping
.
get
(
camera_name
,
'Unknown'
)
def
get_count
(
self
,
start_time
,
end_time
,
camera_name
):
query
=
{
'timestamp'
:
{
'$gte'
:
start_time
,
'$lte'
:
end_time
},
'cameraName'
:
camera_name
}
documents
=
self
.
collection
.
find
(
query
)
.
sort
(
'timestamp'
,
1
)
count_difference
=
0
first_count
=
0
last_count
=
0
for
i
,
document
in
enumerate
(
documents
):
if
i
==
0
:
first_count
=
int
(
document
[
'cement_bag_count'
])
last_count
=
int
(
document
[
'cement_bag_count'
])
count_difference
=
last_count
-
first_count
return
count_difference
def
create_excel_report
(
self
):
report_file
=
'daily_report.xlsx'
current_time
=
datetime
.
now
()
report_date
=
current_time
.
strftime
(
"
%
Y-
%
m-
%
d"
)
report_file
=
f
"daily_report_{report_date}.xlsx"
wb
=
load_workbook
(
self
.
template_file
)
sheet
=
wb
.
active
# Set report date
sheet
[
'L6'
]
=
report_date
serial_number
=
1
# Define the shifts and their respective time ranges
shifts
=
{
'Shift A'
:
(
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
6
,
0
,
0
),
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
14
,
0
,
0
)),
'Shift B'
:
(
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
14
,
0
,
0
),
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
22
,
0
,
0
)),
'Shift C'
:
(
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
-
1
,
22
,
0
,
0
),
datetime
(
current_time
.
year
,
current_time
.
month
,
current_time
.
day
,
6
,
0
,
0
))
}
# Start filling details from row 8
row
=
7
for
camera_name
in
[
'jk'
,
'camera_42'
,
'camera_44'
,
'camera_45'
,
'camera_46'
,
'camera_47'
]:
for
shift
,
(
start_time
,
end_time
)
in
shifts
.
items
():
packer_name
=
self
.
map_packer_name
(
camera_name
)
count
=
self
.
get_count
(
start_time
,
end_time
,
camera_name
)
# Fill in the data in respective cells
sheet
[
f
'A{row}'
]
=
serial_number
sheet
[
f
'B{row}'
]
=
end_time
.
date
()
sheet
[
f
'C{row}'
]
=
shift
sheet
[
f
'D{row}'
]
=
packer_name
sheet
[
f
'E{row}'
]
=
count
row
+=
1
serial_number
+=
1
# Save the report file
wb
.
save
(
report_file
)
# Return the absolute path of the generated report file
file_path
=
os
.
path
.
abspath
(
report_file
)
return
file_path
# def create_excel_report(self):
# report_file = 'daily_report.xlsx'
# current_time = datetime.now()
# report_date = current_time.strftime("%Y-%m-%d")
# report_file = f"daily_report_{report_date}.xlsx"
# 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, 23, 59, 0)
# wb = load_workbook(self.template_file)
# sheet = wb.active
# # Set report date
# sheet['L6'] = report_date
# serial_number = 1
# # Start filling details from row 8
# row = 7
# for camera_name in ['jk', 'camera_42', 'camera_44', 'camera_45', 'camera_46', 'camera_47']:
# shift_name = self.get_shift_name(start_time)
# packer_name = self.map_packer_name(camera_name)
# count = self.get_count(start_time, end_time, camera_name)
# # Fill in the data in respective cells
# sheet[f'A{row}'] = serial_number
# sheet[f'B{row}'] = end_time.date()
# sheet[f'C{row}'] = shift_name
# sheet[f'D{row}'] = packer_name
# sheet[f'E{row}'] = count
# row += 1
# serial_number += 1
# # Save the report file
# wb.save(report_file)
# # Return the absolute path of the generated report file
# file_path = os.path.abspath(report_file)
# return file_path
# Create an instance of DailyReportGenerator
report_generator
=
DailyReportGenerator
()
# Generate the daily report
report_path
=
report_generator
.
create_excel_report
()
# Print the path of the generated report
print
(
f
"Generated Daily Report: {report_path}"
)
templates/daily_report_jk_template.xlsx
View file @
f045dfa4
No preview for this file type
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