From: Jess Date: Wed, 27 Aug 2014 08:02:10 +0000 (+0200) Subject: use template extensions X-Git-Url: https://git.yukkurigames.com/?p=mlpccg-meta.git;a=commitdiff_plain;h=22a94820738824527277e21f2f37bc77638e12bc use template extensions make rating work --- diff --git a/db.sqlite3 b/db.sqlite3 index 6cbee9f..d6eb13b 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/meta/static/js/main.js b/meta/static/js/main.js index 8b13789..4df27d2 100644 --- a/meta/static/js/main.js +++ b/meta/static/js/main.js @@ -1 +1,5 @@ - +function rateDeck() { + $.getJSON('/meta/rate', {url: $('#ponyheadURL').val()}, function(data) { + console.log(data); + }); +} diff --git a/meta/templates/base.html b/meta/templates/base.html new file mode 100644 index 0000000..4015d3f --- /dev/null +++ b/meta/templates/base.html @@ -0,0 +1,69 @@ + + + + + + + + + meta is magic + + + + + + + + + + + + + + + {% block jumbotron %}{% endblock %} + +
+ {% block content %}{% endblock %} +
+ +
+

© Yukkuri Games, 2014

+
+
+ + + + + + diff --git a/meta/templates/index.html b/meta/templates/index.html index f165607..e4f9e6f 100644 --- a/meta/templates/index.html +++ b/meta/templates/index.html @@ -1,135 +1,76 @@ - - - - - - - - - meta is magic - - +{% extends "base.html" %} - - - - - - - - - - + +{% endblock %} diff --git a/meta/templates/rate.html b/meta/templates/rate.html new file mode 100644 index 0000000..c9627a5 --- /dev/null +++ b/meta/templates/rate.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block content %} + +{{ label }} + +{% endblock %} diff --git a/meta/views.py b/meta/views.py index fc1a7af..bb97599 100644 --- a/meta/views.py +++ b/meta/views.py @@ -1,5 +1,6 @@ from django.shortcuts import render -from meta.models import TournamentModel +from django.template import RequestContext +from meta.models import TournamentModel, RecordModel from mlpccg.CardDb import CARDDB from mlpccg.DeckList import DeckList from mlpccg.Clustering import Clustering @@ -7,21 +8,26 @@ from mlpccg.Clustering import Clustering def index(request): tournament_models = TournamentModel.objects.all().order_by('-date') tournament_data = [] - placements = [] for tournament in tournament_models: tournament_records = tournament.recordmodel_set.all().order_by('placement') - tournament_decks = [] - for record in tournament_records: - decklist = DeckList(name=record.decklist.name, url=record.decklist.url) - tournament_decks += [decklist] - if len(decklist.cards) > 0: - placements += [{'decklist': decklist, 'placement': record.placement}] - + tournament_decks = [DeckList(name=record.decklist.name, url=record.decklist.url) for record in tournament_records] tournament_data += [{'tournament': tournament, 'decklists': tournament_decks}] + records = RecordModel.objects.all() + placements = [{'decklist': DeckList(name=record.decklist.name, url=record.decklist.url), 'placement': record.placement} for record in records if record.decklist.url] clustering = Clustering(records=placements) ranking = [(int(avg), label, [decklist for decklist in clustering.clusters[label]]) for avg, label in clustering.ranking()] return render(request, 'index.html', { 'ranking': ranking, - 'tournaments': tournament_data}) + 'tournaments': tournament_data}, + context_instance=RequestContext(request)) + +def rate(request): + records = RecordModel.objects.all() + placements = [{'decklist': DeckList(name=record.decklist.name, url=record.decklist.url), 'placement': record.placement} for record in records if record.decklist.url] + clustering = Clustering(records=placements) + decklist = DeckList(url=request.POST['url']) + label = clustering.predict(decklist) + + return render(request, 'rate.html', {}) diff --git a/meta/views.pyc b/meta/views.pyc index 0c37ebc..cde0787 100644 Binary files a/meta/views.pyc and b/meta/views.pyc differ diff --git a/mlpccg-web/urls.py b/mlpccg-web/urls.py index 7cf9e46..4870720 100644 --- a/mlpccg-web/urls.py +++ b/mlpccg-web/urls.py @@ -3,10 +3,9 @@ from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', - # Examples: - # url(r'^blog/', include('blog.urls')), - - url(r'^meta/$', 'meta.views.index'), +urlpatterns = patterns( + '', url(r'^admin/', include(admin.site.urls)), + url(r'^meta/$', 'meta.views.index'), + url(r'^meta/rate$', 'meta.views.rate'), ) diff --git a/mlpccg-web/urls.pyc b/mlpccg-web/urls.pyc index 4140450..ae1775f 100644 Binary files a/mlpccg-web/urls.pyc and b/mlpccg-web/urls.pyc differ diff --git a/mlpccg/CardDb.py b/mlpccg/CardDb.py index cadbc37..4111683 100644 --- a/mlpccg/CardDb.py +++ b/mlpccg/CardDb.py @@ -5,7 +5,7 @@ import logging import time class CardDb: - set_ids = { + set_ids = { # NOTE: if there is ever an 'f' in here, update the ponyhead link generation 'Premiere': 'pr', 'Canterlot Nights': 'cn', 'Rock \'n Rave': 'rr', diff --git a/mlpccg/DeckList.py b/mlpccg/DeckList.py index 415c91d..5ff46bf 100644 --- a/mlpccg/DeckList.py +++ b/mlpccg/DeckList.py @@ -35,7 +35,7 @@ class DeckList: aspects_sorted = sorted(aspects.iteritems(), reverse=True, key=operator.itemgetter(1)) aspects_sum = float(sum([aspect[1] for aspect in aspects_sorted])) aspects_filtered = [] - cutoff = 0.5 + cutoff = 0.6 amount = 0.0 for aspect, value in aspects_sorted: amount += value / aspects_sum