def print_report(self): total = timedelta() print("\n") for task, task_report in self._report.items(): print("{0}:".format(task)) for day, duration in task_report.items(): print("\t{0:10}: {1:8}".format(DOW[day], str(duration))) total += duration print("") print('Total =', format_duration(total))
def report_to_html(self): day_totals = {} task_day_details = {} report = [] report_header = '<h1>Week Report</h1>' report.append(report_header) table = '<table>' \ ' <tr>' \ ' <th>Task</th>' \ ' <th>Monday</th>' \ ' <th>Tuesday</th>' \ ' <th>Wednesday</th>' \ ' <th>Thursday</th>' \ ' <th>Friday</th>' \ ' <th>Saturday</th>' \ ' <th>Sunday</th>' \ ' <th>Total</th>' \ ' </tr>' for task, task_report in self._report.items(): needs_details = False if 'ELB' in task.upper(): task_day_details[task] = {} needs_details = True # open the row and add task name table += '<tr>' table += '<td><strong>{}</strong></td>'.format(escape(task)) task_total = timedelta() for day in range(7): # find the time spent on this task at this day if day in task_report: duration = task_report[day]['duration'] table += '<td>{}</td>'.format(duration) if needs_details and task_report[day]['descriptions']: if day not in task_day_details[task]: task_day_details[task][day] = set() task_day_details[task][day] |= task_report[day]['descriptions'] else: duration = timedelta(0) table += '<td></td>' # print task/day data # increment totals task_total += duration if day not in day_totals: day_totals[day] = timedelta() day_totals[day] += duration # add task total table += '<td><strong>{}</strong></td>'.format(format_duration(task_total)) # close the row table += '</tr>' # add day and grand totals grand_total = timedelta() table += '<tr><td><strong>Total:</strong></td>' for day in range(7): table += '<td><strong>{}</strong></td>'.format(format_duration(day_totals[day])) grand_total += day_totals[day] table += '<td><strong>{}</strong></td></tr>'.format(format_duration(grand_total)) # we are done table += '</table>' report.append(table) days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] footer = '<h1>Task Details</h1>' for task, day_details in task_day_details.items(): footer += '<h2>{}</h2>'.format(task) for day, details in day_details.items(): footer += '<h3>{}</h3>'.format(days[day]) footer += self.format_details(details) report.append(footer) return ''.join(report)
def report_to_html(self): day_totals = {} task_day_details = {} report = [] report_header = '<h1>Week Report</h1>' report.append(report_header) table = '<table>' \ ' <tr>' \ ' <th>Task</th>' \ ' <th>Monday</th>' \ ' <th>Tuesday</th>' \ ' <th>Wednesday</th>' \ ' <th>Thursday</th>' \ ' <th>Friday</th>' \ ' <th>Saturday</th>' \ ' <th>Sunday</th>' \ ' <th>Total</th>' \ ' </tr>' for task, task_report in self._report.items(): needs_details = False if 'ELB' in task.upper(): task_day_details[task] = {} needs_details = True # open the row and add task name table += '<tr>' table += '<td><strong>{}</strong></td>'.format(escape(task)) task_total = timedelta() for day in range(7): # find the time spent on this task at this day if day in task_report: duration = task_report[day]['duration'] table += '<td>{}</td>'.format(duration) if needs_details and task_report[day]['descriptions']: if day not in task_day_details[task]: task_day_details[task][day] = set() task_day_details[task][day] |= task_report[day][ 'descriptions'] else: duration = timedelta(0) table += '<td></td>' # print task/day data # increment totals task_total += duration if day not in day_totals: day_totals[day] = timedelta() day_totals[day] += duration # add task total table += '<td><strong>{}</strong></td>'.format( format_duration(task_total)) # close the row table += '</tr>' # add day and grand totals grand_total = timedelta() table += '<tr><td><strong>Total:</strong></td>' for day in range(7): table += '<td><strong>{}</strong></td>'.format( format_duration(day_totals[day])) grand_total += day_totals[day] table += '<td><strong>{}</strong></td></tr>'.format( format_duration(grand_total)) # we are done table += '</table>' report.append(table) days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ] footer = '<h1>Task Details</h1>' for task, day_details in task_day_details.items(): footer += '<h2>{}</h2>'.format(task) for day, details in day_details.items(): footer += '<h3>{}</h3>'.format(days[day]) footer += self.format_details(details) report.append(footer) return ''.join(report)