def user_start(client): if not cache.is_empty() and client != None: print(he.indent()) decision = input("Cache can be uploaded. Confirm [y/n]: ") if decision == "y": cache.upload_cache() print(he.indent()) print("1. Session \n2. Cache \n3. Backup") decision = input("\nChoose number or press enter for exit: ") #options = ["strength", "run", "off", "hike"] try: decision = int(decision) except: print("Closing") quit() if decision == 1: client = con.connect_to_client() db = client["TrainingLogData"] session_menu(db) client.close() elif decision == 2: menu_cache() elif decision == 3: backup_menu() else: print("Exit.")
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
def print_session(doc): print(he.indent()) #print("ID:", doc["_id"]) day = doc["day"] assert type(day) == int day = conv.convert_int_todate(day) print("Date:" + day) print("Type:", doc["type"]) if doc["type"] != "off": if doc["type"] == "run": run = doc["run"] print("Distance:", run[0], "km") print("Durationen: " + conv.convert_float_totime(run[1])) print("average Pace: " + conv.convert_float_totime(run[2])) elif doc["type"] == "hike": hike = doc["hike"] print("Distance:", hike[0], "km") print("Height meter:", hike[1], "m") print("Duration: " + conv.convert_float_totime(hike[2])) elif doc["type"] == "cardio": run = doc["run"] distance = run[1] / 60 * run[0] print("Run: " + conv.convert_float_totime(run[1]) + " at", run[0], "(" + str(distance) + ")") circuit = doc["circuit"] print("Circuit:", circuit[0], "Rounds") for exercise in circuit[1:]: reps = str(exercise[1]) weight = str(exercise[2]) print(exercise[0] + ": " + reps + "x" + weight) else: n = doc["amount of exercises"] print("Amount of exercises:", n) print("List of exercises:", end=" ") ex = doc["exercise list"] for i in range(n - 1): print(ex[i], ",", end=" ") print(ex[n - 1]) for i in range(n): print_exercise(doc["exercise" + str(i + 1)]) if len(doc["comments"]) > 3: print("Comments: " + doc["comments"]) print(he.indent())
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")
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)
def see_cache(): print(he.indent()) global CACHE_DIR directory = CACHE_DIR os.chdir(directory) print("Dates with cached session:") for file_ in glob.glob("*.txt"): day = file_.replace(".txt", "") day = day.replace("(1)", "") day = int(day) date = conv.convert_int_todate(day) print(date)
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)
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)
from crud import insert from utils import helper as he from artwork import print_fancy import connect as con from menu.menu import user_start print_fancy print("\n") print("Eisenrecorder started".center(79)) if con.check_internet(): client = con.connect_to_client() else: client = None print("No connection. Only Cache and Backup available.") while True: user_start(client) print(he.indent()) dec2 = input("Back to main menu [y/n]: ") if dec2 != "y": print("\n\n") print("Closing Eisenrecorder".center(79)) print("\n\n") break client.close()