Created
March 5, 2014 14:48
-
-
Save cra/9368639 to your computer and use it in GitHub Desktop.
A simple python script to calculate volumes and densities of your workout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf-8 | |
import readline | |
import sys | |
import re | |
from decimal import Decimal | |
from datetime import datetime | |
def cut(dec, number_of_digits_to_leave=2): | |
D = Decimal | |
return D(dec).quantize(D(10) ** -number_of_digits_to_leave) | |
def parse(exercise_log): | |
time_str, sets_str = exercise_log.split(';') | |
t = datetime.strptime(time_str, "%M:%S").time() | |
total_seconds = t.minute*60 + t.second | |
vol = 0 | |
for s in sets_str.split(): | |
kg, reps = re.match(r"(\d+\.\d+|\d+)x(\d+)", s).groups() | |
vol += float(kg)*float(reps) | |
return vol, t.strftime("%M:%S"), vol/total_seconds*60 | |
if __name__ == "__main__": | |
print("Example input: 9:05; 20.5x5 102.5x3 55x5 75x5 102.5x3") | |
while True: | |
input_str = input("Exercise_log: ") | |
if input_str.startswith("exit") or len(input_str.strip()) == 0: | |
break | |
vol, t_str, den = parse(input_str) | |
print("%s kg in %s --> %s kg/min" % (cut(vol), t_str, cut(den))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment