blob: c9804454c96c46834051eef264981c12ee193b1f [file] [log] [blame]
Yingyi Bue3e13732015-12-30 16:06:04 -08001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20drop dataverse emergencyTest if exists;
21create dataverse emergencyTest;
22use dataverse emergencyTest;
23
24create type CHPReport as
25{ "rid":uuid, "etype":string, "timestamp":datetime, "epicenter":point, "radius":double, "message":string }
26
27create type userLocation as
28{ "id":uuid, "user-id":int64, "timestamp":datetime, "location":point }
29
30create type tornadoShelter as
31{ "tsid":uuid, "name":string, "location":point }
32
33create type sub as closed
34{ "id":int, "param0":int64 }
35
36create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
37primary key id;
38
39create dataset tornadoShelters(tornadoShelter)
40primary key tsid autogenerated;
41
42create dataset userLocations(userLocation)
43primary key id autogenerated;
44
45create dataset CHPReports(CHPReport)
46primary key rid autogenerated;
47
48create function NearbySheltersDuringTornadoDanger($userid) {
49for $emergency in dataset CHPReports
50 let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
51 where (some $user in dataset userLocations satisfies
52 $user.user-id = $userid and spatial-intersect($dangerzone,$user.location))
Yingyi Buae555ba2016-03-09 21:29:32 -080053return { "shelter locations": for $shelter in dataset tornadoShelters return $shelter.location}
Yingyi Bue3e13732015-12-30 16:06:04 -080054};
55
56
57for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
58for $result in NearbySheltersDuringTornadoDanger(int("5"))
59return
60{ "result":$result }
61;