def _write_fact(self, fact): # no having end time is fine end_time_str, end_time_iso_str = "", "" if fact.end_time: end_time_str = fact.end_time.strftime('%H:%M') end_time_iso_str = fact.end_time.isoformat() category = "" if fact.category != _("Unsorted"): #do not print "unsorted" in list category = fact.category data = dict( date=fact.date.strftime( # date column format for each row in HTML report # Using python datetime formatting syntax. See: # http://docs.python.org/library/time.html#time.strftime C_("html report", "%b %d, %Y")), date_iso=fact.date.isoformat(), activity=fact.activity, category=category, tags=", ".join(fact.tags), start=fact.start_time.strftime('%H:%M'), start_iso=fact.start_time.isoformat(), end=end_time_str, end_iso=end_time_iso_str, duration=stuff.format_duration(fact.delta) or "", duration_minutes="%d" % (stuff.duration_minutes(fact.delta)), duration_decimal="%.2f" % (stuff.duration_minutes(fact.delta) / 60.0), description=fact.description or "") self.fact_rows.append( Template(self.fact_row_template).safe_substitute(data))
def _finish(self, facts): # group by date by_date = [] for date, date_facts in itertools.groupby(facts, lambda fact: fact.date): by_date.append((date, [fact.as_dict() for fact in date_facts])) by_date = dict(by_date) date_facts = [] date = min(by_date.keys()) while date <= self.end_date: str_date = date.strftime( # date column format for each row in HTML report # Using python datetime formatting syntax. See: # http://docs.python.org/library/time.html#time.strftime C_("html report", "%b %d, %Y")) date_facts.append([str_date, by_date.get(date, [])]) date += dt.timedelta(days=1) data = dict( title=self.title, totals_by_day_title=_("Totals by Day"), activity_log_title=_("Activity Log"), totals_title=_("Totals"), activity_totals_heading=_("activities"), category_totals_heading=_("categories"), tag_totals_heading=_("tags"), show_prompt=_("Distinguish:"), header_date=_("Date"), header_activity=_("Activity"), header_category=_("Category"), header_tags=_("Tags"), header_start=_("Start"), header_end=_("End"), header_duration=_("Duration"), header_description=_("Description"), data_dir=runtime.data_dir, show_template=_("Show template"), template_instructions= _("You can override it by storing your version in %(home_folder)s") % {'home_folder': runtime.home_data_dir}, start_date=timegm(self.start_date.timetuple()), end_date=timegm(self.end_date.timetuple()), facts=json_dumps([fact.as_dict() for fact in facts]), date_facts=json_dumps(date_facts), all_activities_rows="\n".join(self.fact_rows)) for key, val in data.items(): if isinstance(val, str): data[key] = val self.file.write(Template(self.main_template).safe_substitute(data)) if self.override: # my report is better than your report - overrode and ran the default report trophies.unlock("my_report") return