Example #1
0
 def window(self, min_dt, max_dt):
     tl = TimeLog(self.filename, self.virtual_midnight)
     return TimeWindow(
         tl,
         min_dt,
         max_dt,
     )
Example #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l', '--logfile', nargs=1, metavar='LOGFILE',
                        help='Path to the gtimelog logfile to be use')
    args = parser.parse_args()

    if args.logfile is not None:
        LogFile = set_logfile(args.logfile)
    else:
        LogFile = set_logfile()

    (week_first, week_last) = get_time()
    log_entries = TimeWindow(LogFile, week_first, week_last, virtual_midnight)
    total_work, _ = log_entries.totals()
    _, totals = log_entries.categorized_work_entries()

    ordered_by_time = [(time, cat) for cat, time in totals.items()]
    ordered_by_time.sort(reverse=True)
    max_cat_length = max([len(cat) for cat in totals.keys()])
    line_format = '  %-' + str(max_cat_length + 4) + 's %+5s\t %.0f%%'
    print("\nTotal work done so far : %s\n" %
          format_duration_short(total_work))
    print('Categories by time spent:')
    for time, cat in ordered_by_time:
        print(line_format % (cat, format_duration_short(time),
                             time / total_work * 100))
Example #3
0
 def setUp(self):
     from gtimelog.timelog import TimeWindow
     self.tw = TimeWindow(
         filename=StringIO(self.TEST_TIMELOG),
         min_timestamp=datetime.datetime(2014, 5, 27, 9, 0),
         max_timestamp=datetime.datetime(2014, 5, 27, 23, 59),
         virtual_midnight=datetime.time(2, 0))
Example #4
0
def task_summary(category, task=None):

    total_delta = datetime.timedelta()
    today = datetime.datetime.today()
    epoch = datetime.datetime(1970, 10, 1)
    log_entries = TimeWindow(LogFile, epoch, today, virtual_midnight)
    entries, _ = log_entries.categorized_work_entries()

    for (_, entry, entry_time) in entries[Categories[category] + ' ']:
        if entry.lstrip() == task:
            total_delta += entry_time
    print("total time spent on %s : %d.%d" %
          (task, int(total_delta.seconds / 3600) + int(total_delta.days * 24),
           int(total_delta.seconds / 60 % 60)))
    return 0
Example #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--logfile',
                        nargs=1,
                        metavar='LOGFILE',
                        help='Path to the gtimelog logfile to be use')
    parser.add_argument('-u',
                        '--user',
                        nargs=1,
                        metavar='USER',
                        help='User Identification to be used for report')
    parser.add_argument('-n',
                        '--no-time',
                        help='Print weekly report without spent time',
                        action='store_true')
    parser.add_argument('-m',
                        '--minutes',
                        help='Print weekly report with spent time in minutes',
                        action='store_true')
    args = parser.parse_args()

    if args.logfile is not None:
        LogFile = set_logfile(args.logfile)
    else:
        LogFile = set_logfile()

    if args.user is not None:
        UserId = set_userid(args.user)
    else:
        UserId = set_userid()

    (week_first, week_last) = get_time()
    log_entries = TimeWindow(LogFile, week_first, week_last, virtual_midnight)
    total_work, _ = log_entries.totals()
    entries, totals = log_entries.categorized_work_entries()

    print("[ACTIVITY] %s to %s (%s)" %
          (week_first.isoformat().split("T")[0],
           week_last.isoformat().split("T")[0], UserId))
    if entries:
        if None in entries:
            categories = sorted(entries)
            categories.append('No category')
            entries['No category'] = e
            t = totals.pop(None)
            totals['No category'] = t
        else:
            categories = sorted(entries)
        for cat in categories:
            print('%s:' % cat)

            work = [(entry, duration)
                    for start, entry, duration in entries[cat]]
            work.sort()
            for entry, duration in work:
                if not duration:
                    continue  # skip empty "arrival" entries

                entry = entry[:1].upper() + entry[1:]
                if args.no_time:
                    print(u"  %-61s  " % entry)
                else:
                    if args.minutes:
                        print(u"  %-61s  %+5s %+4s" %
                              (entry, format_duration_short(duration),
                               as_minutes(duration)))
                    else:
                        print(u"  %-61s  %+5s" %
                              (entry, format_duration_short(duration)))

            if args.no_time:
                print("")
            else:
                if args.minutes:
                    print('-' * 75)
                    print(u"%+70s %4s" % (format_duration_short(
                        totals[cat]), as_minutes(totals[cat])))
                else:
                    print('-' * 70)
                    print(u"%+70s" % (format_duration_short(totals[cat])))
        print("Total work done : %s" % format_duration_short(total_work))