Esempio n. 1
0
 def _add_exercise(self):
   name = self.request.get('exerciseName')
   burnrate = calc_burnrate(name)
   duration = int(self.request.get('exerciseDuration'))
   e = Exercise(name = name, burnrate = burnrate, duration = duration)
   e.put()
   foods = self.find_foods_worked_off(e)
   self.present_exercise(e, foods)
Esempio n. 2
0
def add_workout():
    if request.method == 'POST':
        user = User.query.filter_by(name=session['username']).first()

        workout = Workout(date=datetime.utcnow(), user_id=user.id)

        exercise_count = int(request.form['exercise_count'])

        for exercise_num in range(1, exercise_count + 1):
            exercise = Exercise(order=exercise_num,
                                exercise_id=request.form['exercise' +
                                                         str(exercise_num)],
                                workout=workout)

            weights = request.form.getlist('weight' + str(exercise_num))
            reps = request.form.getlist('reps' + str(exercise_num))

            set_order = 1
            for weight, rep in zip(weights, reps):
                work_set = Set(order=set_order,
                               exercise=exercise,
                               weight=weight,
                               reps=rep)
                set_order += 1

        db.session.add(workout)
        db.session.commit()

        return redirect(url_for('index'))

    exercises = Exercises.query.all()
    return render_template('add_workout.html', exercises=exercises)
Esempio n. 3
0
def add_exercise():
    """addition of exercises to DB!, current user is hardcoded
	will change to user in session once it actually functions"""
    user_id = session.get('user')
    exercise_name = request.form["exercise_name"]
    weight = request.form["weight"]
    num_reps = request.form["num_reps"]
    new_entry = None
    new_exercise = None

    check_exercise = Exercise.query.filter_by(user_id = user_id,\
              name = exercise_name).\
              one_or_none()
    if check_exercise == None:
        new_exercise = Exercise(user_id=user_id, name=exercise_name)
        db.session.add(new_exercise)
        db.session.commit()
        check_exercise = Exercise.query.filter_by(user_id = user_id,\
                 name = exercise_name).\
                 one_or_none()

    new_entry = ExerciseEntry(user_id=user_id,
                              exercise_id=check_exercise.exercise_id,
                              num_reps=num_reps,
                              weight=weight)

    db.session.add(new_entry)
    db.session.commit()
    flash("Exercise Logged! Don't Stop Rockin!")
    return "Exercise logged!", 200
Esempio n. 4
0
def exercise_entry():
	""" add user exercise entry"""
	if 'user' in session:
		entry_user_id = session['user']
	else: 
		return redirect('/login')
	exercise_name = request.form["exercise"]
	weight = request.form["weight"]
	num_reps = request.form["num_reps"]

	exercise = Exercise.query.filter_by(exercise_name = exercise_name).first()
	#need to query Exercise table with user_id and exercise name

	if exercise == None:
		new_exercise_name = Exercise(exrs_user_id = entry_user_id,
									 exercise_name = exercise_name,
									 )
		db.session.add(new_exercise_name)
		db.session.commit()
		exercise = Exercise.query.filter_by(exercise_name = exercise_name).first()
	print(exercise.exercise_id, entry_user_id, weight, num_reps)

	new_exercise_entry = ExerciseEntry(entry_user_id = entry_user_id,
									   entry_exercise_id = exercise.exercise_id,
									   num_reps = num_reps,
									   weight = weight,
									   )
	db.session.add(new_exercise_entry)
	db.session.commit()
	return " ", 200
Esempio n. 5
0
def create_exercise(exercise_name, exercise_info, api_id):
    """create and return exercise"""

    exercise = Exercise(exercise_name=exercise_name,
                        exercise_info=exercise_info,
                        api_id=api_id)

    db.session.add(exercise)
    db.session.commit()

    return exercise
