Exemplo n.º 1
0
def read(db, decision):
    if decision == "single":
        date = input("Date of session (dd.mm.yy): ")
        cons_day = he.get_day_in_year(date)

        col = db["AllSessions"]
        session = re.find_session(col, cons_day)
        re.printer.print_session(session)
    elif decision == "week":
        dec = input("Current week[y/n]: ")
        if dec == "y":
            day = str(datetime.now().day)
            month = str(he.month_now())
            year = str(he.year_now())

            date = day + "." + month + "." + year
        else:
            date = input("Date in week of interest: ")

        [start, end] = he.get_week(date)

        doc_list = filter.filter_consecutive_days(db, start, end)

        printer.print_filter(doc_list)

    elif decision == "month":
        date = input("mm.yyyy: ")
        [month, year] = date.split(".")

        if len(year) == 2: year = "20" + year

        month = conv.convert_month_to_int(month)

        monthly_days = he.monthly_days(int(year))

        days = [sum(monthly_days[:month - 1]) + 1, sum(monthly_days[:month])]

        sessions = filter.filter_consecutive_days(db, days[0], days[1])
        printer.print_filter(sessions)

    elif decision == "year":
        year = input("Which year would you like to see: ")

        year = int(year)
        days_in_year = 365

        if he.leap(year): days_in_year += 1

        consecutive_days = 0
        while year > 2019:
            consecutive_days += 365
            if he.leap(year): consecutive_days += 1
            year -= 1
        printer.print_allsessions(
            db, [consecutive_days + 1, consecutive_days + days_in_year])
    elif decision == "all":
        printer.print_allsessions(db)

    else:
        print("No valid input. Closing.")
Exemplo n.º 2
0
def insert_cache():   
    while True:
        dec = input("Current month and year [y/n]: ")
        if dec == "y": 
            year = str(he.year_now())
            month = str(conv.convert_month_to_int(str(he.month_now())))
        else:
            year = input("Year: ")
            month = input("Month: ")
            month = str(conv.convert_month_to_int(month))
            
        
        day = input("Day: ")
        day = check.check_day(day)
        
        if len(day) == 1: day = "0" + day
        if len(month) == 1: month = "0" + month
        if len(year) ==2: year = "20" + year
        
        date = day + "." + month + "." + year
        
        cons_day = he.get_day_in_year(date)
        
        workout_type = input("workout type: ")
        exercises = []
        if workout_type != "off" and workout_type != "run":
            while True:
                exercise = input("Exercise: ")
                if len(exercise) < 4: break
                exercise = conv.convert_input(exercise)
                exercises.append(exercise)
        elif workout_type == "run": 
            stats = input("Distance in km and time in minutes (dis time): ")
            run = conv.convert_run(stats)
            exercises = run
            
        comment_ = input("Any comments regarding the session: ")
        if len(comment_) < 3: comment_ = ""
            
        dic = re.construct_dict_session(cons_day,workout_type, exercises, comment_)
        print(he.indent())
        print("Insert following session:")
        printer.print_session(dic)
        
        print(he.indent())
        decision = input("Correct [y/n]: ")
        if decision == "y": 
            save_cache_entry(dic)
        else: continue
        
        decision = input("Session cached. Insert another one [y/n]: ")
        if decision != "y": break
Exemplo n.º 3
0
def convert_date(string):
    date = he.string_to_list(string, sep=".")

    day = date[0]
    month = date[1]

    if len(date) == 3:
        year = date[2]
        if len(str(year)) == 2:
            year = "20" + str(year)
            year = int(year)
    else:
        year = str(he.year_now())

    return [day, month, year]
Exemplo n.º 4
0
def get_date_from_user():
    dec = input("Current month and year [y/n]: ")
    if dec == "y":
        year = str(year_now())
        month = str(converter.convert_month_to_int(str(he.month_now())))
    else:
        year = input("Year: ")
        month = input("Month: ")
        month = str(converter.convert_month_to_int(month))

    day = input("Day: ")
    day = check.check_day(day)

    if len(day) == 1: day = "0" + day
    if len(month) == 1: month = "0" + month
    if len(year) == 2: year = "20" + year

    date = day + "." + month + "." + year
    return date
