X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/2acf10a88b2307eeb78f74b612586dd079c1b7bf..323c312f13c8d50918c0b8e6350454e6112487ab:/src/minwii/loganalyse.py?ds=sidebyside diff --git a/src/minwii/loganalyse.py b/src/minwii/loganalyse.py index a5f8be7..1a1f676 100755 --- a/src/minwii/loganalyse.py +++ b/src/minwii/loganalyse.py @@ -9,18 +9,22 @@ $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 -DEFAULT_STATS = ('geometricmean', - 'harmonicmean', - 'mean', - 'median', - 'medianscore', +PLAYING_MODES = dict(PLAYING_MODES) + +DEFAULT_STATS = (#'geometricmean', + #'harmonicmean', + #'mean', + ('median', 'Médiane'), + #'medianscore', #'mode', - 'moment', - 'variation', - 'skew', - 'kurtosis', + #'moment', + ('variation', 'Variation'), + #'skew', + ('kurtosis', 'Kurtosis'), #'itemfreq', #'histogram', #'cumfreq', @@ -30,10 +34,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) : @@ -66,15 +72,20 @@ 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))) for name in self.POSSIBLE_ANALYSES[mode] : meth = getattr(self, name) results.append((meth.__doc__, meth())) except : - pass + raise return results + def _toTimeDelta(self, milliseconds) : + duration = milliseconds / 1000. + duration = int(round(duration, 0)) + return str(timedelta(seconds=duration)) + def playingDuration(self) : 'Temps de jeu' #retourne la durée écoulée entre le premier et de dernier message @@ -82,10 +93,11 @@ class LogFileAnalyser(LogFileReader) : last = self.getLastEventTicks() first = self.getFirstEventTicks() - return last - first + return self._toTimeDelta(last - first) + def songDuration(self) : - 'Durée de la chanson' + 'Durée de référence de la chanson' #retourne la durée de référence de la chanson #en prenant en compte le tempo présent dans la transcription #et en effectuant toutes les répétitions des couplets / refrains. @@ -95,7 +107,8 @@ class LogFileAnalyser(LogFileReader) : duration = 0 for note, verseIndex in song.iterNotes() : duration = duration + note.duration - return duration * song.quarterNoteDuration + duration = duration * song.quarterNoteDuration # en milisecondes + return self._toTimeDelta(duration) @statsresults def noteEndNoteOnLatency(self) : @@ -136,7 +149,7 @@ class LogFileAnalyser(LogFileReader) : for note, verseIndex in song.iterNotes() : songNoteCpt = songNoteCpt + 1 - return int(round(self.noteOnCount() / float(songNoteCpt) * 100, 0)) + return round(self.noteOnCount() / float(songNoteCpt) * 100, 1) def missCount(self) : "Nombre d'erreurs"