def getoppositeedge(eid): global e2oppoe,configfile if eid in e2oppoe.keys(): return e2oppoe[eid] ef=open(get_conf(configfile,"edge-files"),'r') for line in ef: line=line.strip() if iprintinfo>1: print(line) if line.startswith('<edge id="'+eid+'"'): st=line.split(' ') toid=st[3].lstrip("to=") fromid=st[2].lstrip("from=") opst='from='+toid+' to='+fromid break ef.seek(0,0) for line in ef: if line.find(opst)!=-1: idstr=line.lstrip().split(' ',2)[1] opeid=idstr.split('"')[1] break ef.close() e2oppoe[eid]=opeid if not opeid in e2oppoe.keys(): e2oppoe[opeid]=eid return opeid
def getoppositeedge(eid): global e2oppoe, configfile if eid in e2oppoe.keys(): return e2oppoe[eid] ef = open(get_conf(configfile, "edge-files"), 'r') for line in ef: line = line.strip() if iprintinfo > 1: print(line) if line.startswith('<edge id="' + eid + '"'): st = line.split(' ') toid = st[3].lstrip("to=") fromid = st[2].lstrip("from=") opst = 'from=' + toid + ' to=' + fromid break ef.seek(0, 0) for line in ef: if line.find(opst) != -1: idstr = line.lstrip().split(' ', 2)[1] opeid = idstr.split('"')[1] break ef.close() e2oppoe[eid] = opeid if not opeid in e2oppoe.keys(): e2oppoe[opeid] = eid return opeid
def run(): wfd = open("net.nod.xml", 'w') wfd.write(st1) nx = int(get_conf(cfg, "grid.x-number")) ny = int(get_conf(cfg, "grid.y-number")) lx = int(get_conf(cfg, "grid.x-length")) ly = int(get_conf(cfg, "grid.y-length")) lout = int(get_conf(cfg, "grid.attach-length")) lvar = int(get_conf(cfg, "varlength")) # gen nodes pref = "n" for j in range(0, ny + 2): for i in range(1, nx + 1): x = i * lx + randint(-lvar, lvar) y = j * ly + randint(-lvar, lvar) nid = pref + "x" + str(i) + "y" + str(j) wfd.write(st3 % (nid, x, y) + "\n") for i in [0, nx + 1]: for j in range(1, ny + 1): x = i * lx + randint(-lvar, lvar) y = j * ly + randint(-lvar, lvar) nid = pref + "x" + str(i) + "y" + str(j) wfd.write(st3 % (nid, x, y) + "\n") wfd.write(st2) wfd.close()
def run(): wfd = open("net.edg.xml", 'w') wfd.write(st1) nx = int(get_conf(cfg, "grid.x-number")) ny = int(get_conf(cfg, "grid.y-number")) lx = int(get_conf(cfg, "grid.x-length")) ly = int(get_conf(cfg, "grid.y-length")) lout = int(get_conf(cfg, "grid.attach-length")) lvar = int(get_conf(cfg, "varlength")) # gen vertical pref = "e" for j in range(0, ny + 1): # 5 for i in range(1, nx + 1): #3 fro = "nx" + str(i) + "y" + str(j) to = "nx" + str(i) + "y" + str(j + 1) eid = pref + fro + to wfd.write(st3 % (eid, fro, to) + "\n") eid = pref + to + fro wfd.write(st3 % (eid, to, fro) + "\n") # gen horizontal for i in range(0, nx + 1): # 6 for j in range(1, ny + 1): #2 fro = "nx" + str(i) + "y" + str(j) to = "nx" + str(i + 1) + "y" + str(j) eid = pref + fro + to # print(eid) wfd.write(st3 % (eid, fro, to) + "\n") eid = pref + to + fro wfd.write(st3 % (eid, to, fro) + "\n") wfd.write(st2) wfd.close()
def run(): wfd = open("net.edg.xml",'w') wfd.write(st1) nx = int(get_conf(cfg,"grid.x-number")) ny = int(get_conf(cfg,"grid.y-number")) lx = int(get_conf(cfg,"grid.x-length")) ly = int(get_conf(cfg,"grid.y-length")) lout = int(get_conf(cfg,"grid.attach-length")) lvar = int(get_conf(cfg,"varlength")) # gen vertical pref = "e" for j in range(0, ny+1): # 5 for i in range(1,nx+1): #3 fro = "nx"+str(i)+"y"+str(j) to = "nx"+str(i)+"y"+str(j+1) eid = pref+fro+to wfd.write(st3%(eid,fro,to)+"\n") eid = pref+to+fro wfd.write(st3%(eid,to,fro)+"\n") # gen horizontal for i in range(0,nx+1): # 6 for j in range(1,ny+1): #2 fro = "nx"+str(i)+"y"+str(j) to = "nx"+str(i+1)+"y"+str(j) eid = pref+fro+to # print(eid) wfd.write(st3%(eid,fro,to)+"\n") eid = pref+to+fro wfd.write(st3%(eid,to,fro)+"\n") wfd.write(st2) wfd.close()
def get_tls2duration(): tls2ph2time = {} with open(get_conf(configfile, "tllogic-files"), 'r') as fd: tlsid = "" ind = 0 for l in fd: l = l.strip() if l.startswith("<tlLogic id="): tlsid = l.split('"')[1] ind = 0 tls2ph2time[tlsid] = {} if l.startswith("<phase duration="): t = int(l.split('"')[1]) if Tls.tlslogic2phn[ind] != -1: tls2ph2time[tlsid][Tls.tlslogic2phn[ind]] = t - 1 else: tls2ph2time[tlsid][Tls.tlslogic2phn[ind - 1]] += YellowTime ind += 1 return tls2ph2time
def get_tls2duration(): tls2ph2time={} with open(get_conf(configfile,"tllogic-files"),'r') as fd: tlsid = "" ind=0 for l in fd: l=l.strip() if l.startswith("<tlLogic id="): tlsid = l.split('"')[1] ind=0 tls2ph2time[tlsid]={} if l.startswith("<phase duration="): t = int(l.split('"')[1]) if Tls.tlslogic2phn[ind]!=-1: tls2ph2time[tlsid][Tls.tlslogic2phn[ind]]=t-1 else: tls2ph2time[tlsid][Tls.tlslogic2phn[ind-1]]+=YellowTime ind+=1 return tls2ph2time
addpath = mypydir + "/mytools" if addpath not in sys.path: sys.path.append(addpath) if mypydir not in sys.path: sys.path.append(mypydir) from readconf import get_conf, get_conf_int, get_conf_float, get_list_startswith, get_dic_startswith from logger import Logger, SimpleAppendLogger, ErrorLogger from util import read_lines_as_list, read_lines_as_dic, read_gzip, strip_illegal_char, strip_newline, unix2datetime, get_file_size_bytes, py_fname, replace_user_home from namehostip import get_my_ip, get_platform from geo import get_bearing_latlng2, min_angle_diff, convert_line_to_dic, get_dist_meters_latlng, latlng_to_city_state_country, get_osm_file_quote_given_file from CacheManager import CacheManager from osmutil import osmPipeline from mem import AccessRestrictionContext, Synchronizer, Mem from myosrm import crawl_nid_to_latlng configfile = "conf.txt" HomeDir = os.path.expanduser("~") DirData = get_conf(configfile, "DirData") #~/greendrive/proc DirOSM = get_conf(configfile, "DirOSM") #~/greendrive/osmdata DirData = replace_user_home(DirData) DirOSM = replace_user_home(DirOSM) gpsfolder = "gps" obdfolder = "obd" combinefolder = "combine" MyIp = get_my_ip() My_Platform = get_platform() # "centos" means cluster On_Cluster = False if My_Platform == 'centos': On_Cluster = True iprint = 2 err = ErrorLogger("allerror.txt", py_fname(__file__, False)) lg = SimpleAppendLogger("./logs/" + py_fname(__file__, False))
def run(): wfd = open("net.con.xml",'w') fdet = open("net.det.xml",'w') ftls = open("net.tls.xml",'w') wfd.write(st1) fdet.write(st4) ftls.write(st4) nx = int(get_conf(cfg,"grid.x-number")) ny = int(get_conf(cfg,"grid.y-number")) lx = int(get_conf(cfg,"grid.x-length")) ly = int(get_conf(cfg,"grid.y-length")) lout = int(get_conf(cfg,"grid.attach-length")) lvar = int(get_conf(cfg,"varlength")) nlist=[] n2xy={} with open("net.nod.xml",'r') as nf: for line in nf: line=line.strip() if line.startswith("<node id"): nlist.append(line.split('"')[1]) x=float(line.split('"')[3]) y=float(line.split('"')[5]) n2xy[line.split('"')[1]]=[x,y] # print(nlist) # print(n2xy) n2e={nd:[[],[]] for nd in nlist} # {nid:[ [ein,],[eout,] ] } with open("net.edg.xml",'r') as ef: for line in ef: line=line.strip() if line.startswith("<edge id"): eid = line.split('"')[1] fro= line.split('"')[3] to = line.split('"')[5] n2e[fro][1].append(eid) n2e[to][0].append(eid) # print(n2e) # connect lanes for nd,eio in n2e.items(): # if nd!='nx1y3': # continue # print(nd) x, y = n2xy[nd] addtls=0 for ei in eio[0]: # if ei!="enx2y4nx1y3": # continue print("\n"+ei) nin = ei.split("n")[1].strip() ix,iy = n2xy["n"+nin] # coord of node from degi = getdeg(ix,iy,x,y) dx1=float(x-ix) dy1=float(y-iy) dd=math.sqrt(dx1*dx1+dy1*dy1) dx1/=dd dy1/=dd tmp = eio[1][:] if len(tmp)<2: continue # peripheral nodes. fdet.write(st6%(ei,ei)) # induction loop # tls if addtls==0: addtls=1 offset = randint(0,tlsoffset) ftls.write(st7%(nd,offset)) t1=randint(tlslg1,tlslg2) t2=randint(tlsg1,tlsg2) t3=randint(tlslg1,tlslg2) t4=randint(tlsg1,tlsg2) ftls.write(st8%(t1,t1,t1,t2,tlsy,t3,t3,t3,t4,tlsy)) ftls.write(st9) tmp.remove("e"+nd+"n"+nin) # no turnaround crpd = {} # vec cross product dotp = {} # dot product for eo in tmp: no = eo.split("n")[2].strip() ox,oy = n2xy["n"+no] # coord of node to dx2=ox-x dy2=oy-y dd=math.sqrt(dx2*dx2+dy2*dy2) dx2/=dd dy2/=dd crpd[dx1*dy2-dx2*dy1] = eo dotp[eo] = dx1*dx2+dy1*dy2 cps = crpd.keys() cps.sort() # cps [ right straight left ] i=len(cps)-1 if cps[i]<=0:# left found wfd.write(st3%(ei,crpd[cps[i]],1,1)) else: # dot smallest is left candi = [] for j in range(len(cps)): if cps[j]>=0: candi.append(crpd[cps[j]]) # find min dot target="" tmp=10000 for eid,dot in dotp.items(): if eid in candi and dot<tmp: tmp=dot target=eid if iprint:print("left ",target) del dotp[target] wfd.write(st3%(ei,target,1,1)) cps = crpd.keys() cps.sort() i=0 # right turn if cps[i]>=0:# right found wfd.write(st3%(ei,crpd[cps[i]],0,0)) else: # dot smallest is right candi = [] for j in range(len(cps)): if cps[j]<=0: candi.append(crpd[cps[j]]) # find min dot target="" tmp=10000 for eid,dot in dotp.items(): if eid in candi and dot<tmp: tmp=dot target=eid if iprint:print("right ",target) del dotp[target] wfd.write(st3%(ei,target,0,0)) # go straight, dot largest is target="" tmp=-10000 for eid,dot in dotp.items(): if dot>tmp: tmp=dotp[eid] target=eid if iprint:print("straight ",target) wfd.write(st3%(ei,target,0,0)) wfd.write(st3%(ei,target,0,1)) # angles = [degi + ang for ang in [-90,90,0]] # for i in range(len(angles)): # if angles[i]<0: # angles[i]=angles[i]+360.0 # if angles[i]>360: # angles[i]=angles[i]-360.0 # for i in range(len(angles)): # first left, then right, last straight. # print(i,tmp) # target="" # dego=-1 # diff = 100000 # for eo in tmp: # no = eo.split("n")[2].strip() # ox,oy = n2xy["n"+no] # coord of node to # deg2 = getdeg(x,y,ox,oy) # print(eo,deg2,angles[i]) # if abs(deg2-angles[i])<diff or abs(deg2-angles[i]+360)<diff or abs(deg2-angles[i]-360)<diff: # diff=min([abs(deg2-angles[i]),abs(deg2-angles[i]+360),abs(deg2-angles[i]-360)]) # target=eo # dego = deg2 # if target!="": # print(degi,dego) # tmp.remove(target) # print(ei,target,i) # if i==0: # left found # wfd.write(st3%(ei,target,1,1)) # if i==1: # right turn # wfd.write(st3%(ei,target,0,0)) # if i==2: # go straight # wfd.write(st3%(ei,target,0,0)) # wfd.write(st3%(ei,target,0,1)) # break # break wfd.write(st2) wfd.close() fdet.write(st5) fdet.close() ftls.write(st5) ftls.close()
from multiColSeqSeparate import multiColSeqSeparate iprint = 1 HomeDir = os.path.expanduser("~") User = getpass.getuser() if HomeDir.endswith("shu"): WORKDIR = os.path.expanduser("~") elif HomeDir.endswith("srallap"): WORKDIR = os.path.expanduser("~") + "/eeg" configfile = "conf.txt" from_conf = get_conf_int(configfile, "from_conf") from_tasklist = get_conf_int(configfile, "from_tasklist") dataSetsDir = get_conf(configfile, "dataSetsDir" + User) dataProcDir = get_conf(configfile, "dataProcDir" + User) rawfolder = get_conf(configfile, "rawfolder") metafolder = get_conf(configfile, "metafolder") datafolder = get_conf(configfile, "datafolder") datasets = get_list_startswith(configfile, "datasets") datapaths = [dataSetsDir + "/" + tmp + "/" for tmp in datasets] if iprint: print(datapaths) for i in range(len(datapaths)): confsuffix = datasets[i] path = datapaths[i] conf = conf = "conf/conf-" + confsuffix + ".txt" iflist = glob.glob(path + "/" + rawfolder + "/*")
WORKDIR = os.path.expanduser("~") elif HomeDir.endswith("srallap"): WORKDIR = os.path.expanduser("~") + "/eeg" configfile = "conf.txt" import memcache # https://www.sinacloud.com/doc/_static/memcache.html CACHE_TIME = 0 # or unix 1497190272, if larger than 30 days. CACHE_SIZE = 100 * 1024 * 1024 * 1024 # 100G, no use, use etc/config use_cache = get_conf_int(configfile, "use_cache") if not use_cache: print( __file__.split("/")[-1], "did not plan to use cache, exit, edit conf") sys.exit(0) cache_place = get_conf(configfile, "cache_place") my_ip = get_my_ip() print("my_ip", my_ip) if cache_place == 'local': mc = memcache.Client(['127.0.0.1:11211'], server_max_value_length=CACHE_SIZE) elif cache_place == 'servers': servers = get_conf(configfile, "cache_servers").split(",") if iprint: print("cache servers", servers) if my_ip.startswith("172.22"): ips = [tarekc2ip[host] + ":11211" for host in servers] else: ips = [host + ":11211" for host in servers]
#!/usr/bin/env python import os, sys, getpass import subprocess import random, time import inspect import collections mypydir =os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe()))) sys.path.append(mypydir) from readconf import get_conf,get_conf_int,get_conf_float,get_list_startswith,get_dic_startswith iprint=2 configfile = "conf.txt" DirGreengps = get_conf(configfile,"DirGreengps") assert(DirGreengps!="") CUT = get_conf(configfile,"CUT") pakFile=DirGreengps+os.sep+"champaign.extracted.geofabrik.sep2011.augmented.pak" nodesAndStopsFile=DirGreengps+os.sep+"champaign.extracted.geofabrik.sep2011.augmented.nodesAndstops" GramPerGallon = get_conf_float(configfile,"GramPerGallon") Bound_N_lat=40.157605 Bound_S_lat=40.020233 Bound_W_lng=-88.314759 Bound_E_lng=-88.128484 def inBound(lat,lng): if (lat<Bound_N_lat and lat>Bound_S_lat and lng<Bound_E_lng and lng>Bound_W_lng): return True return False def query_coef_str(make ,model ,year ,vclass): cmd=DirGreengps+os.sep+"query "+DirGreengps+os.sep+"2014-1-30_u44_[CoeffsOrdered]_model_db_LS_wok7.txt "+make+" "+model+" "+year+" "+vclass
st5="</additional>" st6 = ' <inductionLoop id="%s_1" lane="%s_1" pos="-2" file="/dev/null" freq="1"/>\n' st1="""<?xml version="1.0" encoding="UTF-8"?> <connections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/connections_file.xsd"> """ st2="</connections>" st3= ' <connection from="%s" to="%s" fromLane="%d" toLane="%d"/>\n' # <edge id="-enx3y0nx3y1" from="nx3y1" to="nx3y0" type="a"/> # <node id="nx2y0" x="563" y="35" type="traffic_light"/> st7 = ' <tlLogic id="%s" programID="p1" offset="%d" type="static">\n' st8 = ' <phase duration="%d" state="grrGgrrrgrrGgrrr"/>\n <phase duration="%d" state="gGGGgrrrgrrrgrrr"/>\n <phase duration="%d" state="grrrgrrrgGGGgrrr"/>\n <phase duration="%d" state="gGGggrrrgGGggrrr"/>\n <phase duration="%d" state="gyyygrrrgyyygrrr"/>\n <phase duration="%d" state="grrrgrrGgrrrgrrG"/>\n <phase duration="%d" state="grrrgGGGgrrrgrrr"/>\n <phase duration="%d" state="grrrgrrrgrrrgGGG"/>\n <phase duration="%d" state="grrrgGGggrrrgGGg"/>\n <phase duration="%d" state="grrrgyyygrrrgyyy"/>\n' st9=' </tlLogic>\n' tlsy=int(get_conf(cfg,"tls.yellow.time"))#=3 tlslg1=int(get_conf(cfg,"tls.left-green.time-min"))#=5 tlslg2=int(get_conf(cfg,"tls.left-green.time-max"))#=12 tlsg1=int(get_conf(cfg,"tls.straight-green.time-min"))#=25 tlsg2=int(get_conf(cfg,"tls.straight-green.time-max"))#=50 tlsoffset = int(get_conf(cfg,"tls.offset.max"))#90 def run(): wfd = open("net.con.xml",'w') fdet = open("net.det.xml",'w') ftls = open("net.tls.xml",'w') wfd.write(st1) fdet.write(st4) ftls.write(st4) nx = int(get_conf(cfg,"grid.x-number")) ny = int(get_conf(cfg,"grid.y-number"))
lg = Logger() lg.lg_list([__file__]) from_conf = get_conf_int(configfile, "from_conf") from_tasklist = get_conf_int(configfile, "from_tasklist") use_cache = get_conf_int(configfile, "use_cache") if use_cache: try: import memcache # https://www.sinacloud.com/doc/_static/memcache.html except: use_cache = 0 if use_cache: CACHE_SIZE = 100 * 1024 * 1024 * 1024 # 10G CACHE_TIME = 0 cache_place = get_conf(configfile, "cache_place") My_IP = get_my_ip() if iprint: print("cache loc " + cache_place) if cache_place == 'local': cache_prefix = get_conf(configfile, "cache_prefix") mc = memcache.Client(['127.0.0.1:11211'], server_max_value_length=CACHE_SIZE) elif cache_place == 'servers': cache_prefix = get_conf(configfile, "cache_prefix") servers = get_conf(configfile, "cache_servers").split(",") if iprint: print("cache servers", servers) if My_IP.startswith("172.22"): ips = [tarekc2ip[host] + ":11211" for host in servers] else: ips = [host + ":11211" for host in servers] mc = memcache.Client(ips, server_max_value_length=CACHE_SIZE)
import os, sys import subprocess import random, time import inspect mypydir = os.path.abspath( os.path.dirname(inspect.getfile(inspect.currentframe()))) sys.path.append(mypydir + "/mytools") from readconf import get_conf import collections, math from random import randint random.seed(1) iprint = 1 cfg = "conf.txt" nf = get_conf(cfg, "node-files") ef = get_conf(cfg, "edge-files") cf = get_conf(cfg, "connection-files") tpf = get_conf(cfg, "type-files") tlsf = get_conf(cfg, "tllogic-files") netf = get_conf(cfg, "net-file") tripf = get_conf(cfg, "trip-files") rouf = get_conf(cfg, "route-files") bt = get_conf(cfg, "simulationStartTime") et = get_conf(cfg, "simulationEndTime") pt = get_conf(cfg, "trip-depart-period") pfx = get_conf(cfg, "prefix") tripa = get_conf(cfg, "trip-attributes") vtp = get_conf(cfg, "additional-files-vtype") mind = get_conf(cfg, "min-distance")
try: SUMOPATH = str(os.environ.get("SUMO_HOME")) if SUMOPATH.endswith('/'): sys.path.append(os.path.join(SUMOPATH, "tools")) # */sumo/ else: sys.path.append(os.path.join(SUMOPATH + '/', "tools")) # has to end with '/' from sumolib import checkBinary except ImportError: sys.exit("$SUMO_HOME/tools not defined...") import traci from sumo_car import Car from sumo_tls import Tls, get_tls2duration PORT = int(get_conf(configfile, "port")) PRINT_debug = True iprintstep = 1 iprintinfo = 1 iprintverb = 0 # 64 speed, 132 dist, 101 fuel, 80 road id, 122 wait time, 86 lane pos, 66 pos(x,y) VarSpeed = traci.constants.VAR_SPEED VarDist = traci.constants.VAR_DISTANCE VarFuel = traci.constants.VAR_FUELCONSUMPTION VarEdgeId = traci.constants.VAR_ROAD_ID VarWaitTime = traci.constants.VAR_WAITING_TIME VarLaneId = traci.constants.VAR_LANE_ID VarLanePos = traci.constants.VAR_LANEPOSITION VarPosXY = traci.constants.VAR_POSITION
import os, sys import subprocess import random, time import inspect mypydir = os.path.abspath( os.path.dirname(inspect.getfile(inspect.currentframe()))) sys.path.append(mypydir + "/mytools") from readconf import get_conf import collections, math from random import randint random.seed(1) iprint = 1 cfg = "conf.txt" tlsy = int(get_conf(cfg, "tls.yellow.time")) #=3 tlslg1 = int(get_conf(cfg, "tls.left-green.time-min")) #=5 tlslg2 = int(get_conf(cfg, "tls.left-green.time-max")) #=12 tlsg1 = int(get_conf(cfg, "tls.straight-green.time-min")) #=25 tlsg2 = int(get_conf(cfg, "tls.straight-green.time-max")) #=50 tlsoffset = int(get_conf(cfg, "tls.offset.max")) #90 #netconvert --node-files=net.nod.xml --edge-files=net.edg.xml --connection-files=net.con.xml --type-files=net.typ.xml --tllogic-files=net.tls.xml --output-file=net.cnd.tls.net.xml -v --no-turnarounds.tls true nf = get_conf(cfg, "node-files") ef = get_conf(cfg, "edge-files") cf = get_conf(cfg, "connection-files") tpf = get_conf(cfg, "type-files") tlsf = get_conf(cfg, "tllogic-files") of = get_conf(cfg, "net-file")
if 'Mac' in output: findip = subprocess.Popen('ipconfig getifaddr en0'.split(), stdout=subprocess.PIPE) myip = findip.communicate()[0].rstrip() else: findip = subprocess.Popen('hostname -I'.split(), stdout=subprocess.PIPE) myip = findip.communicate()[0].rstrip() if myip == '': myip = monitor.get_ip_addr() ipsufix = myip.split('.')[-1].rstrip() tname = ip2host[myip] print ' coor ip sufix: ' + ipsufix # get conf masterport = readconf.get_conf(et, 'masterport') # rpc usecache = readconf.get_conf(et, 'usecache') usemysql = readconf.get_conf(et, 'usemysql') writefile = readconf.get_conf(et, 'writefile') sampletime = readconf.get_conf(et, 'sampletime') hitratio = readconf.get_conf(et, 'hitratio') newMonitorFile = readconf.get_conf( et, 'newMonitorFile') # if rewrite monitor.log cpuMeasIntv = readconf.get_conf( et, 'cpuMeasIntv') # measure cpu block intv time monitorSampleTime = readconf.get_conf( et, 'monitorSampleTime') # psutil sample t testtime = int(readconf.get_conf(et, 'testtime')) rpctimeout = int(readconf.get_conf(et, 'servertimeout')) skipservicecheck = int(readconf.get_conf(et, 'skipservicecheck')) skipwarmup = int(readconf.get_conf(et, 'skipwarmup'))
import os, sys, getpass, glob import subprocess import random, time import inspect import gzip mypydir = os.path.abspath( os.path.dirname(inspect.getfile(inspect.currentframe()))) addpath = mypydir + "/../mytools" if addpath not in sys.path: sys.path.append(addpath) from readconf import get_conf, get_conf_int, get_conf_float, get_list_startswith, get_dic_startswith from logger import Logger, SimpleAppendLogger, ErrorLogger from util import read_lines_as_list, read_lines_as_dic, read_gzip, strip_illegal_char, strip_newline, unix2datetime, get_file_size_bytes configfile = "conf.txt" DirData = get_conf(configfile, "DirData") DirOSM = get_conf(configfile, "DirOSM") gpsfolder = "gps" obdfolder = "obd" combinefolder = "combine" matchfolder = "match" userFolder = "user" HomeDir = os.path.expanduser("~") iprint = 2 lg = SimpleAppendLogger("../logs/" + __file__, maxsize=10000, overwrite=True) EXT = get_conf(configfile, "EXT") # .gz CUT = get_conf(configfile, "CUT") # ~| EQU = get_conf(configfile, "EQU", delimiter=":") KeyUserEmail = get_conf(configfile, "KeyUserEmail")
output = grep.communicate()[0] if 'Mac' in output: findip = subprocess.Popen('ipconfig getifaddr en0'.split(), stdout=subprocess.PIPE) myip = findip.communicate()[0].rstrip() else: findip = subprocess.Popen('hostname -I'.split(), stdout=subprocess.PIPE) myip = findip.communicate()[0].rstrip() if myip=='': myip=monitor.get_ip_addr() ipsufix=myip.split('.')[-1].rstrip() tname=ip2host[myip] print myip+' is : '+tname+', role: '+nametag # don't sleep before conf done, may rewrite set_params from coor. # RPC port masterport=int(readconf.get_conf(et,'masterport')) # init timeout, serverruntime=int(readconf.get_conf(et,'testtime')) # must recv cmd within sec # rewrite log: newMonitorFile?.cpuMeasIntv 0.5 .monitorSampleTime 5 rewrite=int(readconf.get_conf(et,'newMonitorFile')) sampleIntv=float(readconf.get_conf(et,'monitorSampleTime')) measureIntv=float(readconf.get_conf(et,'cpuMeasIntv')) rqps=int(readconf.get_conf(et,'rqps')) usecache=readconf.get_conf(et,'usecache') usemysql=readconf.get_conf(et,'usemysql') writefile=readconf.get_conf(et,'writefile') sampletime=readconf.get_conf(et,'sampletime') hitratio=readconf.get_conf(et,'hitratio') newMonitorFile=readconf.get_conf(et,'newMonitorFile') # if rewrite monitor.log cpuMeasIntv=readconf.get_conf(et,'cpuMeasIntv') # measure cpu block intv time monitorSampleTime=readconf.get_conf(et,'monitorSampleTime') # sample every 5 second
try: SUMOPATH=str(os.environ.get("SUMO_HOME")) if SUMOPATH.endswith('/'): sys.path.append(os.path.join(SUMOPATH, "tools")) # */sumo/ else: sys.path.append(os.path.join(SUMOPATH+'/', "tools")) # has to end with '/' from sumolib import checkBinary except ImportError: sys.exit("$SUMO_HOME/tools not defined...") import traci from sumo_car import Car from sumo_tls import Tls,get_tls2duration PORT = int(get_conf(configfile,"port")) PRINT_debug = True iprintstep = 1 iprintinfo = 1 iprintverb = 0 # 64 speed, 132 dist, 101 fuel, 80 road id, 122 wait time, 86 lane pos, 66 pos(x,y) VarSpeed = traci.constants.VAR_SPEED VarDist = traci.constants.VAR_DISTANCE VarFuel = traci.constants.VAR_FUELCONSUMPTION VarEdgeId= traci.constants.VAR_ROAD_ID VarWaitTime=traci.constants.VAR_WAITING_TIME VarLaneId = traci.constants.VAR_LANE_ID VarLanePos= traci.constants.VAR_LANEPOSITION VarPosXY = traci.constants.VAR_POSITION
import gzip mypydir = os.path.abspath( os.path.dirname(inspect.getfile(inspect.currentframe()))) addpath = mypydir + "/mytools" if addpath not in sys.path: sys.path.append(addpath) if mypydir not in sys.path: sys.path.append(mypydir) from namehostip import get_my_ip from hostip import ip2tarekc from readconf import get_conf, get_conf_int, get_conf_float from logger import Logger, SimpleAppendLogger from util import read_lines_as_list, read_lines_as_dic, read_gzip, strip_illegal_char, strip_newline, unix2datetime, get_dist_2latlng, get_file_size_bytes, py_fname from mem import Mem, AccessRestrictionContext, Synchronizer, Semaphore ''' after you run 1.py in /4drive to move from upload/ to raw/''' configfile = "conf.txt" DirRaw = get_conf(configfile, "DirRaw") DirData = get_conf(configfile, "DirData") # /proc assert "/raw" in DirRaw assert "/proc" in DirData SubFolders = ["acc", "gps", "gyr", "lin", "mag", "map", "obd", "user"] NeedProc = ["acc", "gps", "gyr", "lin", "mag", "obd"] MustHave = ["acc", "gps", "gyr", "lin", "mag"] # if all had, already done skip. JustCopy = [x for x in SubFolders if x not in NeedProc] iprint = 2 Force_ReExtract_From_Raw = 0 # redo extract part from dirraw to data Overwrite_cutted = 1 # overwrite if cut yielded timestamps lg = SimpleAppendLogger("logs/" + py_fname(__file__, False), maxsize=10000, overwrite=True)
print("my IP= "+MYIP) try: SUMOPATH=str(os.environ.get("SUMO_HOME")) if SUMOPATH.endswith('/'): sys.path.append(os.path.join(SUMOPATH, "tools")) # */sumo/ else: sys.path.append(os.path.join(SUMOPATH+'/', "tools")) # has to end with '/' from sumolib import checkBinary except ImportError: sys.exit("$SUMO_HOME/tools not defined...") random.seed(1) iprint = 1 cfg = "conf.txt" nf=get_conf(cfg,"node-files") ef=get_conf(cfg,"edge-files") cf=get_conf(cfg,"connection-files") tpf=get_conf(cfg,"type-files") tlsf=get_conf(cfg,"tllogic-files") netf=get_conf(cfg,"net-file") tripf=get_conf(cfg,"trip-files") rouf=get_conf(cfg,"route-files") bt=get_conf(cfg,"simulationStartTime") et=get_conf(cfg,"tripEndTime") pt=get_conf(cfg,"trip-depart-period") pfx = get_conf(cfg,"prefix") tripa = get_conf(cfg,"trip-attributes") vtp = get_conf(cfg,"additional-files-vtype") mind = get_conf(cfg,"min-distance")
import os, sys import subprocess import random,time import inspect mypydir =os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe()))) sys.path.append(mypydir+"/mytools") from readconf import get_conf import collections,math from random import randint random.seed(1) iprint = 1 cfg = "conf.txt" tlsy=int(get_conf(cfg,"tls.yellow.time"))#=3 tlslg1=int(get_conf(cfg,"tls.left-green.time-min"))#=5 tlslg2=int(get_conf(cfg,"tls.left-green.time-max"))#=12 tlsg1=int(get_conf(cfg,"tls.straight-green.time-min"))#=25 tlsg2=int(get_conf(cfg,"tls.straight-green.time-max"))#=50 tlsoffset = int(get_conf(cfg,"tls.offset.max"))#90 #netconvert --node-files=net.nod.xml --edge-files=net.edg.xml --connection-files=net.con.xml --type-files=net.typ.xml --tllogic-files=net.tls.xml --output-file=net.cnd.tls.net.xml -v --no-turnarounds.tls true nf=get_conf(cfg,"node-files") ef=get_conf(cfg,"edge-files") cf=get_conf(cfg,"connection-files") tpf=get_conf(cfg,"type-files") tlsf=get_conf(cfg,"tllogic-files") of=get_conf(cfg,"net-file") def gen_net():