Commit 07489627 authored by Amit Kumar Bala's avatar Amit Kumar Bala

Update window_activity.py

parent 09fa1c12
......@@ -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:%02d:%02d" % (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+"\nstarted: "+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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment