예제 #1
0
def session_menu(db):
    print("1. Create \n2. Read \n3. Update \n4. Delete")

    decision = input("\nChoose number or press enter for exit: ")

    print(he.indent())

    if decision == "1":
        insert.insert_session(db)

    elif decision == "2":
        submenu.read(db, submenu.read_decision())

    elif decision == "3":
        date = input("Date to change (dd.mm.yy): ")
        cons_day = he.get_day_in_year(date)
        sessions = re.find_session(db["AllSessions"], cons_day)
        session = menu_utils.get_session_from_user(sessions=sessions)
        submenu.edit(session, db["AllSessions"])

    elif decision == "4":
        date = input("Date to delete (dd.mm.yy): ")
        cons_day = he.get_day_in_year(date)
        sessions = re.find_session(db["AllSessions"], cons_day)
        session = menu_utils.get_session_from_user(sessions=session)
        dec = input("Delete this session [y/n]: ")
        if dec == "y": re.delete_session(db["AllSessions"], cons_day)
    else:
        print("Closing")
예제 #2
0
def filter_consecutive_days(db, start, end):
    col = db["AllSessions"]
    cursor = col.find().sort("day")
    filtered = []

    if type(start) == str and len(start) > 3:
        start = he.get_day_in_year(start)
    if type(end) == str and len(end) > 3:
        end = he.get_day_in_year(end)

    for doc in cursor:
        day = doc["day"]
        if day >= start and day <= end:
            filtered.append(doc)
    return filtered
예제 #3
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.")
예제 #4
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
예제 #5
0
def insert_session(db):
    col = db["AllSessions"]
    print(he.indent())
    date = crud_utils.get_date_from_user()

    cons_day = he.get_day_in_year(date)
    workout_type = input("workout type: ")

    if workout_type == "off":
        pass
    elif workout_type == "run":
        content = crud_utils.construct_run()
    elif workout_type in he.STRENGHT_TYPES:
        content = crud_utils.construct_exercises()
    elif workout_type == "hike":
        content = crud_utils.construct_hike()
    elif workout_type == "cardio":
        content = crud_utils.construct_cardio()
    else:
        print("No valid session type. Exit.")
        sys.exit()

    comment_ = input("Any comments regarding the session: ")
    if len(comment_) < 3: comment_ = ""

    dic = re.construct_dict_session(cons_day, workout_type, content, comment_)

    print(he.indent())
    print("Insert following session:")
    printer.print_session(dic)
    print(he.indent())

    decision = input("Correct [y/n]: ")
    if decision == "y": re.insert_session(col, dic)
    else: insert_session(db)

    decision = input("Insert another session [y/n]: ")
    if decision == "y": insert_session(db)
예제 #6
0
def menu_cache():
    print(
        "1. Insert cache \n2. Upload cache \n3. See cached sessions \n4. Delete cached sessions"
    )
    dec = input("\nChoose number or press enter for exit: ")

    if dec == "1":
        cache.insert_cache()
    elif dec == "2":
        if con.check_internet():
            cache.upload_cache()
        else:
            print("No network connection. Try later.")
    elif dec == "3":
        cache.see_cache()
    elif dec == "4":
        date = input("['all'/'dd.mm.yy']: ")
        if date == "all":
            cache.delete_cache(date)
        else:
            day = he.get_day_in_year(date)
            cache.delete_cache(day)
    else:
        print("Closing.")
예제 #7
0
def get_missing(db):
    today = he.today()
    today_as_int = he.get_day_in_year(today)
    
    days = he.get_days_col(db)
    for i in range(days[-1], today_as_int):
        days.append(i)
        
    [multi, missing] = check.check_int_list(days)
    return missing
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
예제 #8
0
def edit(session, col):
    print(he.indent())
    print(
        "1. Change day \n2. Change workout type \n3. Change/Add exercises \n4. Delete exercises \n5. Add/Change comment"
    )
    dec = input("\nWhat shall be editted: ")

    print(he.indent())
    if dec == "1":
        newdate = input("New date (dd.mm.yy): ")
        newday = he.get_day_in_year(newdate)
        re.updater.update_day(session, newday, col)
    elif dec == "2":
        oldtype = session["type"]
        newtype = input("New type: ")
        re.updater.update_type(session, newtype, col)
        if oldtype == "off":
            print("Insert the new exercises.")
            if newtype == "run":
                stats = input(
                    "Distance in km and time in minutes (dis time): ")
                run = conv.convert_run(stats)
                session.update({"run": run})
            else:
                print(
                    "Exercises either as 'name sets reps weight' or 'name reps weight'. In the latter seperate reps and weight by comma. Type 'no' if no more exercises shall be implemented."
                )
                exercises = []
                while True:
                    exercise = input("Exercise: ")
                    if len(exercise) < 4: break
                    exercise = he.convert_input(exercise)
                    exercises.append(exercise)
                for i in range(len(exercises)):
                    session.update({"exercise" + str(i + 1): exercises[i]})
                exlist = []
                for j in range(len(exercises)):
                    exercise = exercises[j]
                    exlist.append(exercise[0])
                session.update({"exercise list": exlist})
        col.save(session)
    elif dec == "3":
        if session["type"] != "run":
            while True:
                new_ex = input("New exercise: ")
                if len(new_ex) < 4: break
                new_ex = conv.convert_input(new_ex)
                re.updater.update_exercise(session, new_ex, col)

        else:
            new_ex = input("New Run: ")
            new_ex = conv.convert_run(new_ex)
            re.updater.update_exercise(session, new_ex, col)
    elif dec == "4":
        ex = input("List exercises to be deleted: ")
        ex_list = ex.split()
        re.updater.delete_exercise(session, ex_list, col)

    elif dec == "5":
        newcomment = input("New comment: ")
        re.updater.update_comments(session, newcomment, col)

    else:
        dec = input("No valid input. Back to menu [y/n]: ")
        if dec == "y": edit()
        else: raise SystemExit

    re.printer.print_session(session)
    dec = input("Back to main menu [y/n]: ")
    if dec == "y": menu.user_start(col.database)
예제 #9
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)
예제 #10
0
def find_session_by_date(col, date):
    consday = he.get_day_in_year(date)
    return find_session(col, consday)