From: pin Date: Wed, 7 Jul 2010 16:19:34 +0000 (+0000) Subject: Implémentation de méthodes d'analyse. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/e84b436a6e4043910573b2effe3d65f0a6f1e0b0 Implémentation de méthodes d'analyse. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@278 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/minwii/loganalyse.py b/src/minwii/loganalyse.py index 4a0460a..1772849 100755 --- a/src/minwii/loganalyse.py +++ b/src/minwii/loganalyse.py @@ -5,3 +5,103 @@ Module d'analyse des fichiers de log minwii. $Id$ $URL$ """ + +from logfilereader import LogFileReader +from pprint import pprint +from musicxml import musicXml2Song +from statlib import stats + +DEFAULT_STATS = ('geometricmean', + 'harmonicmean', + 'mean', + 'median', + 'medianscore', + 'mode', + 'moment', + 'variation', + 'skew', + '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 + return computeList + +class LogFileAnalyser(LogFileReader) : + + POSSIBLE_ANALYSES = {'BEGINNER' : ('songDuration', + 'playingDuration', + 'noteEndNoteOnLatency')} + + def analyse(self) : + mode = self.getMode() + print 'Mode :', mode + + results = {} + + for name in self.POSSIBLE_ANALYSES[mode] : + meth = getattr(self, name) + results[name] = meth() + + pprint(results) + + def playingDuration(self) : + last = self.getLastEventTicks() + first = self.getFirstEventTicks() + return last - first + + def songDuration(self) : + songFile = self.getSongFile() + song = musicXml2Song(songFile) + duration = 0 + for note, verseIndex in song.iterNotes(indefinitely=False) : + duration = duration + note.duration + return duration * song.quarterNoteDuration + + @statsresults + def noteEndNoteOnLatency(self) : + eIter = self.getEventsIterator() + latencies = [] + lastnoteEndT = 0 + + for ticks, eventName, message in eIter : + if eventName == 'NOTEEND': + lastnoteEndT = ticks + if eventName == 'NOTEON' and lastnoteEndT : + latencies.append(ticks - lastnoteEndT) + + return latencies + + + + + +def main() : + from optparse import OptionParser + usage = "%prog logfile" + op = OptionParser(usage) + options, args = op.parse_args() + if len(args) != 1 : + op.error("incorrect number of arguments") + + + lfa = LogFileAnalyser(args[0]) + lfa.analyse() + +if __name__ == "__main__" : + from os.path import realpath, sep + import sys + minwiipath = realpath(__file__).split(sep) + minwiipath = minwiipath[:-2] + minwiipath = sep.join(minwiipath) + sys.path.insert(1, minwiipath) + main()