当玩家得分相同时提供相同的等级

2024-03-29 06:25:43 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我第一次在这里发帖。如果我遗漏了什么,请告诉我

我试图创建一个表,为玩家提供个人的等级。我正在努力的一件事是,如果球员得分相同,他们应该拥有相同的排名。当前代码显示得分相同或不同的玩家的排名。。。(例如,排名1和2)。我尝试了在这个网站上找到的几种方法,但我无法正确地显示。。。有人知道吗

我使用以下代码调用数据:

rpi = self.get_rpi()
rpi.sort(key=lambda x: x['rpis'], reverse=True)
goals = self.get_goal()
ranks = []
index = 1
for  rpis in rpi:
ranks.append({'id': rpis['id'], 'rpis': rpis['rpis'], 'rank': index})
index = index + 1
ranks.sort(key=lambda x: x['id'], reverse=False)   
index = 0;
newRanks = []
for goal in goals:
newRanks.append({'id': ranks[index]['id'], 'rank': ranks[index]['rank'], 'goal': goal['goals']})
index = index + 1
return newRanks

然后,我使用下面的代码创建一个表:

<table class="table mb-2">
<thead>
    <tr>
        <th scope="col">Participant No.</th>
        <th scope="col" class="text-center">Goal</th>
        <th scope="col" class="text-center">Performance Rank</th>
    </tr>
</thead>
<tbody>
    {% for item in player.get_ranks %}
    <tr>
        <td>
        {% if player.id_in_group == item.id %}
            Participant {{item.id}} (You)
        {% else %}
            Participant {{item.id}}
        {% endif %}
        
        </td>
        <td class=text-center>{{item.goal}}</td>
        <td class="text-center">{{item.rank}}</td>
    </tr>
    {% endfor %}
</tbody>

先谢谢你


Tags: textinidindexitemrpitrclass