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
3780ce34
Commit
3780ce34
authored
May 18, 2023
by
vaisakh.nair
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added docstrings
parent
a8a54ebb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
19 deletions
+61
-19
app.py
app.py
+1
-4
config.yml
config.yml
+1
-1
report_bkp/daily_report_2023-05-17_20230518103007694297.xlsx
report_bkp/daily_report_2023-05-17_20230518103007694297.xlsx
+0
-0
scripts/__pycache__/create_report_email_utility.cpython-38.pyc
...ts/__pycache__/create_report_email_utility.cpython-38.pyc
+0
-0
scripts/create_report_email_utility.py
scripts/create_report_email_utility.py
+59
-14
No files found.
app.py
View file @
3780ce34
...
@@ -13,12 +13,9 @@ def generate_daily_report():
...
@@ -13,12 +13,9 @@ def generate_daily_report():
# Generate the daily report
# Generate the daily report
report_path
=
report_generator
.
create_excel_report
()
report_path
=
report_generator
.
create_excel_report
()
# saving file locally in one more specified file path
report_generator
.
save_report_locally
(
filepath
=
report_path
)
# Send the email with the report
# Send the email with the report
# please comment out if you are running the create_report.py file without a email method.
# please comment out if you are running the create_report.py file without a email method.
#
report_generator.send_email_from_ut(filepath=report_path)
report_generator
.
send_email_from_ut
(
filepath
=
report_path
)
return
report_path
return
report_path
...
...
config.yml
View file @
3780ce34
template_file
:
D:\vision_utilities\vision_utilities\report_generator\templates\daily_report_jk_template.xlsx
template_file
:
D:\vision_utilities\vision_utilities\report_generator\templates\daily_report_jk_template.xlsx
folder_path
:
D:\vision_utilities\vision_utilities\report_generator\
report_bkp
folder_path
:
D:\vision_utilities\vision_utilities\report_generator\
daily_reports
# logo_image: path/to/logo.png
# logo_image: path/to/logo.png
cameras
:
cameras
:
...
...
report_bkp/daily_report_2023-05-17_20230518103007694297.xlsx
deleted
100644 → 0
View file @
a8a54ebb
File deleted
scripts/__pycache__/create_report_email_utility.cpython-38.pyc
View file @
3780ce34
No preview for this file type
scripts/create_report_email_utility.py
View file @
3780ce34
...
@@ -34,6 +34,13 @@ class DailyReportGenerator:
...
@@ -34,6 +34,13 @@ class DailyReportGenerator:
def
get_shift_name
(
self
,
timestamp
):
def
get_shift_name
(
self
,
timestamp
):
"""
Maps the shift names to the desired timings.
Returns:
str: The shift names.
"""
hour
=
timestamp
.
hour
hour
=
timestamp
.
hour
if
6
<=
hour
<
14
:
if
6
<=
hour
<
14
:
...
@@ -45,10 +52,30 @@ class DailyReportGenerator:
...
@@ -45,10 +52,30 @@ class DailyReportGenerator:
def
get_packer_name
(
self
,
camera_name
):
def
get_packer_name
(
self
,
camera_name
):
"""
Fetches the camera mapping fromt he config file/any for of input file given.
Returns: The mappings
"""
return
self
.
camera_mappings
.
get
(
camera_name
,
'Unknown'
)
return
self
.
camera_mappings
.
get
(
camera_name
,
'Unknown'
)
def
get_count
(
self
,
start_time
,
end_time
,
camera_name
):
def
get_count
(
self
,
start_time
,
end_time
,
camera_name
):
"""
Fetches the count difference between the first and last document within the specified time range and camera name.
Args:
start_time (datetime): The start time of the time range.
end_time (datetime): The end time of the time range.
camera_name (str): The name of the camera.
Returns:
int: The count difference between the first and last document within the specified time range and camera name.
"""
query
=
{
query
=
{
'timestamp'
:
{
'$gte'
:
start_time
,
'$lte'
:
end_time
},
'timestamp'
:
{
'$gte'
:
start_time
,
'$lte'
:
end_time
},
'cameraName'
:
camera_name
'cameraName'
:
camera_name
...
@@ -71,6 +98,18 @@ class DailyReportGenerator:
...
@@ -71,6 +98,18 @@ class DailyReportGenerator:
def
create_excel_report
(
self
):
def
create_excel_report
(
self
):
"""
Generates an Excel report based on the provided data and saves it in the specified folder.
Returns:
str: The absolute path of the generated report file.
"""
reports_folder
=
self
.
config
[
'folder_path'
]
if
not
os
.
path
.
exists
(
reports_folder
):
os
.
makedirs
(
reports_folder
)
report_file
=
'daily_report.xlsx'
report_file
=
'daily_report.xlsx'
...
@@ -141,6 +180,8 @@ class DailyReportGenerator:
...
@@ -141,6 +180,8 @@ class DailyReportGenerator:
print_area
=
f
"A1:{openpyxl.utils.get_column_letter(max_column)}{max_row}"
print_area
=
f
"A1:{openpyxl.utils.get_column_letter(max_column)}{max_row}"
sheet
.
print_area
=
print_area
sheet
.
print_area
=
print_area
report_file
=
os
.
path
.
join
(
reports_folder
,
report_file
)
# Save the report file
# Save the report file
wb
.
save
(
report_file
)
wb
.
save
(
report_file
)
...
@@ -150,23 +191,15 @@ class DailyReportGenerator:
...
@@ -150,23 +191,15 @@ class DailyReportGenerator:
return
file_path
return
file_path
def
save_report_locally
(
self
,
filepath
):
def
get_receiver_emails
(
self
):
# Create the 'daily_reports' folder if it doesn't exist
folder_path
=
self
.
config
[
'folder_path'
]
if
not
os
.
path
.
exists
(
folder_path
):
os
.
makedirs
(
folder_path
)
# Get the filename from the filepath
filename
=
os
.
path
.
basename
(
filepath
)
# Save the report file in the 'daily_reports' folder
destination
=
os
.
path
.
join
(
folder_path
,
filename
)
os
.
rename
(
filepath
,
destination
)
return
destination
"""
Retrieves the email addresses of receivers from the MongoDB collection.
Returns:
list: A list of email addresses of receivers.
def
get_receiver_emails
(
self
):
"""
# Connect to MongoDB and retrieve the email addresses from the collection
# Connect to MongoDB and retrieve the email addresses from the collection
client
=
MongoClient
(
os
.
environ
[
"MONGO_CLIENT"
])
client
=
MongoClient
(
os
.
environ
[
"MONGO_CLIENT"
])
db
=
client
[
os
.
environ
[
"MONGO_DATABASE"
]]
db
=
client
[
os
.
environ
[
"MONGO_DATABASE"
]]
...
@@ -181,6 +214,18 @@ class DailyReportGenerator:
...
@@ -181,6 +214,18 @@ class DailyReportGenerator:
def
send_email_from_ut
(
self
,
filename
=
"daily_report.xlsx"
,
filepath
=
None
):
def
send_email_from_ut
(
self
,
filename
=
"daily_report.xlsx"
,
filepath
=
None
):
"""
Sends an email to the receiver list with the specified file attachment and payload.
Args:
filename (str, optional): The name of the file attachment. Defaults to "daily_report.xlsx".
filepath (str, optional): The file path of the attachment. Defaults to None.
Returns:
bool: True if the email was successfully sent, False otherwise.
"""
logging
.
info
(
"Sending email to {}"
.
format
(
self
.
get_receiver_emails
()))
logging
.
info
(
"Sending email to {}"
.
format
(
self
.
get_receiver_emails
()))
payload
=
dict
()
payload
=
dict
()
...
...
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