Exemplo n.º 1
0
def get_next_workout(filename=main_file, Verbose=False):
	if not filename:
		filename = main_file
	f = open(filename, 'r');
	i = j = 0; found = False;
	workout = [];
	next_days = make_list_of_next_days(max_future_days);

	while i < max_read_lines and not found:
		line = f.readline();
		workout_date = get_workout_date(line);

		if workout_date != -1 and workout_date in next_days: # if the date on the line is in the next few days
			found = True; # found date workout header that is coming up in the next few days
			workout_meas = check_sys(line); # get lbs or kg for system
			workout.append(line);

			for j in range(max_lines_workout): # every line of workout
				nextline = f.readline();
				if j == 0 and string.replace(nextline, '\t', '') == '\n':
					if Verbose: print "'workoutlog.py' - No sets or weights found for your next workout on", workout_date + ".\n\nIt looks like you began writing your workout but haven't added any exercises yet. \nPlease add some exercises with corresponding weights such as: \n\tsquat\t1x5:405\nThis means one set of five reps of squats at a weight of 405.\nOnce we see this, we will calculate what plates to load for each weight.\nThanks!";
					if DBG:
						Dbg('nextline was newline', nextline)
					f.close()
					return -1
				if nextline == '\n':
					break;
				else:
					if Verbose: nextline = re.sub('\t\t', '\t', nextline)
					workout.append(nextline)
		i += 1;

	f.close()

	if not workout and not found: # couldn't find workout at all (no date and no workout sets)
		if Verbose: print "'workoutlog.py' - Sorry, no workouts found in the beginning of", os.path.join(dir, filename), "within the next", max_future_days, "days\nPlease update your workout file and try again"
		return -2;

	return workout
Exemplo n.º 2
0
def calcplates(weight, i = 0, compact=True, SYS=DEFAULT_MEAS):
		if set_program( check_sys(string.lower(SYS)) ) == -1:
			ErrF("'plates.py' - Setting program to Oly or PL failed.")

		oneline = ""
		if MEAS == METRIC:			# Lowercase 'p' for Oly
			PLATE_ABBR = 'p'
		elif MEAS == IMPERIAL:		# Uppercase 'P' for PL
			PLATE_ABBR = 'P'

		rTotal = float(weight)
		if (DBG): Dbg('rtotal', rTotal)

		# Reject input that is not divisible by the plates we're using
		if rTotal % (smallest_plate*2) != 0:
			oneline += "Skipping:", weight, MEAS, "due to not being divisible by the plates we're using"

		if compact:
			if i != 0:		# UNDO - was "if 1 != 0:"
				oneline += ''.join(["Set #", `i`, " = ", `intround(rTotal)`, MEAS, '\n'])
			else:
				oneline += ''.join(["Current set", " = ", `intround(rTotal)`, MEAS, '\n'])

		# Weight is the weight on each side of the bar and
		# gets subtracted after the amount of each plate is calculated
		weight = (rTotal-BAR)/2.0
		if (DBG): Dbg('weight', weight)

		# ONLY HALF THE WEIGHT IS CONSIDERED AFTER THIS POINT!!!

		# Do integer arithmetic to calculate number of plates
		plates  = int(weight) / PLATE

		if plates != 0:
			#mystr = ''.join([str(plates), PLATE_ABBR])
			strplates = str(plates)
			if plates == 1:
				strplates = ""
			oneline += ''.join([strplates, PLATE_ABBR, ', '])

		# Subtract highest plates
		weight -= plates*PLATE
		#print weight, MEAS, "on each side (not incl plates)"

		# Go through plates_arr and calculate how many of each plate necessary
		for j in range( 0, len(plates_arr) ):	# skip first plate for now
			curr_num = int(weight / plates_arr[j])

			if curr_num != 0:
				weight -= curr_num * plates_arr[j]

				if curr_num != 1:
					oneline = ''.join([oneline, `curr_num`, "x", `plates_arr[j]`, ", "])
				else: 	# Shorten plates str if there's only 1 quantity of the plate
					oneline = ''.join([oneline, `plates_arr[j]`, ", "])

		oneline = oneline[:-2]		# Remove trailing comma and one whitespace

		# Some string formatting stuff
		#if oneline[0] = ","
		return oneline
