Best Python code snippet using autotest_python
C6G5CA.py
Source:C6G5CA.py
1# create the grid of points2# for i in range(30,0, -1):3# print("P{} = (10, 10)".format(i))4# create a number to count every element5# for i in range(1,31):6 # print("F{} = 0".format(i))7 # print("SP{} = 0".format(i))8 # print("H{} = 0".format(i))9 # print("PS{} = 0".format(i))10 # print("S{} = 0".format(i))11 #12 # print("M{} = 0".format(i))13 # print("Pk{} = 0".format(i))14 # print("BS{} = 0 \n".format(i))15 #to Delete all these points16 # print("Delete(F{})".format(i))17 # print("Delete(SP{})".format(i))18 # print("Delete(H{})".format(i))19 # print("Delete(PS{})".format(i))20 # print("Delete(S{})".format(i))21 #22 # print("Delete(M{})".format(i))23 # print("Delete(Pk{})".format(i))24 # print("Delete(BS{}) \n".format(i))25# create a list of number to count every element26# listF = []27# listSP = []28# listH = []29# listPS = []30# listS = []31# listM = []32# listPk = []33# listBS = []34# for i in range(1,31):35 # listF.append("F{}".format(i))36 # listSP.append("SP{}".format(i))37 # listH.append("H{}".format(i))38 # listPS.append("PS{}".format(i))39 # listS.append("S{}".format(i))40 # listM.append("M{}".format(i))41 # listPk.append("Pk{}".format(i))42 # listBS.append("BS{}".format(i))43# listF.append(0)44# listSP.append(0)45# listH.append(0)46# listPS.append(0)47# listS.append(0)48# listM.append(0)49# listPk.append(0)50# listBS.append(0)51#52# print(listF)53# print(listSP)54# print(listH)55# print(listPS)56# print(listS)57# print(listM)58# print(listPk)59# print(listBS)60# script inside every polygon61# for i in range(1,31):62# print("If(q==16, If(addMalls == true && Element(listF, {}) == 0 && Element(listSP, {}) == 0 && Element(listH, {}) == 0 && Element(listPS, {}) == 0 && Element(listS, {}) == 0, SetValue[listM,{}, 1], SetValue[listM,{}, 0]))".format(i, i, i, i, i, i, i))63# print("If(q==16, If(addParks == true && Element(listF, {}) == 0 && Element(listSP, {}) == 0 && Element(listH, {}) == 0 && Element(listPS, {}) == 0 && Element(listS, {}) == 0, SetValue[listPk,{}, 1], SetValue[listPk,{}, 0]))".format(i, i, i, i, i, i, i))64# print("If(q==16, If(addBusStops == true && Element(listF, {}) == 0 && Element(listSP, {}) == 0 && Element(listH, {}) == 0 && Element(listPS, {}) == 0 && Element(listS, {}) == 0, SetValue[listBS, {}, 1], SetValue[listBS, {}, 0]))".format(i, i, i, i, i, i, i))65#66# print("If(q==15, If(addFarms == true, SetValue[listF, {}, 1], SetValue[listF, {}, 0]))".format(i, i))67# print("If(q==15, If(addSolarPanels == true, SetValue[listSP, {}, 1], SetValue[listSP, {}, 0]))".format(i, i))68# print("If(q==15, If(addHospitals == true, SetValue[listH, {}, 1], SetValue[listH, {}, 0]))".format(i, i))69# print("If(q==15, If(addPS == true, SetValue[listPS, {}, 1], SetValue[listPS, {}, 0]))".format(i, i))70# print("If(q==15, If(addSchools == true, SetValue[listS, {}, 1], SetValue[listS, {}, 0]))".format(i, i))71#72# print("If(remove == true, {{SetValue[listF, {}, 0], SetValue[listSP, {}, 0], SetValue[listH, {}, 0], SetValue[listPS, {}, 0], SetValue[listPS, {}, 0], SetValue[listM,{}, 0], SetValue[listPk,{}, 0], SetValue[listBS, {}, 0]}})\n".format(i, i, i, i, i, i, i, i))73 # print("If(q==16, If(addMalls == true && F{} == 0 && SP{} == 0 && H{} == 0 && PS{} == 0 && S{} == 0, SetValue[M{}, 1], SetValue[M{}, 0]))".format(i, i, i, i, i, i, i))74 # print("If(q==16, If(addParks == true && F{} == 0 && SP{} == 0 && H{} == 0 && PS{} == 0 && S{} == 0, SetValue[Pk{}, 1], SetValue[Pk{}, 0]))".format(i, i, i, i, i, i, i))75 # print("If(q==16, If(addBusStops == true && F{} == 0 && SP{} == 0 && H{} == 0 && PS{} == 0 && S{} == 0, SetValue[BS{}, 1], SetValue[BS{}, 0]))".format(i, i, i, i, i, i, i))76 #77 # print("If(q==15, If(addFarms == true, SetValue[F{}, 1], SetValue[F{}, 0]))".format(i, i))78 # print("If(q==15, If(addSolarPanels == true, SetValue[SP{}, 1], SetValue[SP{}, 0]))".format(i, i))79 # print("If(q==15, If(addHospitals == true, SetValue[H{}, 1], SetValue[H{}, 0]))".format(i, i))80 # print("If(q==15, If(addPS == true, SetValue[PS{}, 1], SetValue[PS{}, 0]))".format(i, i))81 # print("If(q==15, If(addSchools == true, SetValue[S{}, 1], SetValue[S{}, 0]))".format(i, i))82 #83 # print("If(remove == true, {{SetValue[F{}, 0], SetValue[SP{}, 0], SetValue[H{}, 0], SetValue[PS{}, 0], SetValue[S{}, 0], SetValue[M{}, 0], SetValue[Pk{}, 0], SetValue[BS{}, 0]}})\n").format(i, i, i, i, i, i, i, i)84#script to generate images for the grid85for i in range(1,4):86 point = str(i)87 setToPoint = str(i)88 layer = 189 ## modified for the list90 print("picFarms{}_{{ignore}} = FormulaText( picFarms )".format(point, point, point))91 print("SetCoords(picFarms{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))92 print("SetConditionToShowObject( picFarms{}_{{ignore}},( 15<=q<=qtotal ) && Element(listF_{{ignore}},{}) == 1 )".format(point, point))93 print("SetLayer( picFarms{}_{{ignore}}, {} )".format(point, layer))94 print("SetFixed( picFarms{}_{{ignore}}, true ) \n".format(point))95 print("picSolarPanels{}_{{ignore}} = FormulaText( picSolarPanels )".format(point, point, point))96 print("SetCoords(picSolarPanels{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))97 print("SetConditionToShowObject( picSolarPanels{}_{{ignore}},( 15<=q<=qtotal ) && Element(listSP_{{ignore}},{}) == 1 )".format(point, point))98 print("SetLayer( picSolarPanels{}_{{ignore}}, {} )".format(point, layer))99 print("SetFixed( picSolarPanels{}_{{ignore}}, true ) \n".format(point))100 print("picHospitals{}_{{ignore}} = FormulaText( picHospitals )".format(point, point, point))101 print("SetCoords(picHospitals{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))102 print("SetConditionToShowObject( picHospitals{}_{{ignore}},( 15<=q<=qtotal ) && Element(listH_{{ignore}},{}) == 1 )".format(point, point))103 print("SetLayer( picHospitals{}_{{ignore}}, {} )".format(point, layer))104 print("SetFixed( picHospitals{}_{{ignore}}, true ) \n".format(point))105 print("picPS{}_{{ignore}} = FormulaText( picPS )".format(point, point, point))106 print("SetCoords(picPS{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))107 print("SetConditionToShowObject( picPS{}_{{ignore}},( 15<=q<=qtotal ) && Element(listPS_{{ignore}},{}) == 1 )".format(point, point))108 print("SetLayer( picPS{}_{{ignore}}, {} )".format(point, layer))109 print("SetFixed( picPS{}_{{ignore}}, true ) \n".format(point))110 print("picSchools{}_{{ignore}} = FormulaText( picSchools )".format(point, point, point))111 print("SetCoords(picSchools{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))112 print("SetConditionToShowObject( picSchools{}_{{ignore}},( 15<=q<=qtotal ) && Element(listS_{{ignore}},{}) == 1 )".format(point, point))113 print("SetLayer( picSchools{}_{{ignore}}, {} )".format(point, layer))114 print("SetFixed( picSchools{}_{{ignore}}, true ) \n".format(point))115 print("picMall{}_{{ignore}} = FormulaText( picMall )".format(point, point, point))116 print("SetCoords(picMall{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))117 print("SetConditionToShowObject( picMall{}_{{ignore}},( 15<=q<=qtotal ) && Element(listM_{{ignore}},{}) == 1 )".format(point, point))118 print("SetLayer( picMall{}_{{ignore}}, {} )".format(point, layer))119 print("SetFixed( picMall{}_{{ignore}}, true ) \n".format(point))120 print("picParks{}_{{ignore}} = FormulaText( picParks )".format(point, point, point))121 print("SetCoords(picParks{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))122 print("SetConditionToShowObject( picParks{}_{{ignore}},( 15<=q<=qtotal ) && Element(listPk_{{ignore}},{}) == 1 )".format(point, point))123 print("SetLayer( picParks{}_{{ignore}}, {} )".format(point, layer))124 print("SetFixed( picParks{}_{{ignore}}, true ) \n".format(point))125 print("picBusStops{}_{{ignore}} = FormulaText( picBusStops )".format(point, point, point))126 print("SetCoords(picBusStops{}_{{ignore}}, x(P{}_{{ignore}} + xDist), y(P{}_{{ignore}} + yDist))".format(point, setToPoint, setToPoint))127 print("SetConditionToShowObject( picBusStops{}_{{ignore}},( 15<=q<=qtotal ) && Element(listBS_{{ignore}},{}) == 1 )".format(point, point))128 print("SetLayer( picBusStops{}_{{ignore}}, {} )".format(point, layer))129 print("SetFixed( picBusStops{}_{{ignore}}, true ) \n".format(point))130 # print("picFarms{}_{{ignore}} = FormulaText( picFarms )".format(point, point, point))131 # print("SetCoords(picFarms{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))132 # print("SetConditionToShowObject( picFarms{}_{{ignore}},( 15<=q<=qtotal ) && F{} == 1 )".format(point, point))133 # print("SetLayer( picFarms{}_{{ignore}}, {} )".format(point, layer))134 # print("SetFixed( picFarms{}_{{ignore}}, true ) \n".format(point))135 #136 # print("picSolarPanels{}_{{ignore}} = FormulaText( picSolarPanels )".format(point, point, point))137 # print("SetCoords(picSolarPanels{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))138 # print("SetConditionToShowObject( picSolarPanels{}_{{ignore}},( 15<=q<=qtotal ) && SP{} == 1 )".format(point, point))139 # print("SetLayer( picSolarPanels{}_{{ignore}}, {} )".format(point, layer))140 # print("SetFixed( picSolarPanels{}_{{ignore}}, true ) \n".format(point))141 #142 # print("picHospitals{}_{{ignore}} = FormulaText( picHospitals )".format(point, point, point))143 # print("SetCoords(picHospitals{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))144 # print("SetConditionToShowObject( picHospitals{}_{{ignore}},( 15<=q<=qtotal ) && H{} == 1 )".format(point, point))145 # print("SetLayer( picHospitals{}_{{ignore}}, {} )".format(point, layer))146 # print("SetFixed( picHospitals{}_{{ignore}}, true ) \n".format(point))147 #148 # print("picPS{}_{{ignore}} = FormulaText( picPS )".format(point, point, point))149 # print("SetCoords(picPS{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))150 # print("SetConditionToShowObject( picPS{}_{{ignore}},( 15<=q<=qtotal ) && PS{} == 1 )".format(point, point))151 # print("SetLayer( picPS{}_{{ignore}}, {} )".format(point, layer))152 # print("SetFixed( picPS{}_{{ignore}}, true ) \n".format(point))153 #154 # print("picSchools{}_{{ignore}} = FormulaText( picSchools )".format(point, point, point))155 # print("SetCoords(picSchools{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))156 # print("SetConditionToShowObject( picSchools{}_{{ignore}},( 15<=q<=qtotal ) && S{} == 1 )".format(point, point))157 # print("SetLayer( picSchools{}_{{ignore}}, {} )".format(point, layer))158 # print("SetFixed( picSchools{}_{{ignore}}, true ) \n".format(point))159 #160 # print("picMall{}_{{ignore}} = FormulaText( picMall )".format(point, point, point))161 # print("SetCoords(picMall{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))162 # print("SetConditionToShowObject( picMall{}_{{ignore}},( 15<=q<=qtotal ) && M{} == 1 )".format(point, point))163 # print("SetLayer( picMall{}_{{ignore}}, {} )".format(point, layer))164 # print("SetFixed( picMall{}_{{ignore}}, true ) \n".format(point))165 #166 # print("picParks{}_{{ignore}} = FormulaText( picParks )".format(point, point, point))167 # print("SetCoords(picParks{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))168 # print("SetConditionToShowObject( picParks{}_{{ignore}},( 15<=q<=qtotal ) && Pk{} == 1 )".format(point, point))169 # print("SetLayer( picParks{}_{{ignore}}, {} )".format(point, layer))170 # print("SetFixed( picParks{}_{{ignore}}, true ) \n".format(point))171 #172 # print("picBusStops{}_{{ignore}} = FormulaText( picBusStops )".format(point, point, point))173 # print("SetCoords(picBusStops{}_{{ignore}}, x(P{} + xDist), y(P{} + yDist))".format(point, setToPoint, setToPoint))174 # print("SetConditionToShowObject( picBusStops{}_{{ignore}},( 15<=q<=qtotal ) && BS{} == 1 )".format(point, point))175 # print("SetLayer( picBusStops{}_{{ignore}}, {} )".format(point, layer))...
spr.py
Source:spr.py
1#------------------------------------------------------------2# LOAD GAMES FROM TEXT FILES3#------------------------------------------------------------4import re5from pathlib import Path6import numpy as np7import pandas as pd8from week1 import entropyEmpirical9# moves = { 'scissors':0, 'paper':1, 'rock':2}10def getResult(game1: int, game2: int):11 results = [[0,1, -1], [-1, 0, 1], [1,-1,0]]12 result=results[game1][game2]13 return result14def loadGames(baseUriStr: str):15 player1Regex = re.compile('(?<=Player1:\s).*(?=;)')16 player2Regex = re.compile('(?<=Player2:\s).*(?=$)')17 game1Regex = re.compile('(?<=^)[012](?=\s)')18 game2Regex = re.compile('(?<=\s)[012](?=$)')19 baseUri=Path(baseUriStr)20 txtFiles=[x for x in baseUri.glob('**/*.txt')]21 # game = [game#, player1, player2, moveplayer1, moveplayer2]22 filenum=023 games=list()24 for tf in txtFiles:25 with open(tf, 'rt') as f:26 lines = f.readlines()27 28 for i, line in enumerate(lines):29 if (i == 0):30 player1 = re.findall(player1Regex, line)[0].lower()31 player2 = re.findall(player2Regex, line)[0].lower()32 else:33 game1 = int(re.findall(game1Regex, line)[0])34 game2 = int(re.findall(game2Regex, line)[0])35 result = getResult(game1, game2)36 result2 = getResult(game2, game1)37 games.append([filenum, player1, player2, game1, game2, result, result2])38 filenum+=139 return games40#------------------------------------------------------------41# LIST PLAYERS42#------------------------------------------------------------43def listPlayers(games: list):44 listPs = list()45 listPs += [ [game[1], game[2]] for game in games]46 listPs = np.array(listPs).flatten()47 Ps=list(set(listPs))48 return Ps49#------------------------------------------------------------50# GET 1 PLAYER MOVES AND RESULTS ACCROSS ALL GAMES51#------------------------------------------------------------52def getPlayerAllMovesAndScores(playerName: str, games: np.array):53 playerName = playerName.lower()54 df_games = pd.DataFrame(games, columns = ['Game#', 'Player1', 'Player2', 'Move1', 'Move2', 'Result1', 'Result2' ])55 d1 = df_games.loc[ df_games.Player1 == playerName]56 moveWhen1 = list(d1.Move1)57 winWhen1 = list(d1.Result1)58 d2 = df_games.loc[ df_games.Player2 == playerName]59 moveWhen2 = list(d2.Move2)60 winWhen2 = list(d2.Result2)61 return moveWhen1 + moveWhen2, winWhen1 + winWhen262def getPlayerAndOpponentAllMovesAndScores(playerName: str, games: np.array):63 playerName = playerName.lower()64 df_games = pd.DataFrame(games, columns = ['Game#', 'Player1', 'Player2', 'Move1', 'Move2', 'Result1', 'Result2' ])65 d1 = df_games.loc[ df_games.Player1 == playerName]66 moveWhen1 = list(d1.Move1)67 winWhen1 = list(d1.Result1)68 moveOpponentWhen1 = list(d1.Move2)69 d2 = df_games.loc[ df_games.Player2 == playerName]70 moveWhen2 = list(d2.Move2)71 winWhen2 = list(d2.Result2)72 moveOpponentWhen2 = list(d1.Move1)73 return moveWhen1 + moveWhen2, winWhen1 + winWhen2, moveOpponentWhen1 + moveOpponentWhen274def getPlayerEntropyAndRatios(players: list, games: np.array):75 playersGameEntropy=dict()76 for player in players:77 playersGameEntropy[player]=None78 scores=list()79 entropies=list()80 lossRatios=list()81 winRatios=list()82 for player in players:83 moves, gains = getPlayerAllMovesAndScores(player, games)84 playersGameEntropy[player] = entropyEmpirical(moves)85 gains=np.array(gains)86 score=np.sum(gains)87 winRatio=len(list(gains[gains==1]))/len(list(gains))88 lossRatio=len(list(gains[gains==-1]))/len(list(gains))89 winRatios.append(winRatio)90 lossRatios.append(lossRatio)91 scores.append(score)92 entropies.append(playersGameEntropy[player])93 print('{} plays with entropy {} and in average a score of {}'.format(player, playersGameEntropy[player], score))94 print('winRatio {}, lossRatio {}'.format(winRatio, lossRatio))...
cal_md.py
Source:cal_md.py
1#!/usr/bin/env python2'''3@author Pan Zhou 4email: zhoupan71234@xtu.edu.cn5'''6import re7import os8import sys9import numpy as np10def produce_potcar(pseudo_dir, listpseudo, xc):11 psopt = ''12 for ips in range(len(listpseudo)):13 if xc == 1:14 psopt = psopt + pseudo_dir + 'pbe/' + listpseudo[ips] + '/POTCAR '15 else:16 psopt = psopt + pseudo_dir + 'lda/' + listpseudo[ips] + '/POTCAR '17 os.system('cat ' + psopt + ' >>./POTCAR')18# default values19relax = 0; 20# pbe or lda21pbe = 122# directory23cal_dir = 'calculation'24for arg in sys.argv[1:]:25 k=arg.split("=")[0]26 v="=".join(arg.split("=")[1:])27 if k=="relax" : relax = int(v)28 elif k=="temp" : temp = v29 elif k=="pbe" : pbe = int(v)30 elif k=="npr" : npr = int(v) 31 elif k=="vasp" : vasp = v32 elif k=="psdir" : psdir = v33 elif k=="listps" : listps = v.split()34 elif k=="cal_dir" : cal_dir = v35 36 # phonon calculation37 elif k=="phonon" : phonon = int(v)38 elif k=='dim' : dim = v39 elif k=='kpath_phonon' : kpath_phonon = v40 41 # wannier9042 elif k=='wan' : scf = 1; wan = int(v)43 elif k=='wan_type' : wan_type = v44if not 'npr' in locals().keys():45 print('please set the number of process:')46 sys.exit()47if not 'vasp' in locals().keys():48 print('please set the order of vasp:')49 sys.exit()50 51if not 'psdir' in locals().keys():52 print('please set the directory of the pseudopotential:')53 sys.exit()54 55if not 'listps' in locals().keys():56 print('please set the elements of the pseudopotential:')57 sys.exit()58tmpdir = os.getcwd()59n = 060pathnew = cal_dir61if not os.path.exists(pathnew):62 os.system('mkdir ' + pathnew)63#path_exist = os.path.exists('path.txt')64#if not path_exist:65# while True:66# if os.path.exists(pathnew):67# n = n + 168# pathnew = cal_dir + str(n)69# else:70# os.system('mkdir ' + pathnew)71# pfile = open('path.txt','w')72# pfile.write(pathnew)73# pfile.close()74# break75#else:76# rfile = open('path.txt','r')77# name_tmp = rfile.readline()78# rfile.close()79# pathnew = name_tmp80 81os.system('mv INCAR* KPOINTS* POSCAR* ' + pathnew )82os.chdir('./'+ pathnew)83ispos = os.path.isfile('POTCAR')84if ispos is True:85 os.system('rm POTCAR')86produce_potcar(psdir, listps, pbe)87# relax the structure88if relax == 1:89 if not os.path.exists('relax'):90 os.system('mkdir relax')91 os.system('cp POSCAR POTCAR ./relax')92 os.chdir('./relax')93 os.system('cp ../INCAR_relax ./INCAR')94 os.system('cp ../KPOINTS_relax ./KPOINTS')95 os.system('mpirun -np ' + str(npr) + ' ' + vasp + ' ' + '>./log ')96 os.chdir('../')97 98# and energy band calculation99mdpath = 'md' + temp100if not os.path.exists(mdpath):101 os.system('mkdir ' + mdpath)102 if relax == 1:103 os.system('cp POTCAR ./' + mdpath)104 os.system('cp ./relax/CONTCAR ' + './' + mdpath + '/POSCAR')105 else:106 os.system('cp POSCAR POTCAR ./' + mdpath)107 os.chdir('./' + mdpath)108 os.system('cp ../INCAR_md' + temp + ' ./INCAR')109 os.system('cp ../KPOINTS_md' + temp +' ./KPOINTS')110 os.system('mpirun -np ' + str(npr) + ' ' + vasp + ' ' + '>./log ')111 os.chdir('../')112 cfile = open('calculation.dat','w')113 cfile.write('md'+ temp + '_finished!')114 cfile.close()115 116 117 ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!