I am looking to create a query that scans a table and calculates the difference between a given location and a stored geographic location attribute in a table based on some calc_dist function (attribute), which filters it on the go and returns the results in slices from nearest to far
lets say that the table class looks something like this:
Hoo(Base):
attribute_names = Column(......)
@hybrid_property
def calc_dist(self):
How to do something like:
session.query(Hoo).filter(Hoo.attr_ and given_geo_loc USING this location value- Is there a way to pass this val into calc_dist here?)
Every time a new request arrives with new Geo Location data, how can we pass this using this given location into a filter request so calc_dist computes this?
For each given location argument, there will be a query result that gives a value based on this limit from the closest to the farthest.
UPDATE
:
class Hoo(Base):
__tablename__ = 'hoo'
lat = Column(String(50))
lng = Column(String(50))
@hybrid_method
def rankByloc(self, lat, lng):
return haversine((float(self.lat), float(self.lng)), (float(lat), float(lng)))
@rankByloc.expression
def rankByloc(cls, lat, lng):
return haversine((float(self.lat), float(self.lng)), (float(lat), float(lng)))
session.query(Hoo).order_by(Hoo.rankByloc(lat, lng))
:
NameError: global name 'self' is not defined
@hybrid_property
TypeError: rankByloc() takes exactly 3 arguments (1 given)
# 2
, hybrid_method.
python . :
@rankByloc.expression
def rankByloc(cls, lat, lng):
return haversine((float(self.lat), float(self.lng)), (float(lat), float(lng)))
# 3
, , Sqlalchemy haversine orderby.
SQLA? , , sql.