def get_best_average(length): """ Returns best average of `length` in session """ try: if length == 5: best = add_zero(min([i for i in ao5s if i != ''])) elif length == 12: best = add_zero(min([i for i in ao12s if i != ''])) except ValueError: return "" return best
def get_session_mean(): """ Returns mean of all solves in session """ try: float_times, len_times = convert_to_float(times, 'average') return add_zero(round(sum(float_times) / len_times, 2)) except ZeroDivisionError: return ""
def plus_two(): """ Adds two to the value of the latest solves, while also marking it as a plus two """ # udpate `times` solve_time = times[-1] times[-1] = add_zero(round(float(solve_time) + 2, 2)) + '+' ao5s[-1] = calculate_average(len(ao5s), 5) ao12s[-1] = calculate_average(len(ao12s), 12) # update session file with open(session_file.string, 'r') as f: lines = [line.split('\t') for line in f.read().split('\n')] if [''] in lines: lines.remove(['']) lines[-1][0] = add_zero(round(float(solve_time) + 2, 2)) + '+' with open(session_file.string, 'w') as f: f.write('\n'.join(['\t'.join(line) for line in lines]))
def get_worst_time(): try: converted_times, _ = convert_to_float(times, 'single') float_times = [ float(t[:-1]) if isinstance(t, str) else t for t in converted_times ] worst = converted_times[float_times.index(max(float_times))] if isinstance(worst, float): return add_zero(worst) except ValueError as e: return "" return worst
def calculate_average(solve, length): """ Returns average of `length` during `solve` Looks through times list and finds last `length` solves before `solve` Excludes best and worst times, and returns average of the rest. """ if len(times[:solve]) < length: # `length` solves haven't been done yet. return '' else: latest_average = times[solve - length:] # list of last `length` solves latest_average, _ = convert_to_float(latest_average, "average") if len(latest_average) < (length - 1): return 'DNF' if len(latest_average) == length: latest_average.remove(max(latest_average)) latest_average.remove(min(latest_average)) # calculate average and add zero if it doesn't go to 100ths place. return add_zero(round( sum(latest_average) / len(latest_average), 2))