本文整理汇总了Python中location.Location类的典型用法代码示例。如果您正苦于以下问题:Python Location类的具体用法?Python Location怎么用?Python Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index(location_id):
# return "<h1><b>That's all for tonight folks</b></h1>Thanks for playing!<p><a href='mailto:[email protected]'>Contact the team</a> behind milkshake.fm</p>"
l = Location.from_id(location_id)
if not l:
l = Location(name="whatever")
l.save()
return render_template('client.html')
示例2: walkTo
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise Exception("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
while dist > epsilon:
logging.info("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
示例3: __init__
def __init__(self, config):
Location.__init__(self, config)
self.victory_chance = config['victory_chance']
self.reward = config['reward']
self.exp_reward = config['exp_reward']
self.penalty = config['penalty']
self.drop_object = config['drop_object']
示例4: __init__
def __init__(self,N_mazeSize, x,y, ith, SURFdict):
#self.placeCells = np.zeros((1+4*N_mazeSize))
loc=Location()
loc.setXY(x,y)
#placeId = loc.placeId
#self.placeCells[placeId] = 1
self.grids = loc.getGrids().copy()
self.hd = np.array([0,0,0,0])
self.hd[ith]=1
self.rgb=np.array([0,0,0]) #assume a red poster in the east and a green poster in the north
if ith==0: #NB these differ from head direction cells, as HD odometry can go wrong!
self.rgb[0]=1
if ith==1:
self.rgb[1]=1
if SURFdict is not None:
#HOOK ALAN - include SURF features in the senses of the dictionary
#Problem with merging here is you can only have one image per direction?
self.surfs=findSurfs(x,y,ith,SURFdict)
else:
self.surfs=np.array([])
#print("Surf feature for %d,%d,%d:\n%s" % (x,y,ith,self.surfs))
#x,y relate to surf features in SURFdict
self.whiskers=np.array([0,0,0]) #to be filled in outside
示例5: walkTo
def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
if step >= epsilon:
raise GeneralPogoException("Walk may never converge")
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = closest = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# Run walk
divisions = closest / step
dLat = (latitude - olatitude) / divisions
dLon = (longitude - olongitude) / divisions
logging.info("Walking %f meters. This will take %f seconds..." % (dist, dist / step))
while dist > epsilon:
logging.debug("%f m -> %f m away", closest - dist, closest)
latitude -= dLat
longitude -= dLon
self.setCoordinates(
latitude,
longitude
)
time.sleep(1)
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
示例6: pack
def pack(self, items, fill_limit):
locations = []
other = Location(-1)
for x in range(0, self._location_count):
locations.append(Location(x))
items = sorted(items, key=attrgetter('weight'), reverse=True)
items = sorted(items, key=attrgetter('value'), reverse=True)
for item in items:
stored = False
locations = sorted(locations, key=attrgetter('weight'))
for idx, location in enumerate(locations):
if location.weight < fill_limit and item.weight <= (fill_limit - location.weight):
location.add_item(item)
stored = True
break
if not stored:
other.add_item(item)
return (locations, other)
示例7: walkTo
def walkTo(self, olatitude, olongitude, speed):
# speed in m/s
# Calculate distance to position
latitude, longitude, _ = self.getCoordinates()
dist = Location.getDistance(
latitude,
longitude,
olatitude,
olongitude
)
# don't divide by zero, bad stuff happens
if dist == 0:
return
divisions = dist/speed
dlat = (latitude - olatitude)/divisions
dlon = (longitude - olongitude)/divisions
logging.info("(TRAVEL)\t-\tWalking "+str(dist)+"m at "+str(speed)+"m/s, will take approx "+str(divisions)+"s")
while dist > speed:
latitude-=dlat
longitude-=dlon
self.setCoordinates(latitude, longitude)
time.sleep(1)
dist = Location.getDistance(latitude, longitude, olatitude, olongitude)
#final move
self.setCoordinates(olatitude, olongitude)
示例8: post
def post(self):
locnick=self.request.get('nick')
if not locnick:
return self.error("Parameter 'nick' missing")
loc=Location(nick=locnick)
loc.position=self.request.get('position')
loc.put()
return self.success()
示例9: __init__
def __init__(self, ec, dictGrids, dghelper=None, N_place_cells=13):
self.N_place_cells=N_place_cells
self.dghelper = dghelper
#HOOK:, needs to use EC data to define "combis" of features aswell
if dghelper is not None:
#Lets say for now that place whisker combos etc are all encoded normally, and SURF features are encoded using WTA DG. In the end we may make sure that we have blocks referring only to location, blocks refering only to whiskers, blocks refering only to light, etc.
#FIXME: This needs changing when integrated to just get the number of surf features from ec!
if unittesting:
#Slice the SURF features from the numpy array
self.numOfSurfFeatures = len(ec)
self.surfFeatures = ec[-self.numOfSurfFeatures:]
else:
self.numOfSurfFeatures = len(ec.surfs)
self.surfFeatures = ec.surfs
#Choose semantics by choosing X random features N times to make N blocks
#For now be stupid, allow the same combinations to come up and the same indices to be compared with each other for winner take all (will the conflict break it?)
#Make this more intelligent later
#Make random windows associated with the features, i.e. for N windows, choose X random features to encode, make a matrix with the blocks and values
# <---X--->
# +-------------+
# ^ | 0 0 0 0 1 0 |
# | | 1 0 0 0 0 0 |
# N | |
# | | |
# | | |
# +-------------+
self.semanticValues = dghelper.getSemanticValues(self.surfFeatures)
#These are our input activations, once passed through a neural network with competitive learning applied to its ECDGweights to encourage winner takes all, the output should only have 1 active value per block (row), thus is sparse
#What happens if none of the features are active?? Should the one with the highest weight win? Or should there just be no activation in that block making it a even sparser matrix? I suspect the latter!
self.encode()
if not unittesting:
if dghelper is None:
self.encodedValues = np.array([])
#TODO: Need to remove place cells....
#self.N_place_cells = 13
# N_hd = 4
loc=Location() #NEW, pure place cells in DG
loc.setGrids(ec.grids, dictGrids)
self.place=np.zeros(self.N_place_cells)
self.place[loc.placeId] = 1
self.hd_lightAhead = np.zeros(4)
if ec.lightAhead == 1:
self.hd_lightAhead = ec.hd.copy()
self.whisker_combis = np.zeros(3) #extract multi-whisker features.
self.whisker_combis[0] = ec.whiskers[0] * ec.whiskers[1] * ec.whiskers[2] #all on
self.whisker_combis[1] = (1-ec.whiskers[0]) * (1-ec.whiskers[1]) * (1-ec.whiskers[2]) #none on
self.whisker_combis[2] = ec.whiskers[0] * (1-ec.whiskers[1]) * ec.whiskers[2] # both LR walls but no front
示例10: test_location_on_obstacle
def test_location_on_obstacle(self):
grid = Grid(3, 3)
grid.place_obstacle(0, 1)
location = Location(grid, 0, 0, direction.N)
self.assertFalse(location.is_on_obstacle())
next_location = location.next_location(command.F)
self.assertTrue(next_location.is_on_obstacle())
示例11: test_next_location3
def test_next_location3():
loc = Location(2, 2, 3)
loc_x, loc_y, x, y = loc.next_location("down", 10, loc.size + 1)
assert loc_y == 0
assert loc_x == 2
loc_x, loc_y, x, y = loc.next_location("right", loc.size + 1, 10)
assert loc_x == 0
assert loc_y == 2
示例12: test_next_location2
def test_next_location2():
loc = Location(0, 0, 3)
loc_x, loc_y, x, y = loc.next_location("up", 10, -1)
assert loc_y == 2
assert loc_x == 0
loc_x, loc_y, x, y = loc.next_location("left", -1, 10)
assert loc_x == 2
assert loc_y == 0
示例13: __init__
def __init__(self, map_name, name):
xml = doc.xpath('//map[@name="%s"]/door[@name="%s"]' % (map_name, name))[0]
#~ print etree.tostring(xml)
Location.__init__(self, map_name, xml.get('loc'))
#~ Location.__init__(self, map_name, doc.xpath('//map[@name="%s"]/door[@name="%s"]' % (map_name, name))[0].get('loc'))
self.door_name = name
if not xml.get('target'):
raise Exception("door without target: %s" % etree.tostring(xml))
self.target = xml.get('target')
示例14: testMumbai
def testMumbai(self):
lc = Location()
mumbai_cord = lc.getCoordinates(query="Mumbai")
mumbai_expected = Coordinates(lat=19.017587, lng=72.856248, state="Maharashtra", sub_district="Mumbai",
district="Mumbai", level="Town", name="MUMBAI")
self.assertTrue((float(mumbai_cord.lat) - float(mumbai_expected.lat)) < 0.00001, "Latitude didnot Match for Mumbai")
self.assertTrue((float(mumbai_cord.lng) - float(mumbai_expected.lng))< 0.00001, "Longitude didnot Match for Mumbai")
self.assertEqual(mumbai_cord.state, mumbai_expected.state, "States didnot Match for Mumbai")
self.assertEqual(mumbai_cord.district, mumbai_expected.district, "District didnot Match for Mumbai")
self.assertEqual(mumbai_cord.sub_district, mumbai_expected.sub_district, "SUB District didnot Match for Mumbai")
self.assertEqual(mumbai_cord.level, mumbai_expected.level, "Levels didnot Match for Mumbai")
示例15: test_next_location_wrapped
def test_next_location_wrapped(self):
grid = Grid(3, 3)
location = Location(grid, 0, 0, direction.W)
next_location = location.next_location(command.F)
self.assert_location(Location(grid, 2, 0, direction.W), next_location)
next_location = next_location.next_location(command.L)
self.assert_location(Location(grid, 2, 0, direction.S), next_location)
next_location = next_location.next_location(command.F)
self.assert_location(Location(grid, 2, 2, direction.S), next_location)