Ejemplo n.º 1
0
class Scene(graphics.Scene):
    def __init__(self):
        graphics.Scene.__init__(self)
        self.storage = Storage()

        self._load_end_date = dt.datetime.now()
        self.facts = []

        self.label = layout.Label("Loading...", y=100,
                                    color="#666",
                                    size=50)
        self.add_child(layout.VBox(self.label))

        gobject.timeout_add(10, self.load_facts)


    def load_facts(self):
        # chunk size
        end = self._load_end_date
        start = end - dt.timedelta(days=30)
        self.facts = self.storage.get_facts(start, end) + self.facts

        self._load_end_date = start - dt.timedelta(days=1)

        # limiter
        if end > dt.datetime.now() - dt.timedelta(days=365):
            self.label.text = "Loading %d..." % len(self.facts)
            gobject.timeout_add(10, self.load_facts)
        else:
            self.on_facts_loaded()


    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.º 2
0
def get_timeinfo_hamster(
        date=datetime.now(), baseurl='', loginfo={}, activities=[]):
    default_activity = get_default_activity(activities)
    from hamster.client import Storage
    sto = Storage()
    facts = sto.get_facts(date)
    bookings = []
    for fact in facts:
        #delta = (fact.end_time or datetime.now()) - fact.start_time
        #hours = round(fact.delta.seconds / 3600. * 4 + .25) / 4.
        hours = fact.delta.seconds / 3600.
        existing = filter(
            lambda b: b['description'] == fact.activity and b['spent_on'] ==
            fact.date, bookings)
        if existing:
            existing[0]['hours'] += hours
            continue
        ticket = get_ticket_no(fact.tags + [fact.activity] +
                               [fact.description or ''])
        bookings.append({
            'issue_id': ticket,
            'spent_on': fact.date,
            'hours': hours,
            'description': fact.activity,
            'activity_id': default_activity['id'],
            'comments': '; '.join(loginfo.get(ticket, []))
        })
    return bookings
Ejemplo n.º 3
0
 def get_timeinfo(self, date=datetime.now(), loginfo={}, activities=[]):
     default_activity = get_default_activity(activities)
     from hamster.client import Storage
     sto = Storage()
     facts = sto.get_facts(date)
     bookings = []
     for fact in facts:
         #delta = (fact.end_time or datetime.now()) - fact.start_time
         #hours = round(fact.delta.seconds / 3600. * 4 + .25) / 4.
         minutes = fact.delta.seconds / 60.
         #hours = minutes / 60.
         existing = filter(lambda b: b['description'] == fact.activity
                           and b['spent_on'] == fact.date, bookings)
         if existing:
             existing[0]['time'] += minutes
             continue
         ticket = get_ticket_no(
             ['#' + tag for tag in fact.tags] + [fact.activity] +
             [fact.description or ''])
         bookings.append({'issue_id': ticket,
                          'spent_on': fact.date,
                          'time': minutes,
                          'description': fact.activity,
                          'activity': default_activity.get('name', 'none'),
                          'comments': '. '.join(loginfo.get(ticket, [])),
                          'category': fact.category,
                          'tags': fact.tags,
                          'project': ''})
     return bookings
Ejemplo n.º 4
0
class Scene(graphics.Scene):
    def __init__(self):
        graphics.Scene.__init__(self)
        self.storage = Storage()

        self._load_end_date = dt.datetime.now()
        self.facts = []

        self.label = layout.Label("Loading...", y=100, color="#666", size=50)
        self.add_child(layout.VBox(self.label))

        gobject.timeout_add(10, self.load_facts)

    def load_facts(self):
        # chunk size
        end = self._load_end_date
        start = end - dt.timedelta(days=30)
        self.facts = self.storage.get_facts(start, end) + self.facts

        self._load_end_date = start - dt.timedelta(days=1)

        # limiter
        if end > dt.datetime.now() - dt.timedelta(days=365):
            self.label.text = "Loading %d..." % len(self.facts)
            gobject.timeout_add(10, self.load_facts)
        else:
            self.on_facts_loaded()

    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))
