X-Git-Url: https://svn.cri.ensmp.fr/git/minwii.git/blobdiff_plain/e84b436a6e4043910573b2effe3d65f0a6f1e0b0..323c312f13c8d50918c0b8e6350454e6112487ab:/src/minwii/loganalyse.py?ds=sidebyside diff --git a/src/minwii/loganalyse.py b/src/minwii/loganalyse.py index 1772849..1a1f676 100755 --- a/src/minwii/loganalyse.py +++ b/src/minwii/loganalyse.py @@ -6,69 +6,113 @@ $Id$ $URL$ """ -from logfilereader import LogFileReader +from minwii.logfilereader import LogFileReader from pprint import pprint -from musicxml import musicXml2Song +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', - 'mode', - 'moment', - 'variation', - 'skew', - 'kurtosis', - 'itemfreq', - 'histogram', - 'cumfreq', - 'relfreq', +PLAYING_MODES = dict(PLAYING_MODES) + +DEFAULT_STATS = (#'geometricmean', + #'harmonicmean', + #'mean', + ('median', 'Médiane'), + #'medianscore', + #'mode', + #'moment', + ('variation', 'Variation'), + #'skew', + ('kurtosis', 'Kurtosis'), + #'itemfreq', + #'histogram', + #'cumfreq', + #'relfreq', ) 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) : POSSIBLE_ANALYSES = {'BEGINNER' : ('songDuration', 'playingDuration', - 'noteEndNoteOnLatency')} + 'noteEndNoteOnLatency', + 'realisationRate') + ,'EASY' : ('songDuration', + 'playingDuration', + 'noteEndNoteOnLatency', + 'realisationRate', + 'missCount') + ,'NORMAL' : ('songDuration', + 'playingDuration', + 'realisationRate', + 'missCount') + ,'ADVANCED' : ('songDuration', + 'playingDuration', + 'realisationRate', + 'missCount') + ,'EXPERT' : ('songDuration', + 'playingDuration', + 'realisationRate', + 'missCount') + } def analyse(self) : - mode = self.getMode() - print 'Mode :', mode - - results = {} + results = [] - for name in self.POSSIBLE_ANALYSES[mode] : - meth = getattr(self, name) - results[name] = meth() + try : + self.mode = mode = self.getMode() + 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 : + raise - pprint(results) + 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 + #de type événement : correspond à la durée d'interprétation. + last = self.getLastEventTicks() first = self.getFirstEventTicks() - return last - first + return self._toTimeDelta(last - first) + def songDuration(self) : + '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. + songFile = self.getSongFile() song = musicXml2Song(songFile) duration = 0 - for note, verseIndex in song.iterNotes(indefinitely=False) : + 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) : + 'Réactivité' eIter = self.getEventsIterator() latencies = [] lastnoteEndT = 0 @@ -81,6 +125,61 @@ class LogFileAnalyser(LogFileReader) : return latencies + def noteOnCount(self) : + "retourne le nombre d'événements NOTEON" + + eIter = self.getEventsIterator() + cpt = 0 + + for ticks, eventName, message in eIter : + if eventName == 'NOTEON' : + cpt = cpt + 1 + + return cpt + + def realisationRate(self) : + 'Taux de réalisation' + #taux de réalisation en nombre de note + #peut être supérieur à 100 % car la chanson + #boucle à l'infini. + + songFile = self.getSongFile() + song = musicXml2Song(songFile) + songNoteCpt = 0 + for note, verseIndex in song.iterNotes() : + songNoteCpt = songNoteCpt + 1 + + return round(self.noteOnCount() / float(songNoteCpt) * 100, 1) + + def missCount(self) : + "Nombre d'erreurs" + eIter = self.getEventsIterator() + miss = 0 + if self.mode in ('EASY', 'NORMAL') : + catchColUp = False + for ticks, eventName, message in eIter : + if eventName == 'COLDOWN' : + colState = message.split(None, 2)[1] + colState = colState == 'True' + if colState : + catchColUp = False + continue + else : + catchColUp = True + elif eventName == 'NOTEON' : + catchColUp = False + elif eventName == 'COLUP' and catchColUp : + miss = miss + 1 + else : + for ticks, eventName, message in eIter : + if eventName == 'COLDOWN' : + colState = message.split(None, 2)[1] + colState = colState == 'True' + if not colState : + miss = miss + 1 + + return miss + @@ -95,7 +194,7 @@ def main() : lfa = LogFileAnalyser(args[0]) - lfa.analyse() + pprint(lfa.analyse()) if __name__ == "__main__" : from os.path import realpath, sep