Exemplo n.º 5
0
def summary_run(db, ret=False):
    global START
    current_week = datetime.date(he.year_now(), he.month_now(),
                                 he.day_now()).isocalendar()[1]

    headers = [
        "Week", "Number", "Distance", "Time", "Pace", "Fastest Run",
        "Longest Run"
    ]

    content = []

    all_dist = []
    all_time = []
    all_pace = []
    all_fast = []
    all_long = []

    for week in range(START, current_week):
        runs = weekly_runs(db, week)
        #if runs == []: continue
        summary_float = summary_week(runs)

        all_dist.append(summary_float[0])
        all_time.append(summary_float[1])
        if summary_float[2] == 0:
            all_pace.append(100)
            pace = "-"
        else:
            all_pace.append(summary_float[2])
            pace = conv.convert_float_totime(summary_float[2])
        time = conv.convert_float_totime(summary_float[1])

        fastest = fastest_run(runs)
        if fastest == None:
            out_fastest = "-"
            all_fast.append(1000)
        else:
            fastest_stats = fastest["run"]
            all_fast.append(fastest_stats[2])
            pace_fastest = conv.convert_float_totime(fastest_stats[2])
            dist_fastest = fastest_stats[0]
            out_fastest = str(dist_fastest) + " at " + pace_fastest

        longest = longest_run(runs)
        if longest == None:
            out_longest = "-"
            all_long.append(-1)
        else:
            longest_stats = longest["run"]
            all_long.append(longest_stats[0])
            pace_longest = conv.convert_float_totime(longest_stats[2])
            dist_longest = longest_stats[0]
            out_longest = str(dist_longest) + " at " + pace_longest

        summary_string = [
            str(week - START + 1),
            str(len(runs)),
            str(summary_float[0]), time, pace, out_fastest, out_longest
        ]
        content.append(summary_string)

    dist_index = all_dist.index(max(all_dist))
    time_index = all_time.index(max(all_time))
    pace_index = all_pace.index(min(all_pace))
    fastest_index = all_fast.index(min(all_fast))
    longest_index = all_long.index(max(all_long))

    content = color_content(content, dist_index, time_index, pace_index,
                            fastest_index, longest_index)

    out = tabulate(content, headers)
    print(out)
    if ret: return out
Exemplo n.º 6
0
def summary_off(db):
   
    off_days = filter.filter_type(db, "off")
    strength_days = filter.filter_filtered(db["AllSessions"].find(), "strength")
    run_days = filter.filter_type(db, "run")
    
    print(he.indent())
    
    print("Number off days:", len(off_days))
    print("Number Stength days:", len(strength_days))
    print("Number Runs:", len(run_days))
    
    today = he.today()
    print("Total days:", he.get_day_in_year(today))
    
    last_off = off_days[-1]
    last_off_day = conv.convert_int_todate(last_off["day"])
    print("Last off day:", last_off_day)
    
    days_since_off = he.get_day_in_year(today) - last_off["day"]
    print("Days since off:", days_since_off)
    
    print(he.indent())
    
    content = []
    year = he.year_now()
    for month in range(1,he.month_now()+1):
        monthly_days = he.monthly_days(int(year))
        days = [sum(monthly_days[:month-1])+1,sum(monthly_days[:month])]
        
        counter_month_off = 0
        for session in off_days:
            if session["day"] <= days[1] and session["day"] >= days[0]:
                counter_month_off += 1
        
        counter_month_strength = 0
        for session in strength_days:
            if session["day"] <= days[1] and session["day"] >= days[0]:
                counter_month_strength += 1
                
        counter_month_run = 0
        for session in run_days:
            if session["day"] <= days[1] and session["day"] >= days[0]:
                counter_month_run += 1
            
        
        content.append([conv.convert_to_month(month), str(counter_month_strength), 
                        str(counter_month_run),str(counter_month_off)])
        #print(conv.convert_to_month(month)+ ":" ,counter_month)
    
    header = ["Month", "Strength days", "Runs", "Off days"]
    out = tabulate(content, header)
    print(out)
    
    missing = get_missing(db)
    if missing != []:
        missing_dates = []
        for day in missing:
            missing_dates.append(conv.convert_int_todate(day))
        
        print("These dates are missing:", missing_dates)   
        dec = input("Fill with off days [y/n]: ")
    
        if dec == "y":
            fill_off(db, missing)