def save(self, filename=None): _file_name = filename if filename else "track-%s.json" % track_common.today_str() # print(_file_name) _app_data = self._applications.__data__() with open(_file_name, 'w') as _file: json.dump(_app_data, _file, sort_keys=True) #, indent=4, separators=(',', ': ')) _test_model = track_base.active_applications(None) _test_model.from_dict(_app_data) assert self._applications == _test_model
def __init__(self): self._idle_current = 0 self._current_minute = 0 # does not need to be highest minute index self._current_app_title = "" self._current_process_exe = "" self._user_is_active = True self._active_day = track_common.today_int() # -- persist self._applications = track_base.active_applications() self._rules = track_base.rules_model()
def test_import(): a = track_base.active_applications() _total_dur = 0 _count = 0 _lunch_time = 12 * 60 + 50 for root, dirs, files in os.walk('.'): for _f in [f for f in sorted(files) if f.endswith('.json')]: _file = os.path.join(root, _f) c = json.loads(open(_file).read().decode()) try: a.from_dict(c) except Exception as ex: print('ERROR: could not load "%s"' % _file) print('ERROR: "%s"' % ex) continue _end = a.end_index() _begin = a.begin_index() _dur = _end - _begin (_b, _e), _a = a.info(_lunch_time) _lunch_dur = _e - _b if not (_e - _b >= 30 and _a == 'idle'): _lunch_dur = 0 print("WARNING: no lunch time found for %s" % _file) _dur -= _lunch_dur if _dur > 300: _total_dur += _dur _count += 1 else: print('WARNING: ignore "%s" - less than 5h tracked' % _file) print("f: %23s, count: %3d, begin: %s (%4d), end: %s (%4d), lunch: %7s, dur: %7s" % ( _file, a.count(), track_base.mins_to_date(_begin), _begin, track_base.mins_to_date(_end), _end, track_base.mins_to_dur(_lunch_dur), track_base.mins_to_dur(_dur))) # print(re.search('track-.*.json', _file) is not None) if _count > 0: print(track_base.mins_to_dur(_total_dur / _count))
def test_import(): a = track_base.active_applications() _total_dur = 0 _count = 0 _lunch_time = 12 * 60 + 50 for root, dirs, files in os.walk('.'): for _f in [f for f in sorted(files) if f.endswith('.json')]: _file = os.path.join(root, _f) c = json.loads(open(_file).read().decode()) try: a.from_dict(c) except Exception as ex: print('ERROR: could not load "%s"' % _file) print('ERROR: "%s"' % ex) continue _end = a.end_index() _begin = a.begin_index() _dur = _end - _begin (_b, _e), _a = a.info(_lunch_time) _lunch_dur = _e - _b if not (_e - _b >= 30 and _a == 'idle'): _lunch_dur = 0 print("WARNING: no lunch time found for %s" % _file) _dur -= _lunch_dur if _dur > 300: _total_dur += _dur _count += 1 else: print('WARNING: ignore "%s" - less than 5h tracked' % _file) print( "f: %23s, count: %3d, begin: %s (%4d), end: %s (%4d), lunch: %7s, dur: %7s" % (_file, a.count(), track_base.mins_to_date(_begin), _begin, track_base.mins_to_date(_end), _end, track_base.mins_to_dur(_lunch_dur), track_base.mins_to_dur(_dur))) # print(re.search('track-.*.json', _file) is not None) if _count > 0: print(track_base.mins_to_dur(_total_dur / _count))
def test_active_applications(): aa = track_base.active_applications()