Statistiche.

Leonardo [2010-04-17 08:42]
Statistiche.
Filename
phcstats.py
diff --git a/phcstats.py b/phcstats.py
index ade42f6..97c8fba 100755
--- a/phcstats.py
+++ b/phcstats.py
@@ -5,6 +5,7 @@
 # e restituisce delle statistiche a proposito.

 import subprocess, time
+from optparse import OptionsParser

 # Qualche variabile globale
 database_directory = '/home/robol/client_stats/' # Il traling slash ci serve
@@ -66,9 +67,34 @@ def UpdateClientsData(client, alive):
     data = LoadClientData(client)
     data[time.time()] = alive
     DumpClientData(client, data)
+
+def PrintStats(client):
+    """
+    Stampa le statistiche sul client prescelto
+    """
+    data = LoadClientData(client)
+    uptime = len(filter(lambda s: (s==True), data))/ float(len(filter))
+    print "Uptime: %3.3f (%s)" % (100 * uptime, client)
+



 if __name__ == "__main__":
-    for client in LoadClients():
-        UpdateClientsData(client, IsAlive(client))
+
+    parser = OptionParser()
+    parser.add_option("-c", "--check", dest="check",
+                      help = "Check if clients are up and update database",
+                      action = "store_true", default=True)
+    parser.add_option("-s", "--stats", dest="stats",
+                      help = "Print stats about collected informations",
+                      action = "store_true", default = False)
+
+    (options, args) = parser.parse_args()
+
+    if options.check:
+        for client in LoadClients():
+            UpdateClientsData(client, IsAlive(client))
+
+    if options.stats:
+        for client in LoadClients():
+            PrintStats(client)
ViewGit