Example #1
0
def users_cities(request):
    achievement_id = int(request.matchdict["achievement_id"])
    cities = User.sort("City")
    res_cities = []
    res_cities = np.asarray(cities)
    result = []
    for i in range(len(res_cities)):
        relevance = {'type': 'City', 'value': res_cities[i][0]}
        result.append({
            'City':
            res_cities[i][0],
            'Leaderboard':
            Achievement.get_leaderbord_by_relevance(achievement_id, relevance)
        })
    return result
Example #2
0
def leaderboard(request):
    params = request.GET
    achievement_id = params["id"]
    sorted_by = {"type": "Global"}
    achievement = Achievement.get_achievement(achievement_id)
    if request.method == 'POST':
        if ('sorted_value' in request.POST):
            sorted_by["type"] = params["type"]
            sorted_by.update({'value': request.POST['sorted_value']})
            result = Achievement.get_leaderbord_by_relevance(
                achievement_id, sorted_by)
            header_table = []
            for key, value in result[0]["user"][
                    "additional_public_data"].items():
                header_table.append(key)
            return {
                'header_table': header_table,
                'result': result,
                'winner': result[0],
                'params': params,
                'sorted_by': sorted_by["type"],
                'achievement': achievement,
                'sorted_value': request.POST['sorted_value']
            }
        elif ('sorted_by' in request.POST):
            sorted_by["type"] = request.POST['sorted_by']
            params.update({'type': request.POST['sorted_by']})
            if sorted_by["type"] == 'Global':
                result = Achievement.get_leaderbord_by_achievement(
                    achievement_id)
                header_table = []
                for key, value in result[0]["user"][
                        "additional_public_data"].items():
                    header_table.append(key)
                return {
                    'header_table': header_table,
                    'result': result,
                    'winner': result[0],
                    'params': params,
                    'sorted_by': sorted_by["type"],
                    'achievement': achievement
                }
            else:
                sort_res = User.sort(sorted_by["type"])
                myarray = []
                myarray = np.asarray(sort_res)
                result = Achievement.get_leaderbord_by_achievement(
                    achievement_id)
                header_table = []
                for key, value in result[0]["user"][
                        "additional_public_data"].items():
                    header_table.append(key)
                return {
                    'header_table': header_table,
                    'result': result,
                    'winner': result[0],
                    'exist': sort_res,
                    'sort_res': myarray,
                    'params': params,
                    'sorted_by': sorted_by["type"],
                    'achievement': achievement
                }
    else:
        result = Achievement.get_leaderbord_by_achievement(achievement_id)
        header_table = []
        for key, value in result[0]["user"]["additional_public_data"].items():
            header_table.append(key)
        return {
            'header_table': header_table,
            'result': result,
            'winner': result[0],
            'params': params,
            'sorted_by': sorted_by["type"],
            'achievement': achievement
        }