Example #1
0
 def format_row(self, japword, synonyms):
     leftcol = textual_width_fill(japword, 12, left=False)
     synonyms = sorted(synonyms, reverse=True,  # sort in relevance_order:
                       key=lambda x: x[1] if isinstance(x[1], int) else 0)
     rightcol = ', '.join([syn[0] for syn in synonyms])
     phonetics = ""  # DEV: extract from sentence? THINK if possible?
     return [leftcol, phonetics, rightcol]
 def test_textual_width_fill(self):
     '''Pad a utf8 string'''
     tools.eq_(display.textual_width_fill(self.u_mixed, 1), self.u_mixed)
     tools.eq_(display.textual_width_fill(self.u_mixed, 25),
               self.u_mixed + '  ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, left=False),
               '  ' + self.u_mixed)
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18),
               self.u_mixed[:-4] + '       ')
     tools.eq_(
         display.textual_width_fill(self.u_mixed,
                                    25,
                                    chop=18,
                                    prefix=self.u_spanish,
                                    suffix=self.u_spanish),
         self.u_spanish + self.u_mixed[:-4] + self.u_spanish + '       ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18),
               self.u_mixed[:-4] + '       ')
     tools.eq_(
         display.textual_width_fill(self.u_mixed,
                                    25,
                                    chop=18,
                                    prefix=self.u_spanish,
                                    suffix=self.u_spanish),
         self.u_spanish + self.u_mixed[:-4] + self.u_spanish + '       ')
Example #3
0
 def format_row(self, japword, synonyms):
     leftcol = textual_width_fill(japword, 12, left=False)
     synonyms = sorted(
         synonyms,
         reverse=True,  # sort in relevance_order:
         key=lambda x: x[1] if isinstance(x[1], int) else 0)
     rightcol = ', '.join([syn[0] for syn in synonyms])
     phonetics = ""  # DEV: extract from sentence? THINK if possible?
     return [leftcol, phonetics, rightcol]
 def test_textual_width_fill(self):
     '''Pad a utf8 string'''
     tools.eq_(display.textual_width_fill(self.u_mixed, 1), self.u_mixed)
     tools.eq_(display.textual_width_fill(self.u_mixed, 25), self.u_mixed + u'  ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, left=False), u'  ' + self.u_mixed)
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18), self.u_mixed[:-4] + u'       ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18, prefix=self.u_spanish, suffix=self.u_spanish), self.u_spanish + self.u_mixed[:-4] + self.u_spanish + u'       ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18), self.u_mixed[:-4] + u'       ')
     tools.eq_(display.textual_width_fill(self.u_mixed, 25, chop=18, prefix=self.u_spanish, suffix=self.u_spanish), self.u_spanish + self.u_mixed[:-4] + self.u_spanish + u'       ')
Example #5
0
def output_match_result(data, game_number, short_url, champions, lpl=False):
    print('* Preparing output...')

    output = ''

    # Output the result line-by-line.
    output += (u'\x1b[1;37;46mGame {0:>2}\x1b[m ' + (u'\u2500' * 15) +
               u'\u252c' + (u'\u2500' * 13) + ' {1}\n').format(
                   game_number, data['game_date'])

    blue_team_spaces = 12 - len(data['blue_team_name']) // 2
    red_team_spaces = 12 - len(data['red_team_name']) // 2

    output += (u'{0}\x1b[1;37;44m{1}\x1b[m{2}{3:>6}    '
               u'\x1b[1;36;40m{4:>2}\x1b[m'
               u'  \u2502  \x1b[1;31;40m{5:>2}\x1b[m    '
               u'{6:<6}{7}\x1b[1;37;41m{8}\x1b[m\n').format(
                   ' ' * blue_team_spaces, data['blue_team_name'],
                   ' ' * (24 - blue_team_spaces - len(data['blue_team_name'])),
                   data['blue_golds'], data['blue_kills'], data['red_kills'],
                   data['red_golds'], ' ' * red_team_spaces,
                   data['red_team_name'])
    if lpl:
        output += u'{0}{1}{2}{3}  \u2502  {4}{5}{6}\n'.format(
            ' ' * 8, data['blue_result'], ' ' * 9, ' ' * 11, data['duration'],
            ' ' * 15, data['red_result'])
    else:
        output += u'{0}{1}{2}PATCH{3:>6}  \u2502  {4}{5}{6}\n'.format(
            ' ' * 8, data['blue_result'], ' ' * 9, data['patch_ver'],
            data['duration'], ' ' * 15, data['red_result'])
    output += (u'\u2500' * 19) + u'\u253c' + (u'\u2500' * 19) + '\n'
    output += u'{0} \u2502 {0}\n'.format(
        ' ' * 18 + '\x1b[1;37;40mK  D  A   CS  $/Dmg\x1b[m')

    # Iterrate through all players in the game.
    for i in range(0, 5):
        j = i + 5
        output += (u'\x1b[1;36;40m{0}\x1b[m \u2502 '
                   u'\x1b[1;31;40m{1}\x1b[m\n').format(
                       stats_first(data['participants'][i]['stats'],
                                   data['players'][i]),
                       stats_first(data['participants'][j]['stats'],
                                   data['players'][j]),
                   )
        output += (u'{0} \u2502 {1}\n').format(
            stats_second(data['participants'][i], champions,
                         data['max_damage']),
            stats_second(data['participants'][j], champions,
                         data['max_damage']),
        )

    output += (u'\u2500' * 19) + u'\u253c' + (u'\u2500' * 19) + '\n'

    # Stats like Bans, picks, dragons, barons.
    output += u'{0} {1} {2} {3} \u2502 {0} {4} {5} {6}\n'.format(
        u'\u7981\u7528',
        textual_width_fill(data['blue_bans'][0], 10),
        textual_width_fill(data['blue_bans'][1], 10),
        textual_width_fill(data['blue_bans'][2], 10),
        textual_width_fill(data['red_bans'][0], 10),
        textual_width_fill(data['red_bans'][1], 10),
        textual_width_fill(data['red_bans'][2], 10),
    )
    output += u'{0} {1} {2} {3} \u2502 {0} {4} {5}\n'.format(
        ' ' * 4,
        textual_width_fill(data['blue_bans'][3], 10),
        textual_width_fill(data['blue_bans'][4], 10),
        ' ' * 10,
        textual_width_fill(data['red_bans'][3], 10),
        textual_width_fill(data['red_bans'][4], 10),
    )
    output += u'{0} {1} \u2502 {0} {2}\n'.format(u'\u5c0f\u9f8d',
                                                 data['blue_dragons'],
                                                 data['red_dragons'])
    if lpl:
        output += (u'{0:>2} \u5854 / {1:>2} \u5df4\u9f8d{2}').format(
            data['team_blue']['towerKills'], data['team_blue']['baronKills'],
            ' ' * 22)
        output += u' \u2502 '
        output += (u'{0:>2} \u5854 / {1:>2} \u5df4\u9f8d\n').format(
            data['team_red']['towerKills'],
            data['team_red']['baronKills'],
        )
    else:
        output += (u'{0:>2} \u5854 / {1} \u5175\u71df / '
                   u'{2} \u9810\u793a\u8005 / {3:>2} \u5df4\u9f8d  ').format(
                       data['team_blue']['towerKills'],
                       data['team_blue']['inhibitorKills'],
                       data['team_blue']['riftHeraldKills'],
                       data['team_blue']['baronKills'],
                   )
        output += u' \u2502 '
        output += (u'{0:>2} \u5854 / {1} \u5175\u71df / '
                   u'{2} \u9810\u793a\u8005 / {3:>2} \u5df4\u9f8d\n').format(
                       data['team_red']['towerKills'],
                       data['team_red']['inhibitorKills'],
                       data['team_red']['riftHeraldKills'],
                       data['team_red']['baronKills'],
                   )
    if short_url:
        output += ((u'\u2500' * 19) + u'\u2534' + (u'\u2500' * 6) +
                   '{0:>26}\n\n').format(short_url)
    else:
        output += (u'\u2500' * 19) + u'\u2534' + (u'\u2500' * 19) + '\n\n'
    return output
Example #6
0
def stats_second(participant, champions, max_damage):
    damage = participant['stats']['totalDamageDealtToChampions']
    return u'{0} {1}  {2:>6}'.format(
        textual_width_fill(champions[participant['championId']], 16),
        bar_chart(round(damage * 48.00 / max_damage)), damage)
Example #7
0
def stats_first(stats, player):
    return u'{0} {1:>2}/{2:>2}/{3:>2} {4:>4} {5:>5}k'.format(
        textual_width_fill(player, 16), stats['kills'], stats['deaths'],
        stats['assists'],
        stats['totalMinionsKilled'] + stats['neutralMinionsKilled'],
        round(stats['goldEarned'] / 100.00) / 10)