use template extensions
authorJess <jessicatz.fairymeadow@gmail.com>
Wed, 27 Aug 2014 08:02:10 +0000 (10:02 +0200)
committerJess <jessicatz.fairymeadow@gmail.com>
Wed, 27 Aug 2014 08:02:10 +0000 (10:02 +0200)
make rating work

db.sqlite3
meta/static/js/main.js
meta/templates/base.html [new file with mode: 0644]
meta/templates/index.html
meta/templates/rate.html [new file with mode: 0644]
meta/views.py
meta/views.pyc
mlpccg-web/urls.py
mlpccg-web/urls.pyc
mlpccg/CardDb.py
mlpccg/DeckList.py

index 6cbee9f..d6eb13b 100644 (file)
Binary files a/db.sqlite3 and b/db.sqlite3 differ
index 8b13789..4df27d2 100644 (file)
@@ -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 (file)
index 0000000..4015d3f
--- /dev/null
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
+<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
+<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
+    <head>
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+        <title>meta is magic</title>
+        <meta name="description" content="">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
+
+        <link rel="stylesheet" href="{{STATIC_URL}}css/bootstrap.min.css">
+        <style>
+            body {
+                padding-top: 50px;
+                padding-bottom: 20px;
+            }
+        </style>
+        <link rel="stylesheet" href="{{STATIC_URL}}css/bootstrap-theme.min.css">
+        <link rel="stylesheet" href="{{STATIC_URL}}css/main.css">
+
+        <script src="{{STATIC_URL}}js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
+    </head>
+    <body>
+        <!--[if lt IE 7]>
+            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
+        <![endif]-->
+    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
+      <div class="container">
+        <div class="navbar-header">
+          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+            <span class="sr-only">Toggle navigation</span>
+            <span class="icon-bar"></span>
+            <span class="icon-bar"></span>
+            <span class="icon-bar"></span>
+          </button>
+          <a class="navbar-brand" href="#">meta is magic</a>
+        </div>
+        <!-- <div class="navbar-collapse collapse"> -->
+        <!--   <form class="navbar-form navbar-right" role="form"> -->
+        <!--     <div class="form-group"> -->
+        <!--       <input type="text" placeholder="Email" class="form-control"> -->
+        <!--     </div> -->
+        <!--     <div class="form-group"> -->
+        <!--       <input type="password" placeholder="Password" class="form-control"> -->
+        <!--     </div> -->
+        <!--     <button type="submit" class="btn btn-success">Sign in</button> -->
+        <!--   </form> -->
+        <!-- </div><\!--/.navbar-collapse -\-> -->
+      </div>
+    </div>
+
+    {% block jumbotron %}{% endblock %}
+
+    <div class="container">
+      {% block content %}{% endblock %}
+      <hr>
+
+      <footer>
+        <p>&copy; Yukkuri Games, 2014</p>
+      </footer>
+    </div> <!-- /container -->
+    <!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> -->
+    <script src="{{STATIC_URL}}js/vendor/jquery-1.11.0.min.js"></script>
+    <script src="{{STATIC_URL}}js/vendor/bootstrap.min.js"></script>
+    <script src="{{STATIC_URL}}js/main.js"></script>
+    </body>
+</html>
index f165607..e4f9e6f 100644 (file)
-<!DOCTYPE html>
-<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
-<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
-<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
-<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
-    <head>
-        <meta charset="utf-8">
-        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-        <title>meta is magic</title>
-        <meta name="description" content="">
-        <meta name="viewport" content="width=device-width, initial-scale=1">
+{% extends "base.html" %}
 
-        <link rel="stylesheet" href="{{STATIC_URL}}css/bootstrap.min.css">
-        <style>
-            body {
-                padding-top: 50px;
-                padding-bottom: 20px;
-            }
-        </style>
-        <link rel="stylesheet" href="{{STATIC_URL}}css/bootstrap-theme.min.css">
-        <link rel="stylesheet" href="{{STATIC_URL}}css/main.css">
-
-        <script src="{{STATIC_URL}}js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
-    </head>
-    <body>
-        <!--[if lt IE 7]>
-            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
-        <![endif]-->
-    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
-      <div class="container">
-        <div class="navbar-header">
-          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
-            <span class="sr-only">Toggle navigation</span>
-            <span class="icon-bar"></span>
-            <span class="icon-bar"></span>
-            <span class="icon-bar"></span>
-          </button>
-          <a class="navbar-brand" href="#">meta is magic</a>
+{% block jumbotron %}
+<div class="jumbotron">
+  <div class="container">
+    <h1>How good is your deck?</h1>
+    <p>Curious how decks like yours have performed in tournaments?<br/>
+      Paste your <a href="http://ponyhead.com/deckbuilder">ponyhead.com</a> URL here and find out!</p>
+    <p>
+      <form action="/meta/rate" method="post" class="form-inline" role="form">
+        {% csrf_token %}
+        <div class="form-group">
+          <label class="sr-only" for="ponyheadURL">ponyhead decklist url</label>
+          <input type="url" name="url" class="form-control input-lg" id="ponyheadURL" placeholder="Deck URL, e.g.: http://ponyhead.com/deckbuilder?v1code=..."/>
+          <button type="submit" class="btn btn-lg btn-default btn-primary">Tell me!</button>
         </div>
