Collapse Results into a single object
This commit is contained in:
1 parent
329a955042
commit
6f3a0fc4c3
2 files changed
+30
-4
No files matched your search
+27
-1
@@ -403,9 +403,35 @@ def test(request, id, action=None):
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
if action not in ['APPROVE', 'RESTART', 'STOP', 'DELETE', 'MODIFY']:
|
||||
|
||||
# Select the Test, and all Result objects attached
|
||||
test = Test.objects.get(id=id)
|
||||
results = Result.objects.filter(test=test).order_by('machine_id')
|
||||
data = {'test' : test, 'results': results}
|
||||
data = { 'test' : test, 'results': {} }
|
||||
|
||||
for result in results:
|
||||
|
||||
# Insert the Result into the results
|
||||
if result.machine.id not in data['results'].keys():
|
||||
data['results'][result.machine.id] = {
|
||||
'games' : 0, 'wins' : 0,
|
||||
'losses' : 0, 'draws' : 0,
|
||||
'timeloss' : 0, 'crashes' : 0,
|
||||
}
|
||||
|
||||
# Always use the latest Time stamp, by virtue of sorting Results
|
||||
data['results'][result.machine.id]['machine_id'] = result.machine.id
|
||||
data['results'][result.machine.id]['username' ] = result.machine.user.username
|
||||
data['results'][result.machine.id]['updated' ] = result.updated
|
||||
|
||||
# Sum up all results from a given machine into a single value
|
||||
data['results'][result.machine.id]['games' ] += result.games
|
||||
data['results'][result.machine.id]['wins' ] += result.wins
|
||||
data['results'][result.machine.id]['losses' ] += result.losses
|
||||
data['results'][result.machine.id]['draws' ] += result.draws
|
||||
data['results'][result.machine.id]['timeloss' ] += result.timeloss
|
||||
data['results'][result.machine.id]['crashes' ] += result.crashes
|
||||
|
||||
return render(request, 'test.html', data)
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
|
||||
@@ -164,10 +164,10 @@
|
||||
<th style="width: 60px">Crash</th>
|
||||
</tr>
|
||||
|
||||
{% for result in results %}
|
||||
{% for id, result in results.items %}
|
||||
<tr>
|
||||
<td>{{result.machine.id}}</td>
|
||||
<td>{{result.machine.user.username|capfirst|slice:"6"}}</td>
|
||||
<td>{{result.machine_id}}</td>
|
||||
<td>{{result.username|capfirst|slice:"6"}}</td>
|
||||
<td class="timestamp">{{result.updated|date:'U'}}</td>
|
||||
<td class="numeric">{{result.games}}</td>
|
||||
<td class="numeric">{{result.wins}}</td>
|
||||
|
||||
Reference in new issue
Block a user