def generate_report_for_period(period, table_contents):
        amount = period.time_worked()
        amount_onsite = period.time_worked(only_onsite=True)

        hours_worked_string = DateUtils.format_delta_as_hours(amount)
        if amount_onsite:
            hours_worked_string += " (%s onsite)" % \
                    DateUtils.format_delta_as_hours(amount_onsite)

        table_contents.append([period.short_string(), hours_worked_string])
        return (amount, amount_onsite)
    def generate_report(self):
        self.formatter.generate_header(self.header)

        table_contents = []
        total = datetime.timedelta()
        total_onsite = datetime.timedelta()
        for period in self.time_periods:
            (time, time_onsite) = AggregateReport.generate_report_for_period(period, table_contents)
            total += time
            total_onsite += time_onsite

        self.formatter.generate_table(table_contents, has_headers=False)

        self.formatter.generate_header(
            "Total hours worked: %s" % DateUtils.format_delta_as_hours(total))
        self.formatter.generate_header(
            "Total onsite hours worked: %s" % DateUtils.format_delta_as_hours(total_onsite))
        return self.formatter.flatten()
    def generate_hours(self):
        table = []
        table.append([""] + list(map(DetailedReport.format_date, self.time_period.get_all_dates())) + ["Total"])
        for user in sorted(self.time_period.get_users()):
            table.append([user.login] +
                         self.time_worked(user=user) +
                         self.time_worked(user=user, total=True))
        table.append(["everyone"] +
                     self.time_worked() +
                     self.time_worked(total=True))
        self.formatter.generate_table(table)

        onsite_time = self.time_period.time_worked(only_onsite=True)
        if onsite_time > datetime.timedelta(0):
            self.formatter.generate_large_text("Onsite hours worked: %s" % DateUtils.format_delta_as_hours(onsite_time))
 def time_worked(self, user=None, total=False):
     if total:
         return [DateUtils.format_delta_as_hours(self.time_period.time_worked(user=user))]
     all_dates = self.time_period.get_all_dates()
     return [DateUtils.format_delta_as_hours(self.time_period.time_worked(date=x, user=user)) for x in all_dates]