Exemple #1
0
    def get(self, request, format=None):
        practice = Practice.objects.create(user=request.user,
                                           practice_type=self.practice_type)

        dist_list = pick_standard_putts()
        trajectory_list = TrajectoryValueRange.objects.filter(type='putting')
        # shape_list = ShotImage.objects.all()

        shot_list = []

        for dist in dist_list:
            shot = Shot(shape=None,
                        dist=dist,
                        aim=None,
                        traj=random.choice(trajectory_list))

            shot_list.append(shot)

        serializer = ShotSerializer(shot_list,
                                    many=True,
                                    practice_type=self.practice_type)

        return Response(
            OrderedDict([("practice_id", practice.id),
                         ("practice_type", self.practice_type),
                         ("shots", serializer.data)]))
Exemple #2
0
    def get(self, request, *args, **kwargs):
        practice = self.get_practice_obj(request, *args, **kwargs)
        if practice is None:
            return Response({'error': 'Invalid Practice'},
                            status=status.HTTP_400_BAD_REQUEST)

        dist_list = pick_random_distances(putting=True, practice=practice)
        trajectory_list = TrajectoryValueRange.objects.filter(type='putting')
        # shape_list = ShotImage.objects.all()

        shot_list = []

        for dist in dist_list:
            shot = Shot(shape=None,
                        dist=dist,
                        aim=None,
                        traj=random.choice(trajectory_list))

            shot_list.append(shot)

        serializer = ShotSerializer(shot_list,
                                    many=True,
                                    practice_type=self.practice_type)

        return Response(
            OrderedDict([("practice_id", practice.id),
                         ("practice_type", self.practice_type),
                         ("shots", serializer.data)]))
Exemple #3
0
    def get(self, request, format=None):
        warmup_practice = random.choice(WARMUP_PRACTICE_LIST)

        shot_list = []

        for shot in warmup_practice:
            # dist
            dist = shot.get('dist')
            if dist == 'Driver':
                dist = request.user.longest_distance
            # aim & shape
            aim = None
            shape = None

            aim_name = shot.get('aim', None)
            if aim_name is not None:
                try:
                    aim = AimValueRange.objects.get(description=aim_name)
                    if dist >= settings.DIST_FOR_SHAPE:
                        try:
                            if aim.is_draw:
                                shape = ShotImage.objects.get(name='draw')
                            elif aim.is_straight:
                                shape = ShotImage.objects.get(name='straight')
                            elif aim.is_fade:
                                shape = ShotImage.objects.get(name='fade')
                            else:
                                shape = None

                        except ShotImage.DoesNotExist:
                            pass
                except AimValueRange.DoesNotExist:
                    pass
            # traj
            traj = None
            traj_name = shot.get('traj', None)

            if traj_name is not None:
                try:
                    traj = TrajectoryValueRange.objects.get(
                        description=traj_name, type='long')
                except TrajectoryValueRange.DoesNotExist:
                    pass

            # make shot object
            shot = Shot(shape=shape, dist=dist, aim=aim, traj=traj)
            shot_list.append(shot)

        # make serialiser
        serializer = ShotSerializer(shot_list,
                                    many=True,
                                    practice_type=self.practice_type)

        return Response(
            OrderedDict([("practice_id", -1),
                         ("practice_type", self.practice_type),
                         ("shots", serializer.data)]))
Exemple #4
0
def make_fullswing_shots(dist_list, practice_type):
    """
    :param dist_list:
    :param practice_type:
    :return: shotserializer
    """
    aim_list = AimValueRange.objects.all()
    trajectory_list = TrajectoryValueRange.objects.filter(type='long')

    shot_list = []

    for dist in dist_list:

        if dist >= settings.DIST_FOR_SHAPE:
            aim = random.choice(aim_list)
            traj = random.choice(trajectory_list)

            try:
                if aim.is_draw:
                    shape = ShotImage.objects.get(name='draw')
                elif aim.is_straight:
                    shape = ShotImage.objects.get(name='straight')
                elif aim.is_fade:
                    shape = ShotImage.objects.get(name='fade')
                else:
                    shape = None

            except ShotImage.DoesNotExist:
                shape = None

        else:
            shape = None
            aim = None
            traj = None

        shot = Shot(shape=shape, dist=dist, aim=aim, traj=traj)

        shot_list.append(shot)

    serializer = ShotSerializer(shot_list,
                                many=True,
                                practice_type=practice_type)
    return serializer
Exemple #5
0
    def post(self, request, *args, **kwargs):
        serializer = CustomPuttingSerializer(data=request.data,
                                             user=self.request.user)

        # Check format and unique constraint
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        practice = self.get_practice_obj(request, *args, **kwargs)
        if practice is None:
            return Response({'error': 'Invalid Practice'},
                            status=status.HTTP_400_BAD_REQUEST)

        if practice.min_dist is None:
            practice.min_dist = serializer.validated_data['min_dist']
            practice.max_dist = serializer.validated_data['max_dist']
            practice.save()

        dist_list = pick_custom_distances(
            serializer.validated_data['min_dist'],
            serializer.validated_data['max_dist'])
        trajectory_list = TrajectoryValueRange.objects.filter(type='putting')

        shot_list = []

        for dist in dist_list:
            shot = Shot(shape=None,
                        dist=dist,
                        aim=None,
                        traj=random.choice(trajectory_list))

            shot_list.append(shot)

        serializer = ShotSerializer(shot_list,
                                    many=True,
                                    practice_type=self.practice_type)

        return Response(
            OrderedDict([("practice_id", practice.id),
                         ("practice_type", self.practice_type),
                         ("shots", serializer.data)]))
Exemple #6
0
    def get(self, request, *args, **kwargs):
        practice = self.get_practice_obj(request, *args, **kwargs)
        if practice is None:
            return Response({'error': 'Invalid Practice'},
                            status=status.HTTP_400_BAD_REQUEST)

        dist_list = pick_chip_distances()
        chip_traj = TrajectoryValueRange.objects.get(type='chip')

        shot_list = []

        for dist in dist_list:
            shot = Shot(shape=None, dist=dist, aim=None, traj=chip_traj)
            shot_list.append(shot)

        serializer = ShotSerializer(shot_list,
                                    many=True,
                                    practice_type=self.practice_type)

        return Response(
            OrderedDict([("practice_id", practice.id),
                         ("practice_type", self.practice_type),
                         ("shots", serializer.data)]))