|
| 1 | +import time |
| 2 | +import sys |
| 3 | + |
| 4 | +PRESETS = { |
| 5 | + 1: (20, 1, 1), |
| 6 | + 2: (10, 5, 1.25), |
| 7 | + 3: (25, 2, 1), |
| 8 | + 4: (10, 10, 2), |
| 9 | + 5: (50, 1, 1), |
| 10 | + 6: (25, 3, 1), |
| 11 | +} |
| 12 | + |
| 13 | +def tense_and_relax(reps, tense_time, relax_time): |
| 14 | + print("Starting tense and relax exercise...") |
| 15 | + total_phases = reps * 2 # Tensing and relaxing phases |
| 16 | + for rep in range(1, reps + 1): |
| 17 | + print(f"\nRepetition {rep}/{reps}: Tense!") |
| 18 | + execute_phase(tense_time, total_phases, "green") |
| 19 | + print(f"\nRepetition {rep}/{reps}: Relax!") |
| 20 | + execute_phase(relax_time, total_phases, "red") |
| 21 | + |
| 22 | +def execute_phase(total_time, total_phases, color): |
| 23 | + start_time = time.time() |
| 24 | + end_time = start_time + total_time |
| 25 | + while time.time() <= end_time: |
| 26 | + elapsed_time = time.time() - start_time |
| 27 | + phase_percentage = (elapsed_time / total_time) * 100 |
| 28 | + draw_progress_bar(total_time, elapsed_time, phase_percentage, color) |
| 29 | + time.sleep(0.05) # Adjust the sleep time as needed for smooth updating |
| 30 | + print("\nPhase complete!") |
| 31 | + |
| 32 | +def draw_progress_bar(total_time, elapsed_time, percentage, color): |
| 33 | + bar_length = 50 |
| 34 | + progress = int((elapsed_time / total_time) * bar_length) |
| 35 | + if color == "green": |
| 36 | + bar = '\033[92m' + '#' * progress + '\033[0m' + '-' * (bar_length - progress) |
| 37 | + elif color == "red": |
| 38 | + bar = '\033[91m' + '#' * progress + '\033[0m' + '-' * (bar_length - progress) |
| 39 | + sys.stdout.write("\r[%s] %.1f%%" % (bar, percentage)) |
| 40 | + sys.stdout.flush() |
| 41 | + |
| 42 | +def get_user_input(): |
| 43 | + print("Welcome!") |
| 44 | + while True: |
| 45 | + try: |
| 46 | + print("Choose an option:") |
| 47 | + print("1. Select a preset") |
| 48 | + print("2. Set custom settings") |
| 49 | + option = int(input("Enter your choice: ")) |
| 50 | + if option not in [1, 2]: |
| 51 | + raise ValueError |
| 52 | + return option |
| 53 | + except ValueError: |
| 54 | + print("Invalid option. Please enter 1 or 2.") |
| 55 | + |
| 56 | +def display_presets(): |
| 57 | + print("\nPresets:") |
| 58 | + for key, value in PRESETS.items(): |
| 59 | + print(f"Preset {key}: {value[0]} repetition(s), {value[1]} second(s) tense, {value[2]} second(s) relaxed") |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + selected_settings = None # Initialize selected settings variable |
| 63 | + while True: |
| 64 | + option = get_user_input() |
| 65 | + if option == 1: |
| 66 | + while True: |
| 67 | + try: |
| 68 | + display_presets() |
| 69 | + preset_choice = int(input(f"Enter the preset number (1-{len(PRESETS)}): ")) |
| 70 | + reps, tense_time, relax_time = PRESETS[preset_choice] |
| 71 | + tense_and_relax(reps, tense_time, relax_time) |
| 72 | + |
| 73 | + choice = int(input("Do you want to:\n1. Start another set\n2. Return to the start menu\n3. Quit program\nEnter your choice: ")) |
| 74 | + if choice == 1: |
| 75 | + continue # Start another set |
| 76 | + elif choice == 2: |
| 77 | + break # Return to the start menu |
| 78 | + elif choice == 3: |
| 79 | + sys.exit() # Quit the program |
| 80 | + else: |
| 81 | + print("Invalid choice. Please enter 1, 2, or 3.") |
| 82 | + except KeyError: |
| 83 | + print(f"Invalid preset number. Please enter a number between 1 and {len(PRESETS)}.") |
| 84 | + elif option == 2: |
| 85 | + while True: |
| 86 | + try: |
| 87 | + if selected_settings is None: |
| 88 | + reps = int(input("Enter amount of repetitions: ")) |
| 89 | + tense_time = float(input("Enter seconds to tense: ")) |
| 90 | + relax_time = float(input("Enter seconds to relax: ")) |
| 91 | + else: |
| 92 | + reps, tense_time, relax_time = selected_settings |
| 93 | + |
| 94 | + tense_and_relax(reps, tense_time, relax_time) |
| 95 | + |
| 96 | + choice = int(input("Do you want to:\n1. Start another set\n2. Return to the start menu\n3. Quit program\nEnter your choice: ")) |
| 97 | + if choice == 1: |
| 98 | + selected_settings = (reps, tense_time, relax_time) # Store selected settings |
| 99 | + continue # Start another set |
| 100 | + elif choice == 2: |
| 101 | + selected_settings = None # Reset selected settings |
| 102 | + break # Return to the start menu |
| 103 | + elif choice == 3: |
| 104 | + sys.exit() # Quit the program |
| 105 | + else: |
| 106 | + print("Invalid choice. Please enter 1, 2, or 3.") |
| 107 | + except ValueError: |
| 108 | + print("Invalid input. Please enter a valid number.") |
| 109 | + elif option == 3: |
| 110 | + sys.exit() # Quit the program |
0 commit comments