def convert_lift_history_weight(self, convert_to_units): try: lift_history = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "lift_history")) except TypeError: # lift history is empty return if convert_to_units == "kg": for lift in lift_history: if isinstance( lift[1], list ): # second element of history entry is list, it is lifts_for_reps entry lift[1][1] = str(pounds_to_kg(float(lift[1][1]))) else: lift[1] = str(pounds_to_kg(float(lift[1]))) elif convert_to_units == "lb": for lift in lift_history: if isinstance(lift[1], list): lift[1][1] = str(kg_to_pounds(float(lift[1][1]))) else: lift[1] = str(kg_to_pounds(float(lift[1]))) lift_history = json.dumps(lift_history) self.db_wrapper.update_table_column(self.table_name, "lift_history", lift_history, convert_lift_history_units=True)
def __init__(self, age, gender, height, weight, activity_level, goal, weight_per_week): self.db_wrapper = DatabaseWrapper() self.units = self.db_wrapper.fetch_local_column("Users", "units") self.age = age self.gender = gender activity_factors = {"Maintain": 1, "Sedentary": 1.2, "Lightly active": 1.375, "Moderately active": 1.550, "Very active": 1.725, "Extra active": 1.9} self.activity_level = activity_factors[activity_level] if self.units == "imperial": self.height = imperial_to_metric_height(height["feet"], height["inches"]) self.weight = pounds_to_kg(weight) else: self.height = height self.weight = weight self.goal = goal self.weight_per_week = weight_per_week
def create_age_group_standard(self, standards, age_range): percentages = { "14-17": 13 / 100, "18-23": 2 / 100, "24-39": 0 / 100, "40-49": 5 / 100, "50-59": 17 / 100, "60-69": 31 / 100, "70-79": 45 / 100, "80-89": 56 / 100 } age_group_standards = [standards[0]] if self.units == "lb": old_standards = standards standards = [] for bodyweight_group in old_standards[1:]: converted_weight = [] for weight in map(kg_to_pounds, bodyweight_group): index = bodyweight_group.index(round(pounds_to_kg(weight))) if index == 0: # round number to next 10 if int(str(int(weight))[-1]) > 4: weight = math.ceil(weight / 10.0) * 10 # round number to previous 10 elif int(str(int(weight))[-1]) <= 4: weight = math.floor(weight / 10.0) * 10 converted_weight.append(round(weight)) standards.append(converted_weight) for age_group in standards: if isinstance(age_group[0], str): continue bodyweight = age_group[0] weight = list( map(lambda n: round(n - (n * percentages[age_range])), age_group[1:])) weight.insert(0, bodyweight) age_group_standards.append(weight) return age_group_standards
def __init__(self, parent): super().__init__(parent) self.db_wrapper = DatabaseWrapper() self.table_name = "Weight Loss" self.setStyleSheet(""" QWidget{ color:#c7c7c7; font-weight: bold; } QPushButton{ background-color: rgba(0, 0, 0, 0); border: 1px solid; font-size: 18px; font-weight: bold; border-color: #808080; min-height: 28px; white-space:nowrap; text-align: left; padding-left: 5%; font-family: Montserrat; } QPushButton:hover:!pressed{ border: 2px solid; border-color: #747474; } QPushButton:pressed{ border: 2px solid; background-color: #323232; border-color: #6C6C6C; } QComboBox{ border-radius: 4px; font-size: 18px; font-weight: bold; white-space:nowrap; text-align: left; padding-left: 5%; font-family: Montserrat; min-height: 28px; background-color: #440D0F; } QComboBox:down-arrow{ width: 0px; height: 0px; background: #d3d3d3; opacity:0 } QComboBox:drop-down{ background-color: #440D0F; border: 0px; opacity:0; border-radius: 0px; width: 0px; height: 0px; } QComboBox:hover:!pressed{ background-color: #5D1A1D; } QComboBox:pressed{ background-color: #551812; } """) self.db_wrapper.create_local_table(self.table_name) self.db_wrapper.create_local_table("Nutrition") if self.db_wrapper.local_table_is_empty("Nutrition"): self.db_wrapper.insert_default_values("Nutrition") if self.db_wrapper.local_table_is_empty(self.table_name): self.db_wrapper.insert_default_values(self.table_name) self.fetch_user_data() self.date = datetime.today().strftime("%d/%m/%Y") self.current_year = datetime.today().year self.calorie_goal = self.db_wrapper.fetch_local_column( "Nutrition", "calorie_goal") self.units = "kg" if self.db_wrapper.fetch_local_column( "Users", "units") == "metric" else "lb" weight_loss_units = "kg" if self.db_wrapper.fetch_local_column( self.table_name, "units") == "metric" else "lb" self.weight_history = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "weight_history")) if self.units != weight_loss_units: units_name = "metric" if self.units == "kg" else "imperial" self.db_wrapper.update_table_column(self.table_name, "units", units_name) if units_name == "metric": for date in self.weight_history: self.weight_history[date] = str( pounds_to_kg(self.weight_history[date])) elif units_name == "imperial": for date in self.weight_history: self.weight_history[date] = str( kg_to_pounds(self.weight_history[date])) self.db_wrapper.update_table_column( self.table_name, "weight_history", json.dumps(self.weight_history)) self.preferred_activity = self.db_wrapper.fetch_local_column( self.table_name, "preferred_activity") self.cardio_history = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "cardio_history")) if not self.date in self.cardio_history: self.add_date_to_cardio_history() if not self.date in self.weight_history: self.add_date_to_weight_history() self.init_cardio_labels() self.create_panel()
def __init__(self, parent): super().__init__(parent) self.db_wrapper = DatabaseWrapper() self.table_name = "Compound Exercises" self.setStyleSheet(""" QWidget{ color:#c7c7c7; font-weight: bold; } QPushButton{ background-color: rgba(0, 0, 0, 0); border: 1px solid; font-size: 18px; font-weight: bold; border-color: #808080; min-height: 28px; white-space:nowrap; text-align: left; padding-left: 5%; font-family: Montserrat; } QPushButton:hover:!pressed{ border: 2px solid; border-color: #747474; } QPushButton:pressed{ border: 2px solid; background-color: #323232; border-color: #6C6C6C; } QComboBox{ border-radius: 4px; font-size: 18px; font-weight: bold; white-space:nowrap; text-align: left; padding-left: 5%; font-family: Montserrat; min-height: 28px; background-color: #440D0F; } QComboBox:down-arrow{ width: 0px; height: 0px; background: #d3d3d3; opacity:0 } QComboBox:drop-down{ background-color: #440D0F; border: 0px; opacity:0; border-radius: 0px; width: 0px; height: 0px; } QComboBox:hover:!pressed{ background-color: #5D1A1D; } QComboBox:pressed{ background-color: #551812; } """) self.current_year = str(datetime.now().year) self.db_wrapper.create_local_table(self.table_name) if self.db_wrapper.local_table_is_empty(self.table_name): self.db_wrapper.insert_default_values(self.table_name) self.units = "kg" if self.db_wrapper.fetch_local_column( "Users", "units") == "metric" else "lb" big_lifts_units = "kg" if self.db_wrapper.fetch_local_column( self.table_name, "units") == "metric" else "lb" one_rep_maxes = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "one_rep_maxes")) lifts_for_reps = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "lifts_for_reps")) self.rm_history = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "rm_history")) if not self.current_year in self.rm_history: self.add_year_to_rm_history(self.current_year) self.rm_history = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "rm_history")) if self.units != big_lifts_units: units_name = "metric" if self.units == "kg" else "imperial" self.db_wrapper.update_table_column(self.table_name, "units", units_name) if units_name == "metric": for exercise, weight in one_rep_maxes.items(): one_rep_maxes[exercise] = str(pounds_to_kg(weight)) for exercise, reps_and_weight in lifts_for_reps.items(): lifts_for_reps[exercise] = [ reps_and_weight[0], str(pounds_to_kg(reps_and_weight[1])) ] elif units_name == "imperial": for exercise, weight in one_rep_maxes.items(): one_rep_maxes[exercise] = str(kg_to_pounds(weight)) for exercise, reps_and_weight in lifts_for_reps.items(): lifts_for_reps[exercise] = [ reps_and_weight[0], str(kg_to_pounds(reps_and_weight[1])) ] for year in self.rm_history: for month in self.rm_history[year]: for exercise_type in list(self.rm_history[year][month]): for exercise in list( self.rm_history[year][month][exercise_type]): for i, weight in enumerate( self.rm_history[year][month][exercise_type] [exercise]): if units_name == "imperial": self.rm_history[year][month][ exercise_type][exercise][i] = str( kg_to_pounds(weight)) elif units_name == "metric": self.rm_history[year][month][ exercise_type][exercise][i] = str( pounds_to_kg(weight)) self.db_wrapper.update_table_column(self.table_name, "one_rep_maxes", one_rep_maxes) self.db_wrapper.update_table_column(self.table_name, "lifts_for_reps", lifts_for_reps) self.convert_lift_history_weight(self.units) self.one_RM = [[lift, " ".join([weight, self.units])] for lift, weight in one_rep_maxes.items()] self.lifts_reps = [[lift, " ".join(["x".join(weight), self.units])] for lift, weight in lifts_for_reps.items()] self.lift_history_window = LiftHistory() self.lift_history_window.setGeometry(100, 200, 300, 300) self.plists_window = PreferredLifts() self.plists_window.change_lifts_signal.connect( self.changed_preferred_lifts) self.update_1RM_window = Update1RMWindow() self.update_1RM_window.change_1RM_lifts_signal.connect( self.changed_1RM_lifts) self.update_1RM_window.history_signal.connect( lambda signal: self.lift_history_window.create_history(signal)) self.update_1RM_window.update_graph_signal.connect( lambda signal: self.refresh_graph(signal)) self.lifts_for_reps = UpdateLiftsForRepsWindow() self.lifts_for_reps.change_lifts_for_reps_signal.connect( self.changed_lifts_for_reps) self.lifts_for_reps.history_signal.connect( lambda signal: self.lift_history_window.create_history(signal)) self.preferred_lifts = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "preferred_lifts")) self.one_rep_maxes = json.loads( self.db_wrapper.fetch_local_column(self.table_name, "one_rep_maxes")) self.create_panel()