How to use is_win method in Playwright Python

Best Python code snippet using playwright-python

Testing Gomoku.py

Source:Testing Gomoku.py Github

copy

Full Screen

...141 open_seq_count += open_count142 semi_open_seq_count += semi_open_count143 return open_seq_count, semi_open_seq_count144print(detect_rows(board, 'b', 4))145def is_win(board):146 if detect_wins(board, "b") == "No win" and detect_wins(board, "w") == "No win":147 for i in range(8):148 for y in range(8):149 if board[i][y] == " ":150 return "Continue playing"151 return "Draw"152 elif detect_wins(board, "b") == "b":153 return "Black won"154 elif detect_wins(board, "w") == "w":155 return "White won"156# print(is_win(board))157def detect_win(board, col, y_start, x_start, length, d_y, d_x):158 i = 0159 len = 0160 open_seq_count = 0161 semi_open_seq_count = 0162 while i <= (8-length):163 e = i164 while 0 <= (y_start + d_y * e) <= 7 and 0 <= (x_start + d_x * e) <= 7 and board[y_start + d_y * e][x_start + d_x * e] == col:165 e += 1166 len += 1167 if len == 5:168 return col169 elif len == 0:170 i += 1171 else:172 i += len173 len = 0174 return "none"175# print(detect_win(board, "w", 2, 7, 6, 1, -1))176# print(detect_win(board, "b", 7, 0, 5, 1, 1))177# print(detect_win(board, 'b', 0, 6, 5, 1, 0))178# def detect_win(board, col, y_start, x_start, length, d_y, d_x):179# for i in range(3):180# if board[y_start][x_start] == col:181# for n in range(length):182# if 0 > (y_start + d_y * n) or (y_start + d_y * n) > 7 or 0 > (x_start + d_x * n) or (x_start + d_x * n) > 7 or board[y_start+d_y * n][x_start + d_x * n] != col:183# return "none"184# return col185# def detect_win(board, col, y_start, x_start, length, d_y, d_x):186# count = 0187# for i in range(3):188# if 0 <= (y_start + d_y * i) <= 7 and 0 <= (x_start + d_x * i) <= 7 and board[y_start + d_y * i][x_start + d_x * i] == col:189# for n in range(length):190# if 0 > (y_start + d_y * (i + n)) or (y_start + d_y * (i + n)) > 7 or 0 > (x_start + d_x * (i + n)) or (x_start + d_x * (i + n)) > 7 or board[y_start+d_y * (i + n)][x_start + d_x * (i + n)] != col:191# count = 0192# else:193# count += 1194#195# if count == 5:196# return col197# count = 0198# return "none"199def detect_wins(board, col):200 for row in range(len(board)):201 if detect_win(board, col, row, 0, 5, 0, 1) == col:202 return col203 elif detect_win(board, col, 0, row, 5, 1, 0) == col:204 return col205 elif detect_win(board, col, row, 0, 5, 1, 1) == col:206 return col207 elif detect_win(board, col, 0, row, 5, 1, 1) == col:208 return col209 elif detect_win(board, col, row, 7, 5, 1, -1) == col:# 7 because last row of the board210 return col211 elif detect_win(board, col, 0, row, 5, 1, -1) == col:212 return col213 return "No win"214# print(detect_wins(board, "b"))215def test_is_bounded():216 board = make_empty_board(8)217 x = 7; y = 0; d_x = -1; d_y = 1; length = 3218 put_seq_on_board(board, y, x, d_y, d_x, length, "w")219 print_board(board)220 y_end = 2221 x_end = 5222 if is_bounded(board, y_end, x_end, length, d_y, d_x) == 'SEMIOPEN':223 print("TEST CASE for is_bounded PASSED")224 else:225 print("TEST CASE for is_bounded FAILED")226# def detect_row(board, col, y_start, x_start, length, d_y, d_x):227# # x = 5; y = 1; d_x = 0; d_y = 1; length = 3228# # put_seq_on_board(board, y, x, d_y, d_x, length, "w")229# i = 0230# len = 0231# open_seq_count = 0232# semi_open_seq_count = 0233# while i <= length:234# while board[y_start + d_y * len][x_start + d_x * len] == col:235# len += 1236#237# y_start += i * d_y238# # print(y_start)239# x_start += i * d_x240# y_end = y_start + d_y * (len) - d_y241# x_end = x_start + d_x * (len) - d_x242# if is_bounded(board, y_end, x_end, len, d_y, d_x) == "SEMIOPEN":243# semi_open_seq_count += 1244# elif is_bounded(board, y_end, x_end, len, d_y, d_x) == "OPEN":245# open_seq_count += 1246# i += 1 + len247# len = 0248#249# return open_seq_count, semi_open_seq_count250def test_detect_row():251 board = make_empty_board(8)252 x = 5; y = 1; d_x = 0; d_y = 1; length = 3253 put_seq_on_board(board, y, x, d_y, d_x, length, "w")254 x = 5; y = 5; d_x = 0; d_y = 1; length = 3255 put_seq_on_board(board, y, x, d_y, d_x, length, "w")256 print_board(board)257 if detect_row(board, "w", 0,x,length,d_y,d_x) == (1,1):258 print("TEST CASE for detect_row PASSED")259 else:260 print(detect_row(board, "w", 0,x,length,d_y,d_x))261 print("TEST CASE for detect_row FAILED")262# print(test_detect_row())263#MY VERSION THAT TESTS DIAGONALS264def test_detect_rows():265 board = make_empty_board(8)266 x = 5; y = 1; d_x = 1; d_y = 1; length = 3; col = 'w'267 put_seq_on_board(board, y, x, d_y, d_x, length, "w")268 print_board(board)269 if detect_rows(board, col,length) == (0,1):270 print("TEST CASE for detect_rows PASSED")271 print(detect_rows(board, col, length))272 else:273 print("TEST CASE for detect_rows FAILED")274 print(detect_rows(board, col, length))275# print(test_detect_rows())276def search_max(board):277 new_board = copy.deepcopy(board)278 max_score = -10000000279 move_y = -1280 move_x = -1281 for y in range(0, 8):282 for x in range(0, 8):283 if new_board[y][x] == " ":284 new_board[y][x] = "b"285 if score(new_board) > max_score:286 max_score = max(score(new_board), max_score)287 move_y = y288 move_x = x289 new_board[y][x] = board[y][x]290 return move_y, move_x291def score(board):292 MAX_SCORE = 100000293 open_b = {}294 semi_open_b = {}295 open_w = {}296 semi_open_w = {}297 for i in range(2, 6):298 open_b[i], semi_open_b[i] = detect_rows(board, "b", i)299 open_w[i], semi_open_w[i] = detect_rows(board, "w", i)300 if open_b[5] >= 1 or semi_open_b[5] >= 1:301 return MAX_SCORE302 elif open_w[5] >= 1 or semi_open_w[5] >= 1:303 return -MAX_SCORE304 return (-10000 * (open_w[4] + semi_open_w[4])+305 500 * open_b[4] +306 50 * semi_open_b[4] +307 -100 * open_w[3] +308 -30 * semi_open_w[3] +309 50 * open_b[3] +310 10 * semi_open_b[3] +311 open_b[2] + semi_open_b[2] - open_w[2] - semi_open_w[2])312board = make_empty_board(8)313# print_board(board)314# print(detect_row(board, "w", 0, 5, 3, 1, 0))315# print(is_bounded(board, 3, 5, 3, 1, 0))316# print(test_is_bounded())317#318# test_detect_row()319# board = make_empty_board(8)320# x = 5; y = 1; d_x = 0; d_y = 1; length = 3; col = 'b'321# put_seq_on_board(board, y, x, d_y, d_x, length, "b")322# print_board(board)323# print(search_max(board))324# print(score(board))325board = make_empty_board(8)326print(is_win(board))327##Chek FOR WIN DIRECTION(1, 1)328# x = 3; y = 0; d_x = 1; d_y = 1; length = 4; col = 'w'329# put_seq_on_board(board, y, x, d_y, d_x, length, col)330# x = 1; y = 0; d_x = 1; d_y = 1; length = 5; col = 'b'331# put_seq_on_board(board, y, x, d_y, d_x, length, col)332# print_board(board)333# search_max(board)334# print(detect_win(board, col, 1, 1, 5, 0, 1))335# print(detect_wins(board, "b"))336# print(is_win(board))337##CHECK FOR WIN Direction (0, 1)338# x = 3; y = 0; d_x = 1; d_y = 1; length = 4; col = 'w'339# put_seq_on_board(board, y, x, d_y, d_x, length, col)340# x = 1; y = 0; d_x = 1; d_y = 0; length = 5; col = 'b'341# put_seq_on_board(board, y, x, d_y, d_x, length, col)342# print_board(board)343# print(detect_win(board, "b", 0, 0, 5, 0, 1))344# print(is_win(board))345##CHECK FOR WIN Direction (1, -1)346# x = 3; y = 0; d_x = 1; d_y = 1; length = 1; col = 'w'347# put_seq_on_board(board, y, x, d_y, d_x, length, col)348# x = 7; y = 2; d_x = -1; d_y = 1; length = 5; col = 'w'349# put_seq_on_board(board, y, x, d_y, d_x, length, col)350# print_board(board)351# print(is_win(board))352##CHECK FOR WIN Direction (1, 0)353# x = 3; y = 0; d_x = 0; d_y = 1; length = 5; col = 'w'354# put_seq_on_board(board, y, x, d_y, d_x, length, col)355# x = 7; y = 1; d_x = 0; d_y = 1; length = 2; col = 'b'356# put_seq_on_board(board, y, x, d_y, d_x, length, col)357# print_board(board)358# print(detect_win(board, "b", 0, 0, 5, 1, 0))359# print(is_win(board))360##CHECK MAX SCORE361# x = 1; y = 1; d_x = 1; d_y = 1; length = 4; col = 'w'362# put_seq_on_board(board, y, x, d_y, d_x, length, col)363# x = 5; y = 5; d_x = 0; d_y = 1; length = 1; col = 'b'364# put_seq_on_board(board, y, x, d_y, d_x, length, col)365# print_board(board)366# print(score(board))367# print(search_max(board))368##RANDOM CHECK369# board = make_empty_board(8)370# put_seq_on_board(board, 0, 4, 1, -1, 5, "w")371# #print_board(board)372# print(is_win(board)) #White won373# board[3][1] = "b"374# #print_board(board)375# print(is_win(board)) #Continue playing"376# put_seq_on_board(board, 1, 5, 1, -1, 5, "w")377# #print_board(board)378# print(is_win(board)) #White won379# board[0][6] = "b"380# #print_board(board)381# print(is_win(board)) #White won382# board[1][5] = "b"383# #print_board(board)384# print(is_win(board)) #Continue playing"385# put_seq_on_board(board, 0, 2, 1, 1, 5, "w")386# print(is_win(board)) #White won387# board[2][4] = "b"388# print(is_win(board)) #Continue playing389# put_seq_on_board(board, 0, 3, 1, 1, 5, "w")390# print(is_win(board)) #White won391# board[2][5] = "b"392# print(is_win(board)) #Continue playing393# board[0][5] = "w"394# print(is_win(board)) #Continue playing395# board[0][5] = "w"396# board[0][1] = "w"397# print(is_win(board)) #White won398# board[2][5] = "b"399# print(is_win(board)) #White won400# board[0][2] = "b"401# print(is_win(board)) #Continue playing402# put_seq_on_board(board, 6, 1, 0, 1, 5, "w")403# print(is_win(board)) #White won404# board[6][0] = "b"405# print(is_win(board)) #White won406# board[6][6] = "b"407# print(is_win(board)) #White won408# board[6][3] = "b"409# print(is_win(board)) #Continue playing410# board[5][2] = "w"411# board[3][2] = "w"412# print(is_win(board)) #White won413# board[7][2] = "b"414# print(is_win(board)) #White won415# board[1][2] = "b"416# print(is_win(board)) #White won417# board[4][2] = "b"418# print(is_win(board)) #Continue playing419# board[3][4] = "b"420# board[0][7] = "b"421# board[0][0] = "w"422# board[7][3] = "w"423# board[7][1] = "b"424# board[7][0] = "b"425#426# print_board(board)427# print(is_win(board)) #Continue playing428# board[7][3] = "w"429# put_seq_on_board(board, 5, 3, 0, 1, 4, "b")430# put_seq_on_board(board, 7, 4, 0, 1, 4, "b")431# board[5][7] = "w"432# put_seq_on_board(board, 4, 2, 0, 1, 4, "b")433# board[4][1] = "w"434# print_board(board)435# print(is_win(board)) #Continue playing436# put_seq_on_board(board, 2, 0, 1, 0, 4, "b")437# #print_board(board)438# print(is_win(board))#Continue playing439# put_seq_on_board(board, 3, 7, 1, 0, 4, "w")440# #print_board(board)441# print(is_win(board))#Continue playing442# put_seq_on_board(board, 2, 4, 0, 1, 4, "b")443# board[5][0] = "w"444# board[1][0] = "w"445# board[2][3] = "w"446# put_seq_on_board(board, 0, 1, 1, 0, 3, "w")447# board[1][6] = "w"448# board[1][7] = "w"449# print(is_win(board)) # "Draw"450# print("\n\n")451###Everything says is same except should say black won not white won452# board = make_empty_board(8)453# put_seq_on_board(board, 0, 4, 1, -1, 5, "b")454# #print_board(board)455# print(is_win(board)) #White won456# board[3][1] = "w"457# #print_board(board)458# print(is_win(board)) #Continue playing"459# put_seq_on_board(board, 1, 5, 1, -1, 5, "b")460# #print_board(board)461# print(is_win(board)) #White won462# board[0][6] = "w"463# #print_board(board)464# print(is_win(board)) #White won465# board[1][5] = "w"466# #print_board(board)467# print(is_win(board)) #Continue playing"468# put_seq_on_board(board, 0, 2, 1, 1, 5, "b")469# print(is_win(board)) #White won470# board[2][4] = "w"471# print(is_win(board)) #Continue playing472# put_seq_on_board(board, 0, 3, 1, 1, 5, "b")473# print(is_win(board)) #White won474# board[2][5] = "w"475# print(is_win(board)) #Continue playing476# board[0][5] = "b"477# print(is_win(board)) #Continue playing478# board[0][5] = "b"479# board[0][1] = "b"480# print(is_win(board)) #White won481# board[2][5] = "w"482# # print_board(board)483# print(is_win(board)) #White won484# board[0][2] = "w"485# print(is_win(board)) #Continue playing486# put_seq_on_board(board, 6, 1, 0, 1, 5, "b")487# print(is_win(board)) #White won488# board[6][0] = "w"489# print(is_win(board)) #White won490# board[6][6] = "w"491# print(is_win(board)) #White won492# board[6][3] = "w"493# print(is_win(board)) #Continue playing494# board[5][2] = "b"495# board[3][2] = "b"496# print(is_win(board)) #White won497# board[7][2] = "w"498# print(is_win(board)) #White won499# board[1][2] = "w"500# print(is_win(board)) #White won501# board[4][2] = "w"502# print(is_win(board)) #Continue playing503# board[3][4] = "w"504# board[0][7] = "w"505# board[0][0] = "b"506# board[7][3] = "b"507# board[7][1] = "w"508# board[7][0] = "w"509# #print_board(board)510# print(is_win(board)) #Continue playing511# board[7][3] = "b"512# put_seq_on_board(board, 5, 3, 0, 1, 4, "w")513# put_seq_on_board(board, 7, 4, 0, 1, 4, "w")514# board[5][7] = "b"515# put_seq_on_board(board, 4, 2, 0, 1, 4, "w")516# board[4][1] = "b"517# print(is_win(board)) #Continue playing518# put_seq_on_board(board, 2, 0, 1, 0, 4, "w")519# #print_board(board)520# print(is_win(board))#Continue playing521# put_seq_on_board(board, 3, 7, 1, 0, 4, "b")522# #print_board(board)523# print(is_win(board))#Continue playing524# put_seq_on_board(board, 2, 4, 0, 1, 4, "w")525# board[5][0] = "b"526# board[1][0] = "b"527# board[2][3] = "b"528# put_seq_on_board(board, 0, 1, 1, 0, 3, "b")529# board[1][6] = "b"530# board[1][7] = "b"531# print(is_win(board)) # "Draw"532#533#534#...

