Quelques adaptations pour que ça compile avec Py2Exe.
[minwii.git] / src / minwii / loganalyse.py
index 551af7f..73581cb 100755 (executable)
@@ -6,9 +6,9 @@ $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 statlib import stats
 
 DEFAULT_STATS = ('geometricmean',
@@ -16,15 +16,15 @@ DEFAULT_STATS = ('geometricmean',
                  'mean',
                  'median',
                  'medianscore',
-                 'mode',
+                 #'mode',
                  'moment',
                  'variation',
                  'skew',
                  'kurtosis',
-                 'itemfreq',
-                 'histogram',
-                 'cumfreq',
-                 'relfreq',
+                 #'itemfreq',
+                 #'histogram',
+                 #'cumfreq',
+                 #'relfreq',
                  )
 
 def statsresults(m) :
@@ -41,19 +41,39 @@ class LogFileAnalyser(LogFileReader) :
     POSSIBLE_ANALYSES = {'BEGINNER' : ('songDuration',
                                        'playingDuration',
                                        'noteEndNoteOnLatency',
-                                       'noteOnCount')}
+                                       '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 = {}
         
-        for name in self.POSSIBLE_ANALYSES[mode] :
-            meth = getattr(self, name)
-            results[name] = meth()
+        try :
+            self.mode = mode = self.getMode()
+            results['playingMode'] = mode
+            for name in self.POSSIBLE_ANALYSES[mode] :
+                meth = getattr(self, name)
+                results[name] = meth()
+        except :
+            pass
         
-        pprint(results)
+        return results
     
     def playingDuration(self) :
         """ retourne la durée écoulée entre le premier et de dernier message
@@ -100,9 +120,48 @@ class LogFileAnalyser(LogFileReader) :
                 cpt = cpt + 1
         
         return cpt
-            
+    
+    def realisationRate(self) :
+        """ 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 int(round(self.noteOnCount() / float(songNoteCpt) * 100, 0))
     
+    def missCount(self) :
+        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
+                
         
         
         
@@ -117,7 +176,7 @@ def main() :
 
 
     lfa = LogFileAnalyser(args[0])
-    lfa.analyse()
+    pprint(lfa.analyse())
 
 if __name__ == "__main__" :
     from os.path import realpath, sep