]> git.zarvox.org Git - wp3.git/commitdiff
Refactor analytics code to be more readable.
authorDrew Fisher <drew.m.fisher@gmail.com>
Thu, 10 Sep 2009 21:10:31 +0000 (16:10 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Thu, 10 Sep 2009 21:10:31 +0000 (16:10 -0500)
analytics.py

index ed193084ccc496d242723a480579831ce8dd9dd0..48b91f130b3c147b9335516a44851ea95a51c1b4 100644 (file)
@@ -66,20 +66,16 @@ class Analytics(QWidget):
                                pop = pop + 1
                        maxpop = len(self.roomlists[d]) * 2
                        self.log("Registered Population: {0} of {1} ({2}%)".format(pop , maxpop, pop * 100 / maxpop ) )
-                       self.log("Breakdown by floor:")
+
                        # The following code assumes four floors and a numbering scheme where the
                        # hundreds digit of the room number is the floor.  If this changes, this
                        # code will need to be rewritten.
-                       floors = [ [], [], [], [] ] # Note: sorted from bottom floor to top
-                       for r in self.roomlists[d]:
-                               if r < 200:
-                                       floors[0].append(r)
-                               if r >= 200 and r < 300:
-                                       floors[1].append(r)
-                               if r >= 300 and r < 400:
-                                       floors[2].append(r)
-                               if r >= 400 and r < 500:
-                                       floors[3].append(r)
+                       self.log("Breakdown by floor:")
+                       floors = [] # Note: sorted from bottom floor to top
+                       floors.append( filter(lambda x: x >= 100 and x < 200, self.roomlists[d]) )
+                       floors.append( filter(lambda x: x >= 200 and x < 300, self.roomlists[d]) )
+                       floors.append( filter(lambda x: x >= 300 and x < 400, self.roomlists[d]) )
+                       floors.append( filter(lambda x: x >= 400 and x < 500, self.roomlists[d]) )
                        floorpop = []
                        for floor in floors: # calculate the registered population
                                thisfloorpop = 0
@@ -95,6 +91,8 @@ class Analytics(QWidget):
                        self.log("Second floor: {0} of {1} registered ({2}%)".format( floorpop[1], len(floors[1]) * 2, floorpop[1] * 50 / len(floors[1])))
                        self.log("Third floor: {0} of {1} registered ({2}%)".format( floorpop[2], len(floors[2]) * 2, floorpop[2] * 50 / len(floors[2])))
                        self.log("Fourth floor: {0} of {1} registered ({2}%)".format( floorpop[3], len(floors[3]) * 2, floorpop[3] * 50 / len(floors[3])))
+
+                       # Breakdown by room only in verbose log
                        self.vlog("Breakdown by room:")
                        for room in self.roomlists[d]:
                                q.prepare("SELECT id, surname, forename FROM people WHERE dorm=:dorm AND room=:room")