How to use setup2 method in Sure

Best Python code snippet using sure_python

31_official_.py

Source:31_official_.py Github

copy

Full Screen

...44 e = (3*v)45 v += 146 x += 147 48def setup2():49 global e, x, v, o50 scores[x] = total51 e = (3*v)52 v += 153 o += 154 x += 155 5657def drawcard1(): #add 3 of a kind58 #if newcard doesn't match suit with any card:59 global upcardsuit, upcardnum, total60 if (deck[-o - 1][1]) != deck[e][1] and (deck[-o - 1][1]) != deck[e+1][1] and (deck[-o - 1][1]) != deck[e+2][1]:61 total = max(deck[e][0], deck[e+1][0], deck[e+2][0], (deck[-o - 1][0]))62 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0], (deck[-o - 1][0]))63 if upcardnum == deck[e][0]:64 upcardsuit = deck[e][1]65 setup2()66 elif upcardnum == deck[e+1][0]:67 upcardsuit = deck[e+1][1]68 setup2()69 elif upcardnum == deck[e+2][0]:70 upcardsuit = deck[e+2][1]71 setup2()72 else:73 upcardsuit = deck[-o - 1][1]74 setup2()7576 #if newcard matches suit with card 1:77 elif (deck[-o - 1][1]) == deck[e][1]:78 #if newcard and card 1 combined aren't max or even:79 if ((deck[-o - 1][0]) + deck[e][0]) <= max(deck[e+1][0], deck[e+2][0]):80 total = max(deck[e+1][0], deck[e+2][0])81 upcardnum = min(deck[e+1][0], deck[e+2][0],(deck[-o - 1][0]), deck[e][0])82 if upcardnum == deck[e][0]:83 upcardsuit = deck[e][1]84 setup2()85 elif upcardnum == deck[e+1][0]:86 upcardsuit = deck[e+1][1]87 setup2()88 elif upcardnum == deck[e+2][0]:89 upcardsuit = deck[e+2][1]90 setup2()91 else:92 upcardsuit = deck[-o-1][1]93 setup2()94 95 #if newcard and card 1 combined are max:96 else: 97 total = (deck[-o - 1][0]) + (deck[e][0]) 98 upcardnum = min(deck[e+1][0], deck[e+2][0])99 if upcardnum == deck[e+1][0]:100 upcardsuit = deck[e+1][1]101 setup2()102 else:103 upcardsuit = deck[e+2][1]104 setup2()105106 #if newcard matches suit with card 2: 107 elif (deck[-o - 1][1]) == deck[e+1][1]:108 #if newcard and card 2 combined aren't max or even:109 if ((deck[-o - 1][0]) + deck[e+1][0]) <= max(deck[e][0], deck[e+2][0]):110 total = max(deck[e][0], deck[e+2][0])111 upcardnum = min(deck[e+1][0], deck[e+2][0],(deck[-o - 1][0]), deck[e][0])112 if upcardnum == deck[e][0]:113 upcardsuit = deck[e][1]114 setup2()115 elif upcardnum == deck[e+1][0]:116 upcardsuit = deck[e+1][1]117 setup2()118 elif upcardnum == deck[e+2][0]:119 upcardsuit = deck[e+2][1]120 setup2()121 else:122 upcardsuit = deck[-o-1][1]123 setup2()124 #if newcard and card 2 combined are max:125 else: 126 total = (deck[-o - 1][0]) + (deck[e+1][0]) 127 upcardnum = min(deck[e][0], deck[e+2][0])128 if upcardnum == deck[e][0]:129 upcardsuit = deck[e][1]130 setup2()131 else:132 upcardsuit = deck[e+2][1]133 setup2()134135 #if newcard matches suit with card 3: 136 elif (deck[-o - 1][1]) == deck[e+2][1]:137 #if newcard and card 3 combined aren't max or even:138 if ((deck[-o - 1][0]) + deck[e+2][0]) <= max(deck[e+1][0], deck[e][0]):139 total = max(deck[e+1][0], deck[e][0])140 upcardnum = min(deck[e+1][0], deck[e+2][0],(deck[-o - 1][0]), deck[e][0])141 if upcardnum == deck[e][0]:142 upcardsuit = deck[e][1]143 setup2()144 elif upcardnum == deck[e+1][0]:145 upcardsuit = deck[e+1][1]146 setup2()147 elif upcardnum == deck[e+2][0]:148 upcardsuit = deck[e+2][1]149 setup2()150 else:151 upcardsuit = deck[-o-1][1]152 setup2()153 #if newcard and card 3 combined are max:154 else: 155 total = (deck[-o - 1][0]) + (deck[e+2][0]) 156 upcardnum = min(deck[e+1][0], deck[e][0])157 if upcardnum == deck[e+1][0]:158 upcardsuit = deck[e+1][1]159 setup2()160 else:161 upcardsuit = deck[e][1]162 setup2()163def drawcard2():164 global upcardsuit, upcardnum, total165 #if newcard shares no suits:166 if deck[-o - 1][1] != deck[e][1] and deck[-o - 1][1] != deck[e+2][1]:167 total = max(deck[-o - 1][0], deck[e][0] + deck[e+1][0], deck[e+2][0])168 if deck[-o - 1][0] == min(deck[-o - 1][0], deck[e][0] + deck[e+1][0], deck[e+2][0]):169 upcardnum = deck[-o - 1][0]170 upcardsuit = deck[-o - 1][1]171 setup2()172 elif deck[e+2][0] == min(deck[-o - 1][0], deck[e][0] + deck[e+1][0], deck[e+2][0]):173 upcardnum = deck[e+2][0]174 upcardsuit = deck[e+2][1]175 setup2()176 else: 177 if deck[e][0] < deck[e+1][0]:178 upcardnum = deck[e][0]179 upcardsuit = deck[e][1]180 setup2()181 else:182 upcardnum = deck[e+1][0]183 upcardsuit = deck[e+1][1]184 setup2()185186 #if newcard shares a suit with the 3rd card:187 elif deck[-o - 1][1] == deck[e+2][1]:188 total = max(deck[-o - 1][0] + deck[e+2][0], deck[e][0] + deck[e+1][0])189 if deck[-o - 1][0] + deck[e+2][0] > deck[e][0] + deck[e+1][0]:190 upcardnum = min(deck[e][0], deck[e+1][0])191 if upcardnum == deck[e][0]:192 upcardsuit = deck[e][1]193 setup2()194 else:195 upcardsuit = deck[e+1][1]196 setup2()197 elif deck[-o - 1][0] + deck[e+2][0] < deck[e][0] + deck[e+1][0]:198 upcardnum = min(deck[-o - 1][0], deck[e+2][0])199 if upcardnum == deck[e+2][0]:200 upcardsuit = deck[e+2][1]201 setup2()202 else:203 upcardsuit = deck[-o - 1][1]204 setup2()205 else:206 upcardnum = min(deck[-o - 1][0], deck[e+2][0], deck[e][0], deck[e+1][0])207 if upcardnum == deck[e][0]:208 upcardsuit = deck[e][1]209 setup2()210 elif upcardnum == deck[e+1][0]:211 upcardsuit = deck[e+1][1]212 setup2()213 elif upcardnum == deck[e+2][0]:214 upcardsuit = deck[e+2][1]215 setup2()216 else:217 upcardsuit = deck[-o - 1][1]218 setup2() 219220 #if newcard shares a suit with cards 1 & 2:221 else:222 total = max(deck[-o - 1][0] + deck[e][0] + deck[e+1][0], deck[e+2][0])223 if deck[-o - 1][0] + deck[e][0] + deck[e+1][0] > deck[e+2][0]:224 upcardnum = deck[e+2][0]225 upcardsuit = deck[e+2][1]226 setup2()227 else:228 upcardnum = min(deck[-o - 1][0], deck[e][0], deck[e+1][0])229 if upcardnum == deck[-o - 1][0]:230 upcardsuit = deck[-o - 1][1]231 setup2()232 elif upcardnum == deck[e][0]:233 upcardsuit == deck[e][1]234 setup2()235 else:236 upcardsuit = deck[e+1][1]237 setup2()238239def drawcard3():240 global upcardsuit, upcardnum, total241 #if newcard shares no suits:242 if deck[-o - 1][1] != deck[e+1][1] and deck[-o - 1][1] != deck[e+2][1]:243 total = max(deck[-o - 1][0], deck[e][0] + deck[e+2][0], deck[e+1][0])244 if deck[-o - 1][0] == min(deck[-o - 1][0], deck[e+2][0] + deck[e][0], deck[e+1][0]):245 upcardnum = deck[-o - 1][0]246 upcardsuit = deck[-o - 1][1]247 setup2()248 elif deck[e+1][0] == min(deck[-o - 1][0], deck[e][0] + deck[e+2][0], deck[e+1][0]):249 upcardnum = deck[e+1][0]250 upcardsuit = deck[e+1][1]251 setup2()252 else: 253 if deck[e][0] < deck[e+2][0]:254 upcardnum = deck[e][0]255 upcardsuit = deck[e][1]256 setup2()257 else:258 upcardnum = deck[e+2][0]259 upcardsuit = deck[e+2][1]260 setup2()261262 #if newcard shares a suit with the 2nd card:263 elif deck[-o - 1][1] == deck[e+1][1]:264 total = max(deck[-o - 1][0] + deck[e+1][0], deck[e][0] + deck[e+2][0])265 if deck[-o - 1][0] + deck[e+1][0] > deck[e][0] + deck[e+2][0]:266 upcardnum = min(deck[e][0], deck[e+2][0])267 if upcardnum == deck[e][0]:268 upcardsuit = deck[e][1]269 setup2()270 else:271 upcardsuit = deck[e+2][1]272 setup2()273 elif deck[-o - 1][0] + deck[e+1][0] < deck[e][0] + deck[e+2][0]:274 upcardnum = min(deck[-o - 1][0], deck[e+1][0])275 if upcardnum == deck[e+1][0]:276 upcardsuit = deck[e+1][1]277 setup2()278 else:279 upcardsuit = deck[-o - 1][1]280 setup2()281 else:282 upcardnum = min(deck[-o - 1][0], deck[e+1][0], deck[e][0], deck[e+2][0])283 if upcardnum == deck[e][0]:284 upcardsuit = deck[e][1]285 setup2()286 elif upcardnum == deck[e+1][0]:287 upcardsuit = deck[e+1][1]288 setup2()289 elif upcardnum == deck[e+2][0]:290 upcardsuit = deck[e+2][1]291 setup2()292 else:293 upcardsuit = deck[-o - 1][1]294 setup2() 295296 #if newcard shares a suit with cards 1 & 3:297 else:298 total = max(deck[-o - 1][0] + deck[e][0] + deck[e+2][0], deck[e+1][0])299 if deck[-o - 1][0] + deck[e][0] + deck[e+2][0] > deck[e+1][0]:300 upcardnum = deck[e+1][0]301 upcardsuit = deck[e+1][1]302 setup2()303 else:304 upcardnum = min(deck[-o - 1][0], deck[e][0], deck[e+2][0])305 if upcardnum == deck[-o - 1][0]:306 upcardsuit = deck[-o - 1][1]307 setup2()308 elif upcardnum == deck[e][0]:309 upcardsuit == deck[e][1]310 setup2()311 else:312 upcardsuit = deck[e+2][1]313 setup2()314315def drawcard4():316 global upcardsuit, upcardnum, total317 #if newcard shares no suits:318 if deck[-o - 1][1] != deck[e][1] and deck[-o - 1][1] != deck[e+2][1]:319 total = max(deck[-o - 1][0], deck[e+1][0] + deck[e+2][0], deck[e][0])320 if deck[-o - 1][0] == min(deck[-o - 1][0], deck[e+2][0] + deck[e+1][0], deck[e][0]):321 upcardnum = deck[-o - 1][0]322 upcardsuit = deck[-o - 1][1]323 setup2()324 elif deck[e][0] == min(deck[-o - 1][0], deck[e+1][0] + deck[e+2][0], deck[e][0]):325 upcardnum = deck[e][0]326 upcardsuit = deck[e][1]327 setup2()328 else: 329 if deck[e+1][0] < deck[e+2][0]:330 upcardnum = deck[e+1][0]331 upcardsuit = deck[e+1][1]332 setup2()333 else:334 upcardnum = deck[e+2][0]335 upcardsuit = deck[e+2][1]336 setup2()337338 #if newcard shares a suit with the 1st card:339 elif deck[-o - 1][1] == deck[e][1]:340 total = max(deck[-o - 1][0] + deck[e][0], deck[e+1][0] + deck[e+2][0])341 if deck[-o - 1][0] + deck[e][0] > deck[e+1][0] + deck[e+2][0]:342 upcardnum = min(deck[e+1][0], deck[e+2][0])343 if upcardnum == deck[e+1][0]:344 upcardsuit = deck[e+1][1]345 setup2()346 else:347 upcardsuit = deck[e+2][1]348 setup2()349 elif deck[-o - 1][0] + deck[e][0] < deck[e+1][0] + deck[e+2][0]:350 upcardnum = min(deck[-o - 1][0], deck[e][0])351 if upcardnum == deck[e][0]:352 upcardsuit = deck[e][1]353 setup2()354 else:355 upcardsuit = deck[-o - 1][1]356 setup2()357 else:358 upcardnum = min(deck[-o - 1][0], deck[e+1][0], deck[e][0], deck[e+2][0])359 if upcardnum == deck[e][0]:360 upcardsuit = deck[e][1]361 setup2()362 elif upcardnum == deck[e+1][0]:363 upcardsuit = deck[e+1][1]364 setup2()365 elif upcardnum == deck[e+2][0]:366 upcardsuit = deck[e+2][1]367 setup2()368 else:369 upcardsuit = deck[-o - 1][1]370 setup2() 371372 #if newcard shares a suit with cards 2 & 3:373 else:374 total = max(deck[-o - 1][0] + deck[e+1][0] + deck[e+2][0], deck[e][0])375 if deck[-o - 1][0] + deck[e+1][0] + deck[e+2][0] > deck[e][0]:376 upcardnum = deck[e][0]377 upcardsuit = deck[e][1]378 setup2()379 else:380 upcardnum = min(deck[-o - 1][0], deck[e+1][0], deck[e+2][0])381 if upcardnum == deck[-o - 1][0]:382 upcardsuit = deck[-o - 1][1]383 setup2()384 elif upcardnum == deck[e+1][0]:385 upcardsuit == deck[e+1][1]386 setup2()387 else:388 upcardsuit = deck[e+2][1]389 setup2()390391392393num = int(input('Enter number of players: '))394count = 0395iterations = int(input('Enter number of iterations: '))396all_total = 0397total_scores = []398while count < iterations:399 # 1 = number, 2 = 10, 3 = jack, 4 = queen, 5 = king, 6 = ace400 deck = [(5, 'Club', 1), (10, 'Club', 2), (11, 'Diamond', 6), (10, 'Heart', 2),(6, 'Spade', 1), (3, 'Spade', 1), (10, 'Club', 3), (10, 'Spade', 2), (2, 'Spade', 1),(8, 'Spade', 1), (7, 'Club', 1), (3, 'Heart', 1), (4, 'Spade', 1), (11, 'Club', 6),(5, 'Diamond', 1), (10, 'Heart', 3), (10, 'Diamond', 2), (9, 'Spade', 1), (9, 'Club', 1),(6, 'Heart', 1), (4, 'Heart', 1), (10, 'Diamond', 3), (3, 'Diamond', 1), (6, 'Club', 1),(11, 'Heart', 6), (10, 'Spade', 3), (10, 'Diamond', 4), (10, 'Spade', 4), (5, 'Spade', 1),(7, 'Heart', 1), (6, 'Diamond', 1), (7, 'Diamond', 1), (4, 'Club', 1), (8, 'Heart', 1),(11, 'Spade', 6), (2, 'Club', 1), (3, 'Club', 1), (10, 'Heart', 4), (10, 'Club', 4),(8, 'Club', 1), (2, 'Heart', 1), (9, 'Diamond', 1), (7, 'Spade', 1), (2, 'Diamond', 1),(10, 'Spade', 5), (4, 'Diamond', 1), (10, 'Heart', 5), (9, 'Heart', 1), (8, 'Diamond', 1),(10, 'Club', 5), (5, 'Heart', 1), (10, 'Diamond', 5)]401 deck = random.sample(deck, k=len(deck))402 scores = []403 404#first draw405 e = 0406 v = 1407408 while v <= num:409 total = 0410 #no matching suit:411 if deck[e+1][1] != deck[e+2][1] and deck[e][1] != deck[e+1][1] and deck[e][1] != deck[e+2][1]:412 total = max(deck[e][0], deck[e+1][0], deck[e+2][0])413 414 #all matching suit:415 elif deck[e+1][1] == deck[e+2][1] and deck[e][1] == deck[e+1][1] and deck[e+1][1] == deck[e+2][1]:416 total = deck[e][0] + deck[e+1][0] + deck[e+2][0]417418 #at least 1 matching suit:419 else:420 if deck[e][1] == deck[e+1][1]:421 total = max(deck[e][0] + deck[e+1][0], deck[e+2][0])422 elif deck[e][1] == deck[e+2][1]:423 total = max(deck[e][0] + deck[e+2][0], deck[e+1][0])424 else: 425 total = max(deck[e+1][0] + deck[e+2][0], deck[e][0]) 426 427 scores.append(total)428 total_scores.append(total)429 #print(scores)430 #print(deck[e][0],deck[e][1],deck[e+1][0],deck[e+1][1], deck[e+2][0],deck[e+2][1])431 e = (3*v)432 v += 1433 434435 #2nd draw, 1st player knocks:436437 e = 3438 v = 2439 o = 1440 x = 1441 upcardnum = deck[-o][0]442 upcardsuit = deck[-o][1]443 while v <= (num):444 total = 0445 446#------------------------------------------------------------------------------------------------------------------------------------------------------------------- 447 #all 3 same suit:448 if deck[e+1][1] == deck[e+2][1] and deck[e][1] == deck[e+1][1] and deck[e+1][1] == deck[e+2][1]:449450 #if upcard doesn't share the same suit:451 if upcardsuit != deck[e][1]: 452 #if upcard is greater than or equal to the sum of all 3 cards:453 if upcardnum >= (deck[e][0] + deck[e+1][0] + deck[e+2][0]):454 total = upcardnum455 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0])456 if upcardnum == deck[e][0]:457 upcardsuit = deck[e][1]458 setup1()459 continue460 461 elif upcardnum == deck[e+1][0]:462 upcardsuit = deck[e+1][1]463 setup1()464 continue465 466 else:467 upcardsuit = deck[e+2][1]468 setup1()469 continue470 471 #if upcard is not greater than or equal to the sum of all 3 cards:472 else:473 #if newcard shares a suit:474 if deck[-o - 1][1] == deck[e][1]:475 total = (deck[-o-1][0] + deck[e][0] + deck[e+1][0] + deck[e+2][0]) - min(deck[-o-1][0], deck[e][0], deck[e+1][0], deck[e+2][0])476 upcardnum = min(deck[-o-1][0], deck[e][0], deck[e+1][0], deck[e+2][0])477 upcardsuit = deck[e][1]478 setup2()479 continue480 481 #if newcard doesn't share a suit:482 else:483 #if newcard is greater than or equal to the sum of the three cards:484 if deck[-o - 1][0] >= (deck[e][0] + deck[e+1][0] + deck[e+2][0]):485 total = deck[-o - 1][0]486 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0]) 487 upcardsuit = deck[e][1]488 setup2()489 continue490 491 #if newcard is not greater than or equal to the sum of the three cards:492 else:493 total = deck[e][0] + deck[e+1][0] + deck[e+2][0]494 upcardnum = deck[-o - 1][0]495 upcardsuit = deck[-o - 1][1]496 setup2()497 continue498 499 #if upcard is also same suit:500 elif upcardsuit == deck[e][1]:501 #if upcard is greater than at least 1 of the cards[otherwise newcard]:502 if upcardnum > deck[e][0] or upcardnum > deck[e+1][0] or upcardnum > deck[e+2][0]:503 total = (total + deck[e][0] + deck[e+1][0] + deck[e+2][0] + upcardnum) - min(deck[e][0], deck[e+1][0], deck[e+2][0])504 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0])505506 if upcardnum == deck[e][0]:507 upcardsuit = deck[e][1]508 setup1()509 continue510 511 elif upcardnum == deck[e+1][0]:512 upcardsuit = deck[e+1][1]513 setup1()514 continue515 516 else:517 upcardsuit = deck[e+2][1]518 setup1()519 continue520 521 #if upcard is not greater than any of the cards:522 else:523 #if newcard shares a suit:524 if deck[-o - 1][1] == deck[e][1]:525 total = (deck[-o-1][0] + deck[e][0] + deck[e+1][0] + deck[e+2][0]) - min(deck[-o-1][0], deck[e][0], deck[e+1][0], deck[e+2][0])526 upcardnum = min(deck[-o-1][0], deck[e][0], deck[e+1][0], deck[e+2][0])527 upcardsuit = deck[e][1]528 setup2()529 continue530 531 #if newcard doesn't share a suit:532 else:533 #if newcard is greater than or equal to the sum of the three cards:534 if deck[-o - 1][0] >= (deck[e][0] + deck[e+1][0] + deck[e+2][0]):535 total = deck[-o - 1][0]536 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0]) 537 upcardsuit = deck[e][1]538 setup2()539 continue540 541 #if newcard is not greater than or equal to the sum of the three cards:542 else:543 total = deck[e][0] + deck[e+1][0] + deck[e+2][0]544 upcardnum = deck[-o - 1][0]545 upcardsuit = deck[-o - 1][1]546 setup2()547 continue548 549#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 550 #no same suit:551 if deck[e][1] != deck[e+2][1] and deck[e][1] != deck[e+1][1] and deck[e+1][1] != deck[e+2][1]:552 #if cards are three of a kind:553 #if the cards are below 10:554 if deck[e][0] < 10:555 #if all 3 card values are the same:556 if deck[e][0] == deck[e+1][0] and deck[e][0] == deck[e][0] == deck[e+2][0]:557 total = 30.5558 upcardnum = deck[-o - 1][0]559 upcardsuit = deck[-o - 1][1]560 setup2()561 continue 562 #if the cards are 10 or face cards:563 if deck[e][0] == 10 or deck[e][0] == 11:564 #if all 3 card values are the same:565 if deck[e][2] == deck[e+1][2] and deck[e][2] == deck[e+2][2]:566 total = 30.5567 upcardnum = deck[-o - 1][0]568 upcardsuit = deck[-o - 1][1]569 setup2()570 continue 571572 #if upcard doesn't share a suit:573 if upcardsuit != deck[e][1] and upcardsuit != deck[e+1][1] and upcardsuit != deck[e+2][1]:574 #If upcard is the highest [COULD FLESH OUT MORE: perhaps if upcard is lower than 5 then you choose from the deck, not just the upcard]:575 if upcardnum > deck[e][0] and upcardnum > deck[e+1][0] and upcardnum > deck[e+2][0]:576 total = upcardnum577 upcardnum = min(deck[e][0], deck[e+1][0], deck[e+2][0])578 if upcardnum == deck[e][0]:579 upcardsuit = deck[e][1]580 setup1()581 continue582 elif upcardnum == deck[e+1][0]:583 upcardsuit = deck[e+1][1] ...

