Beispiel #1
0
    def test_merge_records_by_category(self):
        records = track_time.parse(file("categories-001.txt"))

        merged_records = track_time.merge_records_by_category(records)
        self.assertEqual(len(merged_records), 4)

        self.assertEqual(merged_records[0].project, ["project"])
        self.assertEqual(merged_records[1].project, ["holiday"])
        self.assertEqual(merged_records[2].project, ["vacation"])
        self.assertEqual(merged_records[3].project, ["sick"])
Beispiel #2
0
def query_vacation(
        timesheet_pathname,
        nr_hours_to_work,  # Per week.
        nr_hours_vacation):  # Per year.
    records = track_time.parse(file(timesheet_pathname, "r"))
    merged_records = track_time.merge_records_by_category(records)

    # Vacation -----------------------------------------------------------------
    record_by_category = {record.project_string(): record for record in
        merged_records}
    vacation_record = record_by_category["vacation"]
    nr_hours_spent = vacation_record.nr_hours
    nr_hours_left = nr_hours_vacation - nr_hours_spent
    nr_days_left = nr_hours_left / 8.0

    table = prettytable.PrettyTable(["Available", "Spent", "Balance (h)",
        "Balance (d)"])
    table.align = "r"

    table.add_row([
        "{:.2f}".format(nr_hours_vacation),
        "{:.2f}".format(nr_hours_spent),
        "{:.2f}".format(nr_hours_left),
        "{:.2f}".format(nr_days_left)
    ])

    write_table(table, header="vacation")


    # Overtime -----------------------------------------------------------------
    # Number of hours that should have been spent on work, by the end of the
    # week.
    to_time_point = track_time.last_day_of_week(datetime.date.today())
    week_number = to_time_point.isocalendar()[1]
    nr_hours_to_work *= week_number

    # Number of hours that have been spent on work, in whatever way.
    nr_hours_spent_on_work = sum([record.nr_hours for record in merged_records])

    nr_hours_overtime = nr_hours_spent_on_work - nr_hours_to_work
    nr_days_overtime = nr_hours_overtime / 8.0

    table = prettytable.PrettyTable(["To work", "Worked", "Balance (h)",
        "Balance (d)"])
    table.align = "r"

    table.add_row([
        "{:.2f}".format(nr_hours_to_work),
        "{:.2f}".format(nr_hours_spent_on_work),
        "{:.2f}".format(nr_hours_overtime),
        "{:.2f}".format(nr_days_overtime)
    ])

    write_table(table, header="overtime")

    # Overall ------------------------------------------------------------------
    balance_vacation = nr_hours_left
    balance_overtime = nr_hours_overtime
    balance_in_hours = nr_hours_left + nr_hours_overtime
    balance_in_days = balance_in_hours / 8.0

    table = prettytable.PrettyTable(["Balance vacation", "Balance overtime",
        "Balance (h)", "Balance (d)"])
    table.align = "r"

    table.add_row([
        "{:.2f}".format(balance_vacation),
        "{:.2f}".format(balance_overtime),
        "{:.2f}".format(balance_in_hours),
        "{:.2f}".format(balance_in_days)
    ])

    write_table(table, header="balance")