How to use isstr method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

run_1.cgi

Source:run_1.cgi Github

copy

Full Screen

1#!/usr/local/bin/python2#------------------------------------------------------3print "Content-Type: text/html\n\n";4print "<!DOCTYPE html>"5#----------------------------------------------6#### Programmed by Youn Shik Park7import cgi, cgitb, os, string, random, datetime, glob, locale8from string import split,join9form = cgi.FieldStorage()10cgitb.enable()11def isFloat(string):12 try:13 ret = float(string)14 except:15 ret = 016 return ret17def isInt(string):18 try:19 ret = int(string)20 except:21 ret = 022 return ret23def isStr(string):24 try:25 ret = str(string);26 except:27 ret = 028 return ret29#----S input----------------------------------------------------------------------------------------------------30ystime = isStr(form.getvalue('ystime'))31numWSD = isInt(form.getvalue('numWSD'))32path = './tmp/' + ystime + '/'33simDir = glob.glob(path + 'sim_*')34status = isInt(len(simDir))35status = status + 136mkSimDir = 'mkdir ' + path + 'sim_' + isStr('%03i'%status)37os.system(mkSimDir)38cpInp = 'cp ' + path + 'inp/*.* ' + path + 'sim_' + isStr('%03i'%status) + '/.'39os.system(cpInp)40pathSim = path + 'sim_' + isStr('%03i'%status) + '/'41cpPcp = 'cp ' + path + 'cligen/pcp.txt ' + pathSim + '/.'42os.system(cpPcp)43#--myOptPar.pys44cpOptFile = 'cp ' + path + 'myOptPar.pys ' + pathSim + '.'45os.system(cpOptFile)46#print '<li>', ystime, numWSD, status47#----BMP set 1, excluding URBAN BMP (all bmp tables excluding urban)48BMPset_1 = [0.0] * 649for i in range(1,6) :50 BMPset_1[i] = [0.0] * numWSD51 for j in range(1,numWSD) :52 BMPset_1[i][j] = [0.0] * 753 for k in range(1,7) :54 tmpVal = isStr(form.getvalue('BMP_' + isStr(i) + '_' + isStr('%02i' % isInt(j)) + isStr(k)))55 if ( tmpVal == 'None' or tmpVal == '' ) :56 BMPset_1[i][j][k] = '%.4f' % isFloat(0.0)57 else :58 BMPset_1[i][j][k] = '%.4f' % isFloat(tmpVal)59#---BMP set2, Urban Concentration, UrbnCnon, "Urban" sheet, Table 1 (static data)60BMPset_2 = [0.0] * 561for i in range(1,5) :62 BMPset_2[i] = [0.0] * 1063 for j in range(1,10) :64 tmpVal = isStr(form.getvalue('UrbnConc_' + isStr(i) + isStr(j)))65 if ( tmpVal == 'None' or tmpVal == '' ) :66 BMPset_2[i][j] = '%.4f' % isFloat(0.0)67 else :68 BMPset_2[i][j] = '%.4f' % isFloat(tmpVal)69 70#----BMP set3, Urban BMP, "Urban" sheet: Table 2a, 3.2a, 3.3a, 3.4a, 3.5a (urbanMap)71BMPset_3 = [0.0] * 672for i in range(1,6) :73 BMPset_3[i] = [0.0] * numWSD 74 for j in range(1,numWSD) :75 BMPset_3[i][j] = [0.0] * 1076 for k in range(1,10) :77 tmpVal = isStr(form.getvalue('UrbanBMP_' + isStr(i) + '_' + isStr('%02i' % isInt(j)) + isStr(k)))78 if ( tmpVal == 'None' or tmpVal == '' ) :79 BMPset_3[i][j][k] = '%.4f' % isFloat(0.0)80 else :81 BMPset_3[i][j][k] = '%.4f' % isFloat(tmpVal)82#----E input----------------------------------------------------------------------------------------------------83#-------------S BMPs.txt----------------------------------------------------------------------------------------84try:85 BMPsFile = open(pathSim + 'BMPs.txt','w')86 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\tBMP\n')87 for i in range(1,numWSD) :88 BMPsFile.write(isStr(BMPset_1[1][i][1]) + '\t')89 BMPsFile.write(isStr(BMPset_1[1][i][2]) + '\t')90 BMPsFile.write(isStr(BMPset_1[1][i][3]) + '\t')91 BMPsFile.write(isStr(BMPset_1[1][i][4]) + '\t')92 BMPsFile.write(isStr(BMPset_1[1][i][6]) + '\t')93 BMPsFile.write(isStr(isInt(isFloat(BMPset_1[1][i][5]))) + '\n')94 BMPsFile.write('\n')95 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\tBMP\n')96 for i in range(1,numWSD) :97 BMPsFile.write(isStr(BMPset_1[2][i][1]) + '\t')98 BMPsFile.write(isStr(BMPset_1[2][i][2]) + '\t')99 BMPsFile.write(isStr(BMPset_1[2][i][3]) + '\t')100 BMPsFile.write(isStr(BMPset_1[2][i][4]) + '\t')101 BMPsFile.write(isStr(BMPset_1[2][i][6]) + '\t')102 BMPsFile.write(isStr(isInt(isFloat(BMPset_1[2][i][5]))) + '\n')103 BMPsFile.write('\n')104 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\tBMP\n')105 for i in range(1,numWSD) :106 BMPsFile.write(isStr(BMPset_1[3][i][1]) + '\t')107 BMPsFile.write(isStr(BMPset_1[3][i][2]) + '\t')108 BMPsFile.write(isStr(BMPset_1[3][i][3]) + '\t')109 BMPsFile.write(isStr(BMPset_1[3][i][4]) + '\t')110 BMPsFile.write(isStr(BMPset_1[3][i][6]) + '\t')111 BMPsFile.write(isStr(isInt(isFloat(BMPset_1[3][i][5]))) + '\n')112 BMPsFile.write('\n')113 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\tBMP\n')114 for i in range(1,numWSD) :115 BMPsFile.write(isStr(BMPset_1[4][i][1]) + '\t')116 BMPsFile.write(isStr(BMPset_1[4][i][2]) + '\t')117 BMPsFile.write(isStr(BMPset_1[4][i][3]) + '\t')118 BMPsFile.write(isStr(BMPset_1[4][i][4]) + '\t')119 BMPsFile.write(isStr(BMPset_1[4][i][6]) + '\t')120 BMPsFile.write(isStr(isInt(isFloat(BMPset_1[4][i][5]))) + '\n')121 BMPsFile.write('\n')122 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\tBMP\n')123 for i in range(1,numWSD) :124 BMPsFile.write(isStr(BMPset_1[5][i][1]) + '\t')125 BMPsFile.write(isStr(BMPset_1[5][i][2]) + '\t')126 BMPsFile.write(isStr(BMPset_1[5][i][3]) + '\t')127 BMPsFile.write(isStr(BMPset_1[5][i][4]) + '\t')128 BMPsFile.write(isStr(BMPset_1[5][i][6]) + '\t')129 BMPsFile.write(isStr(isInt(isFloat(BMPset_1[5][i][5]))) + '\n')130 BMPsFile.write('------------ Followings are BMPs for Urban-------------------------------------------------\n')131 for i in range(1,5) :132 for j in range(1,10) :133 BMPsFile.write(isStr(BMPset_2[i][j]) + '\t')134 BMPsFile.write('\n')135 BMPsFile.write('\n')136 for i in range(1,numWSD) :137 for j in range(1,10) :138 BMPsFile.write(isStr(BMPset_3[1][i][j]) + '\t')139 BMPsFile.write('\n')140 BMPsFile.write('\n')141 for i in range(1,numWSD) :142 for j in range(1,10) :143 BMPsFile.write(isStr(BMPset_3[2][i][j]) + '\t')144 BMPsFile.write('\n')145 BMPsFile.write('\n')146 for i in range(1,numWSD) :147 for j in range(1,10) :148 BMPsFile.write(isStr(BMPset_3[3][i][j]) + '\t')149 BMPsFile.write('\n')150 BMPsFile.write('\n')151 for i in range(1,numWSD) :152 for j in range(1,10) :153 BMPsFile.write(isStr(BMPset_3[4][i][j]) + '\t')154 BMPsFile.write('\n')155 BMPsFile.write('\n')156 for i in range(1,numWSD) :157 for j in range(1,10) :158 BMPsFile.write(isStr(BMPset_3[5][i][j]) + '\t')159 BMPsFile.write('\n')160 BMPsFile.write('\n')161 BMPsFile.close()162except:163 BMPsFile = 0164#-------------E BMPs.txt----------------------------------------------------------------------------------------165#-----------------------------S Copy STEPL Fortran and Run------------------------------------------------------166cpCmd = 'cp ' + path + 'stepl ' + pathSim + '.'167try:168 os.system(cpCmd)169 os.chdir(pathSim)170 #print '<li>', os.getcwd()171 os.system('./stepl')172 os.chdir('../../../')173except:174 print("<!--error-->")175#print '<li>', os.getcwd()176#-----------------------------E Copy STEPL Fortran and Run------------------------------------------------------177#----S Read Result File-----------------------------------------------------------------------------------------178tmpStr = pathSim + 'myRST.csv'179#print '<li>', tmpStr180#print '<li>', pathSim181try:182 rstFile = open(pathSim + 'myRST.csv','r')183 rst = rstFile.readlines()184 rstFile.close()185except:186 rstFile = 0187try:188 rst[0] = rst[0].split(',')189 for i in range(1,len(rst)) :190 rst[i] = rst[i].replace('\r','')191 rst[i] = rst[i].replace('\n','')192 for j in range(4) :193 rst[i] = rst[i].replace(' ',' ')194 rst[i] = rst[i].split(' ')195except:196 print("<!--Error-->")197#for i in range(len(rst)) :198# print '<li>', rst[i]199#print '<hr>'200#----E Read Result File-----------------------------------------------------------------------------------------201#-------------------------------------------------------S change columns rst >> rst3----------------------------202rst3 = []203try:204 rst3Str = isStr(rst[0][0]) + ',' 205 rst3Str += isStr(rst[0][1]) + ',' + isStr(rst[0][5]) + ',' + isStr(rst[0][9]) + ',' + isStr(rst[0][13]) + ','206 rst3Str += isStr(rst[0][2]) + ',' + isStr(rst[0][6]) + ',' + isStr(rst[0][10]) + ',' + isStr(rst[0][14]) + ','207 rst3Str += isStr(rst[0][3]) + ',' + isStr(rst[0][7]) + ',' + isStr(rst[0][11]) + ',' + isStr(rst[0][15]) + ','208 rst3Str += isStr(rst[0][4]) + ',' + isStr(rst[0][8]) + ',' + isStr(rst[0][12]) + ',' + isStr(rst[0][16])209 rst3.append(rst3Str)210 for i in range(1,len(rst)) :211 rst3Str = isStr(rst[i][1]) + ',' 212 rst3Str += isStr(rst[i][2]) + ',' + isStr(rst[i][6]) + ',' + isStr(rst[i][10]) + ',' + isStr(rst[i][14]) + ','213 rst3Str += isStr(rst[i][3]) + ',' + isStr(rst[i][7]) + ',' + isStr(rst[i][11]) + ',' + isStr(rst[i][15]) + ','214 rst3Str += isStr(rst[i][4]) + ',' + isStr(rst[i][8]) + ',' + isStr(rst[i][12]) + ',' + isStr(rst[i][16]) + ','215 rst3Str += isStr(rst[i][5]) + ',' + isStr(rst[i][9]) + ',' + isStr(rst[i][13]) + ',' + isStr(rst[i][17]) 216 rst3.append(rst3Str)217 # print '<li>', rst[i][0], rst[i][1], rst[i][3]218 # print '<li>----', rst3[i] 219 rst3[0] = rst3[0].replace(' ','')220except:221 print("<!--error-->")222#-------------------------------------------------------E change columns rst >> rst3----------------------------223#------------------------------------------S Plot---------------------------------------------------------------224#for i in range(1,len(rst)) :225# print '<li>', rst[i][2], '::', rst[i][3], '::', rst[i][4], '::', rst[i][5]226#print '<hr>'227#for i in range(1,len(rst)) :228# print '<li>', rst[i][10], '::', rst[i][11], '::', rst[i][12], '::', rst[i][13]229#print '<hr>'230#for i in range(1,len(rst)) :231# print '<li>', rst[i][14], '::', rst[i][15], '::', rst[i][16], '::', rst[i][17]232#print '<hr>'233Narr = []234Parr = []235Barr = []236Sarr = []237try:238 for i in range(1,len(rst)) :239 N_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][14])) + ')\t' + isStr('%.2f'%isFloat(rst[i][2])) + '\t' + isStr('%.2f'%isFloat(rst[i][10]))240 P_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][15])) + ')\t' + isStr('%.2f'%isFloat(rst[i][3])) + '\t' + isStr('%.2f'%isFloat(rst[i][11]))241 B_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][16])) + ')\t' + isStr('%.2f'%isFloat(rst[i][4])) + '\t' + isStr('%.2f'%isFloat(rst[i][12]))242 S_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][17])) + ')\t' + isStr('%.2f'%isFloat(rst[i][5])) + '\t' + isStr('%.2f'%isFloat(rst[i][13]))243 Narr.append(N_Str1)244 Parr.append(P_Str1)245 Barr.append(B_Str1)246 Sarr.append(S_Str1)247except:248 print("<!--error-->")249try:250 #---last line -> total251 N_Str2 = Narr[-1].split('(')252 Narr[-1] = 'Total\\n(' + N_Str2[1]253 P_Str2 = Parr[-1].split('(')254 Parr[-1] = 'Total\\n(' + P_Str2[1]255 B_Str2 = Barr[-1].split('(')256 Barr[-1] = 'Total\\n(' + B_Str2[1]257 S_Str2 = Sarr[-1].split('(')258 Sarr[-1] = 'Total\\n(' + S_Str2[1]259except:260 print("<!--error-->")261#----dat files262def datFile(pathSim,myArr,myName) :263 if ( myName == 'B' ) :264 headerName = 'BOD'265 else :266 headerName = myName267 268 #print '<li>', len(myArr)269 myDat = open(pathSim + myName + 'gnu.dat','w')270 myDat.write('Watershed\t' + headerName + '_Load_(no_BMP)\t' + headerName + '_Load_(with_BMP)\n')271 if ( len(myArr) < 3 ) :272 myDat.write(myArr[-1] + '\n')273 else :274 for i in range(len(myArr)) :275 myDat.write(myArr[i] + '\n')276 myDat.close()277datFile(pathSim,Narr,'N')278datFile(pathSim,Parr,'P')279datFile(pathSim,Barr,'B')280datFile(pathSim,Sarr,'S')281#----script files282def sctFile(pathSim,myName) :283 #----define min & max284 maxVal = 0285 myDatFile = open(pathSim + myName + 'gnu.dat','r')286 myDat = myDatFile.readlines()287 myDatFile.close()288 for i in range(1,len(myDat)) : # first line is header289 if ( 2 < len(myDat[i]) ) :290 tmpDat = myDat[i].replace('\r','')291 tmpDat = tmpDat.replace('\n','')292 tmpDat = tmpDat.split('\t')293 tmpDat[1] = float(tmpDat[1])294 tmpDat[2] = float(tmpDat[2])295 if ( maxVal <= tmpDat[1] ) :296 maxVal = tmpDat[1]297 if ( maxVal <= tmpDat[2] ) :298 maxVal = tmpDat[2]299 maxVal = maxVal * 1.2300 maxVal = '%.2f'%maxVal301 sctArr = [''] * 40302 sctArr[1] = 'set key top left\n'303 sctArr[2] = 'set terminal jpeg font "Helvetica,10"\n'304 sctArr[4] = 'set xtics border in scale 1,0.5 nomirror rotate by 0 offset character 0, 0.5, -2\n'305 sctArr[6] = 'set yrange[0.00:' + str(maxVal) + ']\n'306 #sctArr[6] = 'set autoscale y\n'307 sctArr[8] = 'set autoscale y2\n'308 sctArr[10] = 'set output "' + pathSim + myName + '_bar.jpg"\n'309 sctArr[12] = 'set xlabel "Watershed (Reduction, %)"\n'310 if ( myName == 'S' ) :311 sctArr[14] = 'set ylabel "Annual Loads (tons)"\n'312 else :313 sctArr[14] = 'set ylabel "Annual Loads (lbs)"\n'314 #sctArr[16] = 'set y2label "Total Annual Loads (lbs)"\n'315 sctArr[18] = 'set style data histogram\n'316 sctArr[20] = 'set style histogram cluster gap 1\n'317 sctArr[22] = 'set style fill solid border -1\n'318 sctArr[24] = 'set boxwidth 0.9\n'319 sctArr[26] = 'plot "' + pathSim + myName + 'gnu.dat' + '" using 2:xtic(1) ti col lt 1, "" u 3 ti col lt 2 \n'320 mySct = open(pathSim + myName + 'gnu.script','w')321 for i in range(len(sctArr)) :322 if ( 2 < len(sctArr[i]) ) :323 mySct.write(sctArr[i])324 mySct.close() 325 gnuplotExe = 'gnuplot ' + pathSim + myName + 'gnu.script'326 os.system(gnuplotExe)327sctFile(pathSim,'N')328sctFile(pathSim,'P')329sctFile(pathSim,'B')330sctFile(pathSim,'S')331#------------------------------------------E Plot---------------------------------------------------------------332#----S Result File to Download----------------------------------------------------------------------------------333#dwDatFile = open(pathSim + 'myRST.csv','r')334#dwDat = dwDatFile.readlines()335#dwDatFile.close()336#for i in range(6) :337# dwDat[0] = dwDat[0].replace(' ','')338#for i in range(1,len(dwDat)) :339# dwDat[i] = dwDat[i].replace(' ',',')340try:341 dwFile = open(pathSim + 'AnnualLoads.csv','w')342 for i in range(len(rst3)) :343 # dwFile.write(dwDat[i][1:])344 dwFile.write(rst3[i] + '\n')345 dwFile.write('\n\n----\n')346 dwFile.write('Unit is "ton/year" for sediment and is "lb/year" for the others.\n')347 dwFile.close()348except:349 dwFile = 0350locale.setlocale(locale.LC_ALL, 'en_US')351try:352 for i in range(len(rst3)) :353 rst3[i] = rst3[i].split(',')354 if ( 0 < i ) :355 for j in range(len(rst3[i])) :356 if ( 0 < j ) :357 rst3[i][j] = isStr(locale.format('%d',isInt(isFloat(rst3[i][j])+0.5),1))358except:359 print("<!--error-->")360# print '<li>', rst3[i]361#----E Result File to Download----------------------------------------------------------------------------------362#---------------------------S HTML------------------------------------------------------------------------------363print '<html>'364print '<head>'365print '<meta charset="UTF-8"> '366print ' <title>Web-based STEPL</title>'367print '<script>'368print 'function runTable1() {'369#print ' alert( document.table1.ystime.value );'370print ' if (document.table1.numWSD.value*1.0 > 0 ) document.table1.submit(); '371print '}'372print 'function runBMP() {'373#print ' alert( document.table1.ystime.value );'374print ' if (document.table1.numWSD.value*1.0 > 0 ) document.table2.submit(); '375print '}'376print '</script>'377print '</head>'378print '<body>'379print '<br><img style="margin: 0 auto; display:block " src="./img/STEPL_WEB_title.jpg" alt=" " width=400><br>'380print '<form name=main>'381print ' <br><br>'382print ' <table style="margin: 0px auto; width: 1100px" border=1>'383print ' <tr>'384print ' <td style="text-align:center; vertical-align:middle; font-weight:bold">'385print ' Annual Loads Summary'386dwnBtn = '<input type=button style=\'width:240;height:30;cursor:hand\' value=\'Click to Download\''387dwnBtn += ' onClick="javascript:window.open(\'' + pathSim + 'AnnualLoads.csv' + '\');">'388print dwnBtn389print '<input type=button style="width:200;height:30;cursor:hand;float:center;" value="Print"'390print 'onClick="javascript:window.print();"></td> '391print ' </tr></table>'392print ' <table style="margin: 0px auto; width: 1100px" border=1>'393clmArr = [0,1,3,4,5,7,8,9,11,12,13,15,16]394for i in range(len(rst3)) :395 if ( i < 1 ) : # header396 for j in range(len(clmArr)):397 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Sediment','S')398 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Sed','S')399 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('%','')400 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('(','<br>(')401 if ( j == 1 or j == 2 or j == 4 or j ==5 or j == 7 or j == 8 ) :402 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace(')',')<br>lbs/year')403 elif ( j == 3 or j == 6 or j == 9 or j == 12 ) :404 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Reduction','Reduction<br>%')405 else :406 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace(')',')<br>tons/year')407 print ' <tr>'408 if ( i == 0 ) :409 opt1 = ' align=center><b><font size=2 face="Times New Roman"'410 else :411 opt1 = ' align=right><font size=2 face="Times New Roman"'412 for j in range(len(clmArr)) :413 if ( j < 1 ) :414 opt2 = ' width=80'415 else :416 opt2 = ' width=85'417 tdStr = ' <td' + opt2 + opt1 + '>' + isStr(rst3[i][clmArr[j]]) + '</td>'418 print tdStr419 print ' </tr>'420print ' </table>'421print '<br><hr><br>'422Nstr = '<img src="' + pathSim + 'N_bar.jpg" width=400>'423Pstr = '<img src="' + pathSim + 'P_bar.jpg" width=400>'424Bstr = '<img src="' + pathSim + 'B_bar.jpg" width=400>'425Sstr = '<img src="' + pathSim + 'S_bar.jpg" width=400>'426print '<table style="margin: 0px auto;" border=1>'427print ' <tr>'428print ' <td style="text-align:center; vertical-align:middle;" colspan=2>Graphs</td>'429print ' </tr>'430print ' <tr>'431print ' <td style="text-align:center; vertical-align:middle;">', Nstr, '</td>'432print ' <td style="text-align:center; vertical-align:middle;">', Pstr, '</td>'433print ' </tr>'434print ' <tr>'435print ' <td style="text-align:center; vertical-align:middle;">', Bstr, '</td>'436print ' <td style="text-align:center; vertical-align:middle;">', Sstr, '</td>'437print ' </tr>'438print '</table><br><hr><br>'439print '</form>'440print '<table style="margin: 0px auto; border:0;" >'441print '<tr style="text-align:left"><td>'442print 'Your Log ID is </td><td><span style="color:blue">', ystime , '</span></td></tr>'443print '<tr>'444print '<td>'445print 'Restart STEPL From'446print '</td>'447print '<td>'448print ' <input type=button style=\'width:240px;height:30px;cursor:hand\' value=\'Input Form\''449print ' onClick="runTable1()"> '450print '</td>'451print '<td>'452print ' <input type=button style=\'width:240px;height:30px;cursor:hand\' value=\'BMP Form\''453print ' onClick="runBMP()"> '454print '</td>'455print '</tr></table><br>'456print '<div style="text-align:center; font-size:0.82em; color:grey"><hr>'457print ' Copyright &copy; 2015, Purdue University and Kangwon National University, all rights reserved. <br>'458print ' Purdue University is an equal access/equal opportunity university.<br>'459print ' Contact <a href=mailto:engelb@purdue.edu>Dr. Bernie Engel</a>'460print ' or <a href=mailto:theller@purdue.edu>Larry Theller</a> for more details if you need any help with STEPL WEB. '461print ' <br>'462print ' This implementation of the classic EPA model was designed by Dr. <a href=mailto:ysparkwithyou@gmail.com>Youn Shik Park</a>, Assistant Professor, Kongju National University, South-Korea.'463print ' <br>Programmatic support from US EPA, Illinois-Indiana Sea Grant, and US Army Corp of Engineers.'464print '</div><br>'465print '<a href="' + pathSim + 'myRST.csv" target=new><span style="color:white">.</span></a>'466print '<form name=table1 method="POST" action="./inputMain.cgi" target="_blank">'467print '<input type=hidden name=numWSD value='+ str(numWSD-1) + '>'468print '<input type=hidden name=numGLY value=0>'469print '<input type=hidden name=numSTR value=0>'470print '<input type=hidden name=rerun value=1>'471print '<input type=hidden name=ystime value=' + str(ystime) + '>'472print '<input type=hidden name=ystimeldc value="noldc">'473print '</form>'474print '<form name=table2 method="POST" action="./inputMain.cgi" target="_blank">'475print '<input type=hidden name=numWSD value='+ str(numWSD-1) + '>'476print '<input type=hidden name=numGLY value=0>'477print '<input type=hidden name=numSTR value=0>'478print '<input type=hidden name=rerun value=2 >'479print '<input type=hidden name=ystime value=' + str(ystime) + '>'480print '<input type=hidden name=ystimeldc value="noldc">'481print '</form>'482print '</body>'483print '</html>'484#---------------------------E HTML------------------------------------------------------------------------------485ch777 = 'chmod 777 ' + isStr(pathSim)486try:487 os.system(ch777)488except:489 print("<!--error-->")490ch777 = 'chmod 777 ' + isStr(pathSim) + '*.*'491try:492 os.system(ch777)493except:...

