-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
44 lines (36 loc) · 1.29 KB
/
monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sqlite3
from os import system
from sys import argv
from time import time
def get_timeframe():
now = int(time())
if len(argv) != 2:
print('Timeframe not selected, using all values from table')
return (0, )
days_selected = int(argv[1]) * 60 * 60 * 24
return (now - days_selected, )
def calculate_percents(rows_array):
statistic = dict()
for i, data in enumerate(rows_array[:-1]):
timelength = rows_array[i + 1][1] - data[1]
if data[2] not in statistic:
statistic[data[2]] = 0
statistic[data[2]] += timelength
totaltime = 0
for timestamp in statistic.values():
totaltime += timestamp
timeframevalue = int(time() / 60 / 60 * 24)
if len(argv) == 2:
timeframevalue = argv[1]
percenttime = f'{timeframevalue} day(s)\n'
for coin, timestamp in statistic.items():
percent = timestamp / totaltime * 100
percenttime += f'{int(percent)}% {coin} \n'
system(f'message warning "{percenttime}"')
if __name__ == '__main__':
con = sqlite3.connect('/home/user/gpumining-profitswitcher/database.db')
cur = con.cursor()
print(get_timeframe())
res = cur.execute('SELECT * FROM data WHERE date >= ?',
(get_timeframe())).fetchall()
calculate_percents(res)