Esempio n. 1
0
def stats(args):
    if args.yesterday:
        yesterday_obj = dt.now() - timedelta(days=1)
        date_from = date_to = dt.combine(yesterday_obj, time.min)
    elif args.day:
        date_from = date_to = dt.strptime(args.day, DATE_FORMAT)
    elif args.week:  # TODO: this currently doesn't work. Fix or delete.
        date_from, date_to = get_week_range(args.week)
    elif args.last_week:
        date_from,  date_to = get_last_week()
    elif args.month:
        date_from,  date_to = get_month_range(args.month)
    elif args.last_month:
        date_from,  date_to = get_last_month()
    elif args._from and not args.to:
        date_from = dt.combine(dt.strptime(args._from, DATE_FORMAT), time.min)
        date_to = dt.combine(dt.now(), time.min)
    elif args._from and args.to:
        date_from = dt.combine(dt.strptime(args._from, DATE_FORMAT), time.min)
        date_to = dt.combine(dt.strptime(args.to, DATE_FORMAT), time.min)
    else:
        # default action is to show today's  stats
        date_from = date_to = dt.combine(dt.now(), time.min)

    projects = get_projects(date_from, date_to)

    if args.summary:
        print_stats(projects)
    else:
        print_report(projects, date_from, date_to, colorize=args.no_color)

    if date_from == date_to == dt.combine(dt.now(), time.min):  # then we are looking at today only
        earliest_start = min(min(tl.start for tl in p.timelogs) for p in projects)
        print('\nToday working for: {}'.format(format_timedelta(dt.now() - earliest_start)))
Esempio n. 2
0
def stats(args):
    today = False
    if args.yesterday:
        yesterday_obj = dt.now() - timedelta(days=1)
        date_from = date_to = yesterday_obj.strftime(DATE_FORMAT)
    elif args.day:
        date_from = date_to = args.day
    elif args.week:
        date_from, date_to = get_week_range(args.week)
    elif args.last_week:
        date_from,  date_to = get_last_week()
    elif args.month:
        date_from,  date_to = get_month_range(args.month)
    elif args.last_month:
        date_from,  date_to = get_last_month()
    elif args._from and not args.to:
        date_from = args._from
        date_to = dt.now().strftime(DATE_FORMAT)
    elif args._from and args.to:
        date_from = args._from
        date_to = args.to
    else:
        # default action is to show today's  stats
        date_from = date_to = dt.now().strftime(DATE_FORMAT)
        today = True

    lines = read_log_file_lines()
    work_time, slack_time, today_work_time = calculate_stats(lines, date_from, date_to, today=today)
    if args.report:
        work_report, slack_report = calculate_report(lines, date_from, date_to)

        print_report(work_report, slack_report, work_time, slack_time, colorize=args.color)
        print_today_work_time(today_work_time)
    else:
        print_stats(work_time, slack_time, today_work_time)
        print_today_work_time(today_work_time)