Beispiel #1
0
    def set_user_weight(self):
        new_weight = self.popup_window.entry_weight.get()

        if not main_controller.is_float(new_weight):
            show_errorbox("Błędna waga", f"Waga musi być liczbą rzeczywistą!")
            return

        new_weight = round(float(new_weight), 1)
        if new_weight < WEIGHT_MIN or new_weight > WEIGHT_MAX:
            show_errorbox("Błędna waga", f"Waga musi być z przedziału [{WEIGHT_MIN},{WEIGHT_MAX}]!")
            return

        current_date = self.user_model.user['current_date']
        current_day_weight = self.database_model.select_user_weight_by_date(self.user_model.user['id_user'],
                                                                            current_date)
        update_weight = False
        if current_day_weight:
            if current_day_weight['weight_value'] != new_weight:
                self.database_model.update_user_weight_on_date(self.user_model.user['id_user'],
                                                               current_date, new_weight)
                update_weight = True
        else:
            self.database_model.insert_weight(self.user_model.user['id_user'], new_weight, current_date)
            update_weight = True

        if update_weight:
            self.user_model.set_current_date(self.user_model.user['current_date'])
            self.profile_view.update_weight()

        self.close_popup_window()
Beispiel #2
0
    def register_new_user(self):
        entry_values = self.get_register_entry_values()

        error_title, error_msg = self.check_errors(entry_values)

        if error_title or error_msg:
            show_errorbox(error_title, error_msg)
        else:
            entry_values['weight'] = round(float(entry_values['weight']), 1)
            entry_values['height'] = round(float(entry_values['height']), 1)
            entry_values['age'] = int(entry_values['age'])
            entry_values['activity'] = int(entry_values['activity'])
            entry_values['goal'] = int(entry_values['goal'])

            avatar = convert_to_binary_data(IMG_PATH_NO_PHOTO)
            self.database_model.insert_user(entry_values['login'], entry_values['password'], entry_values['email'],
                                            entry_values['gender'], entry_values['height'], entry_values['age'],
                                            entry_values['activity'], entry_values['goal'], avatar)
            user_id = self.database_model.select_user_by_login(entry_values['login'])['id_user']

            current_date = get_current_date()

            self.database_model.insert_weight(user_id, entry_values['weight'], current_date)

            gda_value = evaluate_gda(entry_values['gender'], entry_values['weight'], entry_values['height'],
                                     entry_values['age'], entry_values['activity'], entry_values['goal'])
            self.database_model.insert_gda(user_id, gda_value, current_date)
            self.close_register_window()
            show_infobox("Rejestracja udana", f"Utworzono nowego użytkownika o loginie: {entry_values['login']}")
Beispiel #3
0
    def correct_name(name):
        if len(name) < FOOD_NAME_LENGTH_MIN or len(name) > FOOD_NAME_LENGTH_MAX:
            show_errorbox("Błędna nazwa",
                          f"Nazwa musi mieć od {FOOD_NAME_LENGTH_MIN} do {FOOD_NAME_LENGTH_MAX} znaków!")
            return False

        return True
Beispiel #4
0
    def login(self):
        login, password = self.get_login_entry_values()
        user = self.database_model.select_user_by_login_and_password(login, password)

        if user is not None:
            self.open_user_window(user)
        else:
            show_errorbox("Błąd logowania", "Podano błędny login lub hasło!")
Beispiel #5
0
    def correct_grammage_value(grammage):
        if not main_controller.is_int(grammage):
            show_errorbox("Błędna waga", f"Waga musi być liczbą całkowitą!")
            return False

        grammage = int(grammage)
        if grammage < GRAMMAGE_MIN or grammage > GRAMMAGE_MAX:
            show_errorbox("Błędna waga", f"Waga musi być z przedziału [{GRAMMAGE_MIN},{GRAMMAGE_MAX}] g!")
            return False

        return True
