Beispiel #1
0
 def get_queryset(self, *args, **kwargs):
     username = self.kwargs['username']
     requested_user = get_object_or_404(User, username=username)
     permission = is_owner_or_friend(self.request, username)
     self._check_failed_vsource(requested_user)
     self.queryset = Session.objects.filter(user=requested_user)
     return self.queryset.order_by("-timestamp")
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     username = self.kwargs['username']
     requested_user = get_object_or_404(User, username=username)
     permission = is_owner_or_friend(self.request, username)
     self._check_failed_videos(requested_user)
     player_profile = {}
     player_profile['user'] = username
     player_profile['lastchange'] = requested_user.userprofile.last_change
     player_profile['shot_count'] = requested_user.shots.count()
     player_profile['videoshot_count'] = requested_user.videoshots.count()
     player_profile['recording_count'] = requested_user.videos.count()
     player_profile['collection_count'] = requested_user.collections.count()
     player_profile['periods'] = {}
     player_profile['periods']['session'] = requested_user.sessions.all(
     ).order_by('-timestamp')
     player_profile['periods']['week'] = requested_user.weeks.all(
     ).order_by('-timestamp')
     player_profile['periods']['month'] = requested_user.months.all(
     ).order_by('-timestamp')
     player_profile['periods']['year'] = requested_user.years.all(
     ).order_by('-timestamp')
     player_profile['collections'] = requested_user.collections.all(
     ).order_by('-timestamp')
     player_profile['labels'] = requested_user.labels.all().order_by(
         'category')
     serializer = PlayerProfileSerializer(player_profile)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #3
0
 def get_queryset(self, *args, **kwargs):
     username = self.kwargs['username']
     requested_user = get_object_or_404(User, username=username)
     permission = is_owner_or_friend(self.request, username)
     model_class = _str_to_periodmodel(self.kwargs['period'])
     period_obj = _url_to_object(requested_user, **self.kwargs)
     queryset = period_obj.shots.all()
     return queryset
Beispiel #4
0
 def get(self, request, *args, **kwargs):
     progress_dict = {}
     requested_user = get_object_or_404(User, username=kwargs['username'])
     permission = is_owner_or_friend(request, kwargs['username'])
     period_model = str_to_periodmodel(kwargs['period'])
     periods = period_model.objects.filter(user=requested_user)
     imperial_units = request.user.userprofile.units == 'M'
     for stat in ['swing_speed', 'ball_speed', 'ball_spin']:
         progress_dict[stat] = (str.encode('data:image/svg+xml;base64,') +
                                box_plot(periods, stat, kwargs['swing'],
                                         imperial_units)).decode("utf-8")
     serializer = SonyProgressSerializer(progress_dict)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #5
0
    def get(self, request, *args, **kwargs):
        username = self.kwargs['username']
        requested_user = get_object_or_404(User, username=username)
        permission = is_owner_or_friend(self.request, username)
        summary = {}
        summary['user'] = username
        if requested_user.shots.count() == 0:
            last_week = requested_user
        else:
            last_week = requested_user.weeks.latest(field_name='timestamp')
        for swing in ['FH', 'BH', 'FS', 'BS', 'FV', 'BV', 'SE', 'SM']:
            summary[swing] = {}
            shots = requested_user.shots.filter(data__swing_type=swing)
            week_shots = last_week.shots.filter(data__swing_type=swing)
            count_week = week_shots.count()
            count_overall = shots.count()
            summary[swing]['count_overall'] = count_overall
            summary[swing]['count_week'] = count_week
            if swing in ['FH', 'BH', 'SE']:
                percentiles = [50, 75, 90, 100]
                percentiles_overall = [-1, -1, -1, -1]
                percentiles_week = [-1, -1, -1, -1]
                if count_overall > 0:
                    percentiles_overall = np.percentile(
                        shots.values_list('data__ball_speed', flat=True),
                        percentiles)
                    if count_week > 0:
                        percentiles_week = np.percentile(
                            week_shots.values_list('data__ball_speed',
                                                   flat=True), percentiles)
                summary[swing]['percentiles_overall'] = percentiles_overall
                summary[swing]['percentiles_week'] = percentiles_week

        #for swing, threshold in zip(['FH', 'BH', 'SE'],[105,105,145]):
        #    summary[swing]['fastest_overall'] = -1
        #    summary[swing]['fastest_week'] = -1
        #    summary[swing]['above_overall'] = -1
        #    summary[swing]['above_week'] = -1
        #    shots = requested_user.shots.filter(data__swing_type=swing)
        #    week_shots = last_week.shots.filter(data__swing_type=swing)
        #    if (shots.count() > 0):
        #        summary[swing]['fastest_overall'] = max(shots.values_list('data__swing_speed', flat=True))
        #        summary[swing]['above_overall'] = shots.filter(data__swing_speed__gte=threshold).count()
        #        if (week_shots.count() > 0):
        #            summary[swing]['fastest_week'] = max(week_shots.values_list('data__swing_speed', flat=True))
        #            summary[swing]['above_week'] = week_shots.filter(data__swing_speed__gte=threshold).count()

        serializer = SummarySerializer(summary)
        return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #6
0
 def get_queryset(self, *args, **kwargs):
     permission = is_owner_or_friend(self.request, self.kwargs['username'])
     queryset = SessionLabel.objects.filter(
         user__username=self.kwargs['username'])
     return queryset.order_by("category")
Beispiel #7
0
 def get_queryset(self, filter_serializer, *args, **kwargs):
     username = filter_serializer.validated_data['username']
     requested_user = get_object_or_404(User, username=username)
     permission = is_owner_or_friend(self.request, username)
     queryset = apply_sonyfilter(filter_serializer.validated_data)
     return queryset