def get_twd_by_traits(traits, twda=twda): trait_counter = len(traits) match_decks = [] for deck in twda: counter = 0 for trait in traits.keys(): if trait == 'star': min = 5 if '200076' in deck['crypt']: min = 4 for k, v in deck['crypt'].items(): # Skip Anarch Convert if k != '200076': if v['q'] >= min: counter += 1 break if trait == 'monoclan': clans = [] for k, v in deck['crypt'].items(): clan = get_crypt_by_id(k)['Clan'] if k != '200076' and clan not in clans: clans.append(get_crypt_by_id(k)['Clan']) if len(clans) <= 1: counter += 1 break if trait_counter == counter: match_decks.append(deck) return match_decks
def get_twd_by_capacity(capacity, twda=twda): [min, max] = capacity.split(',') [min, max] = [float(min), float(max)] match_decks = [] for deck in twda: cryptTotalCap = 0 cryptCards = 0 capacityList = [] for k, v in deck['crypt'].items(): if k != '200076': c = get_crypt_by_id(k)['Capacity'] q = v['q'] cryptTotalCap += c * q cryptCards += q for x in range(q): capacityList.append(c) cryptAvg = cryptTotalCap / cryptCards cryptMax = 0 capacityList.sort() for i in range(4): cryptMax += capacityList[-i - 1] if cryptAvg >= min and cryptAvg <= max and cryptMax <= max * 4 + 6: match_decks.append(deck) return match_decks
def parseDeck(): try: crypt = {} library = {} cards = request.json['cards'] for k, v in cards.items(): k = int(k) if k > 200000: crypt[k] = {'c': get_crypt_by_id(k), 'q': v} elif k < 200000: library[k] = {'c': get_library_by_id(k), 'q': v} decks = {} decks['deckInUrl'] = { 'name': '', 'owner': '', 'author': '', 'description': '', 'deckid': '', 'crypt': crypt, 'library': library, 'timestamp': datetime.utcnow() } if 'name' in request.json: decks['deckInUrl']['name'] = request.json['name'] if 'author' in request.json: decks['deckInUrl']['author'] = request.json['author'] if 'description' in request.json: decks['deckInUrl']['description'] = request.json['description'] return jsonify(decks) except AttributeError: return jsonify({'error': 'not logged'})
def deckProxy(cards): try: crypt = {} library = {} for k, v in cards.items(): k = int(k) if k > 200000 and v > 0: card = get_crypt_by_id(k) name = card['Name'] if card['Adv']: name += 'adv' crypt[letters_to_ascii(re.sub('[\\W]', '', name)).lower() + '.jpg'] = v elif k < 200000 and v > 0: name = get_library_by_id(k)['Name'] library[letters_to_ascii(re.sub('[\\W]', '', name)).lower() + '.jpg'] = v imagelist = [] for card in sorted(crypt.keys()): for i in range(crypt[card]): imagelist.append(card) for card in sorted(library.keys()): for i in range(library[card]): imagelist.append(card) pdf = FPDF('P', 'mm', 'A4') w = 63 h = 88 gap = 0.5 left_margin = 10 top_margin = 10 x_counter = 0 y_counter = 0 pdf.add_page() for image in imagelist: pdf.image('./cards/' + image, (w + gap) * x_counter + left_margin, (h + gap) * y_counter + top_margin, w, h) x_counter += 1 if x_counter == 3: y_counter += 1 x_counter = 0 if y_counter == 3: pdf.add_page() y_counter = 0 file = pdf.output(dest='S').encode('latin-1') return base64.b64encode(file) except Exception: pass
def searchCryptInventoryRoute(): try: crypt = [] for k, v in current_user.inventory.items(): k = int(k) if k > 200000: crypt.append(get_crypt_by_id(k)) result = searchCrypt(request, crypt) if result != 400: return jsonify(result) else: abort(400) except AttributeError: return jsonify({'error': 'not logged'})
def get_twd_by_clan(clan, twda=twda): match_decks = [] for deck in twda: clan_in_deck = 0 crypt_cards = 0 for id in deck['crypt']: # Skip Anarch Convert if id != '200076': q = deck['crypt'][id]['q'] crypt_cards += q if get_crypt_by_id(id)['Clan'].lower() == clan: clan_in_deck += q if (clan_in_deck / crypt_cards) >= 0.65: match_decks.append(deck) return match_decks
def deckExport(d, format): try: crypt = {} library = {} for k, v in d['cards'].items(): k = int(k) if k > 200000 and v > 0: crypt[k] = {'c': get_crypt_by_id(k), 'q': v} elif k < 200000 and v > 0: library[k] = {'c': get_library_by_id(k), 'q': v} deck = '' if format == 'lackey': for k, v in library.items(): deck += str(v['q']) if v['q'] < 10: deck += ' ' else: deck += ' ' deck += v['c']['Name'] + '\n' deck += 'Crypt:\n' for k, v in crypt.items(): deck += str(v['q']) if v['q'] < 10: deck += ' ' else: deck += ' ' if v['c']['Adv']: deck += v['c']['ASCII Name'] + ' (ADV)\n' else: deck += v['c']['ASCII Name'] + '\n' elif format == 'text' or format == 'twd': disciplinesList = { 'Auspex': 'aus', 'Abombwe': 'abo', 'Animalism': 'ani', 'Celerity': 'cel', 'Chimerstry': 'chi', 'Daimoinon': 'dai', 'Dementation': 'dem', 'Dominate': 'dom', 'Fortitude': 'for', 'Melpominee': 'mel', 'Mytherceria': 'myt', 'Necromancy': 'nec', 'Obeah': 'obe', 'Obfuscate': 'obf', 'Obtenebration': 'obt', 'Potence': 'pot', 'Presence': 'pre', 'Protean': 'pro', 'Serpentis': 'ser', 'Sanguinus': 'san', 'Spiritus': 'spi', 'Temporis': 'tem', 'Thanatosis': 'thn', 'Thaumaturgy': 'tha', 'Quietus': 'qui', 'Valeren': 'val', 'Vicissitude': 'vic', 'Visceratika': 'vis', 'Defense': 'def', 'Innocence': 'inn', 'Judgment': 'jud', 'Martyrdom': 'mar', 'Redemption': 'red', 'Vengeance': 'ven', 'Vision': 'vis', } byType = {} byTypeTotal = {} libraryTotal = 0 for k, v in library.items(): libraryTotal += v['q'] cardType = v['c']['Type'] cardName = v['c']['Name'] if cardType not in byType: byType[cardType] = {} byType[cardType][cardName] = v['q'] byTypeTotal[cardType] = v['q'] else: byType[cardType][cardName] = v['q'] byTypeTotal[cardType] += v['q'] cryptTotalCap = 0 capacityList = [] for k, v in crypt.items(): cryptTotalCap += v['c']['Capacity'] * v['q'] for x in range(v['q']): capacityList.append(v['c']['Capacity']) cryptTotalCards = len(capacityList) cryptAvg = cryptTotalCap / cryptTotalCards if cryptTotalCards else 0 cryptMin = 0 cryptMax = 0 capacityList.sort() counter = 4 if len(capacityList) >= 4 else len(capacityList) for i in range(counter): cryptMin += capacityList[i] cryptMax += capacityList[-i - 1] deck += 'Deck Name: ' + d['name'] + '\n' deck += 'Author: ' + d['author'] + '\n' deck += 'Description: ' + d['description'] + '\n' deck += '\n' cryptTitle = 'Crypt (' + str( cryptTotalCards) + ' cards, min=' + str( cryptMin) + ' max=' + str(cryptMax) + ' avg=' + str( round(cryptAvg, 2)) + ')\n' if format == 'twd': cryptSub = re.sub('.', '-', cryptTitle) elif format == 'text': cryptSub = re.sub('.', '=', cryptTitle) deck += cryptTitle deck += cryptSub cryptExport = {} longestQuantity = 0 longestName = 0 longestTitle = 0 longestCapacity = 0 longestDisciplines = 0 for k, v in crypt.items(): baseDisciplines = [] supDisciplines = [] for i, j in v['c']['Disciplines'].items(): if j == 1: baseDisciplines.append(disciplinesList[i].lower()) elif j == 2: supDisciplines.append(disciplinesList[i].upper()) disciplines = ' '.join(baseDisciplines + supDisciplines) name = '' if v['c']['Adv']: name = v['c']['Name'] + ' (ADV)' else: name = v['c']['Name'] cryptExport[name] = { 'Quantity': v['q'], 'Disciplines': disciplines, 'Title': v['c']['Title'], 'Clan': v['c']['Clan'], 'Capacity': v['c']['Capacity'], 'Group': v['c']['Group'] } if len(str(v['q'])) > longestQuantity: longestQuantity = len(str(v['q'])) if len(v['c']['Name']) > longestName: longestName = len(v['c']['Name']) if len(v['c']['Title']) > longestTitle: longestTitle = len(v['c']['Title']) if len(str(v['c']['Capacity'])) > longestCapacity: longestCapacity = len(str(v['c']['Capacity'])) if len(disciplines) > longestDisciplines: longestDisciplines = len(disciplines) for k, v in cryptExport.items(): quantitySpaces = longestQuantity - len(str(v['Quantity'])) nameSpaces = longestName - len(k) + 3 disSpaces = longestDisciplines - len(v['Disciplines']) + 3 capacitySpaces = longestCapacity - len(str(v['Capacity'])) titleSpaces = longestTitle - len(v['Title']) + 3 deck += ' ' * quantitySpaces + str(v['Quantity']) + 'x ' deck += k + ' ' * nameSpaces deck += ' ' * capacitySpaces + str(v['Capacity']) + ' ' deck += v['Disciplines'] + ' ' * disSpaces deck += v['Title'] + ' ' * titleSpaces deck += v['Clan'] + ':' + v['Group'] + '\n' deck += '\n' byTypeOrder = [ 'Master', 'Conviction', 'Action', 'Action/Reaction', 'Action/Combat', 'Ally', 'Equipment', 'Political Action', 'Retainer', 'Power', 'Action Modifier', 'Action Modifier/Combat', 'Action Modifier/Reaction', 'Reaction', 'Reaction/Action Modifier', 'Reaction/Combat', 'Combat', 'Combat/Action Modifier', 'Combat/Reaction', 'Event', ] libraryTitle = 'Library (' + str(libraryTotal) + ' cards)\n' deck += libraryTitle if format == 'text': librarySub = re.sub('.', '=', libraryTitle) deck += librarySub for i in byTypeOrder: if i in byType: typeTitle = i + ' (' + str(byTypeTotal[i]) + ')\n' deck += typeTitle if format == 'text': typeSub = re.sub('.', '-', typeTitle) deck += typeSub for k, v in byType[i].items(): deck += str(v) + 'x ' + k + '\n' deck += '\n' return {'name': d['name'], 'format': format, 'deck': deck} except Exception: pass