1 from django
.shortcuts
import render
2 from meta
.models
import TournamentModel
3 from mlpccg
.CardDb
import CARDDB
4 from mlpccg
.DeckList
import DeckList
5 from mlpccg
.Clustering
import Clustering
8 tournament_models
= TournamentModel
.objects
.all().order_by('-date')
11 for tournament
in tournament_models
:
12 tournament_records
= tournament
.recordmodel_set
.all().order_by('placement')
14 for record
in tournament_records
:
15 decklist
= DeckList(name
=record
.decklist
.name
, url
=record
.decklist
.url
)
16 tournament_decks
+= [decklist
]
17 if len(decklist
.cards
) > 0:
18 placements
+= [{'decklist': decklist
, 'placement': record
.placement
}]
20 tournament_data
+= [{'tournament': tournament
, 'decklists': tournament_decks
}]
22 clustering
= Clustering(records
=placements
)
23 ranking
= [(int(avg
), label
, [decklist
for decklist
in clustering
.clusters
[label
]]) for avg
, label
in clustering
.ranking()]
25 return render(request
, 'index.html', {
27 'tournaments': tournament_data
})