MCPcopy Create free account
hub / github.com/brain-workshop/brainworkshop / parse_statsfile

Method parse_statsfile

brainworkshop.py:3705–3774  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3703 self.sessions_thours = 0
3704
3705 def parse_statsfile(self):
3706 self.clear()
3707 if os.path.isfile(os.path.join(get_data_dir(), cfg.STATSFILE)):
3708 try:
3709 #last_session = []
3710 #last_session_number = 0
3711 last_mode = 0
3712 last_back = 0
3713 statsfile_path = os.path.join(get_data_dir(), cfg.STATSFILE)
3714 statsfile = open(statsfile_path, 'r')
3715 is_today = False
3716 is_thours = False
3717 today = date.today()
3718 yesterday = date.fromordinal(today.toordinal() - 1)
3719 tomorrow = date.fromordinal(today.toordinal() + 1)
3720 for line in statsfile:
3721 if line == '': continue
3722 if line == '\n': continue
3723 if line[0] not in '0123456789': continue
3724 datestamp = date(int(line[:4]), int(line[5:7]), int(line[8:10]))
3725 hour = int(line[11:13])
3726 mins = int(line[14:16])
3727 sec = int(line[17:19])
3728 thour = datetime.datetime.today().hour
3729 tmin = datetime.datetime.today().minute
3730 tsec = datetime.datetime.today().second
3731 if int(strftime('%H')) < cfg.ROLLOVER_HOUR:
3732 if datestamp == today or (datestamp == yesterday and hour >= cfg.ROLLOVER_HOUR):
3733 is_today = True
3734 elif datestamp == today and hour >= cfg.ROLLOVER_HOUR:
3735 is_today = True
3736 if datestamp == today or (datestamp == yesterday and (hour > thour or (hour == thour and (mins > tmin or (mins == tmin and sec > tsec))))):
3737 is_thours = True
3738 if '\t' in line:
3739 separator = '\t'
3740 else: separator = ','
3741 newline = line.split(separator)
3742 newmode = int(newline[3])
3743 newback = int(newline[4])
3744 newpercent = int(newline[2])
3745 newmanual = bool(int(newline[7]))
3746 newsession_number = int(newline[8])
3747 try:
3748 sesstime = int(round(float(newline[25])))
3749 except Exception as e:
3750 debug_msg(e)
3751 # this session wasn't performed with this version of BW, and is therefore
3752 # old, and therefore the session time doesn't matter
3753 sesstime = 0
3754 if newmanual:
3755 newsession_number = 0
3756 self.full_history.append([newsession_number, newmode, newback, newpercent, newmanual])
3757 if is_thours:
3758 stats.sessions_thours += 1
3759 stats.time_thours += sesstime
3760 if is_today:
3761 stats.sessions_today += 1
3762 self.time_today += sesstime

Callers 3

__init__Method · 0.80
set_userFunction · 0.80
brainworkshop.pyFile · 0.80

Calls 6

clearMethod · 0.95
retrieve_progressMethod · 0.95
get_data_dirFunction · 0.85
debug_msgFunction · 0.85
quit_with_errorFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected