def _gex_stats(bot, args, author_id, thread_id, thread_type):
data = CARD_TO_USER_ID
number_of_top_cards_to_list = len(data) // 5
number_of_bottom_cards_to_list = len(data) // 10
num_owners = {}
num_in_circulation = {}
for card in data:
num_owners[card] = len(data[card])
num_in_circulation[card] = sum(q[1] for q in data[card])
most_owned_cards = heapq.nlargest(
number_of_top_cards_to_list, num_owners, key=lambda x: num_owners[x])
most_circulated_cards = heapq.nlargest(
number_of_top_cards_to_list, num_in_circulation, key=lambda x: num_in_circulation[x])
least_owned_cards = heapq.nsmallest(
number_of_bottom_cards_to_list, num_owners, key=lambda x: num_owners[x])
least_circulated_cards = heapq.nsmallest(
number_of_bottom_cards_to_list, num_in_circulation, key=lambda x: num_in_circulation[x])
highest_scrabble_scores = heapq.nlargest(
number_of_top_cards_to_list, data, key=lambda x: _get_scrabble_score(x))
out = 'Cards owned by the most people (top 20%):'
FORMAT = '\n{} ({})'
for card in most_owned_cards:
out += FORMAT.format(card, num_owners[card])
bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)
out = 'Cards with the most copies in circulation (top 20%):'
for card in most_circulated_cards:
out += FORMAT.format(card, num_in_circulation[card])
bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)
out = 'Cards owned by the fewest people (bottom 10%):'
for card in least_owned_cards:
out += FORMAT.format(card, num_owners[card])
bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)
out = 'Cards with the fewest copies in circulation (bottom 10%):'
for card in least_circulated_cards:
out += FORMAT.format(card, num_in_circulation[card])
bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)
out = 'Cards with the highest scrabble score for their ID (top 20%):'
for card in highest_scrabble_scores:
out += FORMAT.format(card, _get_scrabble_score(card))
bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)
评论列表
文章目录