Full Screen

Full Screen

smartplots2_setup.py

Source:smartplots2_setup.py Github

copy

Full Screen

1import matplotlib2import sys3import pandas as pd4import matplotlib.pyplot as plt5import numpy as np6import matplotlib.patches as mpatches7import matplotlib.lines as mlines8import os9plt.style.use('seaborn-colorblind')10# plt.style.use('ggplot')11plt.rcParams['axes.edgecolor'] = 'black'12plt.rcParams['axes.facecolor'] = 'white'13plt.rcParams['savefig.facecolor'] = 'white'14plt.rcParams['savefig.edgecolor'] = 'black'15colors = {'blue': '#377eb8', 'green': '#227222', 'orange': '#C66200', 'purple': '#470467', 'red': '#B30C0C',16 'yellow': '#C6A600', 'light.green': '#C0E0C0', 'magenta': '#D0339D', 'dark.blue': '#23128F',17 'brown': '#542D06', 'grey': '#8A8A8A', 'dark.grey': '#2D2D2D', 'light.yellow': '#FFE664',18 'light.purple': '#9C50C0', 'light.orange': '#FFB164', 'black': '#000000'}19mode_colors = {'RH': colors['red'],20 'Car': colors['grey'],21 'Walk': colors['green'],22 'Transit': colors['blue'],23 'RHT': colors['light.purple'],24 'RHP': 'mediumorchid',25 'CAV': colors['light.yellow'],26 'Bike': colors['light.orange'],27 'NM': colors['light.orange'],28 'electricity': colors['blue'],29 'gas': colors['purple'],30 'diesel': colors['yellow']}31def getDfForPlt(_plt_setup2, _output_folder):32 if not os.path.exists('{}/makeplots'.format(_output_folder)):33 os.makedirs('{}/makeplots'.format(_output_folder))34 top_labels = _plt_setup2['top_labels']35 years = _plt_setup2['scenarios_year']36 ids = _plt_setup2['scenarios_id']37 iterations = _plt_setup2['scenarios_itr']38 top_labels_xpos = [1]39 bottom_labels_xpos = [1]40 for i in range(1, len(top_labels)):41 top_labels_xpos.append(top_labels_xpos[i-1] + 1 + i % 2)42 if i % 2 == 0:43 bottom_labels_xpos.append((top_labels_xpos[i] + top_labels_xpos[i-1])/2)44 df = pd.DataFrame()45 for i in range(len(ids)):46 iteration = iterations[i]47 year = years[i]48 id = ids[i]49 metrics_file = "{}/{}.{}.metrics-final.csv".format(_output_folder, year, iteration)50 df_temp = pd.read_csv(metrics_file).fillna(0)51 df = pd.concat([df, df_temp[df_temp['Rank'] == id]])52 return (df.sort_values(by=['Rank']), top_labels_xpos, bottom_labels_xpos)53# plots54def pltModeSplitByTrips(_plt_setup2, _output_folder):55 plot_size = _plt_setup2['plot_size']56 top_labels = _plt_setup2['top_labels']57 bottom_labels = _plt_setup2['bottom_labels']58 nb_scenarios = len(_plt_setup2['scenarios_id'])59 angle = 1260 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)61 output_png = '{}/makeplots/{}.modesplit_trips.png'.format(_output_folder, _plt_setup2['name'])62 output_csv = '{}/makeplots/{}.modesplit_trips.csv'.format(_output_folder, _plt_setup2['name'])63 createColumnIfNotExist(df, 'cav_counts', 0)64 data = pd.DataFrame(65 {'transit': (df['drive_transit_counts'].values + df['ride_hail_transit_counts'].values + df['walk_transit_counts'].values),66 'car': df['car_counts'].values,67 'cav': df['cav_counts'].values,68 'rh': df['ride_hail_counts'].values,69 'rhp': df['ride_hail_pooled_counts'].values,70 'walk': df['walk_counts'].values,71 'bike': df['bike_counts'].values72 })73 data = data.div(data.sum(axis=1), axis=0)74 data['scenario'] = df['Scenario'].values.copy()75 data['technology'] = df['Technology'].values.copy()76 data.to_csv(output_csv)77 plt.figure(figsize=plot_size)78 plt_transit = plt.bar(x=top_labels_xpos, height=data['transit'], color=mode_colors['Transit'])79 plt_car = plt.bar(x=top_labels_xpos, height=data['car'], bottom=data['transit'], color=mode_colors['Car'])80 plt_cav = plt.bar(x=top_labels_xpos, height=data['cav'], bottom=data[['transit', 'car']].sum(axis=1), color=mode_colors['CAV'])81 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], bottom=data[['transit', 'car', 'cav']].sum(axis=1), color=mode_colors['RH'])82 plt_rhp = plt.bar(x=top_labels_xpos, height=data['rhp'], bottom=data[['transit', 'car', 'cav', 'rh']].sum(axis=1), color=mode_colors['RHP'])83 plt_bike = plt.bar(x=top_labels_xpos, height=data['bike'], bottom=data[['transit', 'car', 'cav', 'rh', 'rhp']].sum(axis=1), color=mode_colors['Bike'])84 plt_walk = plt.bar(x=top_labels_xpos, height=data['walk'], bottom=data[['transit', 'car', 'cav', 'rh', 'rhp', 'bike']].sum(axis=1), color=mode_colors['Walk'])85 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)86 plt.legend((plt_transit, plt_car, plt_cav, plt_rh, plt_rhp, plt_bike, plt_walk),87 ('Transit', 'Car', 'CAV', 'Ridehail', 'Ridehail Pool', 'Bike', 'Walk'),88 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)89 ax = plt.gca()90 ax.grid(False)91 for ind in range(nb_scenarios):92 plt.text(top_labels_xpos[ind], 1.02, top_labels[ind], ha='center')93 ax.set_ylim((0, 1.0))94 plt.ylabel('Portion of Trips')95 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')96 plt.clf()97 plt.close()98def createColumnIfNotExist(df, name, value):99 if name not in df.columns:100 df[name] = value101 else:102 df[name].fillna(0, inplace=True)103def tableSummary(_plt_setup2, _output_folder):104 factor = _plt_setup2['expansion_factor']105 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)106 output_csv = '{}/makeplots/{}.summary.csv'.format(_output_folder, _plt_setup2['name'])107 createColumnIfNotExist(df, 'VMT_car_CAV', 0)108 createColumnIfNotExist(df, 'VMT_car_RH_CAV', 0)109 tot_vmt_transit = (df['VMT_bus'].values+df['VMT_cable_car'].values+df['VMT_ferry'].values+df['VMT_rail'].values +110 df['VMT_subway'].values+df['VMT_tram'].values)111 tot_vmt_non_transit = (df['VMT_car'].values+df['VMT_car_CAV'].values+df['VMT_car_RH'].values +112 df['VMT_car_RH_CAV'].values + df['VMT_walk'].values+df['VMT_bike'].values)113 114 tot_ldv_vmt = (df['VMT_car'].values+df['VMT_car_CAV'].values+df['VMT_car_RH'].values + df['VMT_car_RH_CAV'].values)115 createColumnIfNotExist(df, 'personTravelTime_cav', 0)116 tot_pht = (df['personTravelTime_bike'].values+df['personTravelTime_car'].values+df['personTravelTime_cav'].values +117 df['personTravelTime_drive_transit'].values+df['personTravelTime_mixed_mode'].values +118 df['personTravelTime_onDemandRide'].values+df['personTravelTime_onDemandRide_pooled'].values +119 df['personTravelTime_onDemandRide_transit'].values+df['personTravelTime_walk'].values +120 df['personTravelTime_walk_transit'].values) * factor121 tot_energy = (df['totalEnergy_Biodiesel'].values+df['totalEnergy_Diesel'].values +122 df['totalEnergy_Electricity'].values+df['totalEnergy_Gasoline'].values) * factor123 data = pd.DataFrame(124 {'VMT Total (10^6)': (tot_vmt_transit + tot_vmt_non_transit * factor) / 1000000,125 'VMT per Capita': (tot_vmt_transit+tot_vmt_non_transit)/df['population'],126 'VMT Light Duty Total (10^6)': tot_ldv_vmt * factor / 1000000,127 'VMT Light Duty per Capita': tot_ldv_vmt/df['population'],128 'Driving Speed [miles/h]': tot_ldv_vmt/df['total_vehicleHoursTravelled_LightDutyVehicles'],129 'Person Hours (10^6)': tot_pht / 60 / 1000000,130 'PEV (%)': 0,131 'Vehicle Energy (GJ)': tot_energy / 1000000000,132 'MEP': 0133 })134 data['Scenario'] = df['Scenario'].values.copy()135 data['Technology'] = df['Technology'].values.copy()136 data['year'] = _plt_setup2['scenarios_year']137 data.to_csv(output_csv)138def pltLdvRhOccupancy(_plt_setup2, _output_folder):139 plot_size = _plt_setup2['plot_size']140 top_labels = _plt_setup2['top_labels']141 bottom_labels = _plt_setup2['bottom_labels']142 nb_scenarios = len(_plt_setup2['scenarios_id'])143 factor = _plt_setup2['expansion_factor']144 angle = 12145 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)146 output_png = '{}/makeplots/{}.ldv_rh_occupancy.png'.format(_output_folder, _plt_setup2['name'])147 output_csv = '{}/makeplots/{}.ldv_rh_occupancy.csv'.format(_output_folder, _plt_setup2['name'])148 createColumnIfNotExist(df, 'PMT_car_CAV', 0)149 createColumnIfNotExist(df, 'PMT_car_RH_CAV', 0)150 createColumnIfNotExist(df, 'PMT_car_RH_CAV_shared', 0)151 createColumnIfNotExist(df, 'PMT_car_RH_CAV_shared_2p', 0)152 createColumnIfNotExist(df, 'PMT_car_RH_CAV_shared_3p', 0)153 createColumnIfNotExist(df, 'PMT_car_RH_CAV_shared_4p', 0)154 createColumnIfNotExist(df, 'VMT_car_CAV', 0)155 createColumnIfNotExist(df, 'VMT_car_RH_CAV', 0)156 data = pd.DataFrame(157 {158 'non_rh_ldv': df[['PMT_car', 'PMT_car_CAV']].sum(axis=1),159 'rh_1p': df[['PMT_car_RH', 'PMT_car_RH_CAV']].sum(axis=1)-df[['PMT_car_RH_shared', 'PMT_car_RH_CAV_shared']].sum(axis=1),160 'rh_2p': df[['PMT_car_RH_shared_2p', 'PMT_car_RH_CAV_shared_2p']].sum(axis=1),161 'rh_3p': df[['PMT_car_RH_shared_3p', 'PMT_car_RH_CAV_shared_3p']].sum(axis=1),162 'rh_4p': df[['PMT_car_RH_shared_4p', 'PMT_car_RH_CAV_shared_4p']].sum(axis=1)163 })164 data = data.div(df[['VMT_car', 'VMT_car_CAV', 'VMT_car_RH', 'VMT_car_RH_CAV']].sum(axis=1), axis=0)165 height_all = data.sum(axis=1)166 data['scenario'] = df['Scenario'].values.copy()167 data['technology'] = df['Technology'].values.copy()168 data.to_csv(output_csv)169 plt.figure(figsize=plot_size)170 plt_non_rh_ldv = plt.bar(x=top_labels_xpos, height=data['non_rh_ldv'], color=colors['grey'])171 plt_rh_1p = plt.bar(x=top_labels_xpos, height=data['rh_1p'], bottom=data['non_rh_ldv'], color=mode_colors['RH'])172 plt_rh_shared = plt.bar(x=top_labels_xpos, height=data[['rh_2p', 'rh_3p', 'rh_4p']].sum(axis=1), bottom=data[['non_rh_ldv', 'rh_1p']].sum(axis=1), color=mode_colors['RHP'])173 plt.bar(x=top_labels_xpos, height=data['rh_2p'], bottom=data[['non_rh_ldv', 'rh_1p']].sum(axis=1), hatch='xxx', fill=False, linewidth=0)174 plt.bar(x=top_labels_xpos, height=data['rh_3p'], bottom=data[['non_rh_ldv', 'rh_1p', 'rh_2p']].sum(axis=1), hatch='|||', fill=False, linewidth=0)175 plt.bar(x=top_labels_xpos, height=data['rh_4p'], bottom=data[['non_rh_ldv', 'rh_1p', 'rh_2p', 'rh_3p']].sum(axis=1), hatch='....', fill=False, linewidth=0)176 shared_2p = mpatches.Patch(facecolor='white', label='The white data', hatch='xxx')177 shared_3p = mpatches.Patch(facecolor='white', label='The white data', hatch='|||')178 shared_4p = mpatches.Patch(facecolor='white', label='The white data', hatch='....')179 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)180 plt.legend((plt_non_rh_ldv, plt_rh_1p, plt_rh_shared, shared_2p, shared_3p, shared_4p),181 ('non-Ridehail LDV', 'Ridehail', 'Ridehail Pool', '2 passengers', '3 passengers', '4+ passengers'),182 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)183 plt.axhline(y=1.0, color='black', linestyle='dashed', lw=0.5, alpha=0.2)184 ax = plt.gca()185 ax.grid(False)186 max_value = max(height_all)187 ax.set_ylim((0, max_value))188 for ind in range(nb_scenarios):189 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')190 plt.ylabel('Distance Based Occupancy')191 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')192 plt.clf()193 plt.close()194def pltLdvRhOccupancyByVMT(_plt_setup2, _output_folder):195 plot_size = _plt_setup2['plot_size']196 top_labels = _plt_setup2['top_labels']197 bottom_labels = _plt_setup2['bottom_labels']198 nb_scenarios = len(_plt_setup2['scenarios_id'])199 factor = _plt_setup2['expansion_factor']200 scale = 1 / 1000000201 angle = 12202 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)203 output_png = '{}/makeplots/{}.ldv_rh_occupancy_vmt.png'.format(_output_folder, _plt_setup2['name'])204 output_csv = '{}/makeplots/{}.ldv_rh_occupancy_vmt.csv'.format(_output_folder, _plt_setup2['name'])205 createColumnIfNotExist(df, 'VMT_car_CAV', 0)206 createColumnIfNotExist(df, 'VMT_car_RH_CAV', 0)207 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared', 0)208 createColumnIfNotExist(df, 'VMT_car_CAV_empty', 0)209 createColumnIfNotExist(df, 'VMT_car_CAV_shared', 0)210 createColumnIfNotExist(df, 'VMT_car_RH_CAV_empty', 0)211 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared_2p', 0)212 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared_3p', 0)213 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared_4p', 0)214 data = pd.DataFrame(215 {216 'car': (df[['VMT_car', 'VMT_car_CAV']].sum(axis=1)-df[['VMT_car_shared', 'VMT_car_CAV_shared']].sum(axis=1)) * factor * scale,217 'car_shared': df[['VMT_car_shared', 'VMT_car_CAV_shared']].sum(axis=1) * factor * scale,218 'rh': (df[['VMT_car_RH', 'VMT_car_RH_CAV']].sum(axis=1)-df[['VMT_car_RH_shared', 'VMT_car_RH_CAV_shared']].sum(axis=1)) * factor * scale,219 'rh_2p': df[['VMT_car_RH_shared_2p', 'VMT_car_RH_CAV_shared_2p']].sum(axis=1) * factor * scale,220 'rh_3p': df[['VMT_car_RH_shared_3p', 'VMT_car_RH_CAV_shared_3p']].sum(axis=1) * factor * scale,221 'rh_4p': df[['VMT_car_RH_shared_4p', 'VMT_car_RH_CAV_shared_4p']].sum(axis=1) * factor * scale222 })223 height_all = data.sum(axis=1)224 data['car_empty'] = df[['VMT_car_empty', 'VMT_car_CAV_empty']].sum(axis=1) * factor * scale225 data['rh_empty'] = df[['VMT_car_RH_empty', 'VMT_car_RH_CAV_empty']].sum(axis=1) * factor * scale226 data['scenario'] = df['Scenario'].values.copy()227 data['technology'] = df['Technology'].values.copy()228 data.to_csv(output_csv)229 plt.figure(figsize=plot_size)230 plt_car = plt.bar(x=top_labels_xpos, height=data['car'], color=mode_colors['Car'])231 plt.bar(x=top_labels_xpos, height=-data['car_empty'], bottom=data['car'], hatch='///', fill=False, linewidth=0)232 plt_car_shared = plt.bar(x=top_labels_xpos, height=data['car_shared'], bottom=data['car'], color=mode_colors['CAV'])233 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], bottom=data[['car', 'car_shared']].sum(axis=1), color=mode_colors['RH'])234 plt.bar(x=top_labels_xpos, height=-data['rh_empty'], bottom=data[['car', 'car_shared', 'rh']].sum(axis=1), hatch='///', fill=False, linewidth=0)235 plt_rh_shared = plt.bar(x=top_labels_xpos, height=data[['rh_2p', 'rh_3p', 'rh_4p']].sum(axis=1), bottom=data[['car', 'car_shared', 'rh']].sum(axis=1), color=mode_colors['RHP'])236 plt.bar(x=top_labels_xpos, height=data['rh_2p'], bottom=data[['car', 'car_shared', 'rh']].sum(axis=1), hatch='xxx', fill=False, linewidth=0)237 plt.bar(x=top_labels_xpos, height=data['rh_3p'], bottom=data[['car', 'car_shared', 'rh', 'rh_2p']].sum(axis=1), hatch='|||', fill=False, linewidth=0)238 plt.bar(x=top_labels_xpos, height=data['rh_4p'], bottom=data[['car', 'car_shared', 'rh', 'rh_2p', 'rh_3p']].sum(axis=1), hatch='....', fill=False, linewidth=0)239 empty = mpatches.Patch(facecolor='white', label='The white data', hatch='///')240 shared_2p = mpatches.Patch(facecolor='white', label='The white data', hatch='xxx')241 shared_3p = mpatches.Patch(facecolor='white', label='The white data', hatch='|||')242 shared_4p = mpatches.Patch(facecolor='white', label='The white data', hatch='....')243 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)244 plt.legend((plt_car, plt_car_shared, plt_rh, plt_rh_shared, shared_2p, shared_3p, shared_4p, empty),245 ('Car/CAV', 'CAV Shared', 'Ridehail', 'Ridehail Pool', '2 passengers', '3 passengers', '4+ passengers', 'Deadheading'),246 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)247 plt.axhline(y=1.0, color='black', linestyle='dashed', lw=0.5, alpha=0.2)248 ax = plt.gca()249 ax.grid(False)250 max_value = max(height_all)251 ax.set_ylim((0, max_value))252 for ind in range(nb_scenarios):253 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')254 plt.ylabel('Light Duty Vehicle Miles Traveled (millions)')255 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')256 plt.clf()257 plt.close()258def pltLdvPersonHourTraveled(_plt_setup2, _output_folder):259 plot_size = _plt_setup2['plot_size']260 top_labels = _plt_setup2['top_labels']261 bottom_labels = _plt_setup2['bottom_labels']262 nb_scenarios = len(_plt_setup2['scenarios_id'])263 factor = _plt_setup2['expansion_factor']264 scale = 1 / 1000000 / 60265 angle = 12266 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)267 output_png = '{}/makeplots/{}.ldv_person_hours_traveled.png'.format(_output_folder, _plt_setup2['name'])268 output_csv = '{}/makeplots/{}.ldv_person_hours_traveled.csv'.format(_output_folder, _plt_setup2['name'])269 createColumnIfNotExist(df, 'personTravelTime_cav', 0)270 data = pd.DataFrame(271 {'car': df['personTravelTime_car'].values * factor * scale,272 'cav': df['personTravelTime_cav'].values * factor * scale,273 'rh': df['personTravelTime_onDemandRide'].values * factor * scale,274 'rhp': df['personTravelTime_onDemandRide_pooled'].values * factor * scale275 })276 height_all = data.sum(axis=1)277 data['scenario'] = df['Scenario'].values.copy()278 data['technology'] = df['Technology'].values.copy()279 data.to_csv(output_csv)280 plt.figure(figsize=plot_size)281 plt_car = plt.bar(x=top_labels_xpos, height=data['car'], color=mode_colors['Car'])282 plt_cav = plt.bar(x=top_labels_xpos, height=data['cav'], bottom=data['car'], color=mode_colors['CAV'])283 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], bottom=data[['car', 'cav']].sum(axis=1), color=mode_colors['RH'])284 plt_rhp = plt.bar(x=top_labels_xpos, height=data['rhp'], bottom=data[['car', 'cav', 'rh']].sum(axis=1), color=mode_colors['RHP'])285 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)286 plt.legend((plt_car, plt_cav, plt_rh, plt_rhp),287 ('Car', 'CAV', 'Ridehail', 'Ridehail Pool'),288 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)289 ax = plt.gca()290 ax.grid(False)291 max_value = max(height_all)292 ax.set_ylim((0, max_value))293 for ind in range(nb_scenarios):294 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')295 plt.ylabel('Person Hours Traveled in LDV (millions)')296 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')297 plt.clf()298 plt.close()299 300 301def pltModeSplitInPMT(_plt_setup2, _output_folder):302 pltModeSplitInPMT_internal(_plt_setup2, _output_folder,_plt_setup2['expansion_factor'],'modesplit_pmt',1 / 1000000,'Person Miles Traveled (millions)')303 304def pltModeSplitInPMTPerCapita(_plt_setup2, _output_folder):305 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)306 pltModeSplitInPMT_internal(_plt_setup2, _output_folder,1/df['population'].values,'modesplit_pmt_per_capita',1,'Person Miles Traveled')307def pltModeSplitInPMT_internal(_plt_setup2, _output_folder,factor,fileNameLabel,scale,ylabel):308 plot_size = _plt_setup2['plot_size']309 top_labels = _plt_setup2['top_labels']310 bottom_labels = _plt_setup2['bottom_labels']311 nb_scenarios = len(_plt_setup2['scenarios_id'])312 #factor = _plt_setup2['expansion_factor']313 #scale = 1 / 1000000314 angle = 12315 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)316 output_png = '{}/makeplots/{}.{}.png'.format(_output_folder, _plt_setup2['name'],fileNameLabel)317 output_csv = '{}/makeplots/{}.{}.csv'.format(_output_folder, _plt_setup2['name'],fileNameLabel)318 createColumnIfNotExist(df, 'PMT_car_CAV', 0)319 createColumnIfNotExist(df, 'PMT_car_RH_CAV', 0)320 data = pd.DataFrame(321 {'transit': (df['PMT_bus'].values+df['PMT_ferry'].values+df['PMT_rail'].values+df['PMT_subway'].values+322 df['PMT_tram'].values+df['PMT_cable_car'].values) * factor * scale,323 'car': df['PMT_car'].values * factor * scale,324 'cav': df['PMT_car_CAV'].values * factor * scale,325 'rh': (df['PMT_car_RH'].values+df['PMT_car_RH_CAV'].values) * factor * scale,326 'walk': df['PMT_walk'].values * factor * scale,327 'bike': df['PMT_bike'].values * factor * scale328 })329 height_all = data.sum(axis=1)330 data['scenario'] = df['Scenario'].values.copy()331 data['technology'] = df['Technology'].values.copy()332 data.to_csv(output_csv)333 plt.figure(figsize=plot_size)334 plt_transit = plt.bar(x=top_labels_xpos, height=data['transit'], color=mode_colors['Transit'])335 plt_car = plt.bar(x=top_labels_xpos, height=data['car'], bottom=data['transit'], color=mode_colors['Car'])336 plt_cav = plt.bar(x=top_labels_xpos, height=data['cav'], bottom=data[['transit', 'car']].sum(axis=1), color=mode_colors['CAV'])337 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], bottom=data[['transit', 'car', 'cav']].sum(axis=1), color=mode_colors['RH'])338 plt_bike = plt.bar(x=top_labels_xpos, height=data['bike'], bottom=data[['transit', 'car', 'cav', 'rh']].sum(axis=1), color=mode_colors['Bike'])339 plt_walk = plt.bar(x=top_labels_xpos, height=data['walk'], bottom=data[['transit', 'car', 'cav', 'rh', 'bike']].sum(axis=1), color=mode_colors['Walk'])340 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)341 plt.legend((plt_transit, plt_car, plt_cav, plt_rh, plt_bike, plt_walk),342 ('Transit', 'Car', 'CAV', 'Ridehail', 'Bike', 'Walk'),343 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)344 ax = plt.gca()345 ax.grid(False)346 max_value = max(height_all)347 ax.set_ylim((0, max_value))348 for ind in range(nb_scenarios):349 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')350 plt.ylabel(ylabel)351 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')352 plt.clf()353 plt.close()354def pltModeSplitInVMT(_plt_setup2, _output_folder):355 pltModeSplitInVMT_internal(_plt_setup2, _output_folder,_plt_setup2['expansion_factor'],'modesplit_vmt',1 / 1000000,'Vehicle Miles Traveled (millions)',1)356 357def pltModeSplitInVMTPerCapita(_plt_setup2, _output_folder):358 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)359 pltModeSplitInVMT_internal(_plt_setup2, _output_folder,1/df['population'].values,'modesplit_vmt_per_capita',1,'Vehicle Miles Traveled',1/_plt_setup2['expansion_factor']/df['population'].values)360 361def pltModeSplitInVMT_internal(_plt_setup2, _output_folder,factor,fileNameLabel,scale,ylabel,transitFactor):362 plot_size = _plt_setup2['plot_size']363 top_labels = _plt_setup2['top_labels']364 bottom_labels = _plt_setup2['bottom_labels']365 nb_scenarios = len(_plt_setup2['scenarios_id'])366 #factor = _plt_setup2['expansion_factor']367 #scale = 1 / 1000000368 angle = 12369 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)370 output_png = '{}/makeplots/{}.{}.png'.format(_output_folder, _plt_setup2['name'],fileNameLabel)371 output_csv = '{}/makeplots/{}.{}.csv'.format(_output_folder, _plt_setup2['name'],fileNameLabel)372 createColumnIfNotExist(df, 'VMT_car_CAV', 0)373 createColumnIfNotExist(df, 'VMT_car_RH_CAV', 0)374 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared', 0)375 createColumnIfNotExist(df, 'VMT_car_CAV_empty', 0)376 createColumnIfNotExist(df, 'VMT_car_CAV_shared', 0)377 createColumnIfNotExist(df, 'VMT_car_RH_CAV_empty', 0)378 data = pd.DataFrame(379 {'transit': (df['VMT_bus'].values+df['VMT_ferry'].values+df['VMT_rail'].values+df['VMT_subway'].values+380 df['VMT_tram'].values+df['VMT_cable_car'].values) * scale * transitFactor,381 'car': df['VMT_car'].values * factor * scale,382 'cav': df['VMT_car_CAV'].values * factor * scale,383 'rh': (df['VMT_car_RH'].values+df['VMT_car_RH_CAV'].values-df['VMT_car_RH_shared'].values-df['VMT_car_RH_CAV_shared'].values) * factor * scale,384 'rhp':(df['VMT_car_RH_shared'].values + df['VMT_car_RH_CAV_shared'].values) * factor * scale,385 'nm': (df['VMT_walk'].values+df['VMT_bike'].values) * factor * scale386 })387 height_all = data.sum(axis=1)388 data['cav_empty'] = df['VMT_car_CAV_empty'].values * factor * scale389 data['cav_shared'] = df['VMT_car_CAV_shared'].values * factor * scale390 data['rh_empty'] = (df['VMT_car_RH_empty'].values + df['VMT_car_RH_CAV_empty'].values) * factor * scale391 data['scenario'] = df['Scenario'].values.copy()392 data['technology'] = df['Technology'].values.copy()393 data.to_csv(output_csv)394 plt.figure(figsize=plot_size)395 plt_transit = plt.bar(x=top_labels_xpos, height=data['transit'], color=mode_colors['Transit'])396 plt_car = plt.bar(x=top_labels_xpos, height=data['car'], bottom=data['transit'], color=mode_colors['Car'])397 plt_cav = plt.bar(x=top_labels_xpos, height=data['cav'], bottom=data[['transit', 'car']].sum(axis=1), color=mode_colors['CAV'])398 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], bottom=data[['transit', 'car', 'cav']].sum(axis=1), color=mode_colors['RH'])399 plt_rhp = plt.bar(x=top_labels_xpos, height=data['rhp'], bottom=data[['transit', 'car', 'cav', 'rh']].sum(axis=1), color=mode_colors['RHP'])400 plt_nm = plt.bar(x=top_labels_xpos, height=data['nm'], bottom=data[['transit', 'car', 'cav', 'rh', 'rhp']].sum(axis=1), color=mode_colors['NM'])401 empty = mpatches.Patch(facecolor='white', label='The white data', hatch='///')402 plt.bar(x=top_labels_xpos, height=-data['cav_empty'], bottom=data[['transit', 'car', 'cav']].sum(axis=1), hatch='///', fill=False, linewidth=0)403 plt.bar(x=top_labels_xpos, height=-data['rh_empty'], bottom=data[['transit', 'car', 'cav', 'rh']].sum(axis=1), hatch='///', fill=False, linewidth=0)404 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)405 plt.legend((plt_transit, plt_car, plt_cav, plt_rh, plt_rhp, plt_nm, empty),406 ('Transit', 'Car', 'CAV', 'Ridehail', 'Ridehail Pool', 'NonMotorized', 'Deadheading'),407 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)408 ax = plt.gca()409 ax.grid(False)410 max_value = max(height_all)411 ax.set_ylim((0, max_value))412 for ind in range(nb_scenarios):413 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')414 plt.ylabel(ylabel)415 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')416 plt.clf()417 plt.close()418def pltLdvTechnologySplitInVMT(_plt_setup2, _output_folder):419 plot_size = _plt_setup2['plot_size']420 top_labels = _plt_setup2['top_labels']421 bottom_labels = _plt_setup2['bottom_labels']422 nb_scenarios = len(_plt_setup2['scenarios_id'])423 factor = _plt_setup2['expansion_factor']424 scale = 1 / 1000000425 angle = 12426 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)427 output_png = '{}/makeplots/{}.ldv_technologysplit_vmt.png'.format(_output_folder, _plt_setup2['name'])428 output_csv = '{}/makeplots/{}.ldv_technologysplit_vmt.csv'.format(_output_folder, _plt_setup2['name'])429 data = pd.DataFrame(430 {'L1': df['VMT_L1'].values * factor * scale,431 'L3': df['VMT_L3'].values * factor * scale,432 'L5': df['VMT_L5'].values * factor * scale433 })434 height_all = data.sum(axis=1)435 data['scenario'] = df['Scenario'].values.copy()436 data['technology'] = df['Technology'].values.copy()437 data.to_csv(output_csv)438 plt.figure(figsize=plot_size)439 plt_Low = plt.bar(x=top_labels_xpos, height=data['L1'])440 plt_High = plt.bar(x=top_labels_xpos, height=data['L3'], bottom=data['L1'])441 plt_CAV = plt.bar(x=top_labels_xpos, height=data['L5'], bottom=data[['L1', 'L3']].sum(axis=1))442 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)443 plt.legend((plt_Low, plt_High, plt_CAV),444 ('No Automation', 'Partial Automation', 'Full Automation'),445 labelspacing=-2.5, bbox_to_anchor=(1.05, 0.5), frameon=False)446 ax = plt.gca()447 ax.grid(False)448 max_value = max(height_all)449 ax.set_ylim((0, max_value))450 for ind in range(nb_scenarios):451 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')452 plt.ylabel('Vehicle Miles Traveled (millions)')453 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')454 plt.clf()455 plt.close()456def pltRHWaitTime(_plt_setup2, _output_folder):457 plot_size = _plt_setup2['plot_size']458 top_labels = _plt_setup2['top_labels']459 bottom_labels = _plt_setup2['bottom_labels']460 nb_scenarios = len(_plt_setup2['scenarios_id'])461 angle = 12462 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)463 output_png = '{}/makeplots/{}.rh_wait_time.png'.format(_output_folder, _plt_setup2['name'])464 output_csv = '{}/makeplots/{}.rh_wait_time.csv'.format(_output_folder, _plt_setup2['name'])465 data = pd.DataFrame(466 {'rh_wait_time': df['averageOnDemandRideWaitTimeInMin'].values.copy()467 })468 height_all = data.sum(axis=1)469 data['scenario'] = df['Scenario'].values.copy()470 data['technology'] = df['Technology'].values.copy()471 data.to_csv(output_csv)472 plt.figure(figsize=plot_size)473 plt.bar(x=top_labels_xpos, height=data['rh_wait_time'], color=mode_colors['RH'])474 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)475 ax = plt.gca()476 ax.grid(False)477 max_value = max(height_all)478 ax.set_ylim((0, max_value))479 for ind in range(nb_scenarios):480 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')481 plt.ylabel('Average Ride Hail Wait (min)')482 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')483 plt.clf()484 plt.close()485def pltRHEmptyPooled(_plt_setup2, _output_folder):486 plot_size = _plt_setup2['plot_size']487 top_labels = _plt_setup2['top_labels']488 bottom_labels = _plt_setup2['bottom_labels']489 nb_scenarios = len(_plt_setup2['scenarios_id'])490 factor = _plt_setup2['expansion_factor']491 scale = 1 / 1000000492 angle = 12493 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)494 output_png = '{}/makeplots/{}.rh_empty_shared.png'.format(_output_folder, _plt_setup2['name'])495 output_csv = '{}/makeplots/{}.rh_empty_shared.csv'.format(_output_folder, _plt_setup2['name'])496 createColumnIfNotExist(df, 'VMT_car_CAV', 0)497 createColumnIfNotExist(df, 'VMT_car_RH_CAV', 0)498 createColumnIfNotExist(df, 'VMT_car_RH_CAV_shared', 0)499 createColumnIfNotExist(df, 'VMT_car_CAV_empty', 0)500 createColumnIfNotExist(df, 'VMT_car_CAV_shared', 0)501 createColumnIfNotExist(df, 'VMT_car_RH_CAV_empty', 0)502 data = pd.DataFrame(503 {'rh': (df['VMT_car_RH'].values+df['VMT_car_RH_CAV'].values-df['VMT_car_RH_shared'].values-df['VMT_car_RH_CAV_shared'].values) * factor * scale,504 'rhp': (df['VMT_car_RH_shared'].values+df['VMT_car_RH_CAV_shared'].values) * factor * scale505 })506 507 #print(df['VMT_car_RH_CAV_shared'])508 #print(data)509 510 height_all = data.sum(axis=1)511 data['rh_empty'] = (df['VMT_car_RH_empty'].values+df['VMT_car_RH_CAV_empty'].values) * factor * scale512 data['scenario'] = df['Scenario'].values.copy()513 data['technology'] = df['Technology'].values.copy()514 data.to_csv(output_csv)515 plt.figure(figsize=plot_size)516 plt_rh = plt.bar(x=top_labels_xpos, height=data['rh'], color=mode_colors['RH'])517 plt_rhp = plt.bar(x=top_labels_xpos, height=data['rhp'], bottom=data['rh'], color=mode_colors['RHP'])518 plt.bar(x=top_labels_xpos, height=-data['rh_empty'], bottom=data['rh'], hatch='///', fill=False, lw=0)519 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)520 empty = mpatches.Patch(facecolor='white', label='The white data', hatch='///')521 ax = plt.gca()522 ax.grid(False)523 max_value = max(height_all)524 ax.set_ylim((0, max_value))525 for ind in range(nb_scenarios):526 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')527 plt.ylabel('Ridehail Vehicle Miles Traveled (millions)')528 plt.legend((plt_rh, plt_rhp, empty),529 ('Ridehail', 'Ridehail Pool', 'Deadheading'),530 bbox_to_anchor=(1.05, 0.5), frameon=False)531 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')532 plt.clf()533 plt.close()534def pltEnergyPerCapita(_plt_setup2, _output_folder):535 plot_size = _plt_setup2['plot_size']536 top_labels = _plt_setup2['top_labels']537 bottom_labels = _plt_setup2['bottom_labels']538 nb_scenarios = len(_plt_setup2['scenarios_id'])539 scale = 1 / 1000000000540 angle = 12541 (df, top_labels_xpos, bottom_labels_xpos) = getDfForPlt(_plt_setup2, _output_folder)542 output_png = '{}/makeplots/{}.energy_source_percapita.png'.format(_output_folder, _plt_setup2['name'])543 output_csv = '{}/makeplots/{}.energy_source_percapita.csv'.format(_output_folder, _plt_setup2['name'])544 data = pd.DataFrame(545 {'gas': (df['totalEnergy_Gasoline'].values / df['population'].values) * scale,546 'diesel': (df['totalEnergy_Diesel'].values / df['population'].values) * scale,547 'electricity': (df['totalEnergy_Electricity'].values / df['population'].values) * scale548 })549 height_all = data.sum(axis=1)550 data['scenario'] = df['Scenario'].values.copy()551 data['technology'] = df['Technology'].values.copy()552 data.to_csv(output_csv)553 plt.figure(figsize=plot_size)554 plt_Gas = plt.bar(x=top_labels_xpos, height=data['gas'], color=mode_colors['gas'])555 plt_Diesel = plt.bar(x=top_labels_xpos, height=data['diesel'], bottom=data['gas'], color=mode_colors['diesel'])556 plt_Electricity = plt.bar(x=top_labels_xpos, height=data['electricity'], bottom=data[['gas', 'diesel']].sum(axis=1), color=mode_colors['electricity'])557 plt.xticks(bottom_labels_xpos, bottom_labels, rotation=angle)558 ax = plt.gca()559 ax.grid(False)560 max_value = max(height_all)561 ax.set_ylim((0, max_value))562 for ind in range(nb_scenarios):563 plt.text(top_labels_xpos[ind], max_value + 0.02*max_value, top_labels[ind], ha='center')564 plt.ylabel('Light Duty Vehicle Energy per Capita (GJ)')565 plt.legend((plt_Electricity, plt_Diesel, plt_Gas),566 ('Electricity', 'Diesel', 'Gasoline'), bbox_to_anchor=(1.05, 0.5), frameon=False)567 plt.savefig(output_png, transparent=True, bbox_inches='tight', dpi=200, facecolor='white')568 plt.clf()...

