def reps_smart_text(settings, set_obj): ''' "Smart" textual representation This is a human representation of the settings, in a way that humans would also write: e.g. "8 8 10 10" but "4 x 10" and not "10 10 10 10" :param settings: :param set_obj: :return setting_text, setting_list: ''' unit = _('kg') if set_obj.exerciseday.training.user.userprofile.use_metric else _('lb') if len(settings) == 0: setting_text = '' setting_list = [] weight_list = [] reps_list = [] elif len(settings) == 1: reps = settings[0].reps if settings[0].reps != 99 else u'∞' setting_text = u'{0} × {1}'.format(set_obj.sets, reps) setting_list_text = u'{0}'.format(reps) # The weight can be None, or a decimal. In that case, normalize so # that we don't return e.g. '15.00', but always '15', independently of # the database used. if settings[0].weight: weight = normalize_decimal(settings[0].weight) else: weight = settings[0].weight if weight: setting_text += ' ({0}{1})'.format(weight, unit) setting_list_text += ' ({0}{1})'.format(weight, unit) setting_list = [setting_list_text] * set_obj.sets reps_list = [settings[0].reps] * set_obj.sets weight_list = [weight] * set_obj.sets elif len(settings) > 1: tmp_reps_text = [] tmp_reps = [] tmp_weight = [] for i in settings: reps = str(i.reps) if i.reps != 99 else u'∞' weight = i.weight if i.weight: # Normalize, see comment above weight = normalize_decimal(i.weight) reps += ' ({0}{1})'.format(weight, unit) tmp_reps_text.append(reps) tmp_reps.append(i.reps) tmp_weight.append(weight) setting_text = u' – '.join(tmp_reps_text) setting_list = tmp_reps_text reps_list = tmp_reps weight_list = tmp_weight return setting_text, setting_list, weight_list, reps_list
def get_rir_representation(setting): """ Returns the representation for the RepsInReserve for a setting """ if setting.rir: rir = "{0} RiR".format(normalize_decimal(setting.rir)) else: rir = "" return rir
def normalize_weight(setting): ''' The weight can be None, or a decimal. In that case, normalize so that we don't return e.g. '15.00', but always '15', independently of the database used. ''' if setting.weight: weight = normalize_decimal(setting.weight) else: weight = setting.weight return weight