Corretta l'integrazione sul tempo.

Leonardo Robol [2010-04-17 09:18]
Corretta l'integrazione sul tempo.
Filename
phcstats.py
diff --git a/phcstats.py b/phcstats.py
index a6c386f..6525948 100755
--- a/phcstats.py
+++ b/phcstats.py
@@ -46,7 +46,7 @@ def LoadClientData(client):
         if ":" in line:
             (time, alive) = line.split(":")
             alive = ("True" in alive)
-            data[time] = bool(alive)
+            data[float(time)] = alive
     f.close()
     return data

@@ -67,7 +67,7 @@ def UpdateClientsData(client, alive):
     che in questo momento è acceso.
     """
     data = LoadClientData(client)
-    data[time.time()] = alive
+    data[float(time.time())] = alive
     DumpClientData(client, data)

 def PrintStats(client):
@@ -75,9 +75,20 @@ def PrintStats(client):
     Stampa le statistiche sul client prescelto
     """
     data = LoadClientData(client)
-    up = len(filter(lambda i: i[1] == True, data.items()))
-    total = len(data)
-    uptime = 100.0 * up / total
+    d = data.items()
+    d.sort()
+    ss = 0
+    old_time = d[0][0]
+
+    # Un piccolo integrale sul tempo della funzione
+    # up(client)
+    for (time_entry, up) in d[1:]:
+        if up:
+            ss += (time_entry - old_time)
+        old_time = time_entry
+    ss = ss / (d[-1:][0][0] - d[0][0])
+
+    uptime = 100.0 * ss
     print "Client: %s" % client
     print "Uptime: %3.2f %% " % uptime
     print "----------------------------------------------------"
ViewGit