Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Protracktor
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
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nimesh
Protracktor
Commits
07489627
Commit
07489627
authored
Nov 18, 2020
by
Amit Kumar Bala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update window_activity.py
parent
09fa1c12
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
Protracktor/source/window_activity.py
Protracktor/source/window_activity.py
+49
-0
No files found.
Protracktor/source/window_activity.py
View file @
07489627
...
...
@@ -21,6 +21,14 @@ csvdir = "../results/ActivityTracker/csv"
pltdir
=
"../results/ActivityTracker/usage_graph"
def
currtime
(
tformat
=
None
):
'''
This method checks for the file and returns the time in respective format.
:param tformat: string argument
:returns: date and time
'''
return
time
.
strftime
(
"
%
Y_
%
m_
%
d_
%
H_
%
M_
%
S"
)
if
tformat
==
"file"
\
else
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
try
:
...
...
@@ -41,16 +49,36 @@ log1 = logdir+"/"+read_config()+currtime("file")+".txt"; startt = currtime()
log2
=
csvdir
+
"/"
+
read_config
()
+
currtime
(
"file"
)
+
".csv"
;
startt
=
currtime
()
def
get
(
command
):
'''
This method gets the output of the command and converts it into utf-8 format
:param command: list argument
:returns: output of command in utf-8 format
'''
try
:
return
subprocess
.
check_output
(
command
)
.
decode
(
"utf-8"
)
.
strip
()
except
subprocess
.
CalledProcessError
:
pass
def
time_format
(
s
):
'''
This method coverts cumulative time in seconds into HH:MM:SS
:param s: total seconds time
:returns: time in HH:MM:SS format
'''
m
,
s
=
divmod
(
s
,
60
);
h
,
m
=
divmod
(
m
,
60
)
return
"
%
d:
%02
d:
%02
d"
%
(
h
,
m
,
s
)
def
summarize
(
t
,
winlist
,
applist
):
'''
This is heart of the program it lists the applications and corresponding duration of usage for each application
'''
with
open
(
log1
,
"wt"
)
as
report
:
totaltime
=
sum
([
it
[
2
]
for
it
in
winlist
])
report
.
write
(
""
)
...
...
@@ -89,6 +117,11 @@ def summarize(t,winlist,applist):
report
.
write
(
"
\n
"
+
"="
*
60
+
"
\n
started: "
+
startt
+
"
\t
"
+
"updated: "
+
currtime
()
+
"
\n
"
+
"="
*
60
)
def
plot
():
'''
This method is used for plotting the bar graph from the final csv file
generated by summarize() method
'''
try
:
data
=
pd
.
read_csv
(
log2
)
except
FileNotFoundError
:
...
...
@@ -114,7 +147,15 @@ def plot():
fig
.
savefig
(
pltdir
+
'/'
+
filename
+
'.png'
)
class
myThread4
(
threading
.
Thread
):
'''
It is a threading class which is controlled by our main application file
'''
def
__init__
(
self
):
'''
Initiates the window activity tracking process
'''
threading
.
Thread
.
__init__
(
self
)
self
.
flag
=
0
self
.
t
=
0
...
...
@@ -122,8 +163,16 @@ class myThread4 (threading.Thread):
self
.
winlist
=
[]
def
set
(
self
):
'''
This method triggers to close the thread
'''
self
.
flag
=
1
def
run
(
self
):
'''
This method initiates and continuosly runs the activity tracking with the help of other methods
'''
while
True
:
time
.
sleep
(
period
)
if
self
.
flag
==
1
:
...
...
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