aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Waishnav <waishnavdeore@gmail.com>2022-03-10 22:49:35 +0530
committerLibravatar Waishnav <waishnavdeore@gmail.com>2022-03-10 22:49:35 +0530
commit76405c161762626fe8aece13c2758f68c837ceb9 (patch)
treefa9b0086b8122b352899921bcff21e74e8b912cb /src
parent5e552e7b007f8b13bd3edb221cb162414bac6f03 (diff)
downloadshopno-os-log-sync-76405c161762626fe8aece13c2758f68c837ceb9.tar.gz
shopno-os-log-sync-76405c161762626fe8aece13c2758f68c837ceb9.zip
log_files(implementing new approach) | so some changes in report_creation
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Watcher/colored_text.py30
-rwxr-xr-xsrc/Watcher/log_files.py30
-rwxr-xr-xsrc/Watcher/report_creation.py67
-rwxr-xr-xsrc/Watcher/time_operations.py6
4 files changed, 67 insertions, 66 deletions
diff --git a/src/Watcher/colored_text.py b/src/Watcher/colored_text.py
new file mode 100755
index 0000000..b143829
--- /dev/null
+++ b/src/Watcher/colored_text.py
@@ -0,0 +1,30 @@
+class Color:
+
+ def GREY(text):
+ return '\033[30m' + text + '\033[0m'
+
+ def BLUE(text):
+ return '\033[34m' + text + '\033[0m'
+
+ def GREEN(text):
+ return '\033[32m' + text + '\033[0m'
+
+ def YELLOW(text):
+ return '\033[33m' + text + '\033[0m'
+
+ def RED(text):
+ return '\033[31m' + text + '\033[0m'
+
+ def PURPLE(text):
+ return '\033[95m' + text + '\033[0m'
+
+ def DARKCYAN(text):
+ return '\033[36m' + text + '\033[0m'
+
+ def BOLD(text):
+ return '\033[1m' + text + '\033[0m'
+
+ def UNDERLINE(text):
+ return '\033[4m' + text + '\033[0m'
+
+#print(color.GREEN("hello"))
diff --git a/src/Watcher/log_files.py b/src/Watcher/log_files.py
index 1d73b95..9dfc713 100755
--- a/src/Watcher/log_files.py
+++ b/src/Watcher/log_files.py
@@ -2,6 +2,7 @@ import os
import csv
import time
import get_windows as x
+from time_operations import time_difference
# get current time whenever the function is called
def get_time():
@@ -13,24 +14,19 @@ def get_date():
d = os.popen('''date +"%Y-%m-%d"''').read()
return d[0:-1]
-def append_line_in_csv(date, opened_time, window_name):
+def append_line_in_csv(date, closed_time, window_name):
user = os.getlogin()
filename = "/home/"+user+"/.cache/Watcher/raw_data/"+date+".csv"
- Data = [opened_time, window_name]
+ with open(filename, 'r') as file:
+ last_app_time = file.readlines()[-1][0:8]
+
+ time_spent = time_difference(last_app_time, closed_time)
+
+ Data = [closed_time, time_spent, window_name]
with open(filename, 'a') as csvfile:
csvwriter = csv.writer(csvfile, delimiter='\t')
csvwriter.writerow(Data)
-def is_date_changed(a):
- result = False
- while not(result):
- time.sleep(1)
- b = get_date()
- if a != b :
- result = True
- else:
- result = False
- return result
# Expected Behaviour == if date got changed then append line in new csv file after initializing the csv file
# also if usr is AFK then append line
@@ -40,18 +36,18 @@ def is_date_changed(a):
afk = False
def log_creation():
global afk
-
+ append_line_in_csv(get_date(), get_time(), "User-loged-in")
while True:
previous_window = x.active_window()
if x.is_window_changed(previous_window) and not(afk):
next_window = x.active_window()
- opened_at = get_time()
+ closed_at = get_time() # for next_window its the opening time
date = get_date()
- append_line_in_csv(date, opened_at, next_window)
+ append_line_in_csv(date, closed_at, previous_window)
if afk:
- opened_at = get_time()
- append_line_in_csv(date, opened_at, "AFK")
+ afk_closed_time = get_time()
+ append_line_in_csv(date, afk_closed_time, "AFK")
if __name__ == "__main__":
diff --git a/src/Watcher/report_creation.py b/src/Watcher/report_creation.py
index 3bae496..c635f93 100755
--- a/src/Watcher/report_creation.py
+++ b/src/Watcher/report_creation.py
@@ -2,82 +2,57 @@ import csv
import os
import time_operations as to
from log_files import get_date
+from colored_text import Color
-class color:
- GREY = '\033[30m'
- PURPLE = '\033[95m'
- CYAN = '\033[96m'
- DARKCYAN = '\033[36m'
- BLUE = '\033[34m'
- GREEN = '\033[32m'
- YELLOW = '\033[33m'
- RED = '\033[31m'
- BOLD = '\033[1m'
- UNDERLINE = '\033[4m'
- END = '\033[0m'
-
-date = get_date()
-def load_raw_data(date):
+def imp(date):
user = os.getlogin()
path = "/home/" + user +"/.cache/Watcher/raw_data/"
filename = path + date + ".csv"
- l = list()
+ l = list() # l = list of (app_name, time spent on app on that session)
d = dict()
with open(filename, 'r') as file:
reader = csv.reader(file)
for row in reader:
for column in row:
- l.append([column[0:8],column[9::]])
- d.update({column[9::]: "opened"})
- #print(column[0:8])
- #print(column[9::])
-
- d = list(d)
- return l, d
-#print(raw_data_list[1][1]
-#print(window_opened)
-def each_session(raw_data_list):
- time_spent = []
- for i in range(len(raw_data_list)-1):
- a = raw_data_list[i][0]
- b = raw_data_list[i+1][0]
- time_spent.append([raw_data_list[i][1], to.time_difference(a, b)])
+ l.append([column[18::],column[9:18]])
+ d.update({column[18::]: "O"})
- return time_spent
+ d = list(d) # list of app opened on that day
+ return d, l
-# creating dictionary to store time spend on each applicaitons
+# creating dictionary to store time spend on each applicaitons on that particular day
def final_report(window_opened, time_spent):
report = dict()
- for i in window_opened:
+ for i in window_opened: # i is applications name
time = '00:00:00'
- for j in time_spent:
+ for j in time_spent: # j is list of applicaions_name and time_spent in particular session
if i == j[0]:
- #print(j[to.1],i)
time = to.time_addition(j[1], time)
report.update({i:time})
+ report.pop("User-loged-in")
return report
# ░ ▒ █ ───
#print("▒▒▒\t▒▒▒\n███")
-raw_data_list, window_opened = load_raw_data(date)
-time_spent = each_session(raw_data_list)
-
-
-if __name__ == "__main__":
-
+def prints_report(window_opened, time_spent):
Total_screen_time = "00:00:00"
for x,y in final_report(window_opened, time_spent).items():
Total_screen_time = to.time_addition(y, Total_screen_time)
- print(color.YELLOW + "\n Today's Screen-Time \t\t " + color.END + color.BLUE + to.convert_time(Total_screen_time)+ color.END)
+ print(Color.YELLOW("\n Today's Screen-Time \t\t ") + Color.BLUE(to.convert_time(Total_screen_time)))
print("─────────────────────────────────────────────────")
- print(color.RED + f'{"App Usages":>28}' + color.END)
+ print(Color.RED(f'{"App Usages":>28}'))
print("─────────────────────────────────────────────────")
for x,y in final_report(window_opened, time_spent).items():
if x == "":
- x = "HOME-SCREEN"
- print(color.GREEN + " "+f'{x:<21}' + color.END ,'\t',to.convert_time(y))
+ x = "Home-Screen"
+ print(" " + Color.GREEN(f'{x:<21}') + '\t\t ',to.convert_time(y))
+
+if __name__ == "__main__":
+ date = get_date()
+ window_opened, time_spent = imp(date)
+ prints_report(window_opened, time_spent)
diff --git a/src/Watcher/time_operations.py b/src/Watcher/time_operations.py
index 09cf1f0..985a5e8 100755
--- a/src/Watcher/time_operations.py
+++ b/src/Watcher/time_operations.py
@@ -27,14 +27,14 @@ def time_addition(a,b):
hr = int(b[0:2]) + int(a[0:2])
mn = int(b[3:5]) + int(a[3:5])
sec = int(b[6:8]) + int(a[6:8])
- if mn > 60 and sec > 60:
+ if mn >= 60 and sec >= 60:
hr = hr + 1
mn = mn - 60 + 1
sec = sec - 60
- elif mn > 60:
+ elif mn >= 60:
hr = hr + 1
mn = mn - 60
- elif sec > 60:
+ elif sec >= 60:
mn = mn + 1
sec = sec - 60