Example #1
0
    def get(request):
        sql_param = ''
        platform_in = extractInParams(request, 'platform', 'platform__in')
        token_in = extractInParams(request, 'token', 'token__in')
        startIndex, endIndex = limitOffsetParams(request)
        if platform_in:
            sql_param = 'AND ( '
            sql_param += sqlGenerateOrList('fulfillment.\"platform\"',
                                           len(platform_in), '=')
            sql_param += ' OR '
            sql_param += sqlGenerateOrList('bounty.\"platform\"',
                                           len(platform_in), '=')
            sql_param += ' )'
        platform_in = platform_in + platform_in
        if token_in:
            sql_param += 'AND ( '
            sql_param += "bounty.\"token_contract\" = \'"
            sql_param += token_in[0]
            sql_param += "\')"
            formatted_query = LEADERBOARD_FULFILLER_QUERY_TOKENS.format(
                sql_param)
        else:
            formatted_query = LEADERBOARD_FULFILLER_QUERY.format(sql_param)

        cursor = connection.cursor()
        cursor.execute(formatted_query, platform_in)
        query_result = dictfetchall(cursor)
        narrowed_result = query_result[startIndex:endIndex]
        serializer = LeaderboardFulfillerSerializer(narrowed_result, many=True)
        return JsonResponse(
            {
                'count': len(query_result),
                'results': serializer.data
            },
            safe=False)
Example #2
0
 def get(self, request, address=''):
     bounty_stats = {}
     extra_filters_bounty = {}
     extra_filters_fulfillment = {}
     platform_in = extractInParams(request, 'platform', 'platform__in')
     if platform_in:
         extra_filters_bounty['platform__in'] = platform_in
         extra_filters_fulfillment['platform__in'] = platform_in
     user_bounties = Bounty.objects.filter(issuer=address.lower(),
                                           **extra_filters_bounty)
     for stage in STAGE_CHOICES:
         bounty_stats[stage[1]] = user_bounties.filter(
             bountyStage=stage[0]).count()
     bounties_count = user_bounties.count()
     bounties_accepted_count = user_bounties.filter(
         fulfillments__accepted=True).count()
     bounties_acceptance_rate = bounties_accepted_count / \
         bounties_count if bounties_accepted_count > 0 else 0
     user_submissions = Fulfillment.objects.filter(
         fulfiller=address, **extra_filters_fulfillment)
     submissions_count = user_submissions.count()
     submissions_accepted_count = user_submissions.filter(
         accepted=True).count()
     submissions_acceptance_rate = submissions_accepted_count / \
         submissions_count if submissions_count > 0 else 0
     profile_stats = {
         'bounties': bounties_count,
         'bounties_accepted': bounties_accepted_count,
         'bounties_acceptance_rate': bounties_acceptance_rate,
         'submissions': submissions_count,
         'submissions_accepted_count': submissions_accepted_count,
         'submissions_acceptance_rate': submissions_acceptance_rate,
     }
     return JsonResponse({**bounty_stats, **profile_stats})
Example #3
0
    def get(self, request, address=''):
        platform_in = extractInParams(request, 'platform', 'platform__in')
        extra_filters = {}
        if platform_in:
            extra_filters['platform__in'] = platform_in
        ordered_fulfillments = Fulfillment.objects.filter(
            fulfiller=address.lower(), **extra_filters).order_by('-created')
        if not ordered_fulfillments.exists():
            raise Http404("Address does not exist")

        latest_fulfillment = ordered_fulfillments[0]
        user_profile = {
            "address": address,
            "name": latest_fulfillment.fulfiller_name,
            "email": latest_fulfillment.fulfiller_email,
            "githubUsername": latest_fulfillment.fulfiller_githubUsername,
        }
        return JsonResponse(user_profile)
Example #4
0
    def get(self, request):
        sql_param = ''
        platform_in = extractInParams(request, 'platform', 'platform__in')
        if platform_in:
            sql_param = 'AND ( '
            sql_param += sqlGenerateOrList('fulfillment.\"platform\"',
                                           len(platform_in), '=')
            sql_param += ' OR '
            sql_param += sqlGenerateOrList('bounty.\"platform\"',
                                           len(platform_in), '=')
            sql_param += ' )'
        platform_in = platform_in + platform_in

        formatted_query = LEADERBOARD_QUERY.format(sql_param)
        cursor = connection.cursor()
        cursor.execute(formatted_query, platform_in)
        query_result = dictfetchall(cursor)
        serializer = LeaderboardSerializer(query_result, many=True)
        return JsonResponse(serializer.data, safe=False)
Example #5
0
    def get(self, request):
        sql_param = ''
        platform_in = extractInParams(request, 'platform', 'platform__in')
        startIndex, endIndex = limitOffsetParams(request)
        if platform_in:
            sql_param = 'AND ( '
            sql_param += sqlGenerateOrList(
                'fulfillment.\'platform\'', len(platform_in), '=')
            sql_param += ' OR '
            sql_param += sqlGenerateOrList('bounty.\'platform\'',
                                           len(platform_in), '=')
            sql_param += ' )'
        platform_in = platform_in + platform_in

        formatted_query = LEADERBOARD_ISSUER_QUERY.format(sql_param)
        cursor = connection.cursor()
        cursor.execute(formatted_query, platform_in)
        query_result = dictfetchall(cursor)
        narrowed_result = query_result[startIndex: endIndex]
        serializer = LeaderboardIssuerSerializer(narrowed_result, many=True)
        return JsonResponse({'count': len(query_result), 'results': serializer.data}, safe=False)