def set_event(req): start_point, plist, proplist = extract_features(req) e = Event(start_point=start_point, points=plist, props=proplist) db.session.add(e) db.session.commit() print(e.start_point) for p in e.points: print(p) return gdumps(e)
def get_nearby_points(): lat = request.args.get('lat') lng = request.args.get('lng') dist = request.args.get('dist') if not (lat and lng and dist): abort(400) user_point = WKTElement('POINT({} {})'.format(lng, lat)) points = Point.query.filter( ST_Distance(Point.point, user_point) <= dist).all() return '[' + ','.join(gdumps(p) for p in points) + ']'
def finish_event(event_id): uid = User.query.filter( User.username == auth.username().lower()).with_entities( User.uid).scalar() time = request.args.get('time') or '00:00:00' score = request.args.get('score') h, m, s = time.split(':') event_stat = EventStat(uid, event_id, hours=h, minutes=m, seconds=s, score=score) db.session.add(event_stat) db.session.commit() e = Event.query.get(event_id) return gdumps(e)
def update_point(req): point = Point.query.filter(Point.pid == req['id']).first() if point is None: abort(400) geom = req['geometry'] coords = geom['coordinates'] ewkt = 'Point(' + str(coords[0]) + ' ' + str(coords[1]) + ')' props = [] for key, value in req['properties'].items(): props.append(PointProp(prop_name=key, prop=value)) for prop in point.props: db.session.delete(prop) point.point = ewkt point.props = props db.session.flush() db.session.commit() return gdumps(point)
def set_points(req): plist = [] for point in req: geom = point['geometry'] coords = geom['coordinates'] ewkt = 'Point(' + str(coords[0]) + ' ' + str(coords[1]) + ')' props = [] for key, value in point['properties'].items(): props.append(PointProp(prop_name=key, prop=value)) p = Point(point=ewkt, props=props) plist.append(p) db.session.add(p) db.session.flush() db.session.commit() d = ','.join(gdumps(p) for p in plist) d = '[' + d + ']' return d
def remove_my_event(eid): user = User.query.filter(User.username == auth.username().lower()).first() e = Event.query.get(eid) user.saved_events.remove(e) db.session.commit() return '[' + ','.join(gdumps(e) for e in user.saved_events) + ']'
def get_my_events(): user = User.query.filter(User.username == auth.username().lower()).first() return '[' + ','.join(gdumps(e) for e in user.saved_events) + ']'
def get_event_by_id(event_id): e = Event.query.filter(Event.eid == event_id).first() return gdumps(e)