How to use check_targets method in wpt

Best JavaScript code snippet using wpt

game.js

Source:game.js Github

copy

Full Screen

1class game{2 constructor(play_time = 40, camera_port = 0){ //camera_port = 0 // TO CHANGE3 // pygame.init()4 // this.win_sound = [pygame.mixer.Sound(resource_path("Sounds/pop1.wav")),5 // pygame.mixer.Sound(resource_path("Sounds/pop4.wav")),6 // pygame.mixer.Sound(resource_path("Sounds/pop6.wav"))]7 // this.error_sound = pygame.mixer.Sound(resource_path("Sounds/boom1.wav"))8 // pygame.font.init()9 // all_fonts = pygame.font.get_fonts()10 // this.textsize ={"large": pygame.font.SysFont(all_fonts[3], 200),11 // "medium": pygame.font.SysFont(all_fonts[3], 100),12 // "mid":pygame.font.SysFont(all_fonts[3],60),13 // "small": pygame.font.SysFont(all_fonts[3], 40),14 // "tiny": pygame.font.SysFont(all_fonts[3], 33)}15 // this.textsize = {"large": pygame.font.Font('freesansbold.ttf',200),16 // "medium": pygame.font.Font('freesansbold.ttf',100),17 // "small":pygame.font.Font('freesansbold.ttf',40),18 // "tiny": pygame.font.Font('freesansbold.ttf',20)}19 this.textcolor = {"gray": (100,100,100),20 "white": (255,255,255),21 "black": (0,0,0),22 "red": (255,0,0),23 "green": (0,255,0),24 "blue": (0,0,255)};25 this.camera_port = camera_port;26 this.play_time = play_time;27 this.game_type = null;28 this.wait_time = 5;29 this.obstacle_count = 0;30 this.intervention = 0;31 this.blob_area = 1;32 this.mirror = false;33 this.scaling_factor = 10;34 this.display_score = 0;35 this.old_score = 0;36 this.saveframe = false;37 this.game_params = null; // json.load(open(resource_path('JsonFiles/Player_3/GameParams.json'),'r'));38 this.initializeGameType();39 this.initializeGameFrame();40 this.setGameID();41 this.resetBounds();42 this.resetRotationAngle();43 this.stationary = false;44 this.test_FR = 0;45 }46 resetDamping(damping = 0){47 this.damping = damping; //0 // 0.5 // -0.548 var scale_mat = [[1,0],[0,1]];49 this.damping_mat = scaleMatrix(scale_mat,this.damping);50 // this.damping_mat = this.damping*np.array(((-1, -1),(-1, 1)));51 this.player.resetDamping(this.damping, old_loc_wt = 0.3, new_loc_wt = 0.7) // Setting equal weightage to actual location && predicted location to allow damping effect52 }53 initializeGameType(exploding_perc = 0.33, max_unobs_time = 0.2, max_obs_time = 0.8, 54 vel_max = 1, vel_min = 0.5, acc = 100, theta_max = -30, theta_min = -90,55 min_obstacles = 1, max_obstacles = 4, damping = 0, mirror = false, magnetic_coef = 1000 ){56 this.exploding_perc = exploding_perc;57 this.max_unobs_time = max_unobs_time;58 this.max_obs_time = max_obs_time;59 this.acceleration = [0,acc];60 this.velocity_min = vel_min;61 this.velocity_max = vel_max;62 this.theta_max = theta_max;63 this.theta_min = theta_min;64 this.min_obstacles = min_obstacles;65 this.max_obstacles = max_obstacles;66 this.damping = damping; // 0.5 // -0.567 var scale_mat = [[1,0],[0,1]];68 this.damping_mat = scaleMatrix(scale_mat,this.damping);69 // this.damping_mat = this.damping*np.array(((-1, -1),(-1, 1)))70 this.mirror = mirror;71 this.magnetic_coef = magnetic_coef;72 if (vel_max == vel_min && vel_max == 0){73 this.stationary = true;74 }75 }76 77 resetMagneticCoef(magnetic_coef){78 this.magnetic_coef = magnetic_coef;79 }80 initializeGameFrame(){81 // Function to initialilze the game screen size - background etc.82 drawBG()83 console.log("Screen size is: width=", gameCanvas.width," height=", gameCanvas.height);84 // this.video_capture = cv2.VideoCapture(this.camera_port)85 86 //// For windows87 // root = tk.Tk()88 // screen_width = root.winfo_screenwidth()89 // screen_height = root.winfo_screenheight()90 // this.screen_size_tuple = (screen_width, screen_height)91 // this.game_display = pygame.display.set_mode(this.screen_size_tuple)92 //// For Linux || Mac (?)93 // this.game_display = pygame.display.set_mode((0,0), pygame.FULLSCREEN)94 // screen_width = pygame.display.Info().current_w95 // screen_height = pygame.display.Info().current_h96 // this.screen_size_tuple = (screen_width, screen_height)97 // console.log(f"Width is {screen_width} && height is {screen_height}")98 // frame_width = int(this.video_capture.get(cv2.CAP_PROP_FRAME_WIDTH))99 // frame_height = int(this.video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))100 101 // console.log(f"Width is {frame_width} && height is {frame_height}")102 103 104 // this.original_frame_tuple = (frame_width, frame_height)105 // this.aspectratio = this.original_frame_tuple[0]/this.original_frame_tuple[1]//frame_width/frame_height106 // // console.log(f'aspect ratio {this.aspectratio}')107 // this.frame_size_tuple = (int(this.screen_size_tuple[1]*this.aspectratio),this.screen_size_tuple[1])108 // this.width_ratio = this.original_frame_tuple[0]/(this.screen_size_tuple[1]*this.aspectratio)109 // this.height_ratio = this.original_frame_tuple[1]/this.screen_size_tuple[1]110 // // console.log(f'Width ratio is {this.width_ratio}, height ratio is {this.height_ratio}')111 // this.frame_offset = int((this.screen_size_tuple[0] - int(this.screen_size_tuple[1]*this.aspectratio))/2)112 // this.scaling_factor = 1/this.height_ratio113 // this.calibrate_button = pygame.Rect(this.frame_offset + this.frame_size_tuple[0]/5, np.round(2.5*this.frame_size_tuple[1]/4), this.frame_size_tuple[0]/5, this.frame_size_tuple[0]/15)114 // this.start_button = pygame.Rect(this.frame_offset + 3*this.frame_size_tuple[0]/5, np.round(2.5*this.frame_size_tuple[1]/4), this.frame_size_tuple[0]/5, this.frame_size_tuple[0]/15)115 // this.test_button = pygame.Rect(this.frame_offset + 2*this.frame_size_tuple[0]/5, 3*this.frame_size_tuple[1]/4, this.frame_size_tuple[0]/5, this.frame_size_tuple[0]/15)116 117 // this.button_color = (this.textcolor["grey"]118 // this.player_id_textbox = pygame.Rect(100, 100, 50, 50)119 // this.textbox_color = (255,255,255)120 // pygame.display.set_caption('Reach Ninja')121 }122 setGameID(){123 var d = new Date();124 this.game_id = d.getDate()+ "-" + d.getMonth() + "-" + d.getYear() + 125 "_" + d.getHours() + "-" + d.getMinutes() + "-" + d.getSeconds();// datetime.datetime.now().strftime("%d-%m-%Y_%H-%M-%S");126 }127 startrun(){128 var game_group = 2;129 var current_game_type = "Control";130 if (game_group == 3){ // 3 is curriculum; 2 is control131 current_game_type = "Curriculum";132 }133 // current_game_type = 'Control'134 // clock = pygame.time.Clock()135 136 this.crashed = false;137 // this.game_mode = null;138 // key = cv2.waitKey(1)139 // key = key & 0xFF140 var player_id = 3;141 var gameshape = [gameCanvas.width, gameCanvas.height];142 this.player = new player(gameshape, this.damping, this.mirror, player_id, 0, 1);143 this.init_line = "Screen: " + gameshape;144 // this.gamelog = Gamelog(this.player, this.game_id)145 this.gamelog = new gamelog(this.player, this.game_id);146 147 148 }149 // console.log(t_old);150 // for (var t = 0; t < this.play_time;){151 // t = getTimeS() - start_time;152 // if (Math.ceil(t) != Math.ceil(t_old)){153 // console.log(Math.ceil(t_old));154 // }155 // t_old = t;156 // // for event in pygame.event.get():157 // // if event.type == pygame.QUIT:158 // // this.crashed = true159 // // else if event.type == pygame.KEYDOWN && event.key == pygame.K_q:160 // // this.crashed = true161 // // else if event.type == pygame.KEYDOWN && event.key == pygame.K_s:162 // // this.game_mode = 'StartPlay'163 // // else if event.type == pygame.KEYDOWN && event.key == pygame.K_c:164 // // this.game_mode = 'Calibrate'165 // // this.current_time = getTimeS() 166 // // else if event.type == pygame.KEYDOWN && event.key == pygame.K_t:167 // // this.game_mode = 'Test'168 // // else if event.type == pygame.KEYDOWN && event.key == pygame.K_e:169 // // this.game_mode = null170 // // this.player.start_time = -1171 // // // this.player.attempt -= 1 // TO CHANGE172 // // console.log('Exiting... ')173 // // else if event.type == pygame.MOUSEBUTTONDOWN:174 // // if this.start_button.collidepoint(event.pos):175 // // this.game_mode = 'StartPlay'176 // // else if this.calibrate_button.collidepoint(event.pos):177 // // this.game_mode = 'Calibrate'178 // // this.current_time = getTimeS() 179 // // else if this.test_button.collidepoint(event.pos):180 // // this.game_mode = 'Test'181 // // else:182 // // this.pickColor()183 184 // // if (this.game_mode == null){185 // // this.displayDefault();186 // // }187 // // else if (this.game_mode == 'StartPlay' && this.player.start_time == -1){188 /////////////////////////189 run(){190 var current_game_type = "Control";191 // console.log(this.game_mode);192 if (this.game_mode == 'StartPlay' && this.player.start_time == -1){193 // Check for more than 40 attenpts194 if (this.player.attempt >= 40){195 console.log('Quitting... ');196 this.crashed = true;197 }198 else{199 console.log('Starting... ');200 // alert('starting');201 this.player.setStartTime();202 this.player.last_time = getTimeS();203 this.game_type = current_game_type;204 this.frame_id = 1;205 // // this.waitGame(getTimeS());206 this.check_targets = false;207 console.log('Here');208 this.initializeNewGame();209 if (tracking_type == "Video"){210 this.resetMagneticCoef(1000);211 this.player.resetObsTime(1,0);212 }213 else{214 this.resetMagneticCoef(5000);215 this.player.resetObsTime(1,0);216 }217 this.gamelog.newGameLog(this.player.attempt, this.init_line)218 }219 }220 else if (this.game_mode == 'InPlay' && (getTimeS() - this.player.start_time) <= this.play_time){221 this.current_time = getTimeS();222 this.saveframe = false;//InPlay // NEED TO CHANGE THIS BACK TO TRUE TO SAVE IMAGES223 this.updateGameFrame();224 this.updateGamelog();225 }226 227 else if (this.game_mode == 'InPlay'){228 this.game_mode = null;229 this.saveframe = false;230 // pygame.time.delay(2000);231 // setTimeout(() => {232 // console.log("Waited 2000 ms");233 // }, 2000);234 this.player.setStartTime();235 // console.log(this.gamelog.datalog);236 this.crashed = true;237 }238 // else if (this.game_mode == 'Calibrate'){239 // console.log('Calibrating...')240 // this.frame_id = 1;241 // this.saveframe = false;242 // // this.gamelog.savefolder = this.gamelog.calibration_log_folder243 // this.calibrateGame();244 // this.game_mode = null;245 // }246 // else if (this.game_mode == 'Test'){247 // console.log('Testing...');248 // this.frame_it = 1;249 // this.test_duration = 10; //s250 // this.testGame();251 // this.game_mode = null;252 // }253 // }254 // pygame.display.update()255 // clock.tick(60)256 // this.video_capture.release()257 // cv2.destroyAllWindows()258 // pygame.quit()259 if (this.crashed == true){260 if (confirm("Game ended! Restart?")){261 this.game_mode = 'StartPlay';262 this.player.start_time = -1;263 this.crashed = false;264 }265 }266 }267 // videoFrameToPyGameDisplay(frame, saveframe = false, savelocation = []){268 // frame, center, blob_area = this.blobDetect(frame)269 // frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)270 // if saveframe == true:271 // cv2.imwrite(f"{this.calibration_log_folder}/{this.frame_id:010d}.png",frame)272 // frame = np.rot90(frame)273 // frame = pygame.surfarray.make_surface(frame)274 // frame = pygame.transform.scale(frame, this.frame_size_tuple)275 // return frame276 // }277 updateGameFrame(){278 // ret, frame = this.video_capture.read()279 // frame = cv2.flip(frame, 1)280 // console.log("In game frame");281 this.stepGame();282 // this.game_display.fill([255,255,255]);283 // pygame.draw.rect(this.game_display, (0,0,0), (0,0,this.frame_offset, this.frame_size_tuple[1]))284 // pygame.draw.rect(this.game_display, (0,0,0), (this.frame_offset + this.frame_size_tuple[0],0,this.frame_offset, this.frame_size_tuple[1]))285 286 // console.log(this.player.loc, this.height_ratio)287 // playerloc = (int(this.player.loc[0]/this.width_ratio) + this.frame_offset, int(this.player.loc[1]/this.height_ratio))288 // console.log(f"player.loc {this.player.loc}, height ratio {this.height_ratio}, new updategameframe {playerloc}")289 // if this.player.checkObservable(getTimeS()):290 // pygame.draw.circle(this.game_display, this.player.marker_color, playerloc, int(this.scaling_factor*this.player.radius))291 // 292 drawBG();293 // console.log(this.player.checkObservable(getTimeS()));294 if (this.player.checkObservable(getTimeS())) {295 // console.log(this.player.loc);296 this.drawCircle(this.player);297 } 298 for (var c = 0; c<this.curr_obstacle.length; c++){ //o in this.curr_obstacle:299 // obstacleloc = (int(o.loc[0]/this.width_ratio) + this.frame_offset, int(o.loc[1]/this.height_ratio))300 // console.log(this.curr_obstacle[c].loc);301 this.drawCircle(this.curr_obstacle[c]);302 // pygame.draw.circle(this.game_display, o.marker_color, obstacleloc, int(this.scaling_factor*o.radius))303 }304 305 306 clearCanvas(scoreCanvas);307 var score_line = "Score:";308 this.writeOnCanvas(scoreCanvas, score_line, [scoreCanvas.width/2-75, scoreCanvas.height/2-50], "gray", "50px");309 score_line = this.player.score;310 this.writeOnCanvas(scoreCanvas, score_line, [scoreCanvas.width/2-20, scoreCanvas.height/2+50], "gray", "50px");311 312 clearCanvas(timeCanvas);313 var time_line = "Time:";314 this.writeOnCanvas(timeCanvas, time_line, [timeCanvas.width/2-75, timeCanvas.height/2-50], "gray", "50px");315 time_line = Math.ceil(this.play_time - (this.curr_time - this.player.start_time));316 this.writeOnCanvas(timeCanvas, time_line, [timeCanvas.width/2-20, timeCanvas.height/2+50], "gray", "50px");317 if (tracking_type == "Video"){318 var disp_frames = 10; 319 }320 else{321 var disp_frames = 100;322 }323 324 if (this.display_score > 0 && this.display_score <= disp_frames){325 var score_change = this.player.score - this.old_score;326 // console.log(score_change);327 var dispmsg = Math.ceil(score_change);328 if (score_change < 0){329 dispmsg = Math.ceil(score_change);330 }331 this.writeOnCanvas(gameCanvas,dispmsg, this.player.loc, "black", "20px");332 this.display_score += 1;333 if (this.display_score == disp_frames){334 this.old_score = this.player.score;335 this.display_score = 0;336 }337 }338 // pygame.display.update()339 }340 writeOnCanvas(curr_canvas, display_text, text_loc, textcolor, textsize = "20px"){341 var ctx = curr_canvas.getContext("2d");342 ctx.font = textsize +" Arial";343 ctx.fillStyle = textcolor;344 ctx.fillText(display_text, text_loc[0], text_loc[1]);345 }346 drawHand(marker){347 ctx.beginPath();348 ctx.arc(marker.loc[0], marker.loc[1], marker.radius, 0, Math.PI*2);349 ctx.fillStyle = marker.marker_color;350 ctx.fill();351 ctx.closePath();352 }353 stepGame(){354 this.curr_time = getTimeS();355 // console.log(this.curr_time);356 // frame, center, blob_area = this.blobDetect(rawframe)357 // console.log(f'stepGame center {center}')358 // if blob_area >= this.blob_area:359 // new_loc = np.array(center) 360 // // console.log(f'Observed location is {new_loc}')361 // if this.mirror:362 // new_loc = this.flipMarkerPosition(new_loc, center)363 // // console.log(f'Changed location is {new_loc}')364 // else:365 // new_loc = np.array(this.player.loc)366 // new_loc = this.rotateMarkerPosition(new_loc)367 // console.log(f'Final location is {new_loc}')368 // console.log(f'Stepgame new_loc {new_loc}')369 // this.player.updatePosition(new_loc, this.curr_time)370 // console.log(f'this.player.loc in stepGame after update {this.player.loc}')371 // console.log('Here in Stepgame')372 // drawBG() // Make background black and white - from other script373 // drawHand(newplayer) // Draw the hand marker374 // for(let c=0; c<obstaclecount; c++){375 // ctime = getTimeS();376 // console.log(targets[c].loc)377 // targets[c].updatePosition(ctime, [newplayer.loc[0],newplayer.loc[1]], 10, 1000);378 // console.log(targets[c].loc)379 // if (!targets[c].inframe){380 // targets[c] = new obstacles(gameshape, ctime, expl);381 // }382 // drawMarker(targets[c])383 // }384 var new_obstacle = new Array();385 var resetobstacle_count = false;386 this.check_targets = false;387 if (this.frame_id == 1){388 this.player.obs_start = getTimeS();389 }390 this.frame_id ++;391 var new_marker_no = 0;392 // console.log(this.curr_obstacle.length)393 for (var ob_ctr = 0; ob_ctr < this.curr_obstacle.length; ob_ctr++) {//o in this.curr_obstacle:394 // console.log(this.curr_obstacle[ob_ctr].loc);395 // console.log(ob_ctr);396 this.curr_obstacle[ob_ctr].updatePosition(this.curr_time, this.player.loc, this.player.radius, this.magnetic_coef);397 // console.log(this.curr_obstacle[ob_ctr].loc)398 var o = this.curr_obstacle[ob_ctr];399 // console.log(o.inframe);400 //Check for collision of player && marker - is this happens, score change && reset obstacle count401 if (o.checkCollision(this.player, 1)){ // this.scaling_factor/2)){402 var addscore = this.updateScore(o);403 404 // if o.obstacle_type == 'Exploding':405 // pygame.mixer.Sound.play(this.error_sound);406 // pygame.time.delay(500)407 // else:408 // try:409 // p = max( i for i,o in enumerate(addscore - np.array([0, 8, 15])) if o > 0);410 // except:411 // p = 0;412 // pygame.mixer.Sound.play(this.win_sound[p])413 resetobstacle_count = true;414 new_marker_no = o.new_marker_no;415 this.display_score = 1;416 }417 // Check if marker left the screen, if this happens, reset obstacle count418 else if (!o.inframe){419 resetobstacle_count = true;420 new_marker_no = o.new_marker_no;421 }422 // Old case, where we had stationary markers - timeout after 10s, no longer relevant423 else if (this.stationary && o.obstacle_type == 'Exploding' && (this.curr_time - o.start_time) > 10){424 resetobstacle_count = true;425 new_marker_no = o.new_marker_no;426 }427 428 // Check if the marker is Regular, if it is, check_targets is set to true indicating at least one of the markers in the new obstacle set is regular429 else if (o.obstacle_type == 'Regular'){430 this.check_targets = true;431 new_obstacle.push(o);432 }433 // This case will only be entered when the marker is 'Exploding' && still in frame / not collided with player434 else{435 new_obstacle.push(o)436 }437 }438 // if this.stationary && not this.check_targets:439 // // console.log('Here')440 // resetobstacle_count = true //this.obstacle_count += 1441 // new_marker_no = o.new_marker_no442 // console.log(new_obstacle);443 this.curr_obstacle = new_obstacle; // Effectively removed collided || out of frame markers444 if (resetobstacle_count){445 // Resetting obstacle count. 446 // If this.check_targets is still false, the new count will necessarily be 1 more than the last length447 // Otherwise, the new count will be new_marker_no - from seeds448 this.newobstacle_count(new_marker_no, this.curr_obstacle);449 }450 // console.log('Here before while');451 // this.check_targets has not been updates so it will still be false if null of the obstacles still on screen are 'Regular'452 while (this.curr_obstacle.length < this.obstacle_count){453 this.cur_obstacle_id += 1;454 var ctime = getTimeS();455 var new_obstacle = new obstacles(gameshape, ctime, this.exploding_perc, this.velocity_max, this.velocity_min, this.acceleration[1], this.theta_max, this.theta_min, this.max_obs_time, this.max_unobs_time, this.cur_obstacle_id);456 this.curr_obstacle.push(new_obstacle);457 // console.log('new obstacle ' + new_obstacle.loc);458 // this.cur_obstacle_id += 1;459 // new_obstacle = new obstacles([gameCanvas.width,gameCanvas.height], +460 // this.current_time, this.exploding_perc, +461 // this.velocity_max, this.velocity_min, +462 // this.acceleration[1], this.theta_max, this.theta_min,+463 // this.max_obs_time, this.max_unobs_time, this.cur_obstacle_id);464 // this.curr_obstacle.push(new_obstacle);465 //// The following commented code is required for older curriculums where obstacle properties were being changed.466 // if this.player.attempt in [1,2,3,38,39,40] && this.game_type in ['Curriculum', 'Regular']:467 // this.game_obstacles = json.load(open(resource_path(f'GameSeeds_{this.player.attempt}.json'),'r'))468 // 469 // if this.game_type == 'Control' || (this.game_type == 'Curriculum' && this.player.attempt in [1,2,3,34,35,36,37,38,39,40]):470 // if not (this.game_type == 'Curriculum' && this.player.attempt in training_attempts):471 // this.curr_obstacle[-1].setObstacleParams(**this.game_obstacles[str(this.seeds_used)])472 // this.seeds_used += 1473 // console.log(f'Here for attempt {this.player.attempt}')474 // training_attempts = [5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36]475 // if not (this.game_type == 'Curriculum' && this.player.attempt in training_attempts):476 // if not (this.player.attempt in training_attempts):477 // this.curr_obstacle[-1].setObstacleParams(**this.game_obstacles[str(this.seeds_used)])478 // this.seeds_used += 1479 if (this.curr_obstacle[this.curr_obstacle.length-1].obstacle_type == 'Regular'){480 this.check_targets = true; // Checking if the newly added marker is regular - note that if this was previously false a new marker will necessarily be created481 }482 }483 // if len(this.curr_obstacle) == this.obstacle_count && this.check_targets == false:484 // this.curr_obstacle[-1].setRegularObstacle()485 // if this.stationary && not this.check_targets:486 if (!this.check_targets){487 // If after all this null of the new markers is 'Regular', the most recently created marker will become 'Regular' forcibly488 // Note that this will always be a newly created marker in the above while loop489 this.curr_obstacle[this.curr_obstacle.length-1].setRegularObstacle()490 }491 }492 // blobDetect(frame):493 // center = [0, 0]494 // hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)495 // mask = cv2.inRange(hsv, this.lower, this.upper)496 // contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_null)497 // blob_area = 0498 // if len(contours) > 0:499 // blob = max(contours, key=lambda el: cv2.contourArea(el))500 // M = cv2.moments(blob)501 // if M["m00"] > 0:502 // center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))503 // cv2.circle(frame, center, this.player.radius, (0,0,255), -1)504 // cv2.drawContours(frame, [blob],-1, (0,255,0), 3)505 // blob_area = cv2.contourArea(blob)506 // if this.saveframe:507 // this.gamelog.saveImage(frame)508 // // console.log(f'Bloc detect center {center}')509 // return frame, center, blob_area510 resetBounds(lower = [170, 180,70], upper = [180, 255,255]){511 this.lower = lower;// np.array(lower, dtype = "uint8");512 this.upper = upper;// np.array(upper, dtype = "uint8");513 }514 // pickColor():515 // ret, frame = this.video_capture.read()516 // frame = cv2.flip(frame, 1)517 // pos = pygame.mouse.get_pos()518 // x = int((pos[0] - this.frame_offset)*this.width_ratio)519 // y = int(pos[1]*this.height_ratio)520 // image_hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)521 // try:522 // pixel = image_hsv[y, x]523 // except:524 // pixel = image_hsv[0,0]525 // // you might want to adjust the ranges(+-10, etc):526 // upper_new = np.clip(np.array([pixel[0] + 10, pixel[1] + 80, pixel[2] + 100]), 0, 255)527 // lower_new = np.clip(np.array([pixel[0] - 10, pixel[1] - 80, pixel[2] - 100]), 0, 255)528 // this.resetBounds(lower_new, upper_new)529 // frame, center, blob_area = this.blobDetect(frame)530 // this.blob_area = blob_area*0.1531 waitGame(call_time){532 console.log("in wait time");533 alert('here');534 while ((getTimeS() - call_time) < 1 ){ //this.wait_time){535 // this.game_display.fill([255,255,255])536 drawBG();537 console.log(Math.ceil(getTimeS() - call_time));538 var text_center = [gameCanvas.width/2, gameCanvas.height/2 - 50]; //((this.frame_size_tuple[0]/2) + this.frame_offset,(this.frame_size_tuple[1]/2 - 50))539 // this.messageDisplay(f"Attempt {this.player.attempt+1}", text_center, this.textcolor["black"])540 var msg = "Attempt" + (this.player.attempt+1);541 this.writeOnCanvas(gameCanvas, msg, text_center, "black");542 text_center = [gameCanvas.width/2, gameCanvas.height/2 + 50]; 543 msg = this.wait_time - (getTimeS() - call_time);544 this.writeOnCanvas(gameCanvas, msg, text_center, "black");545 // var text_center = ((this.frame_size_tuple[0]/2) + this.frame_offset,(this.frame_size_tuple[1]/2)+50);546 // this.messageDisplay(f"{int(this.wait_time - (getTimeS() - call_time))}", text_center, this.textcolor["black"])547 // pygame.display.update()548 }549 }550 // textObjects(text, font, color){551 // var text_surface = font.render(text, true, color);552 // return text_surface, text_surface.get_rect();553 // }554 // getTextRect(text, textsize_type = 'medium', color = (0,0,0)){555 // font = this.textsize[textsize_type];556 // var text_surface = font.render(text, true, color);557 // return text_surface.get_rect();558 // }559 // messageDisplay(text, text_center, color, textsize_type = "medium"):560 // // large_text = pygame.font.Font('freesansbold.ttf',200)561 // // medium_text = pygame.font.Font('freesansbold.ttf',100)562 // // small_text = pygame.font.Font('freesansbold.ttf',20)563 564 // text_surf, text_rect = this.textObjects(text, this.textsize[textsize_type], color);565 // text_rect.center = text_center;566 // this.game_display.blit(text_surf, (text_rect[0], text_rect[1]));567 568 newobstacle_count(new_marker_no = 5, curr_obstacle = []){569 //// Commenting this clock because we have already checked for this condition. Whether false || true we have checked whether any markers in curr_obstacle are Regular570 // this.check_targets = false571 // for o in curr_obstacle:572 // if o.obstacle_type == 'Regular':573 // this.check_targets = true574 if (this.check_targets == false){575 // console.log(f'Old obstacle count {this.obstacle_count}')576 // console.log(new_marker_no)577 // if len(curr_obstacle) + 1 < new_marker_no + 1: //this.max_obstacles+1:578 // this.obstacle_count = new_marker_no //this.rs.randint(len(curr_obstacle)+1,this.max_obstacles+1) //np.random.randint(len(curr_obstacle)+1,this.max_obstacles+1) 579 // else:580 this.obstacle_count = Math.max((curr_obstacle.length) + 1, new_marker_no + 1); //this.max_obstacles + 1)581 // console.log(f'New obstacle count {this.obstacle_count}')582 }583 else{584 this.obstacle_count = new_marker_no; //this.rs.randint(this.min_obstacles,this.max_obstacles+1) //np.random.randint(this.min_obstacles,this.max_obstacles+1)585 }586 }587 updateScore(marker){588 var addscore = 0;589 if (marker.obstacle_type == 'Exploding'){590 addscore = -10;591 }592 else{593 var size_effect = (marker.max_radius - marker.radius) / (marker.max_radius - marker.min_radius);594 var velocity_effect = (marker.original_velocity/marker.velocity_scale)/(this.velocity_max);595 // console.log(f'size {size_effect}, velocity {velocity_effect}')596 addscore = 10 + Math.ceil(10*size_effect) + Math.ceil(10*velocity_effect);597 }598 this.player.score = this.player.score + addscore;599 return addscore;600 }601 initializeNewGame(){602 this.gamelog.game_type = this.game_type;603 drawBG()604 this.game_mode = 'InPlay';605 this.display_score = 0;606 this.old_score = 0;607 this.current_time = getTimeS();608 this.player.newGameInit(this.current_time);609 610 console.log('Attempt' + this.player.attempt);611 this.player.resetObsTime(1,0);612 this.initializeGameType();613 // this.player.resetObsTime(1,1);614 // console.log('player start' + this.player.start_time);615 // // if this.player.attempt in [1,38]:616 // // this.rs = np.random.RandomState(38)617 // // else if this.player.attempt in [2,39]:618 // // this.rs = np.random.RandomState(39)619 // // else if this.player.attempt in [3,40]:620 // // this.rs = np.random.RandomState(40)621 // // else:622 // // this.rs = np.random.RandomState(null)623 // if (this.game_type == 'Curriculum' && this.player.attempt <= 40){624 // this.initializeGameType();625 // this.player.resetObsTime(1,1);626 // // this.initializeGameType(**this.game_params[str(this.player.attempt)]);627 // // this.player.resetObsTime(this.game_params[str(this.player.attempt)]['max_obs_time'],628 // // this.game_params[str(this.player.attempt)]['max_unobs_time']);629 // }630 // // console.log('Curriculum')631 // else if (this.game_type == 'Control'){632 // this.initializeGameType();633 // this.player.resetObsTime(1,1);634 // }635 // // console.log('Regular') 636 // // else if this.game_type == 'PositiveDamped':637 // // this.initializeGameType()638 // // this.resetDamping(damping = 10)639 // // // this.player.setObservable()640 // // // console.log('PositiveDamped')641 642 // // else if this.game_type == 'NegativeDamped':643 // // this.initializeGameType()644 // // this.resetDamping(damping = -10)645 // // // this.player.setObservable()646 // // // console.log('NegativeDamped')647 648 // // else if this.game_type == 'MaxUnobservable':649 // // this.initializeGameType()650 // // this.player.resetObsTime(1,1) // this.player.resetObsTime(0.75,1)651 // // // console.log('MaxUnobservable')652 653 // // else if this.game_type == 'Mirror':654 // // this.mirror = true655 // // this.player.mirror = true656 // // // console.log('Mirror')657 658 // // else if this.game_type == 'Rotated':659 // // ang = 45660 // // this.resetRotationAngle(ang)661 // // // console.log(f'Rotated {ang} degrees')662 663 // // else if this.game_type == 'SingleTarget':664 // // this.initializeGameType(exploding_perc = 1, min_obstacles = 3)665 // // // console.log('SingleTarget')666 667 // // else if this.game_type == 'MagneticField':668 // // // magnetic_coef = 5669 // // this.initializeGameType(magnetic_coef = 5000)670 // // // console.log('MagneticField')671 672 // // else if this.game_type == 'MagneticUnobservable':673 // // this.initializeGameType(magnetic_coef = 5000)674 // // this.player.resetObsTime(1,1)675 676 // // else if this.game_type == 'UnobservableDamped':677 // // this.initializeGameType()678 // // this.player.resetObsTime(1,1)679 // // this.resetDamping(damping = -10)680 // // else if this.game_type == 'DampedMagnetic':681 // // this.initializeGameType(magnetic_coef = 5000)682 // // this.resetDamping(damping = -10)683 684 // // else if this.game_type == 'MagneticDampedUnobservable':685 // // this.initializeGameType(magnetic_coef = 5000)686 // // this.resetDamping(damping = -10)687 // // this.player.resetObsTime(1,1)688 // else{689 // console.log('How did you get here?')690 // this.crashed = true691 // }692 // // console.log(this.game_type)693 // // this.player.exploding_perc = 0.9694 // // console.log('Exploding percentage forced to 0.9 - Remove')695 this.newobstacle_count();696 // this.curr_obstacle = [];697 // this.seeds_used = 0;698 this.cur_obstacle_id = 0;699 this.check_targets = false;700 // console.log('Before while');701 this.curr_obstacle = new Array();702 // console.log( this.obstacle_count);703 // console.log(this.curr_obstacle);704 for (var ob_ctr = 0; ob_ctr < this.obstacle_count; ob_ctr ++){705 this.cur_obstacle_id += 1;706 var new_obstacle = new obstacles(gameshape, this.current_time, this.exploding_perc, this.velocity_max, this.velocity_min, this.acceleration[1], this.theta_max, this.theta_min, this.max_obs_time, this.max_unobs_time, this.cur_obstacle_id);707 this.curr_obstacle.push(new_obstacle);708 // console.log(this.curr_obstacle[ob_ctr].loc);709 // console.log(this.cur_obstacle_id);710 // console.log(ob_ctr);711 }712 // setTimeout(function(){ }, 3000);713 // console.log(this.curr_obstacle); // //// The following commented code is required for older curriculums where obstacle properties were being changed.714 // // // if this.game_type == 'Control' || (this.game_type == 'Curriculum' && this.player.attempt in [1,2,3,34,35,36,37,38,39,40]):715 // // if not (this.game_type == 'Curriculum' && this.player.attempt in range(4,34)):716 // // this.game_obstacles = json.load(open(resource_path(f'JsonFiles/GameSeeds_{this.player.attempt}.json'),'r'))717 // // this.curr_obstacle[-1].setObstacleParams(**this.game_obstacles[str(this.seeds_used)])718 // // this.seeds_used += 1719 // // // console.log(f'Here for attempt {this.player.attempt}')720 // // this.game_obstacles = json.load(open(resource_path(f'JsonFiles/Player_3/GameSeeds_{this.player.attempt}.json'),'r'))721 // // training_attempts = [5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36]722 // // if not (this.player.attempt in training_attempts):723 // // this.curr_obstacle[-1].setObstacleParams(**this.game_obstacles[str(this.seeds_used)])724 // // this.seeds_used += 1 725 726 // if (this.curr_obstacle[this.curr_obstacle.length-1].obstacle_type == 'Regular'){727 // this.check_targets = true;728 // }729 730 // if (!this.check_targets){731 // this.curr_obstacle[this.curr_obstacle.length-1].setRegularObstacle();732 // }733 }734 drawCircle(marker){735 ctx.beginPath();736 ctx.arc(marker.loc[0], marker.loc[1], marker.radius, 0, Math.PI*2);737 ctx.fillStyle = marker.marker_color;738 ctx.fill();739 ctx.closePath();740 }741 // displayDefault(saveframe = false){742 // ret, frame = this.video_capture.read()743 // rawframe = cv2.flip(frame, 1)744 // frame = this.videoFrameToPyGameDisplay(frame)745 // this.game_display.fill([0,0,0])746 // this.game_display.blit(frame, (this.frame_offset,0))747 748 // // if this.game_mode == null:749 // pygame.draw.rect(this.game_display, this.textcolor["gray"], this.start_button)750 // this.messageDisplay("Start Game", (this.start_button.center), this.textcolor["black"], textsize_type = "small")751 // pygame.draw.rect(this.game_display, this.textcolor["gray"], this.calibrate_button)752 // this.messageDisplay("Calibrate", (this.calibrate_button.center), this.textcolor["black"], textsize_type = "small")753 // pygame.draw.rect(this.game_display, this.textcolor["gray"], this.test_button)754 // this.messageDisplay("Test", (this.test_button.center), this.textcolor["black"], textsize_type = "small")755 // text_center = ((this.frame_size_tuple[0]/2) + this.frame_offset,(this.frame_size_tuple[1]/6))756 // this.messageDisplay(f"Test frame rate is {this.test_FR}", text_center, this.textcolor["black"], textsize_type = "small")757 758 // pygame.display.update()759 // }760 updateGamelog(){761 this.gamelog.startPlayerLine(this.current_time, this.player, (this.obstacle_count + 1), this.game_type);762 this.gamelog.addObstacleLine(this.curr_obstacle);763 this.gamelog.writeLogLine();764 this.gamelog.clearLogLine();765 }766 // calibrateGame():767 // call_time = getTimeS()768 // console.log('Calibration Start')769 // while (getTimeS() - call_time) < this.wait_time:770 // this.saveframe = false771 // this.displayDefault()772 // text_center = ((this.frame_size_tuple[0]/2) + this.frame_offset,(this.frame_size_tuple[1]/2))773 // this.messageDisplay(f"{this.wait_time - int(getTimeS() - call_time)}", text_center, this.textcolor["black"])774 // pygame.display.update()775 // call_time = getTimeS()776 // while (getTimeS() - call_time) < this.wait_time:777 // // this.saveframe = true // NEED TO CHANGE THIS BACK TO CAPTURE IMAGES778 // this.frame_id += 1779 // this.displayDefault()780 // text_center = ((this.frame_size_tuple[0]/2) + this.frame_offset,(this.frame_size_tuple[1]/2))781 // this.messageDisplay(f"{this.wait_time - int(getTimeS() - call_time)}", text_center, this.textcolor["green"])782 // pygame.display.update()783 // console.log('Calibration End')784 // this.saveframe = false785 // testGame():786 // call_time = getTimeS()787 // this.gamelog.createTestLogger()788 // console.log('Test Start')789 // while (getTimeS() - call_time) < this.test_duration:790 // ret, frame = this.video_capture.read()791 // frame = cv2.flip(frame, 1)792 // this.curr_time = getTimeS()793 // frame, center, blob_area = this.blobDetect(frame)794 // if blob_area >= this.blob_area:795 // new_loc = np.array(center) 796 // if this.mirror:797 // new_loc = this.flipMarkerPosition(new_loc, center)798 // else:799 // new_loc = np.array(this.player.loc)800 // new_loc = this.rotateMarkerPosition(new_loc)801 // this.player.updatePosition(new_loc, this.curr_time)802 // this.game_display.fill([255,255,255])803 // pygame.draw.rect(this.game_display, (0,0,0), (0,0,this.frame_offset, this.frame_size_tuple[1]))804 // pygame.draw.rect(this.game_display, (0,0,0), (this.frame_offset + this.frame_size_tuple[0],0,this.frame_offset, this.frame_size_tuple[1]))805 // playerloc = (int(this.player.loc[0]/this.width_ratio) + this.frame_offset, int(this.player.loc[1]/this.height_ratio))806 // pygame.draw.circle(this.game_display, this.player.marker_color, playerloc, int(this.scaling_factor*this.player.radius))807 // this.messageDisplay(f"{int(this.test_duration - (getTimeS() - call_time))}s", \808 // (this.frame_size_tuple[0] + int(this.frame_offset*3/2), this.frame_size_tuple[1]/2), this.textcolor["gray"])809 // text_rect = this.getTextRect(f"{int(this.test_duration - (getTimeS() - call_time))}") // TO CHANGE810 // this.messageDisplay('Time:', (this.frame_size_tuple[0] + int(this.frame_offset*3/2), this.frame_size_tuple[1]/2 - text_rect[3]), this.textcolor["gray"], "small")811 // this.gamelog.addTestLine((getTimeS() - call_time), this.player.loc)812 // pygame.display.update()813 // this.test_FR = this.frame_id/this.test_duration814 // console.log(f"Test Frame Rate is {this.test_FR}")815 // flipMarkerPosition(new_loc, center):816 // new_loc[0] = this.original_frame_tuple[0] - center[0]817 // new_loc[1] = center[1]818 // return new_loc819 resetRotationAngle(rot_angle = 0){820 this.rotation_angle = rot_angle; //degrees821 }822 // rotateMarkerPosition(new_loc):823 // // console.log(shape)824 // shape = this.original_frame_tuple825 // new_loc = new_loc - np.array((shape[0], shape[1]))/2826 // c, s = np.cos(this.rotation_angle*np.pi/180), np.sin(this.rotation_angle*np.pi/180)827 // R = np.array(((c, -s), (s, c)))828 // new_loc = R.dot(new_loc) + (np.array((shape[0], shape[1])))/2829 // return new_loc...

Full Screen

Full Screen

handle_cmd.js

Source:handle_cmd.js Github

copy

Full Screen

...160 [command, targets, setting, options] = parse_cmd(cmdline)161 // console.log('exe::', command, targets, setting, options)162 switch(command){163 case 'cd': {164 let result = check_targets(targets, [1, 1])165 if(result === true){166 req.change_dir(targets[0], function(res){167 if(res.code === 0 && cb) cb()168 else if(cb) cb(1, res.msg)169 })170 }else{171 if(cb) cb(1, result)172 }173 break174 }175 case 'ls': {176 if(cb){177 // ls <==> ls .178 if(targets.length == 0)179 targets.push('.')180 // 参数检查与调整181 const result = check_targets(targets)182 if(result !== true){183 cb(1, result)184 break185 }186 for(let path of targets){187 let str = ''188 req.list_dir(path, options, function(res){189 if(res.code === 100) cb(0, Object.values(res.ext).join('<br>')) // 部分失败190 else if(res.code > 100) {return cb(1, res.msg) }191 // 多路径192 else if(targets.length > 1) str += '<br>'+path+':<br><br>'193 // 拼接信息194 const {resource = []} = res || {}195 for(let file of resource){196 if(options.indexOf('-l') != -1 || options.indexOf('--line') != -1){197 if(file.type === 'tag')198 str += [file.type, file.name, 'c:'+file.color, '<br>'].join(' ')199 else200 str += [file.type, file.name, file.size, file.tag, '<br>'].join(' ')201 }else{202 str += file.name + ' '203 }204 }205 if(!setting.line && targets.length>1) str += "<br>"206 cb(-1, str)207 })208 }209 }210 break211 }212 case 'open':{213 const result = check_targets(targets)214 if(result !== true){215 cb(1, result)216 }else217 req.open_file(targets[0])218 break219 }220 case 'rm':{221 let result = check_targets(targets, [1])222 if(result !== true){223 if(cb) cb(1, result)224 }else {225 req.remove(targets, options, function(res){226 cli_cb(res, cb)227 })228 }229 break230 }231 case 'cp':{232 let result = check_targets(targets, [2])233 if(result === true){234 let dest = targets.pop()235 req.copy(targets, dest, options, function(res){cli_cb(res, cb)})236 }else if(cb) cb(1, result)237 break238 }239 case 'mv':{240 let result = check_targets(targets, [2])241 if(result === true){242 let dest = targets.pop()243 req.move(targets, dest, options, function(res){cli_cb(res, cb)})244 }else if(cb) cb(1, result)245 break246 }247 case 'mkdir': {248 let result = check_targets(targets, [1, 1])249 if(result === true){250 let path = targets[0]251 req.new_dir(path, options, function(res){cli_cb(res, cb)})252 }else if(cb) cb(1, result)253 break254 }255 case 'pwd':{256 req.pwd(function(pwd){if(cb)cb(-1, pwd)})257 break258 }259 case 'newtag': {260 let result = check_targets(targets, [1, 3], 'other')261 if(result){262 name = targets.shift()263 req.new_tag(name, setting['-c'], setting['-p'], function(res){264 cli_cb(res, cb)265 })266 }else{267 if(cb) cb(1, result)268 }269 break270 }271 case 'settag': {272 // 检查参数数量273 let result = check_targets(targets, [1], 'none')274 // 检查路径275 if(result===true) result = check_targets(targets)276 if(result===true){277 req.set_tag(targets, setting['-a'], setting['-d'], function(res){cli_cb(res, cb)})278 }else if(cb){279 cb(1, result)280 }281 break282 }283 case 'modtag': { // 修改标签284 let name = targets.shift()285 req.mod_tag(name, setting['-n'], setting['-c'], setting['-p'], function(res){cli_cb(res, cb)})286 break287 }288 case 'rmtag': {289 req.rm_tag(targets, options, function(res){cli_cb(res, cb)})290 break291 }292 case 'ct': {293 let result = check_targets(targets, [1, 1], 'tag')294 if(result === true){295 req.change_tag(targets[0], function(res){cli_cb(res, cb)})296 }else if(cb) cb(result)297 break298 }299 case 'unfold': {300 let result = check_targets(targets, [1], 'tag')301 if(result === true){302 req.unfold(targets, function(res){cli_cb(res, cb)})303 }else if(cb) cb(result)304 break305 }306 case 'clear': {307 context.history = ''308 if(cb) cb()309 break310 }311 case 'help': {312 req.help(targets[0], function(res){313 if(cb) cb(res.code>100?1:-1, res.msg.replace(/\n/g, '<br>'))314 })315 break316 }317 case 'alias': {318 let a, c319 [a, c] = targets320 if(options.indexOf('-l') != -1){321 // 查看别名322 if(cb){323 if(a){ // 查看cmd324 if(alias.cmd[a]) cb(-1, '%: %'.format(a, alias.cmd[a]) )325 }else{ // 查看所有别名326 let str = ''327 for(let name in alias.cmd){328 str += '%: %<br>'.format(name, alias.cmd[name])329 }330 cb(-1, str)331 }332 }333 }else{334 req.alias(a, c, options, function(res){335 if(res.code === 0){336 if(options.indexOf('--init') != -1){337 alias = res.content338 if(cb)cb()339 }else if(options.indexOf('-d') != -1){340 delete alias.cmd[a]341 }else{342 alias.cmd[a] = c343 }344 }else{345 if(cb) cb(1, res.msg)346 }347 })348 }349 break350 }351 default: {352 if(cb) cb(1, 'command "' + command + '" not found')353 break354 }355 }356 },357 tab: function(cmdline, cb){358 // console.log('tab cmdline:', cmdline)359 // 预处理命令行360 cmdline = preprocess(cmdline)361 // console.log('tab cmdline:', cmdline)362 // 按空格分隔363 let parts = cmdline.split(/ +/)364 // console.log('tab cmdline:', parts)365 var type, target, command366 if(parts.length == 1){367 // 只有1个部分,需补全指令368 target = parts[0]369 type = 'cmd'370 }else{371 // 否则,关注最后一部分372 target = parts.pop()373 command = parts[0]374 if(target.indexOf('=') != -1){375 [type, target] = target.split('=')376 }377 }378 if(type !== 'cmd'){379 if(type){380 type = type.replace(/^-(p|a|d)$/, 'tag')381 }else{382 if(/^(ls|mv|cp|rm|mkdir|settag|open)$/.test(command))383 type = 'path'384 else if(/^(cd|mkdir)$/.test(command))385 type = 'dir'386 else if(/^(newtag|modtag|ct|rmtag|unfold)$/.test(command))387 type = 'tag'388 else if(command === 'help')389 type = 'cmd'390 }391 if(/(path|dir|file)/.test(type)){392 // 确保target是绝对路径393 target = [target]394 check_targets(target)395 target = target[0]396 }397 }398 // 恢复空格转义399 target = target.replace(/@#\$/g, ' ')400 if(type) req.tab_cmd(target, type, function(res, perfix){401 // 对返回结果,将左边没有反斜杠的空格加上反斜杠402 perfix = perfix.replace(/[^\\] /g, function($0){403 return $0.replace(/ /g, '\\\\ ') // 4个反斜杠匹配一个反斜杠404 })405 // for(let i in res){406 // res[i] = res[i].replace(/[^\\] /g, function($0){407 // return $0.replace(/ /g, '\\ ')408 // }) ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.check_targets(function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10{ locations: 11 [ { location: 'Dulles:Chrome',12 default: true },13 { location: 'Dulles:Firefox',14 default: true },15 { location: 'Dulles:IE10',16 default: true },17 { location: 'Dulles:IE11',18 default: true },19 { location: 'Dulles:Opera',20 default: true },21 { location: 'Dulles:Safari',22 default: true },23 { location: 'Dulles:Chrome',24 default: true },25 { location: 'Dulles:Firefox',26 default: true },27 { location: 'Dulles:IE10',28 default: true },29 { location: 'Dulles:IE11',30 default: true },31 { location: 'Dulles:Opera',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.check_targets(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10{ data:

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('API_KEY');3webPageTest.check_targets(function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var webPageTest = new wpt('API_KEY');8webPageTest.get_locations(function(err, data) {9 console.log(data);10});11var wpt = require('webpagetest');12var webPageTest = new wpt('API_KEY');13webPageTest.get_testers(function(err, data) {14 console.log(data);15});16var wpt = require('webpagetest');17var webPageTest = new wpt('API_KEY');18webPageTest.get_test_status('test_id', function(err, data) {19 console.log(data);20});21var wpt = require('webpagetest');22var webPageTest = new wpt('API_KEY');23webPageTest.get_test_results('test_id', function(err, data) {24 console.log(data);25});26var wpt = require('webpagetest');27var webPageTest = new wpt('API_KEY');28webPageTest.get_test_results('test_id', function(err, data) {29 console.log(data);30});31var wpt = require('webpagetest');32var webPageTest = new wpt('API_KEY');33webPageTest.get_testers(function(err, data) {34 console.log(data);35});36var wpt = require('webpagetest');37var webPageTest = new wpt('API_KEY');38webPageTest.get_test_video('test_id', function(err, data) {39 console.log(data);40});41var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3webpagetest.checkTargets(function (err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var webpagetest = new wpt('API_KEY');12webpagetest.checkTest('TEST_ID', function (err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var webpagetest = new wpt('API_KEY');21webpagetest.getLocations(function (err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('webpagetest');29var webpagetest = new wpt('API_KEY');30webpagetest.getLocation('LOCATION', function (err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('webpagetest');38var webpagetest = new wpt('API_KEY');39webpagetest.getTests(function (err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('webpagetest');47var webpagetest = new wpt('API_KEY');48webpagetest.getTestResult('TEST_ID', function (err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('webpagetest');56var webpagetest = new wpt('API_KEY');57webpagetest.getTestResult('TEST_ID', {pages

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptargets = require('wptargets');2 if (err) {3 console.log('Error: ' + err);4 }5 console.log('Result: ' + JSON.stringify(res));6});7var wptargets = require('wptargets');8 if (err) {9 console.log('Error: ' + err);10 }11 console.log('Result: ' + JSON.stringify(res));12});13var wptargets = require('wptargets');14 if (err) {15 console.log('Error: ' + err);16 }17 console.log('Result: ' + JSON.stringify(res));18});19var wptargets = require('wptargets');20 if (err) {21 console.log('Error: ' + err);22 }23 console.log('Result: ' + JSON.stringify(res));24});25var wptargets = require('wptargets');26 if (err) {27 console.log('Error: ' + err);28 }29 console.log('Result: ' + JSON.stringify(res));30});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt 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