-        <!-- <div class="navbar-collapse collapse"> -->
-        <!--   <form class="navbar-form navbar-right" role="form"> -->
-        <!--     <div class="form-group"> -->
-        <!--       <input type="text" placeholder="Email" class="form-control"> -->
-        <!--     </div> -->
-        <!--     <div class="form-group"> -->
-        <!--       <input type="password" placeholder="Password" class="form-control"> -->
-        <!--     </div> -->
-        <!--     <button type="submit" class="btn btn-success">Sign in</button> -->
-        <!--   </form> -->
-        <!-- </div><\!--/.navbar-collapse -\-> -->
-      </div>
-    </div>
-
-    <!-- Main jumbotron for a primary marketing message or call to action -->
-    <div class="jumbotron">
-      <div class="container">
-        <h1>How good is your deck?</h1>
-        <p>Curious how decks like yours have performed in tournaments?<br/> Paste your <a href="http://ponyhead.com/deckbuilder">ponyhead.com</a> URL here and find out!</p>
-        <p>
-          <form class="form-inline" role="form">
-            <div class="form-group">
-              <label class="sr-only" for="ponyheadURL">ponyhead decklist url</label>
-              <input type="url" class="form-control input-lg" id="ponyheadURL" placeholder="Deck URL, e.g.: http://ponyhead.com/deckbuilder?v1code=..."/>
-              <button type="button" class="btn btn-lg btn-default btn-primary">Tell me!</button>
-            </div>
-          </form>
-        </p>
-      </div>
-    </div>
+      </form>
+    </p>
+  </div>
+</div>
+{% endblock %}
 
-    <div class="container">
-      <div class="row">
-        <div class="col-xs-12">
-          <h2>Deck archetypes</h2>
-          <p>Very fuzzy data, based on past tournaments. The more the deck was played in tournaments, the more accurate this is.</p>
-          <table class="table">
-            <tr>
-              <th>Archetype ID</th>
-              <th>Average placement</th>
-              <th>Example decks</th>
-            </tr>
-          {% load humanize %}
-          {% for avg, label, decks in ranking %}
-            <tr>
-              <td>{{ label }}</td>
-              <td>{{ avg|ordinal }}</td>
-              <td>
-                <ul class="list-inline">
-                {% for d in decks %}
-                  <li><a href="{{ d.ponyhead_link }}">{{ d.description }}</a></li>
-                {% endfor %}
-                </ul>
-              </td>
-          {% endfor %}
-          </table>
-        </div>
-      </div>
+{% block content %}
+<div class="row">
+  <div class="col-xs-12">
+    <h2>Deck archetypes</h2>
+    <p>Very fuzzy data, based on past tournaments. The more the deck was played in tournaments, the more accurate this is.</p>
+    <table class="table">
+      <tr>
+        <th>Archetype ID</th>
+        <th>Average placement</th>
+        <th>Example decks</th>
+      </tr>
+      {% load humanize %}
+      {% for avg, label, decks in ranking %}
+      <tr>
+        <td>{{ label }}</td>
+        <td>{{ avg|ordinal }}</td>
+        <td>
+          <ul class="list-inline">
+            {% for d in decks %}
+            <li><a href="{{ d.ponyhead_link }}">{{ d.description }}</a></li>
+            {% endfor %}
+          </ul>
+        </td>
+        {% endfor %}
+    </table>
+  </div>
+</div>
 
-      <div class="row">
-        <div class="col-xs-12">
-          <h2>Tournaments</h2>
-          <table class="table">
-            <tr>
-              <th>Date</th>
-              <th>Name</th>
-              <th>Top 8 Decks</th>
-            </tr>
-        {% if tournaments %}
-          {% for t in tournaments %}
-            <tr>
-              <td>{{ t.tournament.date }}</td>
-              <td>{{ t.tournament.name }}</td>
-              <td>
-              {% for d in t.decklists|slice:":8" %}
-                <a href="{{ d.ponyhead_link }}">{{ d.name }} ({{ d.description }})</a><br/>
-              {% endfor %}
-              </td>
-            </tr>
+<div class="row">
+  <div class="col-xs-12">
+    <h2>Tournaments</h2>
+    <table class="table">
+      <tr>
+        <th>Date</th>
+        <th>Name</th>
+        <th>Top Decks</th>
+      </tr>
+      {% if tournaments %}
+      {% for t in tournaments %}
+      <tr>
+        <td>{{ t.tournament.date }}</td>
+        <td>{{ t.tournament.name }}</td>
+        <td>
+          {% for d in t.decklists|slice:":8" %}
+          <a href="{{ d.ponyhead_link }}">{{ d.name }} ({{ d.description }})</a><br/>
           {% endfor %}
-        {% endif %}
-          </table>
-        </div>
-      </div>
-      <hr>
-
-      <footer>
-        <p>&copy; Yukkuri Games, 2014</p>
-      </footer>
-    </div> <!-- /container -->
-    <!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> -->
-    <script src="{{STATIC_URL}}js/vendor/jquery-1.11.0.min.js"></script>
-    <script src="{{STATIC_URL}}js/vendor/bootstrap.min.js"></script>
-    <script src="{{STATIC_URL}}js/main.js"></script>
-    </body>
-</html>
+        </td>
+      </tr>
+      {% endfor %}
+      {% endif %}
+    </table>
+  </div>
+</div>
+{% endblock %}
diff --git a/meta/templates/rate.html b/meta/templates/rate.html
new file mode 100644 (file)
index 0000000..c9627a5
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+{% block content %}
+
+{{ label }}
+
+{% endblock %}
index fc1a7af..bb97599 100644 (file)
@@ -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', {})
index 0c37ebc..cde0787 100644 (file)
Binary files a/meta/views.pyc and b/meta/views.pyc differ
index 7cf9e46..4870720 100644 (file)
@@ -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'),
 )
index 4140450..ae1775f 100644 (file)
Binary files a/mlpccg-web/urls.pyc and b/mlpccg-web/urls.pyc differ
index cadbc37..4111683 100644 (file)
@@ -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',
index 415c91d..5ff46bf 100644 (file)
@@ -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