Full Screen

Full Screen

player_stats_splits.py

Source:player_stats_splits.py Github

copy

Full Screen

...119 :type: bool120 """121 self._is_home = is_home122 @property123 def is_win(self):124 """Gets the is_win of this PlayerStatsSplits. # noqa: E501125 :return: The is_win of this PlayerStatsSplits. # noqa: E501126 :rtype: bool127 """128 return self._is_win129 @is_win.setter130 def is_win(self, is_win):131 """Sets the is_win of this PlayerStatsSplits.132 :param is_win: The is_win of this PlayerStatsSplits. # noqa: E501133 :type: bool134 """135 self._is_win = is_win136 @property137 def is_ot(self):138 """Gets the is_ot of this PlayerStatsSplits. # noqa: E501139 :return: The is_ot of this PlayerStatsSplits. # noqa: E501140 :rtype: bool141 """142 return self._is_ot143 @is_ot.setter144 def is_ot(self, is_ot):...

Full Screen

Full Screen

test_checker.py

Source:test_checker.py Github

copy

Full Screen

1from unittest import TestCase, mock2from text_tic_tac_toe_python.checker import is_a_valid_symbol, is_a_valid_move, is_a_give_up_move, is_a_win_move, \3 were_all_moves_done, is_a_tied_game4from text_tic_tac_toe_python import constants5class Checker(TestCase):6 def test_lower_x_is_valid_should_return_true(self):7 self.assertTrue(is_a_valid_symbol('x'))8 def test_upper_x_is_valid_should_return_true(self):9 self.assertTrue(is_a_valid_symbol('X'))10 def test_lower_o_is_valid_should_return_true(self):11 self.assertTrue(is_a_valid_symbol('o'))12 def test_upper_o_is_valid_should_return_true(self):13 self.assertTrue(is_a_valid_symbol('O'))14 def test_lower_z_is_valid_should_return_false(self):15 self.assertFalse(is_a_valid_symbol('z'))16 def test_upper_z_is_valid_should_return_false(self):17 self.assertFalse(is_a_valid_symbol('Z'))18 def test_1_is_valid_should_return_false(self):19 self.assertFalse(is_a_valid_symbol('1'))20 def test_special_symbol_is_valid_should_return_false(self):21 self.assertFalse(is_a_valid_symbol('@'))22 def test_1_is_a_valid_move_on_an_empty_board_should_return_true(self):23 is_valid = is_a_valid_move('1', constants.EMPTY_BOARD)24 self.assertTrue(is_valid)25 def test_10_is_a_valid_move_on_an_empty_board_should_return_false(self):26 is_valid = is_a_valid_move('10', constants.EMPTY_BOARD)27 self.assertFalse(is_valid)28 def test_3_is_a_valid_move_on_a_complete_board_should_return_false(self):29 is_valid = is_a_valid_move('3', ['X','X','O','O','O','X','X','O','X'])30 self.assertFalse(is_valid)31 def test_0_is_a_give_up_move_should_return_true(self):32 is_give_up = is_a_give_up_move('0')33 self.assertTrue(is_give_up)34 def test_00_is_a_give_up_move_should_return_false(self):35 is_give_up = is_a_give_up_move('00')36 self.assertFalse(is_give_up)37 def test_same_symbols_in_the_first_row_should_be_a_win_move(self):38 is_win = is_a_win_move(['X', 'X', 'X', '4', '5', '6', '7', '8', '9'])39 self.assertTrue(is_win)40 def test_same_symbols_in_the_second_row_should_be_a_win_move(self):41 is_win = is_a_win_move(['1', '2', '3', 'O', 'O', 'O', '7', '8', '9'])42 self.assertTrue(is_win)43 def test_same_symbols_in_the_third_row_should_be_a_win_move(self):44 is_win = is_a_win_move(['1', '2', '3', '4', '5', '6', 'X', 'X', 'X'])45 self.assertTrue(is_win)46 def test_same_symbols_in_the_first_column_should_be_a_win_move(self):47 is_win = is_a_win_move(['X', '2', '3', 'X', '5', '6', 'X', '8', '9'])48 self.assertTrue(is_win)49 def test_same_symbols_in_the_second_column_should_be_a_win_move(self):50 is_win = is_a_win_move(['1', 'O', '3', '4', 'O', '6', '7', 'O', '9'])51 self.assertTrue(is_win)52 def test_same_symbols_in_the_third_column_should_be_a_win_move(self):53 is_win = is_a_win_move(['1', '2', 'X', '4', '5', 'X', '7', '8', 'X'])54 self.assertTrue(is_win)55 def test_same_symbols_in_the_second_column_should_be_a_win_move(self):56 is_win = is_a_win_move(['1', 'O', '3', '4', 'O', '6', '7', 'O', '9'])57 self.assertTrue(is_win)58 def test_same_symbols_in_the_left_diagonal_should_be_a_win_move(self):59 is_win = is_a_win_move(['X', '2', '3', '4', 'X', '6', '7', '8', 'X'])60 self.assertTrue(is_win)61 def test_same_symbols_in_the_right_diagonal_should_be_a_win_move(self):62 is_win = is_a_win_move(['1', '2', 'X', '4', 'X', '6', 'X', '8', '9'])63 self.assertTrue(is_win)64 def test_different_symbols_in_the_first_row_should_not_be_a_win_move(self):65 is_win = is_a_win_move(['X', 'O', 'X', '4', '5', '6', '7', '8', '9'])66 self.assertFalse(is_win)67 def test_different_symbols_in_the_second_row_should_not_be_a_win_move(self):68 is_win = is_a_win_move(['1', '2', '3', 'X', 'O', 'O', '7', '8', '9'])69 self.assertFalse(is_win)70 def test_different_symbols_in_the_third_row_should_not_be_a_win_move(self):71 is_win = is_a_win_move(['1', '2', '3', '4', '5', '6', 'X', 'X', '9'])72 self.assertFalse(is_win)73 def test_different_symbols_in_the_first_column_should_not_be_a_win_move(self):74 is_win = is_a_win_move(['O', '2', '3', 'X', '5', '6', 'X', '8', '9'])75 self.assertFalse(is_win)76 def test_different_symbols_in_the_second_column_should_not_be_a_win_move(self):77 is_win = is_a_win_move(['1', 'X', '3', '4', 'O', '6', '7', 'O', '9'])78 self.assertFalse(is_win)79 def test_different_symbols_in_the_third_column_should_not_be_a_win_move(self):80 is_win = is_a_win_move(['1', '2', 'X', '4', '5', 'O', '7', '8', 'X'])81 self.assertFalse(is_win)82 def test_different_symbols_in_the_second_column_should_not_be_a_win_move(self):83 is_win = is_a_win_move(['1', 'O', '3', '4', 'X', '6', '7', 'O', '9'])84 self.assertFalse(is_win)85 def test_different_symbols_in_the_left_diagonal_should_not_be_a_win_move(self):86 is_win = is_a_win_move(['X', '2', '3', '4', 'O', 'O', '7', 'O', 'O'])87 self.assertFalse(is_win)88 def test_different_symbols_in_the_right_diagonal_should_not_be_a_win_move(self):89 is_win = is_a_win_move(['O', 'X', 'X', 'X', 'O', 'O', 'X', 'O', 'X'])90 self.assertFalse(is_win)91 def test_all_moves_were_done_with_an_incomplete_game_should_return_false(self):92 all_moves_done = were_all_moves_done(['1', '2', 'X', 'X', 'O', 'O', 'X', 'O', 'X'])93 self.assertFalse(all_moves_done)94 def test_all_moves_were_done_with_a_complete_game_should_return_true(self):95 all_moves_done = were_all_moves_done(['O', 'X', 'X', 'X', 'O', 'O', 'X', 'O', 'X'])96 self.assertTrue(all_moves_done)97 def test_tied_game_with_an_incomplete_game_should_return_false(self):98 tied_game = is_a_tied_game(['1', '2', 'X', 'X', 'O', 'O', 'X', 'O', 'X'])99 self.assertFalse(tied_game)100 def test_tied_game_with_a_game_won_should_return_false(self):101 tied_game = is_a_tied_game(['X', 'X', 'X', 'O', 'X', 'O', 'X', 'O', 'O'])102 self.assertFalse(tied_game)103 def test_tied_game_with_a_complete_and_a_game_not_won_should_return_true(self):104 all_moves_done = were_all_moves_done(['O', 'X', 'X', 'X', 'O', 'O', 'X', 'O', 'X'])...

