Ejemplo n.º 1
0
    def on_facts_loaded(self):
        stats = Stats(self.facts, lambda fact: (fact.category, fact.activity))
        by_hour = stats.by_hour()


        self.clear()
        main = layout.VBox(padding=10, spacing=10)
        self.add_child(main)

        first_row = layout.HBox(spacing=10, expand=False)
        main.add_child(first_row)

        activity_weekdays = layout.HBox([layout.VBox(spacing=15, expand=False),
                                         layout.VBox(spacing=15, expand=False),
                                         layout.VBox(spacing=15)
                                        ], spacing=20)
        first_row.add_child(activity_weekdays)

        activity_weekdays[0].add_child(layout.Label("Activity", expand=False, x_align=0))
        activity_weekdays[1].add_child(layout.Label("Hour of the day", expand=False, x_align=0))


        for activity in sorted(stats.groups.keys()):
            label = layout.Label("%s@%s" % (activity[1], activity[0]),
                                 color="#333", size=12, x_align=0, y_align=0.5)
            label.max_width = 150
            activity_weekdays[0].add_child(label)
            activity_weekdays[1].add_child(SparkBars(by_hour[activity], 150))
    def _add_stats(self, container, toplevel_group):
        stats = Stats(self.facts, toplevel_group)
        by_week = stats.by_week()

        # group by weekday
        by_weekday = stats.by_weekday()

        # group by workday / holiday
        by_work_hobby = stats.group(lambda fact: "weekend" if fact.date.
                                    weekday() in (5, 6) else "workday")
        for activity, group in by_work_hobby.iteritems():
            work, non_work = group.get("workday", []), group.get("weekend", [])
            total = minutes(work) + minutes(non_work)
            by_work_hobby[activity] = "workday" if minutes(
                work) / total > 0.8 and len(work) > 10 else "other"

        for activity in sorted(stats.groups.keys()):
            label = layout.Label("%s@%s" % (activity[1], activity[0]),
                                 color="#333",
                                 size=12,
                                 x_align=0,
                                 y_align=0.5)
            label.max_width = 150
            container[0].add_child(label)

            if by_work_hobby[activity] == "workday":
                color = graphics.Colors.category10[0]
            else:
                color = graphics.Colors.category10[2]

            hours = [rec for rec in by_weekday[activity]]
            container[1].add_child(SparkBars(hours, color=color))

            weeks = by_week[activity]
            container[2].add_child(SparkBars(weeks, width=200, color=color))
Ejemplo n.º 3
0
    def on_facts_loaded(self):
        stats = Stats(self.facts, lambda fact: (fact.category, fact.activity))
        by_hour = stats.by_hour()

        self.clear()
        main = layout.VBox(padding=10, spacing=10)
        self.add_child(main)

        first_row = layout.HBox(spacing=10, expand=False)
        main.add_child(first_row)

        activity_weekdays = layout.HBox([
            layout.VBox(spacing=15, expand=False),
            layout.VBox(spacing=15, expand=False),
            layout.VBox(spacing=15)
        ],
                                        spacing=20)
        first_row.add_child(activity_weekdays)

        activity_weekdays[0].add_child(
            layout.Label("Activity", expand=False, x_align=0))
        activity_weekdays[1].add_child(
            layout.Label("Hour of the day", expand=False, x_align=0))

        for activity in sorted(stats.groups.keys()):
            label = layout.Label("%s@%s" % (activity[1], activity[0]),
                                 color="#333",
                                 size=12,
                                 x_align=0,
                                 y_align=0.5)
            label.max_width = 150
            activity_weekdays[0].add_child(label)
            activity_weekdays[1].add_child(SparkBars(by_hour[activity], 150))
Ejemplo n.º 4
0
    def _add_stats(self, container, toplevel_group):
        stats = Stats(self.facts, toplevel_group)
        by_week = stats.by_week()

        # group by weekday
        by_weekday = stats.by_weekday()

        # group by workday / holiday
        by_work_hobby = stats.group(lambda fact: "weekend" if fact.date.weekday() in  (5, 6) else "workday")
        for activity, group in by_work_hobby.iteritems():
            work, non_work = group.get("workday", []), group.get("weekend", [])
            total = minutes(work) + minutes(non_work)
            by_work_hobby[activity] = "workday" if minutes(work) / total > 0.8 and len(work) > 10 else "other"



        for activity in sorted(stats.groups.keys()):
            label = layout.Label("%s@%s" % (activity[1], activity[0]),
                                 color="#333",
                                 size=12, x_align=0, y_align=0.5)
            label.max_width = 150
            container[0].add_child(label)

            if by_work_hobby[activity] == "workday":
                color = graphics.Colors.category10[0]
            else:
                color = graphics.Colors.category10[2]

            hours = [rec for rec in by_weekday[activity]]
            container[1].add_child(SparkBars(hours, color=color))

            weeks = by_week[activity]
            container[2].add_child(SparkBars(weeks, width=200, color=color))