Full Screen

Full Screen

run_2.cgi

Source:run_2.cgi Github

copy

Full Screen

1#!/usr/local/bin/python2#------------------------------------------------------3print "Content-Type: text/html\n\n";4print "<!DOCTYPE html>"5#----------------------------------------------6#### Programmed by Youn Shik Park78import cgi, cgitb, os, string, random, datetime, glob, locale9from string import split,join10form = cgi.FieldStorage()11cgitb.enable()1213def isFloat(string):14 try:15 ret = float(string)16 except:17 ret = 018 return ret192021def isInt(string):22 try:23 ret = int(string)24 except:25 ret = 026 return ret2728def isStr(string):29 try:30 ret = str(string);31 except:32 ret = 033 return ret343536#----S input----------------------------------------------------------------------------------------------------37ystime = isStr(form.getvalue('ystime'))38numWSD = isInt(form.getvalue('numWSD'))39path = './tmp/' + ystime + '/'40simDir = glob.glob(path + 'sim_*')41status = isInt(len(simDir))42status = status + 143mkSimDir = 'mkdir ' + path + 'sim_' + isStr('%03i'%status)44os.system(mkSimDir)45cpInp = 'cp ' + path + 'inp/*.* ' + path + 'sim_' + isStr('%03i'%status) + '/.'46os.system(cpInp)47pathSim = path + 'sim_' + isStr('%03i'%status) + '/'48cpPcp = 'cp ' + path + 'cligen/pcp.txt ' + pathSim + '/.'49os.system(cpPcp)5051#--myOptPar.pys52cpOptFile = 'cp ' + path + 'myOptPar.pys ' + pathSim + '.'53os.system(cpOptFile)5455#print '<li>', ystime, numWSD, status5657#----BMP set 1, excluding URBAN BMP58BMPset_1 = [0.0] * 659for i in range(1,6) :60 BMPset_1[i] = [0.0] * numWSD61 for j in range(1,numWSD) :62 BMPset_1[i][j] = [0.0] * 763 for k in range(1,7) :64 tmpVal = isStr(form.getvalue('BMP_' + isStr(i) + '_' + isStr('%02i' % isInt(j)) + isStr(k)))65 if ( tmpVal == 'None' or tmpVal == '' ) :66 BMPset_1[i][j][k] = '%.4f' % isFloat(0.0)67 else :68 BMPset_1[i][j][k] = '%.4f' % isFloat(tmpVal)6970#---BMP set2, Urban Concentration, UrbnCnon, "Urban" sheet, Table 171BMPset_2 = [0.0] * 572for i in range(1,5) :73 BMPset_2[i] = [0.0] * 1074 for j in range(1,10) :75 tmpVal = isStr(form.getvalue('UrbnConc_' + isStr(i) + isStr(j)))76 if ( tmpVal == 'None' or tmpVal == '' ) :77 BMPset_2[i][j] = '%.4f' % isFloat(0.0)78 else :79 BMPset_2[i][j] = '%.4f' % isFloat(tmpVal)80 81#----BMP set3, Urban BMP, "Urban" sheet: Table 2a, 3.2a, 3.3a, 3.4a, 3.5a82BMPset_3 = [0.0] * 683for i in range(1,6) :84 BMPset_3[i] = [0.0] * numWSD 85 for j in range(1,numWSD) :86 BMPset_3[i][j] = [0.0] * 1087 for k in range(1,10) :88 tmpVal = isStr(form.getvalue('UrbanBMP_' + isStr(i) + '_' + isStr('%02i' % isInt(j)) + isStr(k)))89 if ( tmpVal == 'None' or tmpVal == '' ) :90 BMPset_3[i][j][k] = '%.4f' % isFloat(0.0)91 else :92 BMPset_3[i][j][k] = '%.4f' % isFloat(tmpVal)93#----E input----------------------------------------------------------------------------------------------------94#-------------S BMPs.txt----------------------------------------------------------------------------------------95try:96 BMPsFile = open(pathSim + 'BMPs.txt','w')9798 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\n')99 for i in range(1,numWSD) :100 BMPsFile.write(isStr(BMPset_1[1][i][1]) + '\t')101 BMPsFile.write(isStr(BMPset_1[1][i][2]) + '\t')102 BMPsFile.write(isStr(BMPset_1[1][i][3]) + '\t')103 BMPsFile.write(isStr(BMPset_1[1][i][4]) + '\t')104 BMPsFile.write(isStr(BMPset_1[1][i][6]) + '\n')105 BMPsFile.write('\n')106107 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\n')108 for i in range(1,numWSD) :109 BMPsFile.write(isStr(BMPset_1[2][i][1]) + '\t')110 BMPsFile.write(isStr(BMPset_1[2][i][2]) + '\t')111 BMPsFile.write(isStr(BMPset_1[2][i][3]) + '\t')112 BMPsFile.write(isStr(BMPset_1[2][i][4]) + '\t')113 BMPsFile.write(isStr(BMPset_1[2][i][6]) + '\n')114 BMPsFile.write('\n')115116 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\n')117 for i in range(1,numWSD) :118 BMPsFile.write(isStr(BMPset_1[3][i][1]) + '\t')119 BMPsFile.write(isStr(BMPset_1[3][i][2]) + '\t')120 BMPsFile.write(isStr(BMPset_1[3][i][3]) + '\t')121 BMPsFile.write(isStr(BMPset_1[3][i][4]) + '\t')122 BMPsFile.write(isStr(BMPset_1[3][i][6]) + '\n')123 BMPsFile.write('\n')124125 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\n')126 for i in range(1,numWSD) :127 BMPsFile.write(isStr(BMPset_1[4][i][1]) + '\t')128 BMPsFile.write(isStr(BMPset_1[4][i][2]) + '\t')129 BMPsFile.write(isStr(BMPset_1[4][i][3]) + '\t')130 BMPsFile.write(isStr(BMPset_1[4][i][4]) + '\t')131 BMPsFile.write(isStr(BMPset_1[4][i][6]) + '\n')132 BMPsFile.write('\n')133134 BMPsFile.write('\tN\tP\tBOD\tSediment\tAppliedArea\n')135 for i in range(1,numWSD) :136 BMPsFile.write(isStr(BMPset_1[5][i][1]) + '\t')137 BMPsFile.write(isStr(BMPset_1[5][i][2]) + '\t')138 BMPsFile.write(isStr(BMPset_1[5][i][3]) + '\t')139 BMPsFile.write(isStr(BMPset_1[5][i][4]) + '\t')140 BMPsFile.write(isStr(BMPset_1[5][i][6]) + '\n')141142 BMPsFile.write('------------ Followings are BMPs for Urban-------------------------------------------------\n')143144 for i in range(1,5) :145 for j in range(1,10) :146 BMPsFile.write(isStr(BMPset_2[i][j]) + '\t')147 BMPsFile.write('\n')148 BMPsFile.write('\n')149150 for i in range(1,numWSD) :151 for j in range(1,10) :152 BMPsFile.write(isStr(BMPset_3[1][i][j]) + '\t')153 BMPsFile.write('\n')154 BMPsFile.write('\n')155156 for i in range(1,numWSD) :157 for j in range(1,10) :158 BMPsFile.write(isStr(BMPset_3[2][i][j]) + '\t')159 BMPsFile.write('\n')160 BMPsFile.write('\n')161162 for i in range(1,numWSD) :163 for j in range(1,10) :164 BMPsFile.write(isStr(BMPset_3[3][i][j]) + '\t')165 BMPsFile.write('\n')166 BMPsFile.write('\n')167168 for i in range(1,numWSD) :169 for j in range(1,10) :170 BMPsFile.write(isStr(BMPset_3[4][i][j]) + '\t')171 BMPsFile.write('\n')172 BMPsFile.write('\n')173174 for i in range(1,numWSD) :175 for j in range(1,10) :176 BMPsFile.write(isStr(BMPset_3[5][i][j]) + '\t')177 BMPsFile.write('\n')178 BMPsFile.write('\n')179180 BMPsFile.close()181except:182 BMPsFile = 0183184185#-------------E BMPs.txt----------------------------------------------------------------------------------------186#-----------------------------S Copy STEPL Fortran and Run------------------------------------------------------187cpCmd = 'cp ' + path + 'stepl ' + pathSim + '.'188os.system(cpCmd)189os.chdir(pathSim)190#print '<li>', os.getcwd()191os.system('./stepl')192os.chdir('../../../')193#print '<li>', os.getcwd()194#-----------------------------E Copy STEPL Fortran and Run------------------------------------------------------195#----S Read Result File-----------------------------------------------------------------------------------------196tmpStr = pathSim + 'myRST.csv'197#print '<li>', tmpStr198#print '<li>', pathSim199try:200 rstFile = open(pathSim + 'myRST.csv','r')201 rst = rstFile.readlines()202 rstFile.close()203except:204 rstFile = 0205206rst[0] = rst[0].split(',')207for i in range(1,len(rst)) :208 rst[i] = rst[i].replace('\r','')209 rst[i] = rst[i].replace('\n','')210 for j in range(4) :211 rst[i] = rst[i].replace(' ',' ')212 rst[i] = rst[i].split(' ')213214#for i in range(len(rst)) :215# print '<li>', rst[i]216#print '<hr>'217#----E Read Result File-----------------------------------------------------------------------------------------218#-------------------------------------------------------S change columns rst >> rst3----------------------------219rst3 = []220221rst3Str = isStr(rst[0][0]) + ',' 222rst3Str += isStr(rst[0][1]) + ',' + isStr(rst[0][5]) + ',' + isStr(rst[0][9]) + ',' + isStr(rst[0][13]) + ','223rst3Str += isStr(rst[0][2]) + ',' + isStr(rst[0][6]) + ',' + isStr(rst[0][10]) + ',' + isStr(rst[0][14]) + ','224rst3Str += isStr(rst[0][3]) + ',' + isStr(rst[0][7]) + ',' + isStr(rst[0][11]) + ',' + isStr(rst[0][15]) + ','225rst3Str += isStr(rst[0][4]) + ',' + isStr(rst[0][8]) + ',' + isStr(rst[0][12]) + ',' + isStr(rst[0][16])226rst3.append(rst3Str)227228for i in range(1,len(rst)) :229 rst3Str = isStr(rst[i][1]) + ',' 230 rst3Str += isStr(rst[i][2]) + ',' + isStr(rst[i][6]) + ',' + isStr(rst[i][10]) + ',' + isStr(rst[i][14]) + ','231 rst3Str += isStr(rst[i][3]) + ',' + isStr(rst[i][7]) + ',' + isStr(rst[i][11]) + ',' + isStr(rst[i][15]) + ','232 rst3Str += isStr(rst[i][4]) + ',' + isStr(rst[i][8]) + ',' + isStr(rst[i][12]) + ',' + isStr(rst[i][16]) + ','233 rst3Str += isStr(rst[i][5]) + ',' + isStr(rst[i][9]) + ',' + isStr(rst[i][13]) + ',' + isStr(rst[i][17]) 234 rst3.append(rst3Str)235# print '<li>', rst[i][0], rst[i][1], rst[i][3]236# print '<li>----', rst3[i] 237238rst3[0] = rst3[0].replace(' ','')239#-------------------------------------------------------E change columns rst >> rst3----------------------------240#------------------------------------------S Plot---------------------------------------------------------------241#for i in range(1,len(rst)) :242# print '<li>', rst[i][2], '::', rst[i][3], '::', rst[i][4], '::', rst[i][5]243#print '<hr>'244245#for i in range(1,len(rst)) :246# print '<li>', rst[i][10], '::', rst[i][11], '::', rst[i][12], '::', rst[i][13]247#print '<hr>'248249#for i in range(1,len(rst)) :250# print '<li>', rst[i][14], '::', rst[i][15], '::', rst[i][16], '::', rst[i][17]251#print '<hr>'252253Narr = []254Parr = []255Barr = []256Sarr = []257for i in range(1,len(rst)) :258 # wsd name reduction(%) w/o BMP w/ BMP259 N_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][14])) + ')\t' + isStr('%.2f'%isFloat(rst[i][2])) + '\t' + isStr('%.2f'%isFloat(rst[i][10]))260 P_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][15])) + ')\t' + isStr('%.2f'%isFloat(rst[i][3])) + '\t' + isStr('%.2f'%isFloat(rst[i][11]))261 B_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][16])) + ')\t' + isStr('%.2f'%isFloat(rst[i][4])) + '\t' + isStr('%.2f'%isFloat(rst[i][12]))262 S_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][17])) + ')\t' + isStr('%.2f'%isFloat(rst[i][5])) + '\t' + isStr('%.2f'%isFloat(rst[i][13]))263 Narr.append(N_Str1)264 Parr.append(P_Str1)265 Barr.append(B_Str1)266 Sarr.append(S_Str1)267268269#---last line -> total270N_Str2 = Narr[-1].split('(')271Narr[-1] = 'Total\\n(' + N_Str2[1]272P_Str2 = Parr[-1].split('(')273Parr[-1] = 'Total\\n(' + P_Str2[1]274B_Str2 = Barr[-1].split('(')275Barr[-1] = 'Total\\n(' + B_Str2[1]276S_Str2 = Sarr[-1].split('(')277Sarr[-1] = 'Total\\n(' + S_Str2[1]278279280#----dat files281def datFile(pathSim,myArr,myName) :282 if ( myName == 'B' ) :283 headerName = 'BOD'284 else :285 headerName = myName286 287 #print '<li>', len(myArr)288 try:289 myDat = open(pathSim + myName + 'gnu.dat','w')290 myDat.write('Watershed\t' + headerName + '_Load_(no_BMP)\t' + headerName + '_Load_(with_BMP)\n')291 if ( len(myArr) < 3 ) :292 myDat.write(myArr[-1] + '\n')293 else :294 for i in range(len(myArr)) :295 myDat.write(myArr[i] + '\n')296 myDat.close()297 except:298 myDat = 0299300datFile(pathSim,Narr,'N')301datFile(pathSim,Parr,'P')302datFile(pathSim,Barr,'B')303datFile(pathSim,Sarr,'S')304305306#----script files307def sctFile(pathSim,myName) :308 #----define min & max309 maxVal = 0.0310 try:311 myDatFile = open(pathSim + myName + 'gnu.dat','r')312 myDat = myDatFile.readlines()313 myDatFile.close()314 except:315 myDatFile = 0316 for i in range(1,len(myDat)) : # first line is header317 if ( 2 < len(myDat[i]) ) :318 tmpDat = myDat[i].replace('\r','')319 tmpDat = tmpDat.replace('\n','')320 tmpDat = tmpDat.split('\t')321 tmpDat[1] = isFloat(tmpDat[1])322 tmpDat[2] = isFloat(tmpDat[2])323 if ( maxVal <= tmpDat[1] ) :324 maxVal = tmpDat[1]325 if ( maxVal <= tmpDat[2] ) :326 maxVal = tmpDat[2]327 maxVal = maxVal * 1.2328 maxVal = '%.2f'%maxVal329 sctArr = [''] * 40330 sctArr[1] = 'set key top left\n'331 sctArr[2] = 'set terminal jpeg font "Helvetica,10"\n'332 sctArr[4] = 'set xtics border in scale 1,0.5 nomirror rotate by 0 offset character 0, 0.5, -2\n'333 sctArr[6] = 'set yrange[0.00:' + isStr(maxVal) + ']\n'334 #sctArr[6] = 'set autoscale y\n'335 sctArr[8] = 'set autoscale y2\n'336 sctArr[10] = 'set output "' + pathSim + myName + '_bar.jpg"\n'337 sctArr[12] = 'set xlabel "Watershed (Reduction, %)"\n'338 if ( myName == 'S' ) :339 sctArr[14] = 'set ylabel "Annual Loads (tons)"\n'340 else :341 sctArr[14] = 'set ylabel "Annual Loads (lbs)"\n'342 #sctArr[16] = 'set y2label "Total Annual Loads (lbs)"\n'343 sctArr[18] = 'set style data histogram\n'344 sctArr[20] = 'set style histogram cluster gap 1\n'345 sctArr[22] = 'set style fill solid border -1\n'346 sctArr[24] = 'set boxwidth 0.9\n'347 sctArr[26] = 'plot "' + pathSim + myName + 'gnu.dat' + '" using 2:xtic(1) ti col lt 1, "" u 3 ti col lt 2 \n'348 try:349 mySct = open(pathSim + myName + 'gnu.script','w')350 for i in range(len(sctArr)) :351 if ( 2 < len(sctArr[i]) ) :352 mySct.write(sctArr[i])353 mySct.close() 354 except:355 mySct = 0356 gnuplotExe = 'gnuplot ' + pathSim + myName + 'gnu.script'357 os.system(gnuplotExe)358359sctFile(pathSim,'N')360sctFile(pathSim,'P')361sctFile(pathSim,'B')362sctFile(pathSim,'S')363#------------------------------------------E Plot---------------------------------------------------------------364#----S Result File to Download----------------------------------------------------------------------------------365#dwDatFile = open(pathSim + 'myRST.csv','r')366#dwDat = dwDatFile.readlines()367#dwDatFile.close()368369#for i in range(6) :370# dwDat[0] = dwDat[0].replace(' ','')371372#for i in range(1,len(dwDat)) :373# dwDat[i] = dwDat[i].replace(' ',',')374try:375 dwFile = open(pathSim + 'AnnualLoads.csv','w')376 for i in range(len(rst3)) :377 # dwFile.write(dwDat[i][1:])378 dwFile.write(rst3[i] + '\n')379380 dwFile.write('\n\n----\n')381 dwFile.write('Unit is "ton/year" for sediment and is "lb/year" for the others.\n')382 dwFile.close()383except:384 dwFile = 0385386locale.setlocale(locale.LC_ALL, 'en_US')387for i in range(len(rst3)) :388 rst3[i] = rst3[i].split(',')389 if ( 0 < i ) :390 for j in range(len(rst3[i])) :391 if ( 0 < j ) :392 rst3[i][j] = isStr(locale.format('%d',isInt(isFloat(rst3[i][j])+0.5),1))393# print '<li>', rst3[i]394#----E Result File to Download----------------------------------------------------------------------------------395#---------------------------S HTML------------------------------------------------------------------------------396print '<html>'397print '<head>'398print '<meta charset="UTF-8"> '399print ' <title>Web-based STEPL</title>'400print '</head>'401print '<body>'402print '<br><center><img src="./img/STEPL_WEB_title.jpg" width=400><br></center>'403print '<form name=main>'404print ' <br><br><center>'405print ' <table border=1 width=1100>'406407print ' <tr align=middle>'408print ' <td align=center colspan=13>'409print ' <b><font face="Times New Roman">Annual Loads Summary</b>'410dwnBtn = '<input type=button style=\'width:240;height:30;cursor:hand\' value=\'Click to Download\''411dwnBtn += ' onClick="javascript:window.open(\'' + pathSim + 'AnnualLoads.csv' + '\');">'412print dwnBtn413print ' </td>'414print ' </tr>'415416clmArr = [0,1,3,4,5,7,8,9,11,12,13,15,16]417for i in range(len(rst3)) :418 if ( i < 1 ) : # header419 for j in range(len(clmArr)):420 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Sediment','S')421 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Sed','S')422 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('%','')423 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('(','<br>(')424 if ( j == 1 or j == 2 or j == 4 or j ==5 or j == 7 or j == 8 ) :425 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace(')',')<br>lbs/year')426 elif ( j == 3 or j == 6 or j == 9 or j == 12 ) :427 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace('Reduction','Reduction<br>%')428 else :429 rst3[i][clmArr[j]] = rst3[i][clmArr[j]].replace(')',')<br>tons/year')430431 print ' <tr>'432 if ( i == 0 ) :433 opt1 = ' align=center><b><font size=2 face="Times New Roman"'434 else :435 opt1 = ' align=right><font size=2 face="Times New Roman"'436 for j in range(len(clmArr)) :437 if ( j < 1 ) :438 opt2 = ' width=80'439 else :440 opt2 = ' width=85'441 tdStr = ' <td' + opt2 + opt1 + '>' + isStr(rst3[i][clmArr[j]]) + '</td>'442 print tdStr443 print ' </tr>'444print ' </table>'445446print '<br><hr><br>'447448Nstr = '<img src="' + pathSim + 'N_bar.jpg" width=400>'449Pstr = '<img src="' + pathSim + 'P_bar.jpg" width=400>'450Bstr = '<img src="' + pathSim + 'B_bar.jpg" width=400>'451Sstr = '<img src="' + pathSim + 'S_bar.jpg" width=400>'452453print '<table border=1>'454print ' <tr align=middle>'455print ' <td align=center colspan=2>Graphs</td>'456print ' </tr>'457print ' <tr align=middle>'458print ' <td align=center>', Nstr, '</td>'459print ' <td align=center>', Pstr, '</td>'460print ' </tr>'461print ' <tr align=middle>'462print ' <td align=center>', Bstr, '</td>'463print ' <td align=center>', Sstr, '</td>'464print ' </tr>'465print '</table><br>'466467print '</form>'468469print '<center><hr>'470print '<font size=2>'471print ' <font color=gray>'472print ' Copyright &copy; 2015, Purdue University and Kangwon National University, all rights reserved. <br>'473print ' Purdue University is an equal access/equal opportunity university.<br>'474print ' </font>'475print ' Contact <a href=mailto:engelb@purdue.edu>Dr. Bernie Engel</a>'476print ' with more details if you need any help for STEPL WEB.'477print ' <br>'478print ' Web implementation design by <a href=mailto:parkyounshik@gmail.com>Dr. Youn Shik Park</a>, Assistant Professor, Kongju National University, KR.'479print '</font><br>'480481print '<a href="' + pathSim + 'myRST.csv" target=new><font color=white>.</font></a>'482483print '</body>'484print '</html>'485#---------------------------E HTML------------------------------------------------------------------------------486487488489490491492493494495496497498499500501502503504ch777 = 'chmod 777 ' + isStr(pathSim)505os.system(ch777)506ch777 = 'chmod 777 ' + isStr(pathSim) + '*.*'507os.system(ch777)508 ...

Full Screen

Full Screen

Run1.py

Source:Run1.py Github

copy

Full Screen

1#!/usr/local/bin/python2import cgi, cgitb, os, string, random, datetime, glob, locale3from string import split,join4def run1(ystime):5 path = './tmp/' + ystime + '/'6 cpCmd = 'cp ' + 'stepl ' + path7 os.system(cpCmd)8 os.chdir(path)9 cpCmd = 'cp ' + 'cligen/pcp.txt ' + '.'10 os.system(cpCmd)11 #----------------------------S myOptPar.pys default-------------------------------------------------------------12 OptPar = open('myOptPar.pys','w')13 for i in range(6) :14 OptPar.write('1.00\n')15 OptPar.close()16 #-----------------------------S Run------------------------------------------------------17 os.system('./stepl')18 #-----------------------------E Run------------------------------------------------------19 rstFile = open( 'myRST.csv','r')20 rst = rstFile.readlines()21 rstFile.close()22 rst[0] = rst[0].split(',')23 for i in range(1,len(rst)) :24 rst[i] = rst[i].replace('\r','')25 rst[i] = rst[i].replace('\n','')26 for j in range(4) :27 rst[i] = rst[i].replace(' ',' ')28 rst[i] = rst[i].split(' ')29 #-------------------S change columns rst >> rst3----------------------------30 rst3 = []31 rst3Str = isStr(rst[0][0]) + ',' 32 rst3Str += isStr(rst[0][1]) + ',' + isStr(rst[0][5]) + ',' + isStr(rst[0][9]) + ',' + isStr(rst[0][13]) + ','33 rst3Str += isStr(rst[0][2]) + ',' + isStr(rst[0][6]) + ',' + isStr(rst[0][10]) + ',' + isStr(rst[0][14]) + ','34 rst3Str += isStr(rst[0][3]) + ',' + isStr(rst[0][7]) + ',' + isStr(rst[0][11]) + ',' + isStr(rst[0][15]) + ','35 rst3Str += isStr(rst[0][4]) + ',' + isStr(rst[0][8]) + ',' + isStr(rst[0][12]) + ',' + isStr(rst[0][16])36 rst3.append(rst3Str)37 for i in range(1,len(rst)) :38 rst3Str = isStr(rst[i][1]) + ',' 39 rst3Str += isStr(rst[i][2]) + ',' + isStr(rst[i][6]) + ',' + isStr(rst[i][10]) + ',' + isStr(rst[i][14]) + ','40 rst3Str += isStr(rst[i][3]) + ',' + isStr(rst[i][7]) + ',' + isStr(rst[i][11]) + ',' + isStr(rst[i][15]) + ','41 rst3Str += isStr(rst[i][4]) + ',' + isStr(rst[i][8]) + ',' + isStr(rst[i][12]) + ',' + isStr(rst[i][16]) + ','42 rst3Str += isStr(rst[i][5]) + ',' + isStr(rst[i][9]) + ',' + isStr(rst[i][13]) + ',' + isStr(rst[i][17]) 43 rst3.append(rst3Str)44 rst3[0] = rst3[0].replace(' ','')45 #-----------------E change columns rst >> rst3----------------------------46 #------------------S Plot-----------------------------------------------47 Narr = []48 Parr = []49 Barr = []50 Sarr = []51 for i in range(1,len(rst)) :52 N_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][14])) + ')\t' + isStr('%.2f'%isFloat(rst[i][2])) + '\t' + isStr('%.2f'%isFloat(rst[i][10]))53 P_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][15])) + ')\t' + isStr('%.2f'%isFloat(rst[i][3])) + '\t' + isStr('%.2f'%isFloat(rst[i][11]))54 B_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][16])) + ')\t' + isStr('%.2f'%isFloat(rst[i][4])) + '\t' + isStr('%.2f'%isFloat(rst[i][12]))55 S_Str1 = 'W' + isStr(i) + '\\n(' + isStr('%.2f'%isFloat(rst[i][17])) + ')\t' + isStr('%.2f'%isFloat(rst[i][5])) + '\t' + isStr('%.2f'%isFloat(rst[i][13]))56 Narr.append(N_Str1)57 Parr.append(P_Str1)58 Barr.append(B_Str1)59 Sarr.append(S_Str1)60 #---last line -> total61 N_Str2 = Narr[-1].split('(')62 Narr[-1] = 'Total\\n(' + N_Str2[1]63 P_Str2 = Parr[-1].split('(')64 Parr[-1] = 'Total\\n(' + P_Str2[1]65 B_Str2 = Barr[-1].split('(')66 Barr[-1] = 'Total\\n(' + B_Str2[1]67 S_Str2 = Sarr[-1].split('(')68 Sarr[-1] = 'Total\\n(' + S_Str2[1]69 datFile(Narr,'N')70 datFile(Parr,'P')71 datFile(Barr,'B')72 datFile(Sarr,'S')73 sctFile('N')74 sctFile('P')75 sctFile('B')76 sctFile('S')77 #-----------------E Plot---------------------------------------------------78 #----S Result File to Download---------------------------------------------79 dwFile = open( 'AnnualLoads.csv','w')80 for i in range(len(rst3)) :81 # dwFile.write(dwDat[i][1:])82 dwFile.write(rst3[i] + '\n')83 dwFile.write('\n\n----\n')84 dwFile.write('Unit is "ton/year" for sediment and is "lb/year" for the others.\n')85 dwFile.close()86 locale.setlocale(locale.LC_ALL, 'en_US')87 for i in range(len(rst3)) :88 rst3[i] = rst3[i].split(',')89 if ( 0 < i ) :90 for j in range(len(rst3[i])) :91 if ( 0 < j ) :92 rst3[i][j] = isStr(locale.format('%d',isInt(isFloat(rst3[i][j])+0.5),1))93 ch777 = 'chmod 777 *' 94 os.system(ch777)95 #return back to the original dir96 os.chdir("../..")97 return rst398#----dat files99def datFile(myArr,myName) :100 if ( myName == 'B' ) :101 headerName = 'BOD'102 else :103 headerName = myName104 105 #print '<li>', len(myArr)106 myDat = open( myName + 'gnu.dat','w')107 myDat.write('Watershed\t' + headerName + '_Load_(no_BMP)\t' + headerName + '_Load_(with_BMP)\n')108 if ( len(myArr) < 3 ) :109 myDat.write(myArr[-1] + '\n')110 else :111 for i in range(len(myArr)) :112 myDat.write(myArr[i] + '\n')113 myDat.close()114#----script files115def sctFile(myName) :116 #----define min & max117 maxVal = 0118 myDatFile = open(myName + 'gnu.dat','r')119 myDat = myDatFile.readlines()120 myDatFile.close()121 for i in range(1,len(myDat)) : # first line is header122 if ( 2 < len(myDat[i]) ) :123 tmpDat = myDat[i].replace('\r','')124 tmpDat = tmpDat.replace('\n','')125 tmpDat = tmpDat.split('\t')126 tmpDat[1] = float(tmpDat[1])127 tmpDat[2] = float(tmpDat[2])128 if ( maxVal <= tmpDat[1] ) :129 maxVal = tmpDat[1]130 if ( maxVal <= tmpDat[2] ) :131 maxVal = tmpDat[2]132 maxVal = maxVal * 1.2133 maxVal = '%.2f'%maxVal134 sctArr = [''] * 40135 sctArr[1] = 'set key top left\n'136 sctArr[2] = 'set terminal jpeg font "Helvetica,10"\n'137 sctArr[4] = 'set xtics border in scale 1,0.5 nomirror rotate by 0 offset character 0, 0.5, -2\n'138 sctArr[6] = 'set yrange[0.00:' + str(maxVal) + ']\n'139 #sctArr[6] = 'set autoscale y\n'140 sctArr[8] = 'set autoscale y2\n'141 sctArr[10] = 'set output "' + myName + '_bar.jpg"\n'142 sctArr[12] = 'set xlabel "Watershed (Reduction, %)"\n'143 if ( myName == 'S' ) :144 sctArr[14] = 'set ylabel "Annual Loads (tons)"\n'145 else :146 sctArr[14] = 'set ylabel "Annual Loads (lbs)"\n'147 #sctArr[16] = 'set y2label "Total Annual Loads (lbs)"\n'148 sctArr[18] = 'set style data histogram\n'149 sctArr[20] = 'set style histogram cluster gap 1\n'150 sctArr[22] = 'set style fill solid border -1\n'151 sctArr[24] = 'set boxwidth 0.9\n'152 sctArr[26] = 'plot "' + myName + 'gnu.dat' + '" using 2:xtic(1) ti col lt 1, "" u 3 ti col lt 2 \n'153 mySct = open( myName + 'gnu.script','w')154 for i in range(len(sctArr)) :155 if ( 2 < len(sctArr[i]) ) :156 mySct.write(sctArr[i])157 mySct.close() 158 gnuplotExe = 'gnuplot ' + myName + 'gnu.script'...

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 robotframework-appiumlibrary 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