Full Screen

Full Screen

ai_graph.py

Source:ai_graph.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import json3import MySQLdb4import time5from mailsender import sender6sql = '''7SELECT LEFT(DATE_SUB(DATE, INTERVAL 3 HOUR),10),AVG(CASE WHEN ab_test_value = 1 THEN is_win END) AS 'ab1的胜率',8COUNT(CASE WHEN ab_test_value = 1 THEN id END) /5 AS 'ab1的场次',9COUNT(CASE WHEN ab_test_value = 1 THEN id END) * AVG(CASE WHEN ab_test_value = 1 THEN is_win END)/5 AS 'ab1的胜场',10AVG(CASE WHEN ab_test_value = 2 THEN is_win END) AS 'ab2的胜率',11COUNT(CASE WHEN ab_test_value = 2 THEN id END) /5 AS 'ab2的场次',12COUNT(CASE WHEN ab_test_value = 2 THEN id END) * AVG(CASE WHEN ab_test_value = 2 THEN is_win END)/5 AS 'ab2的胜场',13AVG(is_win) AS '总的胜率',14COUNT(*) /5 AS '总的场次',15COUNT(*) * AVG(is_win)/5 AS '总的胜场', 16DATE_FORMAT(DATE, '%W') AS '工作日' 17FROM ai_stat_one_round 18WHERE is_ai = 1 AND map_name = '{map}' AND round_id IN 19(SELECT round_id FROM ai_stat_one_round WHERE is_ai = 1 AND DATE >=DATE_ADD('{st}', INTERVAL 3 HOUR) AND DATE<=DATE_ADD('{et}', INTERVAL 3 HOUR) 20GROUP BY round_id HAVING COUNT(*) = 5 AND SUM(LEVEL = {ai_difficulty}) = 5 AND (SUM(team=1) = 5 OR SUM(team=2) = 5)) GROUP BY LEFT(DATE_SUB(DATE, INTERVAL 3 HOUR),10)21'''22sql10v10 = '''23SELECT LEFT(DATE_SUB(DATE, INTERVAL 3 HOUR),10),AVG(CASE WHEN ab_test_value = 1 THEN is_win END) AS 'ab1的胜率',24COUNT(CASE WHEN ab_test_value = 1 THEN id END) / 10 AS 'ab1的场次',25COUNT(CASE WHEN ab_test_value = 1 THEN id END) * AVG(CASE WHEN ab_test_value = 1 THEN is_win END)/ 10 AS 'ab1的胜场', 26AVG(CASE WHEN ab_test_value = 2 THEN is_win END) AS 'ab2的胜率',27COUNT(CASE WHEN ab_test_value = 2 THEN id END) / 10 AS 'ab2的场次',28COUNT(CASE WHEN ab_test_value = 2 THEN id END) * AVG(CASE WHEN ab_test_value = 2 THEN is_win END)/ 10 AS 'ab2的胜场',29AVG(is_win) AS '总的胜率',30COUNT(*) / 10 AS '总的场次',31COUNT(*) * AVG(is_win)/ 10 AS '总的胜场', 32DATE_FORMAT(DATE, '%W') AS '工作日' 33FROM ai_stat_one_round 34WHERE map_name = '10v10' AND is_ai = 1 and DATE >=DATE_ADD('{st}', INTERVAL 3 HOUR) AND DATE<=DATE_ADD('{et}', INTERVAL 3 HOUR) GROUP BY LEFT(DATE_SUB(DATE, INTERVAL 3 HOUR),10)35'''36settings = json.load(open('settings.json', 'r'))37column_map = ['地图', '难度', 'ab1场次', 'ab1胜场', 'ab1胜率', 'ab2场次', 'ab2胜场', 'ab2胜率', '总场次', '胜场', '胜率']38def gen_table_head():39 head = ''40 for d in column_map:41 head += gen_a_tag('th', d)42 head = gen_a_tag('tr', head)43 return head44def gen_a_tag(tag, c='', attr=''):45 if isinstance(c, unicode):46 c = c.encode('utf-8')47 return '<{} {}>{}</{}>'.format(tag, attr, c, tag)48def send_report_mail(today, yesterday):49 conn_in = MySQLdb.connect(host=settings['host'], user=settings['user'], passwd=settings['passwd'], db=settings['db'], port=settings['port'])50 conn_in.set_character_set("utf8")51 cur_in = conn_in.cursor()52 # head53 content = gen_a_tag('h1', 'DAILY REPORT')54 content += gen_a_tag('p', 'DATE: {}~{}'.format(yesterday, today))55 content += '<br/>'56 # table57 tbl = gen_table_head()58 for m in settings['maps']:59 d_c = 160 if m == 'FantasyAllStar':61 d_c = 462 tbl += '<tr>' + gen_a_tag('td', m, 'rowspan=\"{}\"'.format(d_c))63 closed = False64 for d in settings['difficulty']:65 if closed:66 tbl += '<tr>'67 if m == '10v10':68 cur_in.execute(sql10v10.format(st=yesterday, et=today))69 else:70 cur_in.execute(sql.format(map=m, ai_difficulty=settings['difficulty'][d], st=yesterday, et=today))71 conn_in.commit()72 for res in cur_in:73 row = [d]74 row.extend([75 round(res[2] or 0),76 round(res[3] or 0),77 float(res[1] or 0),78 round(res[5] or 0),79 round(res[6] or 0),80 float(res[4] or 0),81 round(res[8] or 0),82 round(res[9] or 0),83 float(res[7] or 0)84 ])85 print row86 for r in row:87 tbl += gen_a_tag('td', r)88 tbl += '</tr>'89 closed = True90 content += gen_a_tag('table', tbl, 'border=\"1\"')91 title = '[AI]daily report'92 with open('html.html', 'w') as c:93 c.write(content)94 # ms = sender.MailSender()95 # ms.send_mail(title, content, settings['receiver_group'])96if __name__ == '__main__':97 last = ''98 while True:99 now = time.time()100 fmt_now = time.localtime(now)101 today = time.strftime('%Y-%m-%d', fmt_now)102 if fmt_now.tm_hour == 10 and fmt_now.tm_min == 0 and today != last or not last:103 print '{} sending mail'.format(today)104 yesterday = time.strftime('%Y-%m-%d', time.localtime(now - 24 * 3600))105 send_report_mail(today, yesterday)106 last = today...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful