Exemplo n.º 1
0
    def get(self):
        """
        GET API endpoint to provide truck list in json format.
        Optionaly consume 3 items (all are needed when provided):
        lat: float - Latitude of the targetted center
        lng: float - Longitude of the targetted center
        radius: int - Radius of the circle, centerred from the target (x,y)
        """
        parser = reqparse.RequestParser()
        parser.add_argument('lat', type=float)
        parser.add_argument('lng', type=float)
        parser.add_argument('radius', type=int)
        args = parser.parse_args()
        lat = args.get('lat', None)
        lng = args.get('lng', None)
        radius = args.get('radius', None)

        if lat and lng and radius:
            trucks = db.trucks.find({"coordinates": {"$geoWithin": \
            {"$centerSphere": [[lng, lat], meter_to_radian(radius)]}}})
        else:
            trucks = db.trucks.find({})
        return list(trucks)
Exemplo n.º 2
0
def test_meter_to_radian_2():
    assert meter_to_radian(0) == 0.0
Exemplo n.º 3
0
def test_meter_to_radian_1():
    assert meter_to_radian(5000) == 5000