X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/e26832c9e7be68fc16059f7a2d3c2478afbcfa91..fa75b1df8242dff846bd0fd6c2a274170892b73a:/src/minwii/loganalyse.py?ds=sidebyside diff --git a/src/minwii/loganalyse.py b/src/minwii/loganalyse.py index d7e136f..ab8c819 100755 --- a/src/minwii/loganalyse.py +++ b/src/minwii/loganalyse.py @@ -9,19 +9,24 @@ $URL$ from minwii.logfilereader import LogFileReader from pprint import pprint from minwii.musicxml import musicXml2Song +from minwii.globals import PLAYING_MODES from statlib import stats from datetime import timedelta +from xml.etree import ElementTree +import os.path -DEFAULT_STATS = ('geometricmean', - 'harmonicmean', - 'mean', - 'median', - 'medianscore', +PLAYING_MODES = dict(PLAYING_MODES) + +DEFAULT_STATS = (#'geometricmean', + ('harmonicmean', 'Moyenne harmonique'), + ('mean', 'Moyenne '), + ('median', 'Médiane'), + #'medianscore', #'mode', - 'moment', - 'variation', - 'skew', - 'kurtosis', + #'moment', + ('variation', 'Variation'), + #'skew', + ('kurtosis', 'Kurtosis'), #'itemfreq', #'histogram', #'cumfreq', @@ -31,10 +36,12 @@ DEFAULT_STATS = ('geometricmean', def statsresults(m) : def computeList(self): l = m(self) - ret = {} - for name in DEFAULT_STATS : - ret[name] = getattr(stats, name)(l) - return ret + results = [] + for name, label in DEFAULT_STATS : + results.append('%s : %s' % (label, getattr(stats, name)(l))) + return '\n'.join(results) + computeList.__name__ = m.__name__ + computeList.__doc__ = m.__doc__ return computeList class LogFileAnalyser(LogFileReader) : @@ -67,7 +74,11 @@ class LogFileAnalyser(LogFileReader) : try : self.mode = mode = self.getMode() - results.append(('Mode de jeu', mode)) + results.append(('Mode de jeu', PLAYING_MODES.get(mode, mode))) + + self.songTitle = LogFileAnalyser.getSongTitle(self.getSongFile()) + results.append(('Chanson', self.songTitle)) + for name in self.POSSIBLE_ANALYSES[mode] : meth = getattr(self, name) results.append((meth.__doc__, meth())) @@ -76,6 +87,23 @@ class LogFileAnalyser(LogFileReader) : return results + @staticmethod + def getSongTitle(file) : + if os.path.exists(file) : + it = ElementTree.iterparse(file, ['start', 'end']) + creditFound = False + + for evt, el in it : + if el.tag == 'credit' : + creditFound = True + if el.tag == 'credit-words' and creditFound: + return el.text + if el.tag == 'part-list' : + # plus de chance de trouver un titre + return os.path.basename(file) + else : + return os.path.basename(file) + def _toTimeDelta(self, milliseconds) : duration = milliseconds / 1000. duration = int(round(duration, 0))