How to use str_func method in pandera

Best Python code snippet using pandera_python

ps2_answers.py

Source:ps2_answers.py Github

copy

Full Screen

1######################################################################2# This file copyright the Georgia Institute of Technology3#4# Permission is given to students to use or modify this file (only)5# to work on their assignments.6#7# You may NOT publish this file or make it available to others not in8# the course.9#10######################################################################11######################################################################12# How to use:13#14# For fill-in questions, change the value of each answer variable.15#16# For programming questions, change the implementation of the17# function provided.18#19# Run the file from the command line to check:20#21# python ps2_answers.py22#23######################################################################24import checkutil25# NOTE: All questions are presented in the problem set videos (lesson modules), please watch these to get the full26# context on the questions below. Following each question video is a subsequent video with the answer.27# If you see different scores locally and on Gradescope this may be an indication28# that you are uploading a different file than the one you are executing locally.29# If this local ID doesn't match the ID on Gradescope then you uploaded a different file.30OUTPUT_UNIQUE_FILE_ID = False31if OUTPUT_UNIQUE_FILE_ID:32 import hashlib, pathlib33 file_hash = hashlib.md5(pathlib.Path(__file__).read_bytes()).hexdigest()34 print(f'Unique file ID: {file_hash}')35# STUDENT ID36# Please specify your GT login ID in the whoami variable (ex: jsmith322).37whoami = 'lrunyn3'38n = float('nan')39# QUESTION 1: MEASUREMENT UPDATE40#41# How does the variance of the new Gaussian compare to the individual Guassians?42#43possible_answers = ( 'smaller',44 'larger',45 'the same' )46update = 'smaller'47# QUESTION 2: NEW VARIANCE48#49# What is the value for Nu squared as a multiple of Sigma squared?50# Replace n with your answer51#52variance = 1/253# QUESTION 3: HEAVYTAIL GAUSSIAN54#55# Is it possible to represent this function as a Gaussian?56#57possible_answers = ( 'YES',58 'NO' )59heavytail = 'NO'60# QUESTION 4: HOW MANY DIMENSIONS61#62# How many dimensions of the state vector for 2-dimensional space?63# Replace n with your answer64#65dimensions = 466# QUESTION 5: STATE TRANSITION MATRIX67#68# What is the new F matrix for a Kalman filter in 2 dimensions?69# Replace the n's with your answers70#71F = ([[1, 0, 0.1, 0], \72 [0, 1, 0, 0.1], \73 [0, 0, 1, 0], \74 [0, 0, 0, 1]])75# QUESTION 6: PROGRAMMING EXERCISE76# Fill in the matrices P, F, H, R and I at the bottom77#78# This question requires NO CODING, just fill in the 79# matrices by replacing n with your values.80# 81# Please do not delete or modify 82# any provided code. Good luck!83#84Matrices_P = ([[0, 0, 0, 0], \85 [0, 0, 0, 0], \86 [0, 0, 1000, 0], \87 [0, 0, 0, 1000]])88Matrices_F = ([[1, 0, 0.1, 0], \89 [0, 1, 0, 0.1], \90 [0, 0, 1, 0], \91 [0, 0, 0, 1]])92Matrices_H = ([[1, 0, 0, 0], \93 [0, 1, 0, 0]])94Matrices_R = ([[0.1, 0], \95 [0, 0.1]])96Matrices_I = ([[1, 0, 0, 0], \97 [0, 1, 0, 0], \98 [0, 0, 1, 0], \99 [0, 0, 0, 1]])100######################################################################101# Grading methods102#103# Do not modify code below this point.104#105######################################################################106FILL_IN_TEST_CASES = ( {'variable_name': 'update',107 'str_func': checkutil.do_nothing,108 'answer_hash': '43dd639229e914a5327206408c1287c0',109 'points_avail': 1 },110 {'variable_name': 'variance',111 'str_func': checkutil.float_to_str,112 'answer_hash': '2ea3bd7cc5760c8622dfc868bd505c4c',113 'points_avail': 1 },114 {'variable_name': 'heavytail',115 'str_func': checkutil.do_nothing,116 'answer_hash': 'ef544ea31f6ea82b72384a7d9ef3dccf',117 'points_avail': 1 },118 {'variable_name': 'dimensions',119 'str_func': checkutil.float_to_str,120 'answer_hash': 'efb95511d768395bb81769b61a33e0b8',121 'points_avail': 1 },122 {'variable_name': 'F',123 'variable_idxs': (0,0),124 'str_func': checkutil.float_to_str,125 'answer_hash': '7b681f62cc828c6d7568ef7f3a350428',126 'points_avail': 1./16. },127 {'variable_name': 'F',128 'variable_idxs': (0,1),129 'str_func': checkutil.float_to_str,130 'answer_hash': 'ff917d13cdf6acdd0e17a176a570963e',131 'points_avail': 1./16. },132 {'variable_name': 'F',133 'variable_idxs': (0,2),134 'str_func': checkutil.float_to_str,135 'answer_hash': 'd950e2cbd82caf777485907cf003584f',136 'points_avail': 1./16. },137 {'variable_name': 'F',138 'variable_idxs': (0,3),139 'str_func': checkutil.float_to_str,140 'answer_hash': '02c733f0fdc78a155bafe8d953cb95d7',141 'points_avail': 1./16. }, 142 {'variable_name': 'F',143 'variable_idxs': (1,0),144 'str_func': checkutil.float_to_str,145 'answer_hash': '9af9af4c7374f0b14fafa874d5bd003f',146 'points_avail': 1./16. },147 {'variable_name': 'F',148 'variable_idxs': (1,1),149 'str_func': checkutil.float_to_str,150 'answer_hash': 'b3642522f0ba3e96b095f1b16f4c4eca',151 'points_avail': 1./16. },152 {'variable_name': 'F',153 'variable_idxs': (1,2),154 'str_func': checkutil.float_to_str,155 'answer_hash': 'dd0580ff997a6c0ff5b0c5c026844ab0',156 'points_avail': 1./16. },157 {'variable_name': 'F',158 'variable_idxs': (1,3),159 'str_func': checkutil.float_to_str,160 'answer_hash': '044e197410340e5ff6f33350b73d1e89',161 'points_avail': 1./16. }, 162 {'variable_name': 'F',163 'variable_idxs': (2,0),164 'str_func': checkutil.float_to_str,165 'answer_hash': 'c23fe4bb535bac9d90c828dc3717e93b',166 'points_avail': 1./16. },167 {'variable_name': 'F',168 'variable_idxs': (2,1),169 'str_func': checkutil.float_to_str,170 'answer_hash': 'ac45c1a4dc7225534e911394e1370aea',171 'points_avail': 1./16. },172 {'variable_name': 'F',173 'variable_idxs': (2,2),174 'str_func': checkutil.float_to_str,175 'answer_hash': '28d810834d62455e7520b5e6e2990437',176 'points_avail': 1./16. },177 {'variable_name': 'F',178 'variable_idxs': (2,3),179 'str_func': checkutil.float_to_str,180 'answer_hash': '216542c4e092b5267c050babc85adf9d',181 'points_avail': 1./16. }, 182 {'variable_name': 'F',183 'variable_idxs': (3,0),184 'str_func': checkutil.float_to_str,185 'answer_hash': '1b1241ecfc9d00dd5c3bcb35ea370abf',186 'points_avail': 1./16. },187 {'variable_name': 'F',188 'variable_idxs': (3,1),189 'str_func': checkutil.float_to_str,190 'answer_hash': '34a21d761f1b187400b73aabeb42c5bc',191 'points_avail': 1./16. },192 {'variable_name': 'F',193 'variable_idxs': (3,2),194 'str_func': checkutil.float_to_str,195 'answer_hash': 'b17f75679965dfecbb9f4d4f6b898309',196 'points_avail': 1./16. },197 {'variable_name': 'F',198 'variable_idxs': (3,3),199 'str_func': checkutil.float_to_str,200 'answer_hash': '3b2a80974732efdab96fbb189d681695',201 'points_avail': 1./16. }, 202 {'variable_name': 'Matrices_P',203 'variable_idxs': (0,0),204 'str_func': checkutil.float_to_str,205 'answer_hash': '3a7a6580a2f5bb09161b4057bf8c2ec1',206 'points_avail': 1./16. },207 {'variable_name': 'Matrices_P',208 'variable_idxs': (0,1),209 'str_func': checkutil.float_to_str,210 'answer_hash': '1ee7efb648f980167d5b426e506c5e5b',211 'points_avail': 1./16. },212 {'variable_name': 'Matrices_P',213 'variable_idxs': (0,2),214 'str_func': checkutil.float_to_str,215 'answer_hash': 'cf22d8b0a0d84c7e7b938207426c5e9c',216 'points_avail': 1./16. },217 {'variable_name': 'Matrices_P',218 'variable_idxs': (0,3),219 'str_func': checkutil.float_to_str,220 'answer_hash': '8760f75c6a0516216590c1c3ca83da84',221 'points_avail': 1./16. }, 222 {'variable_name': 'Matrices_P',223 'variable_idxs': (1,0),224 'str_func': checkutil.float_to_str,225 'answer_hash': '36b51d06f92a9163470007baf5a10563',226 'points_avail': 1./16. },227 {'variable_name': 'Matrices_P',228 'variable_idxs': (1,1),229 'str_func': checkutil.float_to_str,230 'answer_hash': '0912da826812d262182bc33c2c90ec4b',231 'points_avail': 1./16. },232 {'variable_name': 'Matrices_P',233 'variable_idxs': (1,2),234 'str_func': checkutil.float_to_str,235 'answer_hash': '162ef2da202807abbc1556998d7f7704',236 'points_avail': 1./16. },237 {'variable_name': 'Matrices_P',238 'variable_idxs': (1,3),239 'str_func': checkutil.float_to_str,240 'answer_hash': 'e1036d685ce8c4d8f456e61a27974666',241 'points_avail': 1./16. }, 242 {'variable_name': 'Matrices_P',243 'variable_idxs': (2,0),244 'str_func': checkutil.float_to_str,245 'answer_hash': '706ac89b0d33b893f754e65d4acb52de',246 'points_avail': 1./16. },247 {'variable_name': 'Matrices_P',248 'variable_idxs': (2,1),249 'str_func': checkutil.float_to_str,250 'answer_hash': '92f97f3c6af5bacfef7c456cf38768ba',251 'points_avail': 1./16. },252 {'variable_name': 'Matrices_P',253 'variable_idxs': (2,2),254 'str_func': checkutil.float_to_str,255 'answer_hash': 'aadd46e4fcc00613efc41fc1dd2c4076',256 'points_avail': 1./16. },257 {'variable_name': 'Matrices_P',258 'variable_idxs': (2,3),259 'str_func': checkutil.float_to_str,260 'answer_hash': '01130a22727aa7093fd51789eca6b022',261 'points_avail': 1./16. }, 262 {'variable_name': 'Matrices_P',263 'variable_idxs': (3,0),264 'str_func': checkutil.float_to_str,265 'answer_hash': '3787511c101639cfea71dc055636210c',266 'points_avail': 1./16. },267 {'variable_name': 'Matrices_P',268 'variable_idxs': (3,1),269 'str_func': checkutil.float_to_str,270 'answer_hash': 'e915c6f9fbe1e210f6f5ab6972bac153',271 'points_avail': 1./16. },272 {'variable_name': 'Matrices_P',273 'variable_idxs': (3,2),274 'str_func': checkutil.float_to_str,275 'answer_hash': 'c1545b16b9d69ee83b30124c6ffddcf1',276 'points_avail': 1./16. },277 {'variable_name': 'Matrices_P',278 'variable_idxs': (3,3),279 'str_func': checkutil.float_to_str,280 'answer_hash': '9ae3a299b00c00281f9a0e5a7c6159df',281 'points_avail': 1./16. },282 {'variable_name': 'Matrices_F',283 'variable_idxs': (0,0),284 'str_func': checkutil.float_to_str,285 'answer_hash': 'b4936fdfbe2038c4e8bb14112b118cf7',286 'points_avail': 1./16. },287 {'variable_name': 'Matrices_F',288 'variable_idxs': (0,1),289 'str_func': checkutil.float_to_str,290 'answer_hash': 'a92074802ec38f8634db12e85991766d',291 'points_avail': 1./16. },292 {'variable_name': 'Matrices_F',293 'variable_idxs': (0,2),294 'str_func': checkutil.float_to_str,295 'answer_hash': '36531034cdf99c39a82d4db374afd26b',296 'points_avail': 1./16. },297 {'variable_name': 'Matrices_F',298 'variable_idxs': (0,3),299 'str_func': checkutil.float_to_str,300 'answer_hash': 'ec39ccfce4d82d444c281b0fd9b3629b',301 'points_avail': 1./16. }, 302 {'variable_name': 'Matrices_F',303 'variable_idxs': (1,0),304 'str_func': checkutil.float_to_str,305 'answer_hash': '76fbdc8ddb0567fe6f2286bdb350aa5e',306 'points_avail': 1./16. },307 {'variable_name': 'Matrices_F',308 'variable_idxs': (1,1),309 'str_func': checkutil.float_to_str,310 'answer_hash': '3b2d29301c418594aee149a6a09f5378',311 'points_avail': 1./16. },312 {'variable_name': 'Matrices_F',313 'variable_idxs': (1,2),314 'str_func': checkutil.float_to_str,315 'answer_hash': '1f6f62ec939d2667aedd7c61d2fe1718',316 'points_avail': 1./16. },317 {'variable_name': 'Matrices_F',318 'variable_idxs': (1,3),319 'str_func': checkutil.float_to_str,320 'answer_hash': '21b3d0ab787d745a39852a5b7adb739f',321 'points_avail': 1./16. },322 {'variable_name': 'Matrices_F',323 'variable_idxs': (2,0),324 'str_func': checkutil.float_to_str,325 'answer_hash': '1782be29eef86f321ed17f412ed61688',326 'points_avail': 1./16. },327 {'variable_name': 'Matrices_F',328 'variable_idxs': (2,1),329 'str_func': checkutil.float_to_str,330 'answer_hash': '6bfb14bb97f217616c76cecd6603d14b',331 'points_avail': 1./16. },332 {'variable_name': 'Matrices_F',333 'variable_idxs': (2,2),334 'str_func': checkutil.float_to_str,335 'answer_hash': 'e8be0bea4b8a5514c325006ccb8f1cb0',336 'points_avail': 1./16. },337 {'variable_name': 'Matrices_F',338 'variable_idxs': (2,3),339 'str_func': checkutil.float_to_str,340 'answer_hash': '08e6e70b73b0d5bff020d9c7dd0c3328',341 'points_avail': 1./16. }, 342 {'variable_name': 'Matrices_F',343 'variable_idxs': (3,0),344 'str_func': checkutil.float_to_str,345 'answer_hash': '9ba43f2445c77d6a051ac73eb6225525',346 'points_avail': 1./16. },347 {'variable_name': 'Matrices_F',348 'variable_idxs': (3,1),349 'str_func': checkutil.float_to_str,350 'answer_hash': '22abdaf6b9900e3fdcda70f62c93736b',351 'points_avail': 1./16. },352 {'variable_name': 'Matrices_F',353 'variable_idxs': (3,2),354 'str_func': checkutil.float_to_str,355 'answer_hash': '30e4cfd5cc4ad93d3a91936c44b98573',356 'points_avail': 1./16. },357 {'variable_name': 'Matrices_F',358 'variable_idxs': (3,3),359 'str_func': checkutil.float_to_str,360 'answer_hash': 'fdce1125b7f3004466b23041a155c6c8',361 'points_avail': 1./16. },362 363 {'variable_name': 'Matrices_H',364 'variable_idxs': (0,0),365 'str_func': checkutil.float_to_str,366 'answer_hash': '74ceb436e958faa430acada60dbb01c2',367 'points_avail': 1./8. },368 {'variable_name': 'Matrices_H',369 'variable_idxs': (0,1),370 'str_func': checkutil.float_to_str,371 'answer_hash': 'bb16bfa13304dfe3f96e04f852e8153c',372 'points_avail': 1./8. },373 {'variable_name': 'Matrices_H',374 'variable_idxs': (0,2),375 'str_func': checkutil.float_to_str,376 'answer_hash': 'd4319c9db61c76d4805357ad9da61ecb',377 'points_avail': 1./8. },378 {'variable_name': 'Matrices_H',379 'variable_idxs': (0,3),380 'str_func': checkutil.float_to_str,381 'answer_hash': '4f2a6f99265eb51334385ebaf1932a43',382 'points_avail': 1./8. }, 383 {'variable_name': 'Matrices_H',384 'variable_idxs': (1,0),385 'str_func': checkutil.float_to_str,386 'answer_hash': '06390f337ee1307f64c1b73fc1dd8f8d',387 'points_avail': 1./8. },388 {'variable_name': 'Matrices_H',389 'variable_idxs': (1,1),390 'str_func': checkutil.float_to_str,391 'answer_hash': '5982f8640d6dbfffd76a5c207bfeb6d5',392 'points_avail': 1./8. },393 {'variable_name': 'Matrices_H',394 'variable_idxs': (1,2),395 'str_func': checkutil.float_to_str,396 'answer_hash': '4f8d99e4aa45d6691276bbf514180e1a',397 'points_avail': 1./8. },398 {'variable_name': 'Matrices_H',399 'variable_idxs': (1,3),400 'str_func': checkutil.float_to_str,401 'answer_hash': '9a6fbd59d0109625d271ae6292fd0927',402 'points_avail': 1./8. }, 403 {'variable_name': 'Matrices_R',404 'variable_idxs': (0,0),405 'str_func': checkutil.float_to_str,406 'answer_hash': '03c032f83ce671a5513738c6a86a208d',407 'points_avail': 1./4. },408 {'variable_name': 'Matrices_R',409 'variable_idxs': (0,1),410 'str_func': checkutil.float_to_str,411 'answer_hash': '3fe81ce3e8309b755ecd176ac15a7c69',412 'points_avail': 1./4. },413 {'variable_name': 'Matrices_R',414 'variable_idxs': (1,0),415 'str_func': checkutil.float_to_str,416 'answer_hash': '4e4ebaaf63ea8286e63e23a5c0584376',417 'points_avail': 1./4. },418 {'variable_name': 'Matrices_R',419 'variable_idxs': (1,1),420 'str_func': checkutil.float_to_str,421 'answer_hash': '9087f92b7c60ead8c8a8d15cb55d5c42',422 'points_avail': 1./4. },423 424 {'variable_name': 'Matrices_I',425 'variable_idxs': (0,0),426 'str_func': checkutil.float_to_str,427 'answer_hash': '4e535f04c16bd34dc24b96a683bdd12f',428 'points_avail': 1./16. },429 {'variable_name': 'Matrices_I',430 'variable_idxs': (0,1),431 'str_func': checkutil.float_to_str,432 'answer_hash': '5e705c24a37bcf684ee6654574e69817',433 'points_avail': 1./16. },434 {'variable_name': 'Matrices_I',435 'variable_idxs': (0,2),436 'str_func': checkutil.float_to_str,437 'answer_hash': '69123f79dd97d11ad967ab2fc040ba86',438 'points_avail': 1./16. },439 {'variable_name': 'Matrices_I',440 'variable_idxs': (0,3),441 'str_func': checkutil.float_to_str,442 'answer_hash': 'cd402b6f495d92c79981b76c8f718f62',443 'points_avail': 1./16. }, 444 {'variable_name': 'Matrices_I',445 'variable_idxs': (1,0),446 'str_func': checkutil.float_to_str,447 'answer_hash': 'b2d08b094f666c9352522b410f262bd5',448 'points_avail': 1./16. },449 {'variable_name': 'Matrices_I',450 'variable_idxs': (1,1),451 'str_func': checkutil.float_to_str,452 'answer_hash': 'e4d42e5035083348a00e5aa369f10fab',453 'points_avail': 1./16. },454 {'variable_name': 'Matrices_I',455 'variable_idxs': (1,2),456 'str_func': checkutil.float_to_str,457 'answer_hash': '2787eff86999f3f5ff895424a2fde7ae',458 'points_avail': 1./16. },459 {'variable_name': 'Matrices_I',460 'variable_idxs': (1,3),461 'str_func': checkutil.float_to_str,462 'answer_hash': '3756917536cfb49c289a16d9f3027b0a',463 'points_avail': 1./16. },464 {'variable_name': 'Matrices_I',465 'variable_idxs': (2,0),466 'str_func': checkutil.float_to_str,467 'answer_hash': 'faf1c5b3c37f80173c0a9cf0bcdd8721',468 'points_avail': 1./16. },469 {'variable_name': 'Matrices_I',470 'variable_idxs': (2,1),471 'str_func': checkutil.float_to_str,472 'answer_hash': '71457838393aae391cfa4dc47b726548',473 'points_avail': 1./16. },474 {'variable_name': 'Matrices_I',475 'variable_idxs': (2,2),476 'str_func': checkutil.float_to_str,477 'answer_hash': 'c6932c221e5267b703688bbe56647a11',478 'points_avail': 1./16. },479 {'variable_name': 'Matrices_I',480 'variable_idxs': (2,3),481 'str_func': checkutil.float_to_str,482 'answer_hash': '160c4465ab27eecddb36ac8ffe05f0f5',483 'points_avail': 1./16. }, 484 {'variable_name': 'Matrices_I',485 'variable_idxs': (3,0),486 'str_func': checkutil.float_to_str,487 'answer_hash': '7adfb0c92fc2deeeec7612a9dfcdeed2',488 'points_avail': 1./16. },489 {'variable_name': 'Matrices_I',490 'variable_idxs': (3,1),491 'str_func': checkutil.float_to_str,492 'answer_hash': 'c5cd88be595e5796feee90a5b1b4cf62',493 'points_avail': 1./16. },494 {'variable_name': 'Matrices_I',495 'variable_idxs': (3,2),496 'str_func': checkutil.float_to_str,497 'answer_hash': '467eff2e5881cdedaddad426d6efeee8',498 'points_avail': 1./16. },499 {'variable_name': 'Matrices_I',500 'variable_idxs': (3,3),501 'str_func': checkutil.float_to_str,502 'answer_hash': 'b752232e68c33928284abfd5f76a14fa',503 'points_avail': 1./16. } ) 504if __name__ == '__main__':...

