X-Git-Url: https://git.yukkurigames.com/?p=mlpccg-meta.git;a=blobdiff_plain;f=mlpccg%2FDeckList.py;h=ec576456dbebf93b51238d740c76d383ef710a46;hp=749410978e637b7544e405f0661bdd951d883eb7;hb=HEAD;hpb=a7a7ac1456426456a5a33ebeac28693804693716 diff --git a/mlpccg/DeckList.py b/mlpccg/DeckList.py index 7494109..ec57645 100644 --- a/mlpccg/DeckList.py +++ b/mlpccg/DeckList.py @@ -19,19 +19,49 @@ class DeckList: return self.name @property - def description(self): + def aspects(self): mane = None - colors = defaultdict(int) - + aspects = defaultdict(int) for card in self.cards: if card['type'] == 'Mane': - mane = '%s %s' % (card['title'], mlpccg.CardDb.set_ids[card['set']].upper()) + mane = (card['title'], mlpccg.CardDb.CardDb.set_ids[card['set']].upper()) + + elif card['type'] == 'Friend': + aspects[card['color']] += 1 + + elif card['type'] != 'Problem': + aspects[card['type']] += 1 + + 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.6 + amount = 0.0 + for aspect, value in aspects_sorted: + amount += value / aspects_sum + aspects_filtered += [aspect] + if amount >= cutoff: + break + + return (mane, aspects_filtered) + + @property + def description(self): + mane, aspects = self.aspects + if not mane or len(aspects) == 0: + return 'Unknown' + + return '%s %s %s' % (mane[0], mane[1], '/'.join(aspects)) + + @property + def ponyhead_link(self): + cards = defaultdict(int) + for card in self.cards: + cards[card['id'].replace('pf', 'PF').replace('f', 'F')] += 1 - if card['type'] == 'Friend': - colors[card['color']] += 1 + cards = ['%sx%d' % (id, amount) for id, amount in cards.iteritems()] - colors_sorted = filter(lambda c: c[1] >= 6, sorted(colors.iteritems(), reverse=True, key=operator.itemgetter(1))) - return '%s %s' % (mane, '/'.join(map(lambda c: c[0], colors_sorted))) + return 'http://ponyhead.com/deckbuilder?v1code=%s' % '-'.join(cards) def parse_ponyhead_xml(self, path): logging.debug('loading decklist from xml')