Skip to content

Commit

Permalink
Merge pull request #1993 from NitkarshChourasia/testing
Browse files Browse the repository at this point in the history
add: one rep max calculator, weightlifting.
  • Loading branch information
geekcomputers authored Oct 8, 2023
2 parents ba3d171 + 58b7c25 commit 660c1dd
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
25 changes: 25 additions & 0 deletions nitkarshchourasia/one_rep_max_calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# One-Rep Max Calculator

This repository contains two Python programs that can calculate the estimated one-repetition maximum (1RM) for a weightlifting exercise. The 1RM is the maximum amount of weight that you can lift for one rep. It is useful for tracking your strength progress and planning your training.

## Command-line version

The file `one_rep_max_calculator.py` is a command-line version of the 1RM calculator. It prompts the user to enter the weight lifted and the number of reps performed, and then calculates and displays the estimated 1RM based on the *Epley formula*.

To run this program, you need Python 3 installed on your system. You can execute the program by typing `python one_rep_max_calculator.py` in your terminal.

## Graphical user interface version

The file `one_rep_max_calculator_gui.py` is a graphical user interface version of the 1RM calculator. It uses Tkinter to create a window with entry fields, labels, and a button. The user can input the weight lifted and the number of reps performed, and then click the calculate button to see the estimated 1RM based on the Epley formula.

To run this program, you need Python 3 and Tkinter installed on your system. You can execute the program by typing `python one_rep_max_calculator_gui.py` in your terminal.

## References

- Epley, B. Poundage chart. In: Boyd Epley Workout. Lincoln, NE: Body Enterprises, 1985. p. 23.
- https://en.wikipedia.org/wiki/One-repetition_maximum
- https://www.topendsports.com/testing/calculators/1repmax.htm

<!-- author: Nitkarsh Chourasia -->
<!-- github_Username: NitkarshChourasia -->
<!-- github_profil_url: https://github.com/NitkarshChourasia -->
45 changes: 45 additions & 0 deletions nitkarshchourasia/one_rep_max_calculator/one_rep_max_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class OneRepMaxCalculator:
"""
A class to calculate the one-repetition maximum (1RM) for a weightlifting exercise.
"""

def __init__(self):
"""
Initializes the OneRepMaxCalculator with default values.
"""
self.weight_lifted = 0
self.reps_performed = 0

def get_user_input(self):
"""
Prompts the user to enter the weight lifted and the number of reps performed.
"""
self.weight_lifted = int(input("Enter the weight you lifted (in kg): "))
self.reps_performed = int(input("Enter the number of reps you performed: "))

def calculate_one_rep_max(self):
"""
Calculates the one-rep max based on the Epley formula.
"""
return (self.weight_lifted * self.reps_performed * 0.0333) + self.weight_lifted

def display_one_rep_max(self):
"""
Displays the calculated one-rep max.
"""
one_rep_max = self.calculate_one_rep_max()
print(f"Your estimated one-rep max (1RM) is: {one_rep_max} kg")


def main():
"""
The main function that creates an instance of OneRepMaxCalculator and uses it to get user input,
calculate the one-rep max, and display the result.
"""
calculator = OneRepMaxCalculator()
calculator.get_user_input()
calculator.display_one_rep_max()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import tkinter as tk


class OneRepMaxCalculator:
"""
A class used to calculate the estimated one-repetition maximum (1RM) for a weightlifting exercise.
Attributes
----------
window : tk.Tk
The main window of the application.
weight_entry : tk.Entry
Entry field to input the weight lifted.
rep_entry : tk.Entry
Entry field to input the number of reps performed.
result_value_label : tk.Label
Label to display the calculated 1RM.
Methods
-------
calculate_1rm():
Calculates the estimated 1RM based on the Epley formula.
display_result():
Displays the calculated 1RM in the application window.
run():
Runs the application.
"""

def __init__(self):
"""Initializes the OneRepMaxCalculator with a window and widgets."""
self.window = tk.Tk()
self.window.title("One-Rep Max Calculator")
self.window.geometry("300x150")

# Create and pack widgets
tk.Label(self.window, text="Enter the weight you lifted (in kg):").pack()
self.weight_entry = tk.Entry(self.window)
self.weight_entry.pack()

tk.Label(self.window, text="Enter the number of reps you performed:").pack()
self.rep_entry = tk.Entry(self.window)
self.rep_entry.pack()

tk.Button(self.window, text="Calculate", command=self.display_result).pack()

tk.Label(self.window, text="Your estimated one-rep max (1RM):").pack()
self.result_value_label = tk.Label(self.window)
self.result_value_label.pack()

def calculate_1rm(self):
"""Calculates and returns the estimated 1RM."""
weight = int(self.weight_entry.get())
reps = int(self.rep_entry.get())
return (weight * reps * 0.0333) + weight

def display_result(self):
"""Calculates the 1RM and updates result_value_label with it."""
one_rep_max = self.calculate_1rm()
self.result_value_label.config(text=f"{one_rep_max} kg")

def run(self):
"""Runs the Tkinter event loop."""
self.window.mainloop()


# Usage
if __name__ == "__main__":
calculator = OneRepMaxCalculator()
calculator.run()

# Improve the program.
# Make the fonts, bigger.
# - Use text formatting...
# Use dark mode.
# Have an option to use dark mode and light mode.

0 comments on commit 660c1dd

Please sign in to comment.