class Scene(graphics.Scene):
    def __init__(self):
        graphics.Scene.__init__(self)
        self.storage = Storage()

        self._load_end_date = dt.datetime.now()
        self.facts = []

        self.label = layout.Label("Loading...", y=100, color="#666", size=50)
        self.add_child(layout.VBox(self.label))

        gobject.timeout_add(10, self.load_facts)

    def load_facts(self):
        # chunk size
        end = self._load_end_date
        start = end - dt.timedelta(days=30)
        self.facts = self.storage.get_facts(start, end) + self.facts

        self._load_end_date = start - dt.timedelta(days=1)

        # limiter
        if end > dt.datetime.now() - dt.timedelta(days=565):
            self.label.text = "Loading %d..." % len(self.facts)
            gobject.timeout_add(10, self.load_facts)
        else:
            self.on_facts_loaded()

    def on_facts_loaded(self):
        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)

        # add sparkbars of activity by weekday
        row = layout.HBox([
            layout.VBox(spacing=20, expand=False),
            layout.VBox(spacing=15, expand=False),
            layout.VBox(spacing=15)
        ],
                          spacing=20)
        first_row.add_child(row)

        row[0].add_child(layout.Label("Category", expand=False, x_align=0))
        row[1].add_child(layout.Label("Weekdays", expand=False, x_align=0))
        row[2].add_child(layout.Label("By week", expand=False, x_align=0))
        self._add_stats(row, lambda fact: (fact.category, ""))

        row[0].add_child(
            layout.Label("Activity", expand=False, x_align=0, margin_top=20))
        row[1].add_child(
            layout.Label("Weekdays", expand=False, x_align=0, margin_top=20))
        row[2].add_child(
            layout.Label("By week", expand=False, x_align=0, margin_top=20))
        self._add_stats(row, lambda fact: (fact.category, fact.activity))

    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.º 6
0
class Scene(graphics.Scene):
    def __init__(self):
        graphics.Scene.__init__(self)
        self.storage = Storage()

        self._load_end_date = dt.datetime.now()
        self.facts = []

        self.label = layout.Label("Loading...", y=100,
                                    color="#666",
                                    size=50)
        self.add_child(layout.VBox(self.label))

        gobject.timeout_add(10, self.load_facts)


    def load_facts(self):
        # chunk size
        end = self._load_end_date
        start = end - dt.timedelta(days=30)
        self.facts = self.storage.get_facts(start, end) + self.facts

        self._load_end_date = start - dt.timedelta(days=1)

        # limiter
        if end > dt.datetime.now() - dt.timedelta(days=565):
            self.label.text = "Loading %d..." % len(self.facts)
            gobject.timeout_add(10, self.load_facts)
        else:
            self.on_facts_loaded()

    def on_facts_loaded(self):
        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)

        # add sparkbars of activity by weekday
        row = layout.HBox([layout.VBox(spacing=20, expand=False),
                                       layout.VBox(spacing=15, expand=False),
                                       layout.VBox(spacing=15)
                           ], spacing=20)
        first_row.add_child(row)

        row[0].add_child(layout.Label("Category", expand=False, x_align=0))
        row[1].add_child(layout.Label("Weekdays", expand=False, x_align=0))
        row[2].add_child(layout.Label("By week", expand=False, x_align=0))
        self._add_stats(row, lambda fact: (fact.category, ""))

        row[0].add_child(layout.Label("Activity", expand=False, x_align=0, margin_top=20))
        row[1].add_child(layout.Label("Weekdays", expand=False, x_align=0, margin_top=20))
        row[2].add_child(layout.Label("By week", expand=False, x_align=0, margin_top=20))
        self._add_stats(row, lambda fact: (fact.category, fact.activity))



    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))