Skip to content

Commit

Permalink
Merge pull request #6 from sdrewc/master
Browse files Browse the repository at this point in the history
Looks good, @sdrewc !
  • Loading branch information
e-lo committed Feb 12, 2015
2 parents 5f9c8a5 + ae80d8f commit 6575880
Show file tree
Hide file tree
Showing 29 changed files with 2,962 additions and 108 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
205 changes: 155 additions & 50 deletions Network.py → Wrangler/Network.py

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 20 additions & 18 deletions PlanSpecs.py → Wrangler/PlanSpecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ class PlanSpecs:
""" Simple class to read in the plan specifications from a CSV file.
"""

def __init__(self,basedir,networkdir,plansubdir,projectsubdir=None,tag=None,tempdir=None, **kwargs):
def __init__(self,champVersion,basedir,networkdir,plansubdir,projectsubdir=None,tag=None,tempdir=None, **kwargs):
"""
Read specs file, check out projects and check the network type and project year
"""
self.projects = [] # list of projects included in the plan
self.projectdict = {} # plan name => dictionary of attributes
self.network = Network(champVersion="4.3",
networkBaseDir=basedir,
networkPlanSubdir=plansubdir,
networkProjectSubdir=projectsubdir)
self.projects = [] # list of projects included in the plan
self.projectdict = {} # plan name => dictionary of attributes
#network is necessary to check out projects
self.network = Network(champVersion=champVersion,
networkBaseDir=basedir,
networkPlanSubdir=plansubdir,
networkProjectSubdir=projectsubdir)
self.plan_tag = None
self.override = []

specs = open(os.path.join(basedir,plansubdir,networkdir,'planSpecs.csv'),'r')
specs = open(os.path.join(tempdir,plansubdir,networkdir,'planSpecs.csv'),'r')
i=0
for line in specs:
i+=1
if i==1:
header=line.strip().split(',')
else:
l = line.strip().split(',')
#print l

