Ejemplo n.º 1
0
Archivo: game.py Proyecto: dwt/congo
    def GET(self, seq, pos):
        count = Vote.count(web.ctx.game.id, seq, pos)
        comments = Comment.details(web.ctx.game.id, seq, pos)
        votes = Vote.details(web.ctx.game.id, seq, pos)

        all_comments = {}
        for c in comments:
            all_comments[(c.rating, c.name)] = (c.notes, 'comment')

        for v in votes:
            all_comments[(v.rating, v.name)] = (v.notes, 'vote')

        sorted_comments = sorted(
            all_comments.iteritems(),
            key=lambda ((rating, name), _): -rating,
        )

        return json.dumps({
            'display_pos': Pretty.pos(pos),
            'count': count,
            'votes': [
                {
                    'name': name,
                    'rating': Pretty.rating(rating),
                    'notes': notes,
                    'type': note_type,
                }
                for (rating, name), (notes, note_type) in sorted_comments
            ],
        })
Ejemplo n.º 2
0
    def GET(self, seq, pos):
        count = Vote.count(web.ctx.game.id, seq, pos)
        comments = Comment.details(web.ctx.game.id, seq, pos)
        votes = Vote.details(web.ctx.game.id, seq, pos)

        all_comments = {}
        for c in comments:
            all_comments[(c.rating, c.name)] = (c.notes, 'comment')

        for v in votes:
            all_comments[(v.rating, v.name)] = (v.notes, 'vote')

        sorted_comments = sorted(
            all_comments.iteritems(),
            key=lambda ((rating, name), _): -rating,
        )

        return json.dumps({
            'display_pos': Pretty.pos(pos),
            'count': count,
            'votes': [
                {
                    'name': name,
                    'rating': Pretty.rating(rating),
                    'notes': notes,
                    'type': note_type,
                }
                for (rating, name), (notes, note_type) in sorted_comments
            ],
        })
Ejemplo n.º 3
0
    def GET(self):
        get_data = web.input(last_id=0)

        last_id = int(get_data.last_id)
        room_id = web.ctx.game.player_color

        messages = []
        delete_id = None
        if last_id == 0:
            messages = ChatMessage.load(room_id, last_id)
        else:
            action, kwargs = wait_for_message(room_id)
            #sleep up to 300 ms to prevent the thundering herd
            time.sleep(random.random() * .3)
            if action == 'send':
                messages = ChatMessage.load(room_id, last_id)
            elif action == 'delete':
                delete_id = kwargs['id']

        deletable = is_admin()

        ChatRoom.set_online(room_id)
        online_users = [{
            'name': u[1],
            'rating': Pretty.rating(u[2]),
        } for u in ChatRoom.get_online(room_id)]

        return json.dumps({
            'messages':
            list(
                reversed([{
                    'id': x.id,
                    'name': x.name,
                    'rating': Pretty.rating(x.rating),
                    'message': x.message,
                    'deletable': deletable,
                } for x in messages])),
            'online_users':
            online_users,
            'refresh':
            False,
            'delete_id':
            delete_id,
        })
Ejemplo n.º 4
0
Archivo: chat.py Proyecto: dwt/congo
    def GET(self):
        get_data = web.input(last_id=0)

        last_id = int(get_data.last_id)
        room_id = web.ctx.game.player_color

        messages = []
        delete_id = None
        if last_id == 0:
            messages = ChatMessage.load(room_id, last_id)
        else:
            action, kwargs = wait_for_message(room_id)
            #sleep up to 300 ms to prevent the thundering herd
            time.sleep(random.random() * .3)
            if action == 'send':
                messages = ChatMessage.load(room_id, last_id)
            elif action == 'delete':
                delete_id = kwargs['id']

        deletable = is_admin()

        ChatRoom.set_online(room_id)
        online_users = [{
            'name': u[1],
            'rating': Pretty.rating(u[2]),
        } for u in ChatRoom.get_online(room_id)]

        return json.dumps({
            'messages': list(reversed([
                {
                    'id': x.id,
                    'name': x.name,
                    'rating': Pretty.rating(x.rating),
                    'message': x.message,
                    'deletable': deletable,
                } for x in messages
            ])),
            'online_users': online_users,
            'refresh': False,
            'delete_id': delete_id,
        })
Ejemplo n.º 5
0
Archivo: stats.py Proyecto: dwt/congo
    def GET(self):
        game_id = web.ctx.game.id;
        players = Player.game_stats(game_id)
        num_players = len(players)

        black = []
        white = []
        for player in players:
            ([], black, white)[player.color].append('%s (%s)' % (
                player.name,
                Pretty.rating(player.rating),
            ))

        num_votes = Vote.game_stats(game_id)

        return json.dumps({
            'num_players': num_players,
            'num_votes': num_votes,
            'black_players': '<br>'.join(black),
            'white_players': '<br>'.join(white),
        })
Ejemplo n.º 6
0
Archivo: sgf.py Proyecto: dwt/congo
    def GET(self):

        game = Game.current()

        web.header(
            'Content-Disposition',
            'attachment; filename="ConGo-game-%s.sgf"' % (game.id,),
        )
        web.header('Content-Type', 'application/x-go-sgf')

        data = [
            '(;GM[1]FF[4]CA[UTF-8]AP[ConGo:0.1]ST[2]',
            'RU[Japanese]SZ[19]KM[6.50]',
            'GN[ConGo Game %s]PW[White Team]PB[Black Team]' % (game.id,),
            'CP[2015 Jay Chan]RO[%s]' % (game.id),
        ]

        end_seq = game.current_seq + 1

        for seq in range(1, end_seq):
            vote_counts = Vote.summary(game.id, seq)
            show_current_move = seq < end_seq - 1

            if seq > 1:
                data.append(';%s[%s]' % (
                    (seq - 1) % 2 == 1 and 'B' or 'W',
                    prev_chosen_move,
                ))

            if show_current_move:
                data.append('LB')
            vote_data = []

            for i, vote in enumerate(list(vote_counts)[:7]):
                label = chr(i + 65)
                if i == 0:
                    chosen_move = vote.move
                if vote.move != 'tt':
                    if show_current_move:
                        data.append('[%s:%s]' % (vote.move, label))
                    vote_data.append('%s: %s votes\n' % (label, vote.cnt))
                else:
                    vote_data.append('Pass: %s votes\n' % (vote.cnt,))

            if seq == 1:
                data.append('C[con-go.net\n\n')
            else:
                data.append('C[')
                votes = Vote.details(game.id, seq - 1, prev_chosen_move)
                for vote in list(votes)[:5]:
                    data.append('%s (%s)\\: ' % (vote.name, Pretty.rating(vote.rating)))
                    notes = re.sub('\n', ' ', vote.notes)
                    notes = re.sub('\[', '(', notes)
                    notes = re.sub('\]', ')', notes)
                    notes = re.sub(r'\\', '\\\\', notes)
                    notes = re.sub(r':', '\\:', notes)
                    data.append(notes + '\n\n')
                data.append('\n')

            if show_current_move:
                data.extend(vote_data)
            data.append(']')
            prev_chosen_move = chosen_move

        data.append(')')

        return ''.join(data)