Exemplo n.º 3
0
def check_args():
	if len(sys.argv) < 2 or sys.argv[1] == "-h": 	# No args => print usage
		print "Plates Calculator by Boris Joffe (Copyright 2011-2012)\n\
Usage:\t./plates [space separated list of weights] [either 'kg' or 'lbs']\n\
\t./plates --auto\t\tRead next workout automatically from main file";
		sys.exit();

	if sys.argv[1] == '--auto' or sys.argv[1] == '-a':

		weight_regexp = '(?<=:)\d+';
		plates_list = [];
		my_workout = workoutlog.get_next_workout();

		if my_workout == -1:
			#workout_date = workoutlog.get_workout_date( my_workout[0] )

			print "No weights found for your next workout.\n\nIt looks like you began writing your workout but have not added any weights for your exercises. \nPlease add some weights for each exercise such as this example: \n\tsquat\t1x5:405\nThis means one set of five reps of squats at a weight of 405.\nOnce we see this, we will calculate what plates to load for each weight.\nThanks!"
		elif my_workout == -2:
			print "Sorry, no workouts found in the beginning of", workoutlog.main_file, "within the next", workoutlog.max_future_days, "days\nPlease update your workout file and try again"
		else:
			firstline = my_workout[0];
			workout_date = workoutlog.get_workout_date( firstline  )

			# TODO - change !=-1 to something better like have an is error function
			if workout_date != -1: # if the date on the line is in the next few days
				print "==== NEXT WORKOUT on", workout_date, "====";
				workout_meas = check_sys(firstline); # get lbs or kg for system

				weights = [];
				for j in range(1, len(my_workout)): # every line of workout, line 0 is the date so skip it
					nextline = my_workout[j]
					if DBG: Dbg('nextline', nextline);

					if j == 1 and nextline == '\n': 	# If the line immediately after the date is blank
						print "No sets or weights found for your next workout on", workout_date + ".\n\nIt looks like you began writing your workout but haven't added any exercises yet. \nPlease add some exercises with corresponding weights such as: \n\tsquat\t1x5:405\nThis means one set of five reps of squats at a weight of 405.\nOnce we see this, we will calculate what plates to load for each weight.\nThanks!";
						return -1
					else:
						if j != 1 and weights:
							plates_list.append('\n' + BREAK_STR + '\n'); # add break before every workout exercise except the 1st one if workout weights were found

						weights = [];
						sets = string.split(nextline, ',');  #TODO - remove comments on each line
						for set in sets: 	# build weight[] of all sets
							if DBG: Dbg('Searching for weight set',set);
							m = re.search(weight_regexp, set);
							if m:
								weights.append(m.group());

						if weights:		# if weights were found on the line
							if DBG: Dbg('weight[]',weights);
							plates_list.append(calcplatearr(weights, 1, True, workout_meas));	# add plates calculation for the current line

						elif not weights:
							print "No sets or weights found for your next workout on", workout_date + ".\n\nIt looks like you began writing your workout but haven't added any exercises yet. \nPlease add some exercises with corresponding weights such as: \n\tsquat\t1x5:405\nThis means one set of five reps of squats at a weight of 405.\nOnce we see this, we will calculate what plates to load for each weight.\nThanks!";
							return -1

		if plates_list:
			print ''.join(plates_list);

		return 0; # for --auto option

	# Last arg is lbs or kg
	lastarg = sys.argv[len(sys.argv)-1]
	if check_sys(lastarg, True) == -1: # return error if no valid lastarg
		NO_MEAS_SPECIFIED = True;

	if set_program( check_sys(string.lower(lastarg), True) ) == -1:
		Err("'plates.py' - Please specify last argument to be 'lbs' or 'kg'.")
		lastarg = DEFAULT_MEAS