Beispiel #6
0
    def correct_calories_value(calories):
        if not main_controller.is_int(calories):
            show_errorbox("Błędna liczba kalorii", f"Liczba kalorii musi być liczbą całkowitą!")
            return False

        calories = int(calories)
        if calories < CALORIES_MIN or calories > CALORIES_MAX:
            show_errorbox("Błędna liczba kalorii",
                          f"Liczba kalorii musi być z przedziału [{CALORIES_MIN},{CALORIES_MAX}] kcal!")
            return False

        return True
Beispiel #7
0
    def correct_duration_value(duration):
        if not main_controller.is_int(duration):
            show_errorbox("Błędny czas treningu", f"Czas trwania treningu musi być liczbą całkowitą!")
            return False

        duration = int(duration)
        if duration < TRAINING_DURATION_MIN or duration > TRAINING_DURATION_MAX:
            show_errorbox("Błędny czas treningu",
                          f"Czas trwania treningu musi być z przedziału "
                          f"[{TRAINING_DURATION_MIN},{TRAINING_DURATION_MAX}] min!")
            return False

        return True
Beispiel #8
0
    def set_user_goal(self):
        new_goal = self.popup_window.goal_value.get()[0]

        if not main_controller.is_int(new_goal):
            show_errorbox("Błędny cel", f"Wybierz swoj cel!")
            return

        new_goal = int(new_goal)
        if new_goal < GOAL_VALUE_MIN or new_goal > GOAL_VALUE_MAX:
            show_errorbox("Błędny cel", f"Wybierz swoj cel!")
            return

        if new_goal != self.user_model.user['goal']:
            self.database_model.update_user_goal(self.user_model.user['id_user'], new_goal)
            self.user_model.user['goal'] = new_goal
            self.profile_view.update_goal()

        self.close_popup_window()
Beispiel #9
0
    def set_user_physical_activity(self):
        new_physical_activity = self.popup_window.activity_value.get()[0]

        if not main_controller.is_int(new_physical_activity):
            show_errorbox("Błędna aktywność ruchowa", f"Wybierz swoją aktywność ruchową!")
            return

        new_physical_activity = int(new_physical_activity)
        if new_physical_activity < ACTIVITY_VALUE_MIN or new_physical_activity > ACTIVITY_VALUE_MAX:
            show_errorbox("Błędna aktywność ruchowa", f"Wybierz swoją aktywność ruchową!")
            return

        if new_physical_activity != self.user_model.user['physical_activity']:
            self.database_model.update_user_physical_activity(self.user_model.user['id_user'], new_physical_activity)
            self.user_model.user['physical_activity'] = new_physical_activity
            self.profile_view.update_physical_activity()

        self.close_popup_window()
Beispiel #10
0
    def set_user_age(self):
        new_age = self.popup_window.entry_age.get()

        if not main_controller.is_int(new_age):
            show_errorbox("Błędny wiek", f"Wiek musi być liczbą całkowitą!")
            return

        new_age = int(new_age)
        if new_age < AGE_MIN or new_age > AGE_MAX:
            show_errorbox("Błędny wiek", f"Wiek musi być z przedziału [{AGE_MIN},{AGE_MAX}]!")
            return

        if new_age != self.user_model.user['age']:
            self.database_model.update_user_age(self.user_model.user['id_user'], new_age)
            self.user_model.user['age'] = new_age
            self.profile_view.update_age()

        self.close_popup_window()
Beispiel #11
0
    def set_user_height(self):
        new_height = self.popup_window.entry_height.get()

        if not main_controller.is_float(new_height):
            show_errorbox("Błędny wzrost", f"Wzrost musi być liczbą rzeczywistą!")
            return

        new_height = round(float(new_height), 1)
        if new_height < HEIGHT_MIN or new_height > HEIGHT_MAX:
            show_errorbox("Błędny wzrost", f"Wzrost musi być z przedziału [{HEIGHT_MIN},{HEIGHT_MAX}]!")
            return

        if new_height != self.user_model.user['height']:
            self.database_model.update_user_height(self.user_model.user['id_user'], new_height)
            self.user_model.user['height'] = new_height
            self.profile_view.update_height()

        self.close_popup_window()