1 # -*- coding: utf-8 -*-
3 Module d'analyse des fichiers de log minwii.
9 from logfilereader
import LogFileReader
10 from pprint
import pprint
11 from musicxml
import musicXml2Song
12 from statlib
import stats
14 DEFAULT_STATS
= ('geometricmean',
31 def computeList(self
):
34 for name
in DEFAULT_STATS
:
35 ret
[name
] = getattr(stats
, name
)(l
)
39 class LogFileAnalyser(LogFileReader
) :
41 POSSIBLE_ANALYSES
= {'BEGINNER' : ('songDuration',
43 'noteEndNoteOnLatency')}
51 for name
in self
.POSSIBLE_ANALYSES
[mode
] :
52 meth
= getattr(self
, name
)
53 results
[name
] = meth()
57 def playingDuration(self
) :
58 last
= self
.getLastEventTicks()
59 first
= self
.getFirstEventTicks()
62 def songDuration(self
) :
63 songFile
= self
.getSongFile()
64 song
= musicXml2Song(songFile
)
66 for note
, verseIndex
in song
.iterNotes(indefinitely
=False) :
67 duration
= duration
+ note
.duration
68 return duration
* song
.quarterNoteDuration
71 def noteEndNoteOnLatency(self
) :
72 eIter
= self
.getEventsIterator()
76 for ticks
, eventName
, message
in eIter
:
77 if eventName
== 'NOTEEND':
79 if eventName
== 'NOTEON' and lastnoteEndT
:
80 latencies
.append(ticks
- lastnoteEndT
)
89 from optparse
import OptionParser
90 usage
= "%prog logfile"
91 op
= OptionParser(usage
)
92 options
, args
= op
.parse_args()
94 op
.error("incorrect number of arguments")
97 lfa
= LogFileAnalyser(args
[0])
100 if __name__
== "__main__" :
101 from os
.path
import realpath
, sep
103 minwiipath
= realpath(__file__
).split(sep
)
104 minwiipath
= minwiipath
[:-2]
105 minwiipath
= sep
.join(minwiipath
)
106 sys
.path
.insert(1, minwiipath
)