Esempio n. 1
0
 def get_tournament_details(self):
     """
     возврщает информацию по турниру
     его хар-ки и список туров
     """
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM\
             (SELECT *,\
                 (SELECT count(*) FROM  chess_db.game\
                 WHERE chess_db.tour.id = chess_db.game.tour_id) AS game_amount,\
                 (SELECT count(*) FROM  chess_db.game WHERE\
                 chess_db.tour.id = chess_db.game.tour_id\
                     and chess_db.game.finished = True) AS game_done_amount\
             FROM chess_db.tour) AS T\
             WHERE T.game_amount > 0 AND tournament_id = %s;" ,
     [self.id]
     )
     tours_list = get_result_dic(cursor)
     result = dict({
         'id' : self.id,
         'name': self.name,
         'prizes': self.prize_positions_amount,
         'finished': self.finished,
         'players_count': self._players.count(),
         'tours_amount' : self._tours.count(),
         'pairing_method_first' : self.get_pairing_method_first_display(),
         'tours_list': tours_list,
     })
     return result
Esempio n. 2
0
 def check_if_played(player1, player2, tournament_id):
     """
     возращает играли ли в турнире игроки
     """
     cursor = connection.cursor()
     cursor.execute("SELECT count(*) FROM\
             chess_db.player_in_game\
             INNER JOIN chess_db.player_in_game AS g2\
             ON chess_db.player_in_game.game_id = g2.game_id AND\
             chess_db.player_in_game.player_id <> g2.player_id\
             WHERE chess_db.player_in_game.tournament_id = %s AND\
             chess_db.player_in_game.player_id in (%s,%s) AND\
             g2.player_id IN (%s,%s);" ,
     [tournament_id, player1.id, player2.id, player1.id, player2.id]
     )
     result = get_result_dic(cursor)
     if result[0]['count(*)'] > 0:
         return True
     else:
         return False
Esempio n. 3
0
 def played_with(self):
     """
     возвращает список игроков с которым в данном турнире играл участник
     """
     cursor = connection.cursor()
     cursor.execute("SELECT g2.player_id FROM\
             chess_db.player_in_game\
             INNER JOIN chess_db.player_in_game AS g2\
             ON chess_db.player_in_game.game_id = g2.game_id AND\
             chess_db.player_in_game.player_id <> g2.player_id\
             WHERE chess_db.player_in_game.tournament_id = %s AND\
             chess_db.player_in_game.player_id = %s" , [self.tournament_id, self.player_id]
     )
     result = get_result_dic(cursor)
     players_in_tournaments = []
     for res in result:
         players_in_tournaments.append(
             PlayersInTournament.objects.get(player_id = res['player_id'],
                 tournament_id = self.tournament_id)
         )
     return players_in_tournaments