rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
cnv_ls = [[1, (2323,2600)], [2,(50000,)], [3,(43214,78788)], [5, (43242,)], [5,(144,566)], [5,(150,500)], [5,(500,950)], [5, (43241, 43242)]]
cnv_ls = [[1, (2323,2600)], [2,(50000,)], [3,(43214,78788)], [5,(150,500)], [5,(500,950)], [5, (43241, 43242)]]
def getCNVDataFromFileInGWA(input_fname_ls, array_id, max_amp=-0.33, min_amp=-0.33, min_size=50, min_no_of_probes=None, report=False): """ 2009-10-31 get deletion (below max_amp) or duplication (above min_amp) from files (output by RunGADA.py) """ sys.stderr.write("Getting CNV calls for array %s, min_size %s, min_no_of...
print "==", segmentKey1==segmentKey2
print "==", segmentKey1==segmentKey2 """
def getCNVDataFromFileInGWA(input_fname_ls, array_id, max_amp=-0.33, min_amp=-0.33, min_size=50, min_no_of_probes=None, report=False): """ 2009-10-31 get deletion (below max_amp) or duplication (above min_amp) from files (output by RunGADA.py) """ sys.stderr.write("Getting CNV calls for array %s, min_size %s, min_no_of...
@classmethod
def __init__(self, **keywords): """ 2008-11-10 upgrade option handling to ProcessOptions 2008-4-2 2008-02-28 argument_default_dict is a dictionary of default arguments, the key is a tuple, ('argument_name', is_argument_required, argument_type) argument_type is optional """ #argument dictionary #self.ad = process_funct...
get_phenotype_method_id_info = classmethod(get_phenotype_method_id_info)
@classmethod
def get_phenotype_method_id_info(cls, curs, phenotype_avg_table, phenotype_method_table ): """ 2009-2-2 curs could be either MySQLdb cursor or elixirdb.metadata.bind. do two selects in one 2008-4-2 """ sys.stderr.write("Getting phenotype_method_id info ... " ) phenotype_method_id2index = {} #index of the matrix method...
get_ecotype_id2info = classmethod(get_ecotype_id2info)
@classmethod
def get_ecotype_id2info(cls, curs, phenotype_avg_table, ecotype_table): """ 2009-2-2 curs could be either MySQLdb cursor or elixirdb.metadata.bind. do two selects in one 2008-4-2 """ sys.stderr.write("Getting ecotype id info ... " ) ecotype_id2index = {} #index of the matrix ecotype_id_ls = [] ecotype_name_ls = [] row...
get_matrix = classmethod(get_matrix)
@classmethod
def get_matrix(cls, curs, phenotype_avg_table, ecotype_id2index, phenotype_info, get_raw_data=0, \ phenotype_method_table='phenotype_method'): """ 2009-9-2 if value>-5e-7 and value<+5e-7: #beyond float resolution by a python float value = 0 without condition above, values like -5.32907e-15 would be taken as -5.32907e,...
getPhenotypeData = classmethod(getPhenotypeData)
def getPhenotypeData(cls, curs, phenotype_avg_table=None, phenotype_method_table=None, ecotype_table='stock.ecotype', get_raw_data=1): """ 2009-2-2 wrap up all other 3 methods """ phenotype_info = cls.get_phenotype_method_id_info(curs, phenotype_avg_table, phenotype_method_table) ecotype_id2index, ecotype_id_ls, ecotyp...
write_data_matrix(pheno_data.data_matrix, self.output_fname, header, pheno_data.row_id_ls, pheno_data.row_label_ls)
write_data_matrix(pheno_data.data_matrix, self.output_fname, header, pheno_data.row_id_ls, pheno_data.row_label_ls, \ transform_to_numpy=False)
def run(self): import MySQLdb conn = MySQLdb.connect(db=self.dbname, host=self.hostname, user = self.db_user, passwd = self.db_passwd) curs = conn.cursor() pheno_data = self.getPhenotypeData(curs, self.phenotype_avg_table, self.phenotype_method_table, \ self.ecotype_table, get_raw_data=self.get_raw_data) header = ['e...
def output(self, data_matrix, probe_id_ls, chr_pos_ls, header, output_fname_prefix, split_genome_into_chromosomes=False): """
@classmethod def output(cls, data_matrix, probe_id_ls, chr_pos_ls, header, output_fname_prefix, split_genome_into_chromosomes=False): """ 2010-2-10 becomes classmethod
def output(self, data_matrix, probe_id_ls, chr_pos_ls, header, output_fname_prefix, split_genome_into_chromosomes=False): """ 2009-10-11 add argument split_genome_into_chromosomes 2009-5-18 split output into different chromosomes """ sys.stderr.write("Outputting ...") no_of_rows, no_of_cols = data_matrix.shape old_chr ...
return redirect_to("/css/main.css")
response.headers['content-type'] = 'text/css; charset=utf-8' return render("/css/main.css")
def index(self): return redirect_to("/css/main.css")
self.url = ozutil.check_url(self.url)
self.url = ozutil.check_url(idl.url())
def __init__(self, idl, config): update = idl.update() if idl.arch() != "i386": raise Exception, "Invalid arch " + arch + "for RHEL-2.1 guest" self.ks_file = ozutil.generate_full_auto_path("rhel-2.1-jeos.ks")
self.log.info("%dkB of %dkB" % (down_current/1024, down_total/1024))
if down_total == 0: return current_mb = int(down_current) / 10485760 if current_mb > self.last_mb or down_current == down_total: self.last_mb = current_mb self.log.debug("%dkB of %dkB" % (down_current/1024, down_total/1024))
def progress(down_total, down_current, up_total, up_current): # FIXME: we should probably not print every single time this is # called; maybe every 1MB or so? self.log.info("%dkB of %dkB" % (down_current/1024, down_total/1024))
initrdline += self.url + "\n"
initrdline += " repo=" + self.url + "\n"
def modify_iso(self): self.log.debug("Putting the kickstart in place")
interfaceModel.setProp("type", "virtio")
interfaceModel.setProp("type", self.nicmodel)
def generate_define_xml(self, bootdev, want_install_disk=True): self.log.info("Generate/define XML for guest %s with bootdev %s" % (self.name, bootdev))
self.url = ozutil.check_url(self.url)
self.url = ozutil.check_url(idl.url())
def __init__(self, idl, config): update = idl.update() arch = idl.arch() self.ks_file = ozutil.generate_full_auto_path("rhel-3-jeos.ks")
disks = input_doc.xpathEval('/domain/devices/disk/source')
disks = input_doc.xpathEval('/domain/devices/disk')
def guestfs_handle_setup(self, libvirt_xml): input_doc = libxml2.parseMemory(libvirt_xml, len(libvirt_xml)) namenode = input_doc.xpathEval('/domain/name') if len(namenode) != 1: raise Exception, "invalid libvirt XML with no name" input_name = namenode[0].getContent() disks = input_doc.xpathEval('/domain/devices/disk/so...
input_disk = disks[0].prop('file')
source = disks[0].xpathEval('source') if len(source) != 1: raise Exception, "invalid <disk> entry without a source" input_disk = source[0].prop('file') driver = disks[0].xpathEval('driver') if len(driver) == 0: input_disk_type = 'raw' elif len(driver) != 1: input_disk_type = driver[0].prop('type') else: raise Exception...
def guestfs_handle_setup(self, libvirt_xml): input_doc = libxml2.parseMemory(libvirt_xml, len(libvirt_xml)) namenode = input_doc.xpathEval('/domain/name') if len(namenode) != 1: raise Exception, "invalid libvirt XML with no name" input_name = namenode[0].getContent() disks = input_doc.xpathEval('/domain/devices/disk/so...
g.add_drive(input_disk)
g.add_drive_opts(input_disk, format=input_disk_type)
def guestfs_handle_setup(self, libvirt_xml): input_doc = libxml2.parseMemory(libvirt_xml, len(libvirt_xml)) namenode = input_doc.xpathEval('/domain/name') if len(namenode) != 1: raise Exception, "invalid libvirt XML with no name" input_name = namenode[0].getContent() disks = input_doc.xpathEval('/domain/devices/disk/so...
os = g.inspect_os()
roots = g.inspect_os() if len(roots) == 0: raise Exception, "No operating systems found on the disk"
def guestfs_handle_setup(self, libvirt_xml): input_doc = libxml2.parseMemory(libvirt_xml, len(libvirt_xml)) namenode = input_doc.xpathEval('/domain/name') if len(namenode) != 1: raise Exception, "invalid libvirt XML with no name" input_name = namenode[0].getContent() disks = input_doc.xpathEval('/domain/devices/disk/so...
mountpoints = g.inspect_get_mountpoints(os[0]) self.log.debug("Mounting /") for point in mountpoints: if point[0] == '/': g.mount(point[1], '/') break self.log.debug("Mount other filesystems") for point in mountpoints: if point[0] != '/': g.mount(point[1], point[0])
for root in roots: self.log.debug("Root device: %s" % root) mps = g.inspect_get_mountpoints(root) def compare(a, b): if len(a[0]) > len(b[0]): return 1 elif len(a[0]) == len(b[0]): return 0 else: return -1 mps.sort(compare) for mp_dev in mps: g.mount_options('', mp_dev[1], mp_dev[0])
def guestfs_handle_setup(self, libvirt_xml): input_doc = libxml2.parseMemory(libvirt_xml, len(libvirt_xml)) namenode = input_doc.xpathEval('/domain/name') if len(namenode) != 1: raise Exception, "invalid libvirt XML with no name" input_name = namenode[0].getContent() disks = input_doc.xpathEval('/domain/devices/disk/so...
tarout = self.iso_contents + "/data.tar"
def copy_iso(self): self.log.info("Copying ISO contents for modification") if os.access(self.iso_contents, os.F_OK): shutil.rmtree(self.iso_contents) os.makedirs(self.iso_contents)
gfs.add_drive(self.orig_iso)
gfs.add_drive_opts(self.orig_iso, readonly=1, format='raw')
def copy_iso(self): self.log.info("Copying ISO contents for modification") if os.access(self.iso_contents, os.F_OK): shutil.rmtree(self.iso_contents) os.makedirs(self.iso_contents)
gfs.mount("/dev/sda", "/") self.log.debug("Getting data from ISO onto %s" % (tarout)) gfs.tar_out("/", tarout) self.log.debug("Cleaning up guestfs process")
gfs.mount_options('ro', "/dev/sda", "/") rd,wr = os.pipe() current = os.getcwd() os.chdir(self.iso_contents) tar = subprocess.Popen(["tar", "-x", "-v"], stdin=rd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.log.debug("Extracting ISO contents:") gfs.tar_out("/", "/dev/fd/%d" % wr) self.log.debug("%s" % t...
def copy_iso(self): self.log.info("Copying ISO contents for modification") if os.access(self.iso_contents, os.F_OK): shutil.rmtree(self.iso_contents) os.makedirs(self.iso_contents)
self.log.debug("Extracting tarball") tar = tarfile.open(tarout) tar.extractall(path=self.iso_contents) self.log.debug("Removing tarball") os.unlink(tarout)
def copy_iso(self): self.log.info("Copying ISO contents for modification") if os.access(self.iso_contents, os.F_OK): shutil.rmtree(self.iso_contents) os.makedirs(self.iso_contents)
def __init__(self, idl, config, nicmodel, haverepo, diskbus):
def __init__(self, idl, config, nicmodel, haverepo, diskbus, brokenisomethod):
def __init__(self, idl, config, nicmodel, haverepo, diskbus): update = idl.update() arch = idl.arch() self.ks_file = ozutil.generate_full_auto_path("fedora-" + update + "-jeos.ks") self.haverepo = haverepo self.installtype = idl.installtype()
eltoritodata = cdfile.read(count*2048)
eltoritodata = cdfile.read(count*512)
def checksum(data): s = 0 for i in range(0, len(data), 2): w = ord(data[i]) + (ord(data[i+1]) << 8) s = numpy.uint16(numpy.uint16(s) + numpy.uint16(w)) return s
initrdline = " append initrd=initrd.img ks=cdrom:/ks.cfg method="
initrdline = " append initrd=initrd.img ks=cdrom:/ks.cfg"
def modify_iso(self): self.log.debug("Putting the kickstart in place")
initrdline += "cdrom:/dev/cdrom\n"
initrdline += "\n"
def modify_iso(self): self.log.debug("Putting the kickstart in place")
if self.haverepo: initrdline += " repo=" else: initrdline += " method="
def modify_iso(self): self.log.debug("Putting the kickstart in place")
packages = cdl.newChild(None, "packages", None)
def output_cdl_xml(self, lines, services): doc = libxml2.newDoc("1.0") cdl = doc.newChild(None, "cdl", None) packages = cdl.newChild(None, "packages", None)
packages.newChild(None, "package", None) packages.setProp("name", line)
package = packages.newChild(None, "package", None) package.setProp("name", line)
def output_cdl_xml(self, lines, services): doc = libxml2.newDoc("1.0") cdl = doc.newChild(None, "cdl", None) packages = cdl.newChild(None, "packages", None)
self.log.debug("Name: %s, UUID: %s, MAC: %s, distro: %s" % (self.name, self.uuid, self.macaddr, self.distro))
self.log.debug("Name: %s, UUID: %s" % (self.name, self.uuid)) self.log.debug("MAC: %s, distro: %s" % (self.macaddr, self.distro))
def __init__(self, distro, update, arch, nicmodel, clockoffset, mousetype, diskbus, config): if arch != "i386" and arch != "x86_64": raise Exception, "Unsupported guest arch " + arch self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__)) self.uuid = uuid.uuid4() mac = [0x52, 0x54, 0x00, random.rand...
"-o", output, inputdir])
"-o", self.output_iso, self.iso_contents])
def generate_new_iso(self): self.log.info("Generating new ISO") Guest.subprocess_check_output(["mkisofs", "-r", "-V", "Custom", "-cache-inodes", "-J", "-l", "-b", "isolinux/isolinux.bin", "-c", "isolinux/boot.cat", "-no-emul-boot", "-boot-load-size", "4", "-boot-info-table", "-v", "-v", "-o", output, inputdir])
def targetDev(self, doc, type, path, bus):
def targetDev(self, doc, devicetype, path, bus):
def targetDev(self, doc, type, path, bus): installNode = doc.createElement("disk") installNode.setAttribute("type", "file") installNode.setAttribute("device", type) sourceInstallNode = doc.createElement("source") sourceInstallNode.setAttribute("file", path) installNode.appendChild(sourceInstallNode) targetInstallNode =...
installNode.setAttribute("device", type)
installNode.setAttribute("device", devicetype)
def targetDev(self, doc, type, path, bus): installNode = doc.createElement("disk") installNode.setAttribute("type", "file") installNode.setAttribute("device", type) sourceInstallNode = doc.createElement("source") sourceInstallNode.setAttribute("file", path) installNode.appendChild(sourceInstallNode) targetInstallNode =...
dl.ReplyToThread(game.threadId, ":redhammer: " + (msg % name))
dl.ReplyToThread(game.threadId, ":redhammer: " + (message % name))
def PostLynchedMessage(self, game, name): if not game.post_lynches: return
current_day = models.IntegerField() living_count = models.IntegerField() players_count = models.IntegerField()
current_day = models.IntegerField(default=1) living_count = models.IntegerField(default=0) players_count = models.IntegerField(default=0)
def twitter_in_bg(msg): consumer_key = "r11W5M2m2tdNtcknWSjNKw" consumer_secret = "zSd0vCV2mTcWVyKfAKiIcm6gdzozLEVMjXXpT51XV3c" oauth_token = "166303978-z0Dp7pAoKrgs2ZjN7rCmwVmd9zum4LaUNjH5fzhJ" oauth_token_secret = "YK7cOAF7HcSbvn43EPGBgSXyQ5RWIaruYAfTz3lNpwE" twitter = OAuthApi(consumer_key, consumer_secret, oauth_t...
inputs['disablesmilies'] = 'no'
del inputs['disablesmilies']
def ReplyToThread(self, thread, message): getUrl = "http://forums.somethingawful.com/newreply.php?action=newreply&threadid=%s" % thread postUrl = "http://forums.somethingawful.com/newreply.php?action=newreply"
a.disconnect() a.connect("localhost", 6000, sys.argv[1])
def think(self): """ Performs a single step of thinking for our agent. Gets called on every iteration of our think loop. """
def __init__(self, world_model):
def __init__(self, world_model, body_model):
def __init__(self, world_model): self.world_model = world_model
msg = "(kick %.10f %.10f)"
msg = "(kick %.10f %.10f)" % (power, relative_direction)
def kick(self, power, relative_direction): """ Accelerates the ball with the given power in the given direction, relative to the current direction of the player's body. """
setattr(self, item, lambda *args: bork())
setattr(self, item, lambda *args: destroyed_method())
def destroyed_method(): """ Raises an error, no matter the arguments given. """ m = ("Agent has been disconnected and no longer supports " "any method calls.") raise NotImplementedError(m)
super.__init__(self, distance, direction)
GameObject.__init__(self, distance, direction)
def __init__(self, distance, direction, position): """ Field objects have a position in addition to GameObject's members. """
super.__init__(self, distance, direction)
GameObject.__init__(self, distance, direction)
def __init__(self, distance, direction, line_id): self.line_id = line_id super.__init__(self, distance, direction)
super.__init__(self, distance, direction, position)
FieldObject.__init__(self, distance, direction, position)
def __init__(self, distance, direction, position, dist_change, dir_change, speed): """ Adds variables for velocity vector deltas. """
super.__init__(self, distance, direction, position)
FieldObject.__init__(self, distance, direction, position)
def __init__(self, distance, direction, position):
super.__init__(self, distance, direction, position, dist_change,
MobileObject.__init__(self, distance, direction, position, dist_change,
def __init__(self, distance, direction, position, dist_change, dir_change, speed): super.__init__(self, distance, direction, position, dist_change, dir_change, speed)
super.__init__(self, distance, direction, position, dist_change,
MobileObject.__init__(self, distance, direction, position, dist_change,
def __init__(self, distance, direction, position, dist_change, dir_change, speed, team, side, uniform_number, body_direction, face_direction, neck_direction): """ Adds player-specific information to a mobile object. """
super.__init__(self, distance, direction, position)
StationaryObject.__init__(self, distance, direction, position)
def __init__(self, distance, direction, position, marker_id): """ Adds a marker id for this field object. Every marker has a unique id. """
for agent in xrange(max(11, int(sys.argv[2]))):
for agent in xrange(min(11, int(sys.argv[2]))):
def think(self): """ Performs a single step of thinking for our agent. Gets called on every iteration of our think loop. """
m = "Server returned an error: '%s'" % msg[1:]
m = "Server returned an error: '%s'" % msg[1]
def _handle_error(self, msg): """ Deals with error messages by raising them as exceptions. """
self.msg_handler = handler.MessageHandler(self.world)
self.msg_handler = handler.MessageHandler(self.world, self.body)
def __init__(self, host, port, teamname, version=11): """ Gives us a connection to the server as one player on a team. This immediately connects the agent to the server and starts receiving and parsing the information it sends. """
self.act_handler.move(1000, 1000)
if not self.moved: self.act_handler.move(1000, 1000) self.moved = True if self.world.ball is not None: if self.world.ball.distance <= 1: self.act_handler.kick(100, random.randint(0, 181) - 180) return elif -5 < self.world.ball.direction < 5: self.act_handler.dash(100) return else: self.act_handler.turn(self.world.b...
def think(self): """ Performs a single step of thinking for our agent. Gets called on every iteration of our think loop. """
parse_message(line.strip())
parse(line.strip())
def stringify(itemlist): """ Takes a list generated by parsing a message and condenses the characters it contains into strings, seperating them by spaces and leaving them alongside the lists therin. """ result = [] s = "" for item in itemlist: if item == " ": if s != "": result.append(s) s = "" elif type(item) is typ...
for i, (vertex1_label, vertex2_label, edge ) in enumerate( edges_from_osmdb( osmdb, vertices_namespace, slogs, profiledb ) ):
for i, (vertex1_label, vertex2_label, edge ) in enumerate( edges_from_osmdb( osmdb, vertex_namespace, slogs, profiledb ) ):
def gdb_import_osm(gdb, osmdb, vertex_namespace, slogs, profiledb=None): cursor = gdb.get_cursor() n_edges = osmdb.count_edges() # for each edge in the osmdb for i, (vertex1_label, vertex2_label, edge ) in enumerate( edges_from_osmdb( osmdb, vertices_namespace, slogs, profiledb ) ): if i%(n_edges//100+1)==0: sys.std...
c = gdb.get_cursor()
def gdb_load_gtfsdb(gdb, agency_namespace, gtfsdb, cursor, agency_id=None, maxtrips=None, sample_date=None, reporter=sys.stdout): # determine which service periods run on the given day, if a day is given if sample_date is not None: sample_date = datetime.date( *parse_gtfs_date( sample_date ) ) acceptable_service_ids =...
gdb.add_vertex( fromv_label, c )
gdb.add_vertex( fromv_label, cursor )
def gdb_load_gtfsdb(gdb, agency_namespace, gtfsdb, cursor, agency_id=None, maxtrips=None, sample_date=None, reporter=sys.stdout): # determine which service periods run on the given day, if a day is given if sample_date is not None: sample_date = datetime.date( *parse_gtfs_date( sample_date ) ) acceptable_service_ids =...
gdb.add_vertex( tov_label, c )
gdb.add_vertex( tov_label, cursor )
def gdb_load_gtfsdb(gdb, agency_namespace, gtfsdb, cursor, agency_id=None, maxtrips=None, sample_date=None, reporter=sys.stdout): # determine which service periods run on the given day, if a day is given if sample_date is not None: sample_date = datetime.date( *parse_gtfs_date( sample_date ) ) acceptable_service_ids =...
gdb.add_edge( fromv_label, tov_label, edge, c ) gdb.commit()
gdb.add_edge( fromv_label, tov_label, edge, cursor )
def gdb_load_gtfsdb(gdb, agency_namespace, gtfsdb, cursor, agency_id=None, maxtrips=None, sample_date=None, reporter=sys.stdout): # determine which service periods run on the given day, if a day is given if sample_date is not None: sample_date = datetime.date( *parse_gtfs_date( sample_date ) ) acceptable_service_ids =...
if reporter and i%(n//100)==0: reporter.write( "%d/%d vertices dumped\n"%(i,n) )
if reporter and i%(nseg//100)==0: reporter.write( "%d/%d vertices dumped\n"%(i,n) )
def populate(self, graph, reporter=None): c = self.conn.cursor() n = len(graph.vertices) for i, vv in enumerate( graph.vertices ): if reporter and i%(n//100)==0: reporter.write( "%d/%d vertices dumped\n"%(i,n) ) c.execute( "INSERT INTO vertices VALUES (?)", (vv.label,) ) for ee in vv.outgoing: c.execute( "INSERT INTO...
id = self.index.nearest( (lon, lat), 1 )[0]
id = list(self.index.nearest( (lon, lat), 1 ))[0]
def nearest_node(self, lat, lon, range=0.005): c = self.get_cursor() if self.index: #print "YOUR'RE USING THE INDEX" id = self.index.nearest( (lon, lat), 1 )[0] #print "THE ID IS %d"%id c.execute( "SELECT id, lat, lon FROM nodes WHERE id = ?", (id,) ) else: c.execute( "SELECT id, lat, lon FROM nodes WHERE endnode_refs...
TestHeadwayAlight,
def glen(gen): return len(list(gen))
if not dryrun: superself.add_way( self.currElem, c )
if not dryrun and accept(self.currElem.tags): superself.add_way( self.currElem, c )
def endElement(self,name): if name=='node': if superself.n_nodes%5000==0: print "node %d"%superself.n_nodes superself.n_nodes += 1 if not dryrun: superself.add_node( self.currElem, c ) elif name=='way': if superself.n_ways%5000==0: print "way %d"%superself.n_ways superself.n_ways += 1 if not dryrun: superself.add_way( ...
log.debug(gtfs_header)
print(gtfs_header)
def load_gtfs_table_to_sqlite(fp, gtfs_basename, cc, header=None, verbose=False): """header is iterable of (fieldname, fieldtype, processing_function). For example, (("stop_sequence", "INTEGER", int),). "TEXT" is default fieldtype. Default processing_function is lambda x:x""" ur = UTF8TextFile( fp ) rd = csv.reader( u...
log.debug( insert_template )
print( insert_template )
def load_gtfs_table_to_sqlite(fp, gtfs_basename, cc, header=None, verbose=False): """header is iterable of (fieldname, fieldtype, processing_function). For example, (("stop_sequence", "INTEGER", int),). "TEXT" is default fieldtype. Default processing_function is lambda x:x""" ur = UTF8TextFile( fp ) rd = csv.reader( u...
if i%5000==0: log.debug(i)
if i%5000==0: print(i)
def load_gtfs_table_to_sqlite(fp, gtfs_basename, cc, header=None, verbose=False): """header is iterable of (fieldname, fieldtype, processing_function). For example, (("stop_sequence", "INTEGER", int),). "TEXT" is default fieldtype. Default processing_function is lambda x:x""" ur = UTF8TextFile( fp ) rd = csv.reader( u...
log.init("gtfsdb")
def __init__(self, sqlite_filename, overwrite=False): log.init("gtfsdb") self.dbname = sqlite_filename if overwrite: try: os.remove(sqlite_filename) except: pass self.conn = sqlite3.connect( sqlite_filename )
log.debug( "skipping table %s - not included in 'tables' list"%tablename )
print( "skipping table %s - not included in 'tables' list"%tablename )
for tablename, table_def in self.GTFS_DEF: if tables is not None and tablename not in tables: log.debug( "skipping table %s - not included in 'tables' list"%tablename ) continue
log.debug( "creating table %s\n"%tablename )
print( "creating table %s\n"%tablename )
for tablename, table_def in self.GTFS_DEF: if tables is not None and tablename not in tables: log.debug( "skipping table %s - not included in 'tables' list"%tablename ) continue
log.debug( "loading table %s\n"%tablename )
print( "loading table %s\n"%tablename )
create_table( c, tablename, table_def )
log.debug( "NOTICE: GTFS feed has no file %s.txt, cannot load\n"%tablename )
print( "NOTICE: GTFS feed has no file %s.txt, cannot load\n"%tablename )
create_table( c, tablename, table_def )
log.debug("usage: python gtfsdb.py gtfsdb_filename [query]")
print("usage: python gtfsdb.py gtfsdb_filename [query]")
def main_inspect_gtfsdb(): from sys import argv if len(argv) < 2: log.debug("usage: python gtfsdb.py gtfsdb_filename [query]") exit() gtfsdb_filename = argv[1] gtfsdb = GTFSDatabase( gtfsdb_filename ) if len(argv) == 2: for table_name, fields in gtfsdb.GTFS_DEF: log.debug("Table: %s"%table_name) for field_name, fiel...
log.debug("Table: %s"%table_name)
print("Table: %s"%table_name)
def main_inspect_gtfsdb(): from sys import argv if len(argv) < 2: log.debug("usage: python gtfsdb.py gtfsdb_filename [query]") exit() gtfsdb_filename = argv[1] gtfsdb = GTFSDatabase( gtfsdb_filename ) if len(argv) == 2: for table_name, fields in gtfsdb.GTFS_DEF: log.debug("Table: %s"%table_name) for field_name, fiel...
log.debug("\t%s %s"%(field_type, field_name))
print("\t%s %s"%(field_type, field_name))
def main_inspect_gtfsdb(): from sys import argv if len(argv) < 2: log.debug("usage: python gtfsdb.py gtfsdb_filename [query]") exit() gtfsdb_filename = argv[1] gtfsdb = GTFSDatabase( gtfsdb_filename ) if len(argv) == 2: for table_name, fields in gtfsdb.GTFS_DEF: log.debug("Table: %s"%table_name) for field_name, fiel...
log.debug(record)
print(record)
def main_inspect_gtfsdb(): from sys import argv if len(argv) < 2: log.debug("usage: python gtfsdb.py gtfsdb_filename [query]") exit() gtfsdb_filename = argv[1] gtfsdb = GTFSDatabase( gtfsdb_filename ) if len(argv) == 2: for table_name, fields in gtfsdb.GTFS_DEF: log.debug("Table: %s"%table_name) for field_name, fiel...
log.debug("Converts GTFS file to GTFS-DB, which is super handy\nusage: python process_gtfs.py gtfs_filename gtfsdb_filename")
print("Converts GTFS file to GTFS-DB, which is super handy\nusage: python process_gtfs.py gtfs_filename gtfsdb_filename")
def main_build_gtfsdb(): parser = OptionParser() parser.add_option("-t", "--table", dest="tables", action="append", default=[], help="copy over only the given tables") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="make a bunch of noise" ) (options, args) = parser.parse_...
resource_count = list(c.execute( "SELECT count(*) FROM resources WHERE name = ?", (name,) ))[0][0]
resource_count = list(cc.execute( "SELECT count(*) FROM resources WHERE name = ?", (name,) ))[0][0]
def store(self, name, obj, c=None): cc = self.conn.cursor() if c is None else c resource_count = list(c.execute( "SELECT count(*) FROM resources WHERE name = ?", (name,) ))[0][0] if resource_count == 0: cc.execute( "INSERT INTO resources VALUES (?, ?)", (name, cPickle.dumps( obj )) ) if not c: self.conn.commit() if not...
(lgs.cpSoul, c_void_p, [LGSTypes.CustomPayload]),
(lgs.cpSoul, py_object, [LGSTypes.CustomPayload]),
def _declare(fun, restype, argtypes): fun.argtypes = argtypes fun.restype = restype fun.safe = True
lgs.vecExpand( addressof(address), amount )
lgs.vecExpand( addressof(self), amount )
def expand(self, amount): lgs.vecExpand( addressof(address), amount )
lgs.vecAdd( addressof(address), element )
lgs.vecAdd( addressof(self), element )
def add(self, element): lgs.vecAdd( addressof(address), element )
if min_transfer_time == None:
if min_transfer_time in ("", None):
def gtfsdb_to_transfer_edges( self ): # load transfers if self.reporter: self.reporter.write( "Loading transfers to graph...\n" ) # keep track to avoid redundancies # this assumes that transfer relationships are bi-directional. # TODO this implementation is also incomplete - it's theoretically possible that # a trans...
yield (s1, s2, ElapseTime(min_transfer_time)) yield (s2, s1, ElapseTime(min_transfer_time))
yield (s1, s2, ElapseTime(int(min_transfer_time))) yield (s2, s1, ElapseTime(int(min_transfer_time)))
def gtfsdb_to_transfer_edges( self ): # load transfers if self.reporter: self.reporter.write( "Loading transfers to graph...\n" ) # keep track to avoid redundancies # this assumes that transfer relationships are bi-directional. # TODO this implementation is also incomplete - it's theoretically possible that # a trans...
yield (s1, s2, ElapseTime(min_transfer_time)) yield (s2, s1, ElapseTime(min_transfer_time))
yield (s1, s2, int(ElapseTime(min_transfer_time))) yield (s2, s1, int(ElapseTime(min_transfer_time)))
def gtfsdb_to_transfer_edges( self ): # load transfers if self.reporter: self.reporter.write( "Loading transfers to graph...\n" ) # keep track to avoid redundancies # this assumes that transfer relationships are bi-directional. # TODO this implementation is also incomplete - it's theoretically possible that # a trans...
assert False, "Support for no-transfer (transfers.txt transfer_type=3) not implemented."
print "WARNING: Support for no-transfer (transfers.txt transfer_type=3) not implemented."
def gtfsdb_to_transfer_edges( self ): # load transfers if self.reporter: self.reporter.write( "Loading transfers to graph...\n" ) # keep track to avoid redundancies # this assumes that transfer relationships are bi-directional. # TODO this implementation is also incomplete - it's theoretically possible that # a trans...
c.execute( "INSERT INTO edges VALUES (?, ?, ?, ?)", (from_v_label, to_v_label, cPickle.dumps( payload.__class__ ), cPickle.dumps( payload.__getstate__() ) ) )
epid = self.put_edge_payload( payload, c ) c.execute( "INSERT INTO edges VALUES (?, ?, ?)", (from_v_label, to_v_label, epid) )
def add_edge(self, from_v_label, to_v_label, payload, outside_c=None): c = outside_c or self.conn.cursor() c.execute( "INSERT INTO edges VALUES (?, ?, ?, ?)", (from_v_label, to_v_label, cPickle.dumps( payload.__class__ ), cPickle.dumps( payload.__getstate__() ) ) ) if hasattr(payload, "__resources__"): for name, reso...
if vertex_soul == NULL:
if vertex_soul is None:
def getVertex( self, i ): vertex_soul = lgs.pathGetVertex( addressof(self), i ) # reinterpret the error code as an exception if vertex_soul == NULL: raise IndexError("%d is out of bounds"%i) return Vertex.from_pointer( vertex_soul )
if edge_soul == NULL:
if edge_soul is None:
def getEdge( self, i ): edge_soul = lgs.pathGetEdge( addressof(self), i ) # reinterpret the error code as an exception if edge_soul == NULL: raise IndexError("%d is out of bounds"%i) return Edge.from_pointer( edge_soul )
return edge is not None and isinstance(edge.state, graphserver.core.TripAlight)
return edge is not None and isinstance(edge.payload, graphserver.core.TripAlight)
def applies_to(vertex1, edge, vertex2): return edge is not None and isinstance(edge.state, graphserver.core.TripAlight)
count = c_int()
count = c_long()
def vertices(self): self.check_destroyed() count = c_int() p_va = lgs.gVertices(self.soul, byref(count)) verts = [] arr = cast(p_va, POINTER(c_void_p)) # a bit of necessary voodoo for i in range(count.value): v = Vertex.from_pointer(arr[i]) verts.append(v) del arr libc.free(p_va) return verts
main()
def main(): usage = """usage: python dedupe.py <graphdb_filename>""" parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() exit(-1) graphdb_filename = args[0] gtfsdb = GTFSDatabase( graphdb_filename ) query = """ SELECT count(*), monday, tuesday, wednesday,...
(lgs.gAddVertices, None, [LGSTypes.Graph, c_char_p, c_int]),
(lgs.gAddVertices, None, [LGSTypes.Graph, POINTER(c_char_p), c_int]),
def _declare(fun, restype, argtypes): fun.argtypes = argtypes fun.restype = restype fun.safe = True
self.b *= 1.0 / sqrt(sqmag(self.b))
self.b.x *= 1.0 / sqrt(sqmag(self.b.x))
def normalize(self): self.b *= 1.0 / sqrt(sqmag(self.b))
img = hg.cvQueryFrame(self.cap)
img = hg.cvRetrieveFrame(self.cap)
def frame(self): if self.framepos == -1: raise Exception('call next before the first frame!') format = self.format img = hg.cvQueryFrame(self.cap) nchannels = 1 if format == FORMAT_GRAY else 3 shape = \ (img.height, img.width) if nchannels == 1 else \ (img.height, img.width, nchannels) if format == FORMAT_BGR: # defa...
def __init__(self, *args):
def __init__(self, fname, format=FORMAT_RGB):
def __init__(self, *args): self.create_capture = hg.cvCreateFileCapture super(video_file, self).__init__(*args)
super(video_file, self).__init__(*args)
super(video_file, self).__init__(format, fname)
def __init__(self, *args): self.create_capture = hg.cvCreateFileCapture super(video_file, self).__init__(*args)
if pos < self.pos:
if pos < self.framepos:
def seek(self, pos): #if pos < self.pos: # self._destr_cap() # self._init_cap() if pos < self.pos: hg.cvSetCaptureProperty(self.cap, hg.CV_CAP_PROP_POS_FRAMES, 0.0) self.framepos = -1 return super(video_file, self).seek(pos)
def correlate(input, kernel, output=None, accumulate=False): out_shape = tuple(np.subtract(input.shape, kernel.shape) + 1) if output is None: output = np.zeros(out_shape, input.dtype) assert (out_shape == output.shape), "shapes don't match" uin = input for d, kd in enumerate(kernel.shape): uin = unfold(uin, d, kd, 1) m...
pass def gen_correlate_scipy(input, kernel, output=None, accumulate=False): y = sig_correlate(input, kernel, 'valid') if output is None: output = y elif accumulate: output += y else: output[:] = y return output def gen_correlate_noscipy(input, kernel, output=None, accumulate=False): out_shape = tu...
def correlate(input, kernel, output=None, accumulate=False): y = sig_correlate(input, kernel, 'valid') if output is None: output = y elif accumulate: output += y else: output[:] = y return output
if pos < self.framepos:
if pos <= self.framepos:
def seek(self, pos): #if pos < self.framepos: # self._destr_cap() # self._init_cap() if pos < self.framepos: hg.cvSetCaptureProperty(self.cap, hg.CV_CAP_PROP_POS_FRAMES, 0.0) self.framepos = -1 return super(video_file, self).seek(pos)
self.tbl_jik = sp.asarray([(b,a,k) for (k,(a,b)) in e(conn_table)], int)
self.tbl_jik = sp.asarray([(b,a,k) for (k,(a,b)) in e(conn_table)], 'i')
def __init__(self, kernel_shape, conn_table): super(back_convolution, self).__init__(kernel_shape, conn_table)
def _step_direction(self, p):
def _perform_step(self, p, grad, coeff): states = p.states for (g, state) in zip(grad,states): state.x += coeff * g def _step_direction(self, p, dostep = True):
def iterstats(self): return {'grad norm': self.cur_grad_norm}