47 lines
1.7 KiB
Python
Executable file
47 lines
1.7 KiB
Python
Executable file
from django.http import Http404
|
|
from django.shortcuts import render_to_response
|
|
from mtgweb.analyzer.models import Deck
|
|
from mtgweb.lib.mtg import mtg
|
|
from pygooglechart import PieChart3D
|
|
|
|
def index(request):
|
|
decks = Deck.objects.all()
|
|
return render_to_response('decks/index.html', {'decks': decks})
|
|
def detail(request, id):
|
|
try:
|
|
deck = Deck.objects.get(pk=id)
|
|
except Deck.DoesNotExist:
|
|
raise Http404
|
|
|
|
# Generate charts
|
|
colors = {
|
|
'R': 'FF0000',
|
|
'G': '00FF00',
|
|
'U': '0000FF',
|
|
'W': 'FFFFFF',
|
|
'B': '000000',
|
|
}
|
|
land_chart = PieChart3D(250, 100)
|
|
lands = dict([(k, v) for k, v in deck.lands().items() if v])
|
|
land_chart.fill_solid(PieChart3D.BACKGROUND, 'FFFFFF00')
|
|
land_chart.add_data(lands.values())
|
|
land_chart.set_pie_labels([mtg.Mana.types[m] for m in lands.keys()])
|
|
land_chart.set_colours([colors[m] for m in lands.keys()])
|
|
|
|
symbol_chart = PieChart3D(250, 100)
|
|
symbols = dict([(k, v) for k, v in deck.symbols().items() if v])
|
|
symbol_chart.fill_solid(PieChart3D.BACKGROUND, 'FFFFFF00')
|
|
symbol_chart.add_data(symbols.values())
|
|
symbol_chart.set_pie_labels([mtg.Mana.types[m] for m in symbols.keys()])
|
|
symbol_chart.set_colours([colors[m] for m in symbols.keys()])
|
|
|
|
curve = deck.mana_curve()
|
|
for i in range(max(curve.keys()) + 1):
|
|
if i not in curve:
|
|
curve[i] = 0
|
|
|
|
return render_to_response('decks/detail.html', {
|
|
'deck': deck,
|
|
'land_chart': land_chart,
|
|
'symbol_chart': symbol_chart,
|
|
'curve': curve})
|