project_name = l[header.index("projectname")]
projType = l[header.index("type")]
self.projectdict[project_name] = {}
Expand All @@ -35,18 +38,19 @@ def __init__(self,basedir,networkdir,plansubdir,projectsubdir=None,tag=None,temp
self.projectdict[project_name]["projtype"]=projType
if kwargs:
self.projectdict[project_name]["kwargs"]=kwargs
else:
print "kwargs not coming through.", kwargs
assert(1==2)

if 'plan_tag' in kwargs.keys():
plan_tag = kwargs['plan_tag']
if 'override' in kwargs.keys():
override = kwargs['override']

# if project = "dir1/dir2" assume dir1 is git, dir2 is the projectsubdir
(head,tail) = os.path.split(os.path.join(networkdir,project_name))
(head,tail) = os.path.split(project_name)
if head:
applied_SHA1 = self.network.cloneAndApplyProject(networkdir=head, projectsubdir=tail, tag=tag,
applied_SHA1 = self.network.cloneProject(networkdir=head, projectsubdir=tail, tag=tag,
projtype=projType, tempdir=tempdir)
self.projectdict[project_name]["nettypes"]=self.network.getNetTypes(tempdir,head,tail)
else:
applied_SHA1 = self.network.cloneAndApplyProject(networkdir=project_name, tag=tag,
applied_SHA1 = self.network.cloneProject(networkdir=project_name, tag=tag,
projtype=projType, tempdir=tempdir)
self.projectdict[project_name]["nettypes"]=self.network.getNetTypes(tempdir,project_name)

Expand All @@ -68,8 +72,6 @@ def listOfProjects(self,netType='hwy'):

for proj in self.projects:
if netType in self.projectdict[proj]['nettypes']:
print "proj: ", proj
print "projAsDict: ", self.projectAsDict(proj)
projectlist.append(self.projectAsDict(proj))
return projectlist

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions Wrangler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from .Linki import Linki
from .Network import Network
from .NetworkException import NetworkException
from .PNRLink import PNRLink
from .Supplink import Supplink
from .TransitAssignmentData import TransitAssignmentData ##
from .TransitCapacity import TransitCapacity
from .TransitLine import TransitLine
from .TransitLink import TransitLink
from .TransitNetwork import TransitNetwork
from .TransitParser import TransitParser
from .HighwayNetwork import HighwayNetwork
from .Logger import setupLogging, WranglerLogger
from .Node import Node
from .HwySpecsRTP import HwySpecsRTP


__all__ = ['NetworkException', 'setupLogging', 'WranglerLogger',
'Network', 'TransitAssignmentData', 'TransitNetwork', 'TransitLine', 'TransitParser',
'Node', 'TransitLink', 'Linki', 'PNRLink', 'Supplink', 'HighwayNetwork', 'HwySpecsRTP',
'TransitCapacity',
]


if __name__ == '__main__':

LOG_FILENAME = "Wrangler_main_%s.info.LOG" % time.strftime("%Y%b%d.%H%M%S")
setupLogging(LOG_FILENAME, LOG_FILENAME.replace("info", "debug"))

net = Network()
net.cloneAndApplyProject(projectname="Muni_TEP")
net.cloneAndApplyProject(projectname="Muni_CentralSubway", tag="1-latest", modelyear=2030)
net.cloneAndApplyProject(projectname="BART_eBART")

net.write(name="muni", writeEmptyFiles=False)
43 changes: 3 additions & 40 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
import sys
from .Linki import Linki
from .Network import Network
from .NetworkException import NetworkException
from .PNRLink import PNRLink
from .Supplink import Supplink
try:
from .TransitAssignmentData import TransitAssignmentData
except:
print "Unexpected error:", sys.exc_info()
from .transitAssignmentData import TransitAssignmentData
from .TransitCapacity import TransitCapacity
from .TransitLine import TransitLine
from .TransitLink import TransitLink
from .TransitNetwork import TransitNetwork
from .TransitParser import TransitParser
from .HighwayNetwork import HighwayNetwork
from .Logger import setupLogging, WranglerLogger
from .Node import Node
from .HwySpecsRTP import HwySpecsRTP


__all__ = ['NetworkException', 'setupLogging', 'WranglerLogger',
'Network', 'TransitAssignmentData', 'TransitNetwork', 'TransitLine', 'TransitParser',
'Node', 'TransitLink', 'Linki', 'PNRLink', 'Supplink', 'HighwayNetwork', 'HwySpecsRTP',
'TransitCapacity',
]


if __name__ == '__main__':

LOG_FILENAME = "Wrangler_main_%s.info.LOG" % time.strftime("%Y%b%d.%H%M%S")
setupLogging(LOG_FILENAME, LOG_FILENAME.replace("info", "debug"))

net = Network()
net.cloneAndApplyProject(projectname="Muni_TEP")
net.cloneAndApplyProject(projectname="Muni_CentralSubway", tag="1-latest", modelyear=2030)
net.cloneAndApplyProject(projectname="BART_eBART")

net.write(name="muni", writeEmptyFiles=False)
__all__ = ["Wrangler"]
__version__ = 2.0
version = __version__
174 changes: 174 additions & 0 deletions _static/Cube/CubeNet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# -*- coding: utf-8 -*-
"""
This is based on scripts/walkSkims/gothroughme/cube/cubeNet.py
But I left the original in place because of the dependency on the network object, which I didn't want
to bring in here (as the functionality we want is more simplistic).
-Lisa 2012.03.12
"""
import copy, os
from socket import gethostname

CUBE_COMPUTER = "vanness"

def getCubeHostnames():
"""
Cube hostnames in Y:\COMMPATH\HostnamesWithCube.txt
"""
hostnames = []
f = open(r"Y:\COMMPATH\HostnamesWithCube.txt")
for line in f:
if line[0] == "#": continue
hostnames.append(line.split()[0]) # use the first token of non-comment lines
f.close()
return hostnames

def export_cubenet_to_csvs(file, extra_link_vars=[], extra_node_vars=[],
links_csv=None, nodes_csv=None):
"""
Export cube network to csv files
If *links_csv* and *nodes_csv* filenames passed, will use those.
Otherwise, will output into %TEMP%\link.csv and %TEMP%\node.csv
options:
extra_link_vars, extra_node_vars: list extra variables to export
"""
import subprocess
script = os.path.join(os.path.dirname(os.path.abspath(__file__)),"exportHwyfromPy.s")

#set environment variables
env = copy.copy(os.environ)

env['CUBENET']=file
env['PATH'] = os.environ['PATH'] # inherit this

if links_csv:
env["CUBELINK_CSV"] = links_csv
else:
env["CUBELINK_CSV"] = os.path.join(os.environ["TEMP"], "link.csv")
if nodes_csv:
env["CUBENODE_CSV"] = nodes_csv
else:
env["CUBENODE_CSV"] = os.path.join(os.environ["TEMP"], "node.csv")

if len(extra_link_vars)>0:
extra_vars_str=","
extra_vars_str+=extra_vars_str.join(extra_link_vars)
env['XTRALINKVAR']=extra_vars_str
else:
env['XTRALINKVAR']=''

if len(extra_node_vars)>0:
extra_vars_str=","
extra_vars_str+=extra_vars_str.join(extra_node_vars)
env['XTRANODEVAR']=extra_vars_str
else:
env['XTRANODEVAR']=' '

#run it on CUBE_COMPUTER; cube is installed there
filedir = os.path.dirname(os.path.abspath(file))
hostname = gethostname().lower()
if hostname not in getCubeHostnames():
if links_csv == None or nodes_csv == None:
print "export_cubenet_to_csvs requires a links_csv and nodes_csv output file if dispatching to %s (temp won't work)" % CUBE_COMPUTER
sys.exit(2)

env["MACHINES"] = CUBE_COMPUTER

cmd = r'y:\champ\util\bin\dispatch-one.bat "runtpp ' + script + '"'
print cmd
proc = subprocess.Popen( cmd, cwd = filedir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
for line in proc.stdout:
line = line.strip('\r\n')
print "stdout: " + line
else:
cmd = 'runtpp.exe ' + script
print cmd
print filedir

proc = subprocess.Popen( cmd, cwd = filedir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
for line in proc.stdout:
line = line.strip('\r\n')
print "stdout: " + line


print "EXPORTING CUBE NETWORK: ",env['CUBENET']
print "...adding variables %s, %s:" % (env['XTRALINKVAR'], env['XTRANODEVAR'])
print "...running script: \n %s" % (script)



retStderr = []
for line in proc.stderr:
line = line.strip('\r\n')
print "stderr: " + line
retcode = proc.wait()
if retcode != 0: raise


print "Received %d from [%s]" % (retcode, cmd)
print "Exported network to: %s, %s" % (env["CUBELINK_CSV"], env["CUBENODE_CSV"])


def import_cube_nodes_links_from_csvs(cubeNetFile,
extra_link_vars=[], extra_node_vars=[],
links_csv=None, nodes_csv=None,
exportIfExists=True):
"""
Imports cube network from network file and returns (nodes_dict, links_dict).
Nodes_dict maps node numbers to [X, Y, vars given by *extra_node_vars*]
Links_dict maps (a,b) to [DISTANCE, STREETNAME, *extra_link_vars*]
"""

if not links_csv:
links_csv=os.path.join(os.environ['TEMP'],"node.csv")
if not nodes_csv:
nodes_csv=os.path.join(os.environ['TEMP'],"link.csv")

# don't export if
if (not exportIfExists and links_csv and nodes_csv and
os.path.exists(links_csv) and os.path.exists(nodes_csv)):
pass # don't need to do anything
else:
export_cubenet_to_csvs(cubeNetFile,extra_link_vars, extra_node_vars, links_csv=links_csv, nodes_csv=nodes_csv)


# Open node file and read nodes
nodes_dict = {}
F=open(nodes_csv,mode='r')
for rec in F:
r=rec.strip().split(',')
n=int(r[0])
x=float(r[1])
y=float(r[2])
node_array = [x,y]
node_array.extend(r[3:])

nodes_dict[n] = node_array
F.close()

# Open link file and read links
links_dict = {}
F=open(links_csv,mode='r')
for rec in F:
r=rec.strip().split(',')

#add standard fields
a=int(r[0])
b=int(r[1])
dist=float(r[2])
streetname=str(r[3])

#add additional fields
link_array = [dist, streetname]
link_array.extend(r[4:])

links_dict[(a,b)] = link_array
F.close()

return (nodes_dict, links_dict)


10 changes: 10 additions & 0 deletions _static/Cube/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 22 12:05:51 2010
@author: Elizabeth
"""

from .CubeNet import export_cubenet_to_csvs, import_cube_nodes_links_from_csvs

__all__ = ['export_cubenet_to_csvs', 'import_cube_nodes_links_from_csvs']
7 changes: 7 additions & 0 deletions _static/Cube/exportHwyFromPy.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RUN PGM=NETWORK

NETI[1]="%CUBENET%"
LINKO="%CUBELINK_CSV%",FORMAT=SDF,INCLUDE=A,B,DISTANCE,STREETNAME %XTRALINKVAR%
NODEO="%CUBENODE_CSV%",FORMAT=SDF,INCLUDE=N,X,Y %XTRANODEVAR%

ENDRUN
Loading

0 comments on commit 6575880

Please sign in to comment.