Full Screen

Full Screen

bench.py

Source:bench.py Github

copy

Full Screen

1import timeit, codecs2reqs = """3python setup.py install4pip install simplejson5pip install ujson6pip install python-rapidjson7pip install mrpacker8"""9setup = u'''10import codecs, json, mrpacker11import ZZZ12f = codecs.open( "bench/json/YYY", "rb", encoding="utf-8")13s = f.read()14f.close()15obj = json.loads(s)16packed = mrpacker.pack(obj)17'''18mods = ["json", "simplejson", "rapidjson", "ujson", "mrjson"]19tsts = ["str128.json", "canada.json", "twit.json", "twitter.json", "citm_catalog.json"]20for tst in tsts:21 print ("Test",tst,"loads")22 23 for mod in mods:24 setup2 = setup.replace("ZZZ",mod).replace("YYY",tst)25 print (" ",(min(timeit.Timer(mod+'.loads(s)', setup=setup2).repeat(10, 1))), " \t", mod)26 setup2 = setup.replace("ZZZ","mrpacker").replace("YYY",tst)27 print (" ",(min(timeit.Timer('mrpacker.unpack(packed)', setup=setup2).repeat(10, 1))), " \t", "mrpacker")28for tst in tsts:29 print ("Test",tst,"dumps")30 for mod in mods:31 setup2 = setup.replace("ZZZ",mod).replace("YYY",tst)32 print (" ",(min(timeit.Timer(mod+'.dumps(obj)', setup=setup2).repeat(10, 1))), " \t", mod)33 setup2 = setup.replace("ZZZ","mrpacker").replace("YYY",tst)...

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