def update_weight(self): new_weight, ok = QInputDialog.getDouble(self.page(), "Update weight", "Enter your new weight", 65, 60, 80) if ok: self.data.append(new_weight) self._user_model.update_weight(self._user, new_weight) self._basic_goal_progress_model.addBasicProgress(self._user, new_weight, date.today()) self.parent.update() display_message('Weight added successfully', f'Good work! You are now {new_weight} kg', False)
def edit_details(self, user): valid = True # get all data from the view new_username = self._view.username.text() new_name = self._view.name.text() new_dob = self._view.dob.text() new_gender = self._view.gender.currentText().lower() new_weight = self._view.weight.value() new_height = self._view.height.value() new_email = self._view.email.text() # validate the input if len(new_username) == 0: display_message('username is empty', 'username cannot be empty') valid = False if len(new_name) == 0: display_message('name is empty', 'name cannot be empty') valid = False if len(new_email) == 0 or not validate_email(new_email): display_message( 'email is empty or invalid', 'email cannot be empty, please enter a valid email') valid = False if valid: # push changes to the database self._user_model.edit_details(user, new_username, new_name, new_dob, new_gender, new_weight, new_height, new_email) display_message('Details editted successfully', 'You have update your details!', False)
def make_basic_goal(self): # get data from the view weight_goal = self._view.lose_weight_goal.value() complete_date = self._view.basic_goal_completion_date.date().toPyDate() # pass them to model to create basic goal try: self._basic_goal_model.create_basic_goal(self._user, weight_goal, complete_date) display_message('Basic goal created', 'You have just created a basic goal', False) except Exception as e: print(e) display_message( 'Fail to create basic goal', 'Please check if you have already created a new basic goal')
def joinNewGroup(self): groupName = self.ui.group_name_output.text() groupGoal = self.ui.group_goal_output.text() try: self._user_group_model.addUserGroup( self._user, self._group_model.get_id_by_name(groupName)) self.data = self.read_data() self.model = CustomTableModel(self.data) # reset model self.proxyModel.setSourceModel( self.model) # display added food without a need for refreshing self.ui.group_table.setModel(self.proxyModel) display_message('Joined group', 'You have joined a new group successfully', False) except Exception as e: display_message( 'Fail to join group', 'Error joining the group, please check your input and try again!' ) print(e)
def make_custom_goal(self): # get data from the view description = self._view.goal_description.toPlainText() days = self._view.days.value() period = self._view.period.value() complete_date = self._view.completion_date.date().toPyDate() # pass them to model to create custom goal try: self._user_custom_goal_model.create_custom_goal( self._user, description, complete_date, checkin_interval=days, act_period_length=period) display_message('Custom goal created', 'You have just created a new custom goal', False) except Exception as e: print(e) display_message( 'Fail to create custom goal', 'Please check if you have already created a new basic goal')
def addNewGroup(self): if (self.ui.group_name_input.text() == '' or self.ui.group_goal_input.text() == ''): # disallow adding food with empty text print('not allowed') display_message('Input cannot be empty', 'Please enter valid group name and description') else: groupName = self.ui.group_name_input.text() groupType = self.ui.group_type.currentText().upper() groupGoal = self.ui.group_goal_input.text() completionDate = self.ui.completion_date.date().toPyDate() try: groupID = Group.createGroup(groupName, groupType, completionDate) self._user_group_model.createUserGroup(self._user, groupID) self._custom_goal.create_custom_goal(self._user, groupGoal, date.today(), group_id=groupID) self.data = self.read_data() self.model = CustomTableModel(self.data) # reset model self.proxyModel.setSourceModel( self.model ) # display added food without a need for refreshing self.ui.group_table.setModel(self.proxyModel) display_message('New group added', 'You have added a new group successfully', False) except Exception as e: display_message( 'Invalid input', 'Please enter a valid group name or description!') print(e)
def addExerciseToday(self): try: # find foodId to place in userMeal index = self.ui.exercise_table.currentIndex().row() + 1 caloriesBurnt = float(self.ui.add_calories_2.text()) today = datetime.today().strftime('%d/%m/%Y') userexercise = Table('userExercise', ModelHandler.return_meta(), autoload=True, autoload_with=ModelHandler.engine) insert = userexercise.insert().values(exerciseId=index, username=self._user, caloriesBurnt=caloriesBurnt, activityDate=today) conn = ModelHandler.return_connection() conn.execute(insert) display_message('Your exercise for today has been added', 'You have added an exercise successfully', False) except Exception as e: display_message('Your exercise has not been added', 'Adding a exercise has failed', False) print(e)
def addNewExercise(self): if(self.ui.durationLineEdit_5.text()=='' or self.ui.add_calories.text()==''):#disallow adding food with empty text #TODO to be printed in the GUI as a label # Find a more efficient way to refresh page after model is updated print('not allowed') display_message('Input cannot be empty', 'Please enter valid exercise duration and calories') else: exerciseName=self.ui.durationLineEdit_5.text() calories=self.ui.add_calories.text() try: activity = None ExerciseDictionary.addExercise(activity, exerciseName, calories) self.data = self._exercise_model.get_all_exercises() self.model = CustomTableModel(self.data) # reset model self.proxyModel.setSourceModel(self.model) # display added food without a need for refreshing self.ui.exercise_table.setModel(self.proxyModel) display_message('New exercise added', 'You have added a new exercise successfully', False) except Exception as e: display_message('Invalid duration/calories input', 'Please enter valid exercise duration and calories burnt!') print(e)