+
+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()