Full Screen

Full Screen

testForPart2.py

Source:testForPart2.py Github

copy

Full Screen

1import random2import numpy3# k=random.randint(1,10) ########################################################################## mispar kvoutsot4# scale=random.randint(-1,20) #################################################### scale5k=56scale =57def find_leader(dic, element): # dic={group1:[group1, group2],...8 for leaders in dic:9 if(element in dic[leaders][0]):10 return leaders11### player_dic={player_id:[playerid, group_id, score, level],...}12### groups_dic={group_id9=([group3,group4,group9],[player1, player2,...]), group_id=[]...}13def union(player_dic,dic, group1, group2):14 leaders1=find_leader(dic,group1)15 leaders2=find_leader(dic,group2)16 new_group=dic[leaders2][0]+dic[leaders1][0]17 player1=dic[leaders1][1]18 player2 = dic[leaders2][1]19 players=player1+player220 if(len(dic[leaders2][0])>len(dic[leaders1][0])):21 # for play in player_dic:22 # if (player_dic[play[1]] == group1 or player_dic[play[1]] == group2 or player_dic[play[1]] == leaders1 or player_dic[play[1]] == leaders2):23 # player_dic[play[1]]=leaders224 dic[leaders2][0]=new_group25 dic[leaders2][1] = players26 dic.pop(leaders1)27 elif (len(dic[leaders2][0]) < len(dic[leaders1][0])):28 dic[leaders1][0] = new_group29 dic[leaders1][1] = players30 dic.pop(leaders2)31 elif(leaders1>leaders2):32 dic[leaders1][0]=new_group33 dic[leaders1][1] = players34 dic.pop(leaders2)35 elif (leaders1 < leaders2):36 dic[leaders2][0] = new_group37 dic[leaders2][1] = players38 dic.pop(leaders1)39### player_dic={player_id:[playerid, group_id, score, level],...}40### groups_dic={group_id9=([group3,group4,group9],[player1, player2,...]), group_id=[]...}41def addPlayer(dic_group,dic_player,player_id, group_id,score):42 if(group_id>k or group_id<=0 or player_id<=0 or score>scale or score<=0):43 return "INVALID_INPUT"44 if(player_id in dic_player):45 return "FAILURE"46 leader=find_leader(dic_group,group_id)47 dic_player[player_id] = [player_id,leader,score,0]48 (dic_group[leader])[1].append(player_id)49 return "SUCCESS"50def remove_player(dic_group,dic_player,player_id):51 if(player_id<=0):52 return "INVALID_INPUT"53 if(player_id not in dic_player):54 return "FAILURE"55 group=dic_player[player_id][1]56 group=find_leader(dic_group,group)57 dic_player.pop(player_id)58 ((dic_group[group])[1]).remove(player_id)59 return "SUCCESS"60def increase_level(dic_player, player_id,level_increase):61 if(player_id<=0 or level_increase <=0):62 return "INVALID_INPUT"63 if (player_id not in dic_player):64 return "FAILURE"65 (dic_player[player_id])[3]=(dic_player[player_id])[3]+level_increase66 return "SUCCESS"67def changePlayerIDScore(dic_player, player_id,NewScore):68 if(player_id<=0 or NewScore> scale or NewScore<=0):69 return "INVALID_INPUT"70 if(player_id not in dic_player):71 return "FAILURE"72 (dic_player[player_id])[2] = NewScore73 return "SUCCESS"74### player_dic={player_id:[playerid, group_id, score, level],...}75### groups_dic={group_id9=([group3,group4,group9],[player1, player2,...]), group_id=[]...}76def init(dic_groups):77 for i in range(1,k+1):78 dic_groups[i]=[[i]]79 dic_groups[i].append([])80### player_dic={player_id:[playerid, group_id, score, level],...}81### groups_dic={group_id9=([group3,group4,group9],[player1, player2,...]), group_id=[]...}82def merge(dic_group, dic_player,groupID1,groupID2):83 if(groupID1<=0 or groupID2<=0 or groupID1>k or groupID2>k):84 return "INVALID_INPUT"85 union(dic_player,dic_group,groupID1,groupID2)86 return "SUCCESS"87def averageHighestPlayerLevelByGroup(dic_group,dic_player, group_id, m, a):88 if group_id > k or group_id < k or m <= 0:89 return "INVALID_INPUT"90 if group_id == 0 and m > len(dic_player):91 return "FAILURE"92 group_leader = find_leader(dic_group,group_id)93 if len(dic_group[group_leader][1]) < m:94 return "FAILURE"95 if group_id == 0:96 lvls = []97 for x in dic_player:98 lvls.append(x[3])99 sorted_lvls = sorted(lvls)100 summ = 0101 for lvl in sorted_lvls[-m:]:102 summ += lvl103 a = [summ / m]104 return "SUCCESS"105 else:106 players = dic_group[group_leader][1]107 lvls = []108 for x in players:109 lvls.append(dic_player[x][3])110 sorted_lvls = sorted(lvls)111 summ = 0112 for lvl in sorted_lvls[-m:]:113 summ += lvl114 a = [summ / m]115 return "SUCCESS"116def getPercentOfPlayersWithScoreInBounds(dic_players,dic_groups,groupID,score, lowerLevel,higherLevel,a):117 if groupID > k or groupID<0:118 return -1119 group_leader = find_leader(dic_groups, groupID)120 if(groupID>0):121 group_leader = find_leader(dic_groups, groupID)122 players=dic_groups[group_leader][1]123 arr=[]124 for play in players:125 if(dic_players[play][2]==score):126 arr.append(dic_players[play][3])127 arr.sort()128 for element in arr:129 if(element<lowerLevel or element>higherLevel):130 arr.remove(element)131 if(groupID==0):132 for players in dic_players:133 if(dic_players[players][2]==score):134 arr.append(dic_players[players][3])135 arr.sort()136 for element in arr:137 if (element < lowerLevel or element > higherLevel):138 arr.remove(element)139 if(len(arr)==0):140 return -2141 counter=0142 for element in arr:143 if(element==score):144 counter+=1145 a=(counter/len(arr))*100146 return a147########################################################################################################################148def main():149 outfile=open("test.txt","w")150 str_main= """151 #include "DS.h"152 #include <cassert>153 int main()154 {\n155 """156 outfile.write(str_main)157 string_init="PlayerManager player("+str(k)+","+str(scale)+");\n"158 outfile.write(string_init)159 dic_grp={}160 dic_player={}161 player_in_game=[]162 init(dic_grp)163 number_of_functions=800##random.randint(1,800)##############################################the num of functions calls164 for i in range(number_of_functions):165 func= numpy.random.choice(numpy.arange(1, 6), p=[0.4, 0.1, 0.25, 0.05, 0.2])166 num_of_player=random.randint(1,700)##############################################the num of players167 if(func==1):168 player=random.randint(1,num_of_player) ###can change here this is the parameters of add players169 group=random.randint(1,k+1) ###can change here this is the parameters of add players170 score=random.randint(-1,scale+1) ###can change here this is the parameters of add players171 res=addPlayer(dic_grp, dic_player, player, group, score)172 if(res=="SUCCESS"):173 player_in_game.append(player)174 str_func="assert(player.addPlayer("+str(player)+","+ str(group)+ ","+str(score)+")=="+res+");\n" ##TODO:write the DS175 if (func == 2):176 if(len(dic_player)==0):177 player=random.randint(1,num_of_player)178 else:179 player = random.choice(player_in_game)###can change here this is the parameters of add players180 player_in_game.remove(player)181 str_func = "assert(player.removePlayer(" + str(player) + ")==" + remove_player(dic_grp,dic_player,player) + ");\n" ##TODO:write the DS182 if (func == 3):183 if(len(player_in_game)==0):184 player=random.randint(1,num_of_player)185 else:186 player = random.choice(player_in_game)187 lvl_increase=1188 str_func = "assert(player.increasePlayerIDLevel(" + str(player) +","+ str(lvl_increase) + ")==" + increase_level(dic_player,player,lvl_increase) + ");\n" ##TODO:write the DS189 if(func == 4):190 if(len(player_in_game)==0):191 player=random.randint(1,num_of_player)192 else:193 player = random.choice(player_in_game) ###can change here this is the parameters of add players194 score= random.randint(1,scale+1)###can change here this is the parameters of add players195 str_func = "assert(changePlayerIDScore("+str(player)+","+str(score)+")==" + changePlayerIDScore(dic_player,player,score) + ");\n"196 if(func==5):197 group = random.randint(1, k) ###can change here this is the parameters of add players198 score_in_grp=[]199 for element in (dic_grp[find_leader(dic_grp,group)])[1]:200 if((dic_player[element])[2] not in score_in_grp):201 score_in_grp.append(dic_player[element][2])202 score = random.randint(1, scale + 1) ###can change here this is the parameters of add players203 low =0204 high=9205 a=0206 a=getPercentOfPlayersWithScoreInBounds(dic_player,dic_grp,group,score,low,high,a)207 str_func="double res=0;\n"208 if(a==-1):209 res="INVALID_INPUT"210 if(a==-2):211 res="FAILURE"212 else:213 res="SUCCESS"214 str_func = str_func + "assert(player.getPercentOfPlayersWithScoreInBounds("+str(group)+","+str(score)+","+str(low)+","+str(high)+",&res)=="+res+");\n" ##TODO:write the DS215 str_func=str_func+"assert(res=="+str(a)+");\n"216 if(func==6):217 group = random.randint(1, k + 20) ###can change here this is the parameters of add players218 m=random.randint(1, num_of_player + 20)219 lstres = []220 str_func = "double res=-1;\n"221 string_res = averageHighestPlayerLevelByGroup(dic_grp,dic_player,group,m,lstres)222 str_func = str_func + "assert(AverageHighestPlayerLevelByGroup(,"+"data structure"+str(group)+","+str(m)+",&res)=="+string_res+ ");\n" ##TODO:write the DS223 if(string_res !="SUCCESS"):224 str_func=str_func+ "assert(res==-1);\n"225 else:226 str_func = str_func + "assert(res==" + str(lstres[0]) + ");\n"227 if(func==7):228 group1 = random.randint(1, k + 20) ###can change here this is the parameters of add players229 group2 = random.randint(1, k + 20) ###can change here this is the parameters of add players230 str_func = "assert(mergeGroups(" + "data structure" + "," + str(group1) + ","+ str(group2) + ")==" + merge(dic_grp,dic_player,group1,group2) + ");\n" ##TODO:write the DS231 outfile.write(str_func)232 str_end="player.Quit();\n}"233 outfile.write(str_end)234 outfile.close()...