Esempio n. 6
0
def load_exercise():
    exercise_result_list = call_api('exercise')
    valid_exercises_id_list = []

    for result_dict in exercise_result_list:
        language = result_dict['language']

        exercise_id = result_dict['id']
        name = result_dict['name']
        if name:
            # description = result_dict['description']\
            #     .replace('<p>', '').replace('</p>', '')
            description = result_dict['description']
            category_code = result_dict['category']

            # filter out non-English exercises
            if (language != 2) or not detect_en(description):
                continue
            equipment_code_list = result_dict['equipment']
            if not equipment_code_list:
                equipment_code_list = [7]

            # filter out exercises without a name
            # if not name:
            #     continue

            exercise = Exercise(exercise_id=exercise_id,
                                name=name,
                                description=description,
                                equipment=equipment_code_list,
                                category_id=category_code)

            db.session.add(exercise)
            for code in equipment_code_list:
                if Exercise.query.get(exercise_id):
                    ee_entry = ExerciseEquipment(exercise_id=exercise_id,
                                                 equipment_id=code)
                    db.session.add(ee_entry)

            db.session.commit()

            valid_exercises_id_list.append(exercise_id)
    # need it?
    db.session.commit()

    return valid_exercises_id_list
Esempio n. 7
0
def create_exercise(name,
                    description,
                    duration,
                    equip_req,
                    freq,
                    img="/404_smile.jpg"):
    """Create and return a new exercise record"""

    exercise = Exercise(name=name,
                        description=description,
                        duration=duration,
                        equip_req=equip_req,
                        freq=freq,
                        img=img)

    db.session.add(exercise)
    db.session.commit()

    return exercise
Esempio n. 8
0
def create_exercise(exercise_name, main_muscle_group, type_of_exercise,
                    difficulty, equipment, instructions, exercise_img1,
                    exercise_img2, reps):
    """Create and return a exercise."""

    exercise = Exercise(exercise_name=exercise_name,
                        main_muscle_group=main_muscle_group,
                        type_of_exercise=type_of_exercise,
                        difficulty=difficulty,
                        equipment=equipment,
                        instructions=instructions,
                        exercise_img1=exercise_img1,
                        exercise_img2=exercise_img2,
                        reps=reps)

    db.session.add(exercise)
    db.session.commit()

    return exercise
Esempio n. 9
0
def last(user_id) -> List[Exercise]:
    """Возвращает последние несколько расходов"""
    cursor = db.get_cursor()
    cursor.execute(
        'SELECT e.id, e.weight*e.repetitions, e.repetitions, e.name, c.name '
        'FROM exercises e '
        'LEFT JOIN category c '
        'ON c.codename=e.category_codename '
        'WHERE e.user_id={user_id} '
        'ORDER BY created DESC limit 10'.format(user_id=user_id))
    rows = cursor.fetchall()
    last_exercises = [
        Exercise(user_id=row[0],
                 weight=row[1],
                 repetitions=row[2],
                 name=row[3],
                 category_codename=row[4]) for row in rows
    ]
    return last_exercises
Esempio n. 10
0
    def parse_exercise(self, message: types.Message) -> Exercise:
        """Парсит текст пришедшего сообщения о новом подходе"""
        try:
            parsed_message = message.text.split()
            user_id = int(message.from_user.id)
            weight = int(parsed_message[0])
            repetitions = int(parsed_message[1])
            exercise_name = parsed_message[2]
            category: Category = self.categories.get_category_by_name(
                exercise_name)
            return Exercise(user_id=user_id,
                            weight=weight,
                            repetitions=repetitions,
                            category_codename=category.codename,
                            name=exercise_name)

        except Exception:
            raise NotCorrectMessage(
                'Не могу понять сообщение. Напишите сообщение в формате, "например: 100 4 жим"'
            )
