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 6cbee9fb87b2c8046c77d193c01fb0ca08989d12..d6eb13b53e58baff15226414eec3830a7311d744 100644 (file)
Binary files a/db.sqlite3 and b/db.sqlite3 differ
index 8b137891791fe96927ad78e64b0aad7bded08bdc..4df27d2fa16ce7b0a90ede5a5f4e483362338734 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 f16560770228787c6997dedf6135b22746a378ee..e4f9e6f72f3ac1d6be0e57c25bfa9b3f148c9866 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 fc1a7afa7c211ab561f8339e0a92f6c981bd58c8..bb9759917d34a531f8370006c9236fefc07e8b86 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 0c37ebc34749879d4c47f8eb7df7e5a5eb67c02d..cde0787ef6173065228635a107d936a368cb6be5 100644 (file)
Binary files a/meta/views.pyc and b/meta/views.pyc differ
index 7cf9e46f582c7e350f98332bc4e8583292ca27af..48707204f067e68848be25b1ee804665d8b63c36 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 4140450d63f8550456f6736fd4d63509205b46b8..ae1775fb50f1e9d0bcf90574fc45bb7172000d2f 100644 (file)
Binary files a/mlpccg-web/urls.pyc and b/mlpccg-web/urls.pyc differ
index cadbc37951ea72546ecb75f5cac3d240fe6efeb8..4111683cd649ea30402a927ec2539a7f058231d6 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 415c91d561cc6bb1a6f238916d8cedc4e8518227..5ff46bf9d6ec720dc5f20f552da6fee2a8d2aa1a 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