added textfile event logger FIRMWARE_BEFORE_BINARY_COMMUNICATION

Sat, 22 Jun 2013 18:21:13 +0200

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 22 Jun 2013 18:21:13 +0200
changeset 137
94d71156517b
parent 136
e7336e63acf6
child 138
a570dd24a413

added textfile event logger

slotUI/logger.py file | annotate | diff | comparison | revisions
slotUI/profiles/default file | annotate | diff | comparison | revisions
slotUI/slotCli.py file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/slotUI/logger.py	Sat Jun 22 18:21:13 2013 +0200
@@ -0,0 +1,40 @@
+class eventLogger:
+    def __init__(self, filename):
+        self.filename = filename
+
+    def push(self, data):
+        """Pushes data to logfile CSV output:
+        struc:
+            unix timestamp
+            system clock
+            rennbezeichnung
+            slot
+            slotname (player)
+            runde
+            letzte rundenzeit
+            beste rundenzeit
+            laplimit
+            timelimit
+        """
+        try:
+            fd = open(self.filename, 'a')
+            ok = True
+        except:
+            ok = False
+        if not ok:
+            fd = open(self.filename, 'w')
+        if ok:
+            fd.write("%s;%s;\"%s\";%s;\"%s\";%s;%s;%s;%s;%s\n" % (
+                data[0],
+                data[1],
+                data[2],
+                data[3],
+                data[4],
+                data[5],
+                data[6],
+                data[7],
+                data[8],
+                data[9]
+                ))
+            fd.close()
+
--- a/slotUI/profiles/default	Sun Dec 23 09:53:00 2012 +0100
+++ b/slotUI/profiles/default	Sat Jun 22 18:21:13 2013 +0200
@@ -1,8 +1,8 @@
 [Settings]
 Name=unnamed
 Fuel=100
-Accel=10
-Limit=10
+Accel=11
+Limit=11
 Brake=15
 
 [Stats]
--- a/slotUI/slotCli.py	Sun Dec 23 09:53:00 2012 +0100
+++ b/slotUI/slotCli.py	Sat Jun 22 18:21:13 2013 +0200
@@ -8,10 +8,11 @@
 from optparse import OptionParser
 from operator import itemgetter
 from subprocess import Popen, PIPE
+from logger import eventLogger
 import sys, os
 from copy import copy
 import curses
-from time import sleep
+from time import sleep, time
 import ConfigParser
 
 import SimpleXMLRPCServer
@@ -19,7 +20,7 @@
 import threading
 
 
-VERSION = "1.8"
+VERSION = "1.8.1"
 MAXSLOTS = 6
 TERM = {
     "caption": "\033[1;37m\033[1;44m",
@@ -119,6 +120,8 @@
         self.timelimit = 0 # race timelimit
         self.firstpos = -1 # first position slot
         self.freerun = True # freerun mode = sort order by best lap
+        self.raceName = "Freestyle"
+        self.log = eventLogger("events.log")
 
     def reset_slots(self):
         idx = 0
@@ -256,6 +259,21 @@
         curses.noecho()
         self.scr.nodelay(1) # disable delay on readkey
 
+    def readRaceName(self):
+        self.scr.nodelay(0) # enable delay on readkey
+        curses.echo()
+        self.scr.addstr(0,0, "Enter Race Name [%s]:" % (
+            self.raceName),
+            curses.color_pair(1))
+        self.scr.refresh()
+        name = self.scr.getstr(1,0, 15)
+        if name != "":
+            self.raceName = name
+        self.cleartop()
+        self.scr.refresh()
+        curses.noecho()
+        self.scr.nodelay(1) # disable delay on readkey
+
     def readLimit(self, slot):
         limit = self.readInt("SPEEDLIMIT for %s (%i)" % (
             self.slot[slot]["name"],
@@ -452,6 +470,7 @@
             #elif key == ord('r'): self.readLimit(3)
             #elif key == ord('t'): self.readLimit(4)
             #elif key == ord('z'): self.readLimit(5)
+            elif key == ord('n'): self.readRaceName()
             elif key == ord('a'):
                 if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1
                 cli.box.speedminimum(4, self.slot[4]["drive"])
@@ -515,6 +534,23 @@
                             self.slot[slot]["status"] = "WINNER!"
                             self.box.query("+") # stop race
 
+                        tmpname = "n/a"
+                        if not self.freerun:
+                            tmpname = self.raceName
+                        self.log.push([
+                            time(),
+                            self.sysclk,
+                            tmpname,
+                            slot,
+                            self.slot[slot]["name"],
+                            l,
+                            t,
+                            self.slot[slot]["best"],
+                            self.laplimit,
+                            self.timelimit
+                            ])
+
+
                         self.render_slots()
 
                     if rx[:2] == "F:":

mercurial