Esempio n. 11
0
def create_exercise():
    """Create some test exercises"""

    ex1 = Exercise(name="Crab Walk", 
        description="With knees bent, step one foot out to the side, then bring the other foot to it. Continuing walking sideways like this for 20 steps, then switch sides.", 
        duration=4,
        equip_req=False,
        exercise_type="endurance",
        freq=3,
        max_reps=20,
        img="/static/img/crab-walk.jpg")
    db.session.add(ex1)

    ex2 = Exercise(name="Ankle Flex with Resistance Band",
        description="With one end of the resistance band looped around the ball of the foot, and the other held in place by your hand, or tied to a stable object, pull against the band using your ankle. Hold for 3 seconds, then release.", 
        duration=5,
        equip_req=True,
        exercise_type="strength",
        freq=7,
        max_reps=20,
        img="/static/img/ankle-flex.jpg")
    db.session.add(ex2)

    ex3 = Exercise(name="Ankle Circles",
        description="Slowly rotate your ankle clockwise. Repate counterclockwise.",
        duration=3,
        equip_req=False,
        exercise_type="flexibility",
        freq=7,
        max_reps=20,
        img="/static/img/ankle-circles.jpg")
    db.session.add(ex3)

    ex4 = Exercise(name="Squats (supported)",
        description="Stand with feet shoulder-width apart, in front of a stable support for balance if needed. Slowly bend your knees and lower your body toward the floor. Your body weight should be mostly directed your the heels of your feet. Return to standing.",
        duration=5,
        equip_req=False,
        exercise_type="strength",
        freq=3,
        max_reps=10,
        img="/static/img/supported-squat.jpg")
    db.session.add(ex4)

    ex5 = Exercise(name="Step Up",
        description="Start by standing in front of a step/step stool with both feet on the ground. Step up the step with one leg and then with the other. Return to starting position by taking a step back toward the floor leading with the same leg you started with.",
        duration=3,
        equip_req=True,
        exercise_type="balance",
        freq=4,
        max_reps=20,
        img="/static/img/step-up.jpg")
    db.session.add(ex5)

    ex6 = Exercise(name="Standing Heel Raises",
        description="Stand in front of a counter or other surface at about waist height. Rise up on your toes and lift your heels off the ground. Start with lifting only a couple inches off the ground, then progress, as strength allows. Lower back to the floor slowly. Start by shifting weight onto uninjured foot, then shift to even weight distribution once you've reached the top of the lift. Try to stay even as you lower back down.",
        duration=1,
        equip_req=False,
        exercise_type="strength",
        freq=7,
        max_reps=20,
        img="/static/img/heel-raise.jpg")
    db.session.add(ex6)

    ex7 = Exercise(name="Walking",
        description="Concentrate on form, rather than endurance or speed. Focus on making sure strides are even in length, and roll all the way through your injured foot if possible (stead of limping). Take it slow, take shorter strides to start.",
        duration=2,
        equip_req=False,
        exercise_type="endurance",
        freq=7,
        max_reps=30,
        img="/static/img/walking.jpg")
    db.session.add(ex7)

    ex8 = Exercise(name="Arch Lifts",
        description="Start with both feet on the floor. While pressing your toes and heels into the floor, try to peel the arch of your foot off the floor. Hold for 2 seconds, release slowly.",
        duration=3,
        equip_req=False,
        exercise_type="flexibility",
        freq=7,
        max_reps=15,
        img="/static/img/arch-lift.jpg")
    db.session.add(ex8)
    
    ex9 = Exercise(name="Toe Yoga",
        description="Sit with knees over ankles. Keep ball and heel of the foot on the floor at all times. Lift the big toe, presisng the other toes into the floor. Hold for 5 seconds. Alternate by pressing the big toes into the floor, while lifting all other toes and hold for 5 seconds.",
        duration=6,
        equip_req=False,
        exercise_type="flexibility",
        freq=7,
        max_reps=20,
        img="/static/img/toe-yoga.jpg")
    db.session.add(ex9)

    ex10 = Exercise(name="Seated Calf Stretch",
        description="While sitting, use a towel or other strap (without stretch) looped around the base of your foot. Gently pull the towel taut, and press against it with your foot. You should feel a stretch along the back of your leg. Attempt to straighten your knee for added stretch, if it's comfortable. Hold for 1 minute.",
        duration=60,
        equip_req=True,
        exercise_type="flexibility",
        freq=7,
        max_reps=1,
        img="/static/img/seated-calf-stretch.jpg")
    db.session.add(ex10)

    db.session.commit()
