Enable reset stats feature for all stats
This commit is contained in:
parent
da06d15851
commit
8ef8a5293c
|
@ -141,6 +141,7 @@ class SafeEyes(object):
|
|||
self.safe_eyes_core.stop()
|
||||
self.plugins_manager.exit()
|
||||
self.rpc_server.stop()
|
||||
self.persist_session()
|
||||
Gtk.main_quit()
|
||||
# Exit all threads
|
||||
os._exit(0)
|
||||
|
|
|
@ -43,23 +43,33 @@ def init(ctx, safeeyes_config, plugin_config):
|
|||
global no_of_breaks
|
||||
global no_of_cycles
|
||||
global reset_interval
|
||||
global safe_eyes_start_time
|
||||
global total_idle_time
|
||||
logging.debug('Initialize Health Stats plugin')
|
||||
context = ctx
|
||||
reset_interval = plugin_config.get('statistics_reset_interval', 24) * 3600
|
||||
if session is None:
|
||||
session = context['session']['plugin'].get('healthstats', None)
|
||||
if session is None:
|
||||
session = {'no_of_skipped_breaks': 0,
|
||||
'no_of_breaks': 0, 'no_of_cycles': -1}
|
||||
'no_of_breaks': 0,
|
||||
'no_of_cycles': -1,
|
||||
'safe_eyes_start_time': safe_eyes_start_time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'total_idle_time': 0}
|
||||
context['session']['plugin']['healthstats'] = session
|
||||
no_of_skipped_breaks = session.get('no_of_skipped_breaks', 0)
|
||||
no_of_breaks = session.get('no_of_breaks', 0)
|
||||
no_of_cycles = session.get('no_of_cycles', -1)
|
||||
reset_interval = session.get('screen_time_reset_interval', 24) * 3600
|
||||
total_idle_time = session.get('total_idle_time', 0)
|
||||
str_time = session.get('safe_eyes_start_time', None)
|
||||
if str_time:
|
||||
safe_eyes_start_time = datetime.datetime.strptime(str_time, "%Y-%m-%d %H:%M:%S")
|
||||
_reset_stats()
|
||||
|
||||
|
||||
def on_stop_break():
|
||||
"""
|
||||
After the break, play the alert sound
|
||||
After the break, check if it is skipped.
|
||||
"""
|
||||
global no_of_skipped_breaks
|
||||
if context['skipped']:
|
||||
|
@ -78,18 +88,33 @@ def get_widget_title(break_obj):
|
|||
no_of_cycles += 1
|
||||
session['no_of_breaks'] = no_of_breaks
|
||||
session['no_of_cycles'] = no_of_cycles
|
||||
session['safe_eyes_start_time'] = safe_eyes_start_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
session['total_idle_time'] = total_idle_time
|
||||
return _('Health Statistics')
|
||||
|
||||
|
||||
def _reset_screen_time():
|
||||
def _reset_stats():
|
||||
global no_of_breaks
|
||||
global no_of_cycles
|
||||
global safe_eyes_start_time
|
||||
global total_idle_time
|
||||
global no_of_skipped_breaks
|
||||
current_time = datetime.datetime.now()
|
||||
total_duration_sec = (current_time - safe_eyes_start_time).total_seconds()
|
||||
if total_duration_sec >= reset_interval:
|
||||
total_duration_sec -= reset_interval
|
||||
safe_eyes_start_time = current_time - datetime.timedelta(seconds=total_duration_sec)
|
||||
safe_eyes_start_time = current_time - \
|
||||
datetime.timedelta(seconds=total_duration_sec)
|
||||
total_idle_time = 0
|
||||
no_of_breaks = 0
|
||||
no_of_cycles = 0
|
||||
no_of_skipped_breaks = 0
|
||||
session['no_of_breaks'] = 0
|
||||
session['no_of_cycles'] = 0
|
||||
session['no_of_skipped_breaks'] = 0
|
||||
session['safe_eyes_start_time'] = safe_eyes_start_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
session['total_idle_time'] = total_idle_time
|
||||
|
||||
return total_duration_sec
|
||||
|
||||
|
||||
|
@ -97,7 +122,7 @@ def get_widget_content(break_obj):
|
|||
"""
|
||||
Return the statistics.
|
||||
"""
|
||||
total_duration_sec = _reset_screen_time()
|
||||
total_duration_sec = _reset_stats()
|
||||
screen_time = round((total_duration_sec - total_idle_time) / 60)
|
||||
hours, minutes = divmod(screen_time, 60)
|
||||
time_format = '{:02d}:{:02d}'.format(hours, minutes)
|
||||
|
@ -114,7 +139,8 @@ def on_start():
|
|||
"""
|
||||
Add the idle period to the total idle time.
|
||||
"""
|
||||
_reset_screen_time()
|
||||
_reset_stats()
|
||||
global total_idle_time
|
||||
# idle_period is provided by Smart Pause plugin
|
||||
total_idle_time += context.get('idle_period', 0)
|
||||
session['total_idle_time'] = total_idle_time
|
||||
|
|
Loading…
Reference in New Issue