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

Method parse_stats

brainworkshop.py:1472–1557  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1470 self.batch = None
1471
1472 def parse_stats(self):
1473 self.batch = None
1474 self.reset_dictionaries()
1475 self.reset_percents()
1476 ind = {'date':0, 'modename':1, 'percent':2, 'mode':3, 'n':4, 'ticks':5,
1477 'trials':6, 'manual':7, 'session':8, 'position1':9, 'audio':10,
1478 'color':11, 'visvis':12, 'audiovis':13, 'arithmetic':14,
1479 'image':15, 'visaudio':16, 'audio2':17, 'position2':18,
1480 'position3':19, 'position4':20, 'vis1':21, 'vis2':22, 'vis3':23,
1481 'vis4':24}
1482
1483 if os.path.isfile(os.path.join(get_data_dir(), cfg.STATSFILE)):
1484 try:
1485 statsfile_path = os.path.join(get_data_dir(), cfg.STATSFILE)
1486 statsfile = open(statsfile_path, 'r')
1487 for line in statsfile:
1488 if line == '': continue
1489 if line == '\n': continue
1490 if line[0] not in '0123456789': continue
1491 datestamp = date(int(line[:4]), int(line[5:7]), int(line[8:10]))
1492 hour = int(line[11:13])
1493 if hour < cfg.ROLLOVER_HOUR:
1494 datestamp = date.fromordinal(datestamp.toordinal() - 1)
1495 if line.find('\t') >= 0:
1496 separator = '\t'
1497 else: separator = ','
1498 newline = line.split(separator)
1499 try:
1500 if int(newline[7]) != 0: # only consider standard mode
1501 continue
1502 except:
1503 continue
1504 newmode = int(newline[3])
1505 newback = int(newline[4])
1506
1507 while len(newline) < 24:
1508 newline.append('0') # make it work for image mode, missing visaudio and audio2
1509 if len(newline) >= 16:
1510 for m in mode.modalities[newmode]:
1511 self.percents[newmode][m].append(int(newline[ind[m]]))
1512
1513 dictionary = self.dictionaries[newmode]
1514 if datestamp not in dictionary:
1515 dictionary[datestamp] = []
1516 dictionary[datestamp].append([newback] + [int(newline[2])] + \
1517 [self.percents[newmode][n][-1] for n in mode.modalities[newmode]])
1518
1519 statsfile.close()
1520 except:
1521 quit_with_error(_('Error parsing stats file\n %s') %
1522 os.path.join(get_data_dir(), cfg.STATSFILE),
1523 _('Please fix, delete or rename the stats file.'))
1524
1525 def mean(x):
1526 if len(x):
1527 return sum(x)/float(len(x))
1528 else:
1529 return 0.

Callers 2

next_styleMethod · 0.95
on_key_pressFunction · 0.80

Calls 7

reset_dictionariesMethod · 0.95
reset_percentsMethod · 0.95
get_data_dirFunction · 0.85
quit_with_errorFunction · 0.85
get_threshold_advanceFunction · 0.85
get_threshold_fallbackFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected