Exemple #1
0
    def do_charts(self, facts):
        all_categories = self.popular_categories
        
        
        #the single "totals" (by category) bar
        category_sums = stuff.totals(facts, lambda fact: fact["category"],
                      lambda fact: stuff.duration_minutes(fact["delta"]) / 60.0)
        category_totals = [category_sums.get(cat, 0)
                                                      for cat in all_categories]
        category_keys = ["%s %.1f" % (cat, category_sums.get(cat, 0.0))
                                                      for cat in all_categories]
        self.category_chart.plot([_("Total")],
                                 [category_totals],
                                 stack_keys = category_keys)
        
        # day / category chart
        all_days = [self.start_date + dt.timedelta(i)
                    for i in range((self.end_date - self.start_date).days  + 1)]        

        by_date_cat = stuff.totals(facts,
                                   lambda fact: (fact["date"],
                                                 fact["category"]),
                                   lambda fact: stuff.duration_minutes(fact["delta"]) / 60.0)
        res = [[by_date_cat.get((day, cat), 0)
                                 for cat in all_categories] for day in all_days]

        #show days or dates depending on scale
        if (self.end_date - self.start_date).days < 20:
            day_keys = [day.strftime("%a") for day in all_days]
        else:
            day_keys = [_("%(m_b)s %(m_d)s") %  stuff.dateDict(day, "m_") for day in all_days]

        self.day_chart.plot(day_keys, res, stack_keys = all_categories)


        #totals by activity, disguised under a stacked bar chart to get category colors
        activity_sums = stuff.totals(facts,
                                     lambda fact: (fact["name"],
                                                   fact["category"]),
                                     lambda fact: stuff.duration_minutes(fact["delta"]))
        by_duration = sorted(activity_sums.items(),
                             key = lambda x: x[1],
                             reverse = True)
        by_duration_keys = [entry[0][0] for entry in by_duration]

        category_sums = [[entry[1] / 60.0 * (entry[0][1] == cat)
                            for cat in all_categories] for entry in by_duration]
        self.activity_chart.plot(by_duration_keys,
                                 category_sums,
                                 stack_keys = all_categories)
Exemple #2
0
def check_ongoing(todays_facts):
    if not storage or not todays_facts: return

    last_activity = None
    if todays_facts[-1].end_time is None:
        last_activity = todays_facts[-1]
        last_activity.delta = dt.datetime.now() - last_activity.start_time

    # overwhelmed: tracking for more than 16 hours during one day
    total = stuff.duration_minutes([fact.delta for fact in todays_facts])
    if total > 16 * 60:
        unlock("overwhelmed")

    if last_activity:
        # Welcome! – track an activity for 10 minutes
        if last_activity.delta >= dt.timedelta(minutes=10):
            unlock("welcome")

        # in_the_zone - spend 6 hours non-stop on an activity
        if last_activity.delta >= dt.timedelta(hours=6):
            unlock("in_the_zone")

        # insomnia - meet the new day while tracking an activity
        if last_activity.start_time.date() != dt.date.today():
            unlock("insomnia")
def check_ongoing(todays_facts):
    if not storage or not todays_facts: return

    last_activity = None
    if todays_facts[-1].end_time is None:
        last_activity = todays_facts[-1]
        last_activity.delta = dt.datetime.now() - last_activity.start_time

    # overwhelmed: tracking for more than 16 hours during one day
    total = stuff.duration_minutes([fact.delta for fact in todays_facts])
    if total > 16 * 60:
        unlock("overwhelmed")

    if last_activity:
        # Welcome! – track an activity for 10 minutes
        if last_activity.delta >= dt.timedelta(minutes = 10):
            unlock("welcome")

        # in_the_zone - spend 6 hours non-stop on an activity
        if last_activity.delta >= dt.timedelta(hours = 6):
            unlock("in_the_zone")

        # insomnia - meet the new day while tracking an activity
        if last_activity.start_time.date() != dt.date.today():
            unlock("insomnia")