Beispiel #1
0
    def setUp(self):
        super().setUp()
        self.test_client.post('/api/register', json={'username': '******', 'password': '******'})
        self.token = self.test_client.get('/api/token',
                                          headers={'Authorization': b'Basic ' + b64encode(b'test:pass')}) \
                                     .json.get('token')

        for ex in ['exercise1', 'exercise2', 'exercise3']:
            db.session.add(Exercise(exercise_name=ex))
        db.session.commit()

        json1 = {"date" : "2019-05-31",
                 "exercises" : [{"exercise name" : "exercise1", "reps": [8, 8, 8], "weights": [100, 100, 100]},
                                {"exercise name" : "exercise2", "reps": [6, 5], "weights": [100, 100]},
                                {"exercise name" : "exercise3", "reps": [12, 10, 8, 6], "weights": [120, 100, 80, 60]}]}

        json2 = {"date" : "2019-06-30",
                 "exercises" : [{"exercise name" : "exercise1", "reps": [8, 8, 8], "weights": [100, 100, 100]},
                                {"exercise name" : "exercise3", "reps": [12, 10, 8], "weights": [120, 80, 60]}]}

        json3 = {"date" : "2019-07-31",
                 "exercises" : [{"exercise name" : "exercise1", "reps": [8, 8, 8], "weights": [100, 100, 100]},
                                {"exercise name" : "exercise2", "reps": [8, 7, 6], "weights": [100, 110, 120]}]}

        response = self.test_client.post('/api/sessions', headers={'Authorization': 'Bearer ' + self.token}, json=json1)
        response = self.test_client.post('/api/sessions', headers={'Authorization': 'Bearer ' + self.token}, json=json2)
        response = self.test_client.post('/api/sessions', headers={'Authorization': 'Bearer ' + self.token}, json=json3)
Beispiel #2
0
def can_send_solution(exercise: Exercise, sorted_solutions: List[Solution]) -> bool:
    solutions_amount = len(sorted_solutions)
    if exercise.is_finished() or solutions_amount >= exercise.max_attempts:
        return False
    if solutions_amount == 0:
        return True
    else:
        last_solution = sorted_solutions[0]
        second_difference = (get_current_date() - get_offset_aware(last_solution.send_date)).seconds
        return second_difference > last_solution.exercise.interval
def json_to_workout_obj(json_workout):
    new_workout = Workout()
    if json_workout["name"] is not None:
        new_workout.name = json_workout["name"]
    else:
        new_workout.name = "Çalışma Programı"

    for day in json_workout["days"]:
        daily_exercises = []
        for exercise in day:
            new_exercise = Exercise()
            new_exercise.exercise_id = ExerciseTemplate.objects(
                id=exercise["exercise"]).first()
            new_exercise.sets = int(exercise["sets"])
            new_exercise.reps = int(exercise["reps"])
            daily_exercises.append(new_exercise)
        new_workout.days.append(daily_exercises)

    new_workout.save()
    return new_workout
    def setUp(self):
        super().setUp()
        self.test_client.post('/api/register',
                              json={
                                  'username': '******',
                                  'password': '******'
                              })
        self.token = self.test_client.get('/api/token',
                                          headers={'Authorization': b'Basic ' + b64encode(b'test:pass')}) \
                                     .json.get('token')

        for ex in ['exercise1', 'exercise2', 'exercise3']:
            db.session.add(Exercise(exercise_name=ex))
        db.session.commit()
def create_exercise():
    request_body = request.json
    id_ejercicio = request_body['id_ejercicio']
    id_tipo_ejercicio = request_body['id_tipo_ejercicio']
    nombre_ejercicio = request_body['nombre_ejercicio']
    dsc_ejercicio = request_body['dsc_ejercicio']
    exercise = Exercise(id_ejercicio=id_ejercicio,
                        id_tipo_ejercicio=id_tipo_ejercicio,
                        nombre_ejercicio=nombre_ejercicio,
                        dsc_ejercicio=dsc_ejercicio)
    try:
        exercise_service.save_exercise(exercise)
        response = json.dumps({"Message": "Creado satisfactoriamente"}), 200
        return response
    except Exception as e:
        print('Error:', e)
        raise e
Beispiel #6
0
def create_exercise_table():
    """Заполняет справочник упражнений из csv файла
    вначале обнуляет все данные по занесенным соревнования и
     потом перезаписывает справочник"""
    db.session.query(ExerciseData).delete()
    db.session.query(EventsData).delete()
    db.session.query(Exercise).delete()

    db.session.commit()
    with open('app/res/exercisetable.csv', newline='',
              encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile, delimiter=";")
        for row in reader:
            # print(row.keys())
            # print(row['id_static'])
            dist = []
            dist.append(row['distance1'])
            dist.append(row['distance2'])
            rank_values = []
            rank_values.append(row['msmk_m'])
            rank_values.append(row['msmk_f'])
            rank_values.append(row['ms_m'])
            rank_values.append(row['ms_f'])
            rank_values.append(row['kms_m'])
            rank_values.append(row['kms_f'])
            rank_values.append(row['1_m'])
            rank_values.append(row['1_f'])
            rank_values.append(row['2_m'])
            rank_values.append(row['2_f'])
            rank_values.append(row['3_f'])
            rank_values.append(row['3_f'])
            new_base_node = Exercise(ExerciseID=row['id'],
                                     name=row['name'],
                                     name_gun=row['name_gun'],
                                     dist=dist,
                                     series=row['series'],
                                     total_shoot=row['total_shoot'],
                                     caption=row['caption'],
                                     measure=row['measure'],
                                     rank_values=rank_values)
            db.session.add(new_base_node)
    db.session.commit()
Beispiel #7
0
    def post(self):
        # validate JSON data
        parser = reqparse.RequestParser()
        parser.add_argument('exercises',
                            type=self.parse_exercises,
                            required=True,
                            case_sensitive=False,
                            location='json')
        exercises = parser.parse_args(strict=True)['exercises']

        # return 409 if content duplicated
        for exercise in exercises:
            if db.session \
                 .query(Exercise) \
                 .filter_by(exercise_name = exercise) \
                 .first() is not None:
                abort(409)

        # create new Exercise object
        for exercise_name in exercises:
            db.session.add(Exercise(exercise_name=exercise_name))
        db.session.commit()

        return exercises, 201
Beispiel #8
0
 def __init__(self, exercise: Exercise, points: float):
     self.exercise = exercise
     self.points = points
     self.course = exercise.get_course()
     self.lesson = exercise.lesson
     self.max_points = exercise.get_max_points()
Beispiel #9
0
 def __init__(self, exercise_name):
     super().__init__()
     self.object = Exercise(exercise_name=exercise_name)
Beispiel #10
0
def validate_exercise_student(member: Member, required_role: str,
                              exercise: Exercise):
    validate_exists(exercise)
    validate_course(member, required_role, exercise.get_course())
    if not exercise.is_published:
        abort(404)
Beispiel #11
0
def validate_exercise_teacher(member: Member, required_role: str,
                              exercise: Exercise):
    validate_exists(exercise)
    validate_course(member, required_role, exercise.get_course())