Full Screen

Full Screen

generate_analyzer_class.py

Source:generate_analyzer_class.py Github

copy

Full Screen

1#!/usr/bin/env python323"""4@brief generate_analyzer_class.py5"""67import os8import json910class CParameter():11 def __init__(self):12 self.__str_name = "" # Ex: 'consumable_uuid'13 self.__str_desciption = "" # Ex: 'The UUID of the consumable'14 self.__str_openapi_type = "" # Ex: 'string'15 self.__str_dbus_type = "" # Ex: 's'161718class CFunction():19 def __init__(self):20 self.__path = "" # Ex: /measurement/consumable/{consumable_uuid}21 self.__str_name = "" # Ex: def measurement_consumable_post(self, consumable_uuid : 's') -> 's':22 self.__list_requestBody = "" # Ex: /components/requestBodies/body_script_json23 self.__list_parameters = "" # Ex: 24 self.__responses = ""2526 def build_function(str_path : str) -> str:27 # Ex:28 # def measurement_consumable_post(self, consumable_uuid : 's') -> 's':2930 str_function = "\t{func_decorator}\n"31 str_function += "\tdef {func_name}(self{path_parameters}) -> {func_return_type}:\n"32 str_function += "\t\t\"\"\"{path_desciption}\n"33 str_function += "{param_decription}\n"34 str_function += "\t\t\"\"\"\n"35 str_function += "\t\treturn {default_return}\n\n"36373839class COpenAPI_JSON():40 def __init__(self):41 self.__dict_spec = {} # dictionary of the entire specification42 self.__dict_functions = {} # dictionary of type CFunction4344 def load_file(self, str_openapi_json_file_name : str) -> bool:45 f = open(str_openapi_json_file_name, "r")46 self.__dict_spec = json.loads(f.read())47 f.close()48495051 return True5253 def generate_class(self, str_path_class) -> bool:54 f = open(str_path_class, "w")55 f.write("#!/usr/bin/env python3\n")56 f.write("\"\"\"\n")57 f.write("@breif CAnalyzerBase.py\n")58 f.write("\n")59 f.write("Purpose: DBus service interface for the analyzer app.\n")60 f.write("\n")61 f.write("Notes:\n")62 f.write("The parameters and return types must be type cast. For example: use 's' for str type.\n")63 f.write("See https://python-dbus-next.readthedocs.io/en/latest/type-system\n")64 f.write("\n")6566 f.write("\"\"\"\n")67 f.write("\n")68 f.write("from dbus_next.service import (ServiceInterface, method)\n")69 f.write("\n")70 f.write("# ServiceInterface exports Methods: @method(), Properties: @property, Signals:@signal()\n")71 f.write("class CAnalyzerBase(ServiceInterface):\n")72 f.write("\tdef __init__(self, str_analyzer_name):\n")73 f.write("\t\tsuper().__init__(str_analyzer_name)\n")74 f.write("\n")7576 paths = self.__dict_spec['paths']7778 for path in paths:79 str_func = spec.make_function_get(path)80 if (0 < len(str_func)):81 #print(str_func)82 f.write(str_func)83 84 str_func = spec.make_function_put(path)85 if (0 < len(str_func)):86 #print(str_func)87 f.write(str_func)8889 str_func = spec.make_function_post(path)90 if (0 < len(str_func)):91 #print(str_func)92 f.write(str_func)9394 f.close()9596if __name__ == '__main__':97 dir_path = os.path.dirname(os.path.realpath(__file__))98 str_openapi_json_file_name = dir_path + '/openAPISpec.json'99 str_path_class = dir_path + '/../CAnalyzerBase.py'100101 JFile = COpenAPI_JSON()102 b_rtn = JFile.load_file(str_openapi_json_file_name)103 if (not b_rtn):104 print("ERROR: failed to load file")105 exit(1)106107 b_rtn = JFile.generate_class(str_path_class)108 if (not b_rtn):109 print("ERROR: failed to generate class")110 exit(1)111 112 ...

Full Screen

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 pandera 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