diff --git a/analyzer/models.py b/analyzer/models.py index 26c1fd6..d216a8a 100755 --- a/analyzer/models.py +++ b/analyzer/models.py @@ -1,6 +1,6 @@ import re from django.db import models -from mtgweb.lib.mtg import mtg +from mtgweb.lib.mtg import mtg, analyze # Create your models here. class CardType(models.Model): @@ -87,6 +87,28 @@ class Deck(models.Model): else: curve[cost] += included.count return curve + def ramp(self, type=None): + ramp = {} + deck_size = sum([i.count for i in self.included_set.all()]) + lands = sum([i.count for i in self.included_set.all() if 'land' in i.card.type.name.split(' ')]) + if type: + cards = [i for i in self.included_set.all() if type in i.card.type.name.split(' ')] + else: + cards = [i for i in self.included_set.all() if 'land' not in i.card.type.name.split(' ')] + card_count = sum([i.count for i in cards]) + card_costs = sum([i.count * mtg.ManaCost(i.card.cost).converted() for i in cards]) + max_cost = max([mtg.ManaCost(i.card.cost).converted() for i in cards]) + avg_cost = card_costs / float(card_count) + avg_cost = int(round(avg_cost)) + turns = [] + for turn in range(avg_cost, max_cost + 1): + castable = sum([i.count for i in cards if mtg.ManaCost(i.card.cost).converted() <= turn]) + p_land = 1 - analyze.draw_probability(lands, deck_size, avg_cost, turn) + p_spell = 1 - analyze.draw_probability(castable, deck_size, 1, turn, avg_cost) + probability = 1 - p_land - p_spell + turns.append({'turn': turn, 'probability': probability * 100}) + return turns + class Included(models.Model): card = models.ForeignKey(Card) deck = models.ForeignKey(Deck) diff --git a/decks/views.py b/decks/views.py index fdebfd3..3bac627 100755 --- a/decks/views.py +++ b/decks/views.py @@ -34,6 +34,20 @@ def detail(request, id): 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()]) + + ramp_data = deck.ramp() + min_range = min([t['probability'] for t in ramp_data]) // 5 * 5 + ramp_chart = SimpleLineChart(250, 100, y_range=[min_range, 100]) + ramp_chart.fill_solid(SimpleLineChart.BACKGROUND, 'FFFFFF00') + ramp_chart.add_data([t['probability'] for t in ramp_data]) + labels_left = range(min_range, 100, (100 - min_range) // 5) + labels_left[0] = '' + ramp_chart.set_axis_labels(Axis.LEFT, labels_left) + ramp_chart.set_axis_labels(Axis.BOTTOM, ['Turn {0}'.format(t['turn']) for t in ramp_data]) + for i in range(len(ramp_data)): + p = ramp_data[i]['probability'] + ramp_chart.add_marker(0, i, 'd', '000000', 5) + #ramp_chart.add_marker(0, i, 't{0}%'.format(round(p)), '000000', 10) curve = deck.mana_curve() for i in range(max(curve.keys()) + 1): diff --git a/lib/mtg b/lib/mtg index d5206fc..9b5f01a 160000 --- a/lib/mtg +++ b/lib/mtg @@ -1 +1 @@ -Subproject commit d5206fc6df410836b0b24d1e8d9eae34e4a1ea65 +Subproject commit 9b5f01ab8b5701e1e3222ab6a29f728f82fbc0cb