From: Drew Fisher Date: Thu, 10 Sep 2009 21:10:31 +0000 (-0500) Subject: Refactor analytics code to be more readable. X-Git-Url: http://git.zarvox.org/%7Bthis.props.bicon_url%7D?a=commitdiff_plain;h=478ec4dcc34cdc8b8164a47b5a17d0c66c6546ae;p=wp3.git Refactor analytics code to be more readable. --- diff --git a/analytics.py b/analytics.py index ed19308..48b91f1 100644 --- a/analytics.py +++ b/analytics.py @@ -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")