コード例 #1
0
    def most_location_wins_for_top_team(self, request):
        __doc__ = "Which location has the most number of wins for the top team"

        if not request.data.get('season', None):
            return Response({"message": "Season is missing"},
                            status=status.HTTP_400_BAD_REQUEST)

        queryset = Match.get_most_location_wins_for_top_team(
            season=request.data.get('season'), limit=1)
        serializer_data = MatchSerializer(queryset, many=True)
        return Response(serializer_data.data, status=status.HTTP_200_OK)
コード例 #2
0
    def most_matches_hosted_location(self, request):
        __doc__ = "Which team won the most number of tosses in the season"

        if not request.data.get('season', None):
            return Response({"message": "Season is missing"},
                            status=status.HTTP_400_BAD_REQUEST)

        limit = int(request.data.get('limit', 1))

        queryset = Match.get_most_matches_hosted_location(
            season=request.data.get('season'), limit=limit)
        serializer_data = MatchSerializer(queryset, many=True)
        return Response(serializer_data.data, status=status.HTTP_200_OK)
コード例 #3
0
    def most_mom_wins(self, request):
        __doc__ = "Which player won the maximum number of Player of the Match awards in the whole season"

        if not request.data.get('season', None):
            return Response({"message": "Season is missing"},
                            status=status.HTTP_400_BAD_REQUEST)

        limit = int(request.data.get('limit', 1))

        queryset = Match.get_most_mom_wins(season=request.data.get('season'),
                                           limit=limit)
        serializer_data = MatchSerializer(queryset, many=True)
        return Response(serializer_data.data, status=status.HTTP_200_OK)
コード例 #4
0
    def handle(self, *args, **kwargs):
        Match.objects.all().delete()
        matches_data = pd.read_csv("data/matches.csv").to_dict('records')
        match_generator = (Match(**m) for m in matches_data)
        Match.objects.bulk_create(match_generator, batch_size=200)

        print("Matches created")

        Delivery.objects.all().delete()
        deliveries_data = pd.read_csv("data/deliveries.csv").to_dict('records')
        deliveries_generator = (Delivery(**m) for m in deliveries_data)
        Delivery.objects.bulk_create(deliveries_generator, batch_size=200)

        print("Deliveries created")
コード例 #5
0
    def most_wins(self, request):
        __doc__ = "Top 4 teams in terms of wins & Which team won max matches in the whole season"

        if not request.data.get('season', None):
            return Response({"message": "Season is missing"},
                            status=status.HTTP_400_BAD_REQUEST)

        limit = int(request.data.get('limit', 1))

        queryset = Match.get_most_wins(season=request.data.get('season'),
                                       limit=limit)

        serializer_data = MatchSerializer(queryset, many=True)

        return Response(serializer_data.data, status=status.HTTP_200_OK)
コード例 #6
0
    def bat_first_per(self, request):
        __doc__ = "Which location has the most number of wins for the top team"

        if not request.data.get('season', None):
            return Response({"message": "Season is missing"},
                            status=status.HTTP_400_BAD_REQUEST)

        queryset = Match.get_toss_decisions(season=request.data.get('season'))

        batting_win_count = 0
        total_count = 0
        for d in queryset:
            if d['toss_decision'] == 'bat':
                batting_win_count = d['toss_counts']
            total_count += d['toss_counts']

        bat_first_win_per = batting_win_count / total_count * 100

        return Response({"bat_first_win_percentage": bat_first_win_per},
                        status=status.HTTP_200_OK)