Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Downtime_log
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
vidya.m
Downtime_log
Commits
3cc68ffa
Commit
3cc68ffa
authored
Apr 12, 2023
by
vidya.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firstcommit
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
main.py
main.py
+51
-0
No files found.
main.py
0 → 100644
View file @
3cc68ffa
import
pandas
as
pd
import
sqlalchemy
import
matplotlib.pyplot
as
plt
def
get_downtime_data
():
engine
=
sqlalchemy
.
create_engine
(
'postgresql://ilensdev:ilens5432@192.168.0.220/downtime_db'
)
query
=
'SELECT start_time, end_time FROM downtime_log ORDER BY start_time'
return
pd
.
read_sql_query
(
query
,
engine
)
def
downtime_data
(
data
,
unit
=
'hour'
):
if
unit
==
'minute'
:
divisor
=
60
elif
unit
==
'hour'
:
divisor
=
3600
else
:
raise
ValueError
(
'Invalid unit. Please enter "hour" or "minute".'
)
data
[
'downtime'
]
=
(
data
[
'start_time'
]
.
shift
(
-
1
)
-
data
[
'end_time'
])
.
dt
.
total_seconds
()
/
divisor
data
.
loc
[
data
.
index
[
-
1
],
'downtime'
]
=
0
return
data
def
plot_downtime
(
data
,
unit
=
'hour'
):
data
[
'date'
]
=
data
[
'start_time'
]
.
dt
.
date
downtime_per_day
=
data
.
groupby
(
'date'
)[
'downtime'
]
.
sum
()
plot_title
=
f
'Downtime by Day ({unit.capitalize()}s)'
ylabel
=
unit
.
capitalize
()
+
's'
downtime_per_day
.
plot
(
kind
=
'bar'
,
stacked
=
True
,
title
=
plot_title
)
plt
.
xlabel
(
'Date'
)
plt
.
ylabel
(
ylabel
)
plt
.
xticks
(
rotation
=
90
)
plt
.
show
()
def
main
():
data
=
get_downtime_data
()
data
=
downtime_data
(
data
)
plot_downtime
(
data
)
data_minute
=
downtime_data
(
data
,
unit
=
'minute'
)
plot_downtime
(
data_minute
,
unit
=
'minute'
)
if
__name__
==
'__main__'
:
main
()
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