Esempio n. 12
0
def example_data():
    """Sample data to help with testing"""

    Workout_exercise.query.delete()
    Exercise.query.delete()
    Workout.query.delete()
    User.query.delete()

    jess = User(user_name='jess',
                password='******',
                user_age='75',
                user_weight='130',
                user_zipcode='48189')
    ankit = User(user_name='ankit',
                 password='******',
                 user_age='35',
                 user_weight='180',
                 user_zipcode='48076')
    lily = User(user_name='lily',
                password='******',
                user_age='16',
                user_weight='25',
                user_zipcode='75201')
    riley = User(user_name='riley',
                 password='******',
                 user_age='101',
                 user_weight='100',
                 user_zipcode='48076')

    db.session.add_all([jess, ankit, lily, riley])
    db.session.commit()

    kb_swing = Exercise(exercise_name='kb_swing',
                        exercise_info='two handed grip and hinge at hips')
    squat = Exercise(
        exercise_name='squat',
        exercise_info='spine straight drive through heels bend at knees')
    crunch = Exercise(
        exercise_name='crunch',
        exercise_info='lay on back on the floor lift shoulders off ground')
    boat_row = Exercise(exercise_name='boat_row',
                        exercise_info='row row row the boat')

    db.session.add_all([kb_swing, squat, crunch, boat_row])
    db.session.commit()

    jess_wrkt = Workout(user_id=jess.user_id,
                        workout_name='Monday',
                        workout_date=datetime.now())
    ankit_wrkt = Workout(user_id=ankit.user_id,
                         workout_name='Tuesday',
                         workout_date=datetime.now())
    lily_wrkt = Workout(user_id=lily.user_id,
                        workout_name='Wednesday',
                        workout_date=datetime.now())
    riley_wrkt = Workout(user_id=riley.user_id,
                         workout_name='Thursday',
                         workout_date=datetime.now())

    db.session.add_all([jess_wrkt, ankit_wrkt, lily_wrkt, riley_wrkt])
    db.session.commit()

    wrkt_kb = Workout_exercise(workout_id=jess_wrkt.workout_id,
                               exercise_id=kb_swing.exercise_id,
                               we_sets=3,
                               we_reps=20,
                               we_repunit='repetitions',
                               we_weight=10,
                               we_weightunit='lb',
                               we_equipment='kettlebell')

    wrkt_squat = Workout_exercise(workout_id=ankit_wrkt.workout_id,
                                  exercise_id=squat.exercise_id,
                                  we_sets=5,
                                  we_reps=30,
                                  we_repunit='seconds',
                                  we_weight=1,
                                  we_weightunit='bodyweight',
                                  we_equipment='none')

    wrkt_crunch = Workout_exercise(workout_id=lily_wrkt.workout_id,
                                   exercise_id=crunch.exercise_id,
                                   we_sets=3,
                                   we_reps=30,
                                   we_repunit='until failure',
                                   we_weight=5,
                                   we_weightunit='lb',
                                   we_equipment='swiss ball')

    wrkt_boat_row = Workout_exercise(workout_id=riley_wrkt.workout_id,
                                     exercise_id=boat_row.exercise_id,
                                     we_sets=1,
                                     we_reps=60,
                                     we_repunit='minutes',
                                     we_weight=1,
                                     we_weightunit='bodyweight',
                                     we_equipment='row machine')

    db.session.add_all([wrkt_kb, wrkt_squat, wrkt_crunch, wrkt_boat_row])
    db.session.commit()
Esempio n. 13
0
 def _query_object(self, criteria, cursor):
     cursor.execute(self.__sql_query_by_uk, criteria)
     rec = cursor.fetchone()
     if rec:
         return Exercise(**rec)