blob: da7d535dbd3c245343d37516b854b2fa12462805 [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
20
21drop dataverse emergencyTest if exists;
22create dataverse emergencyTest;
23use dataverse emergencyTest;
24
25create type CHPReport as
26{ "rid":uuid, "epicenter":point, "radius":double }
27
28create type userLocation as
29{ "id":uuid, "user-id":int64, "location":point }
30
31create type tornadoShelter as
32{ "tsid":uuid, "location":point }
33
34create type sub as closed
35{ "id":int, "param0":int64 }
36
37create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
38primary key id;
39
40create dataset tornadoShelters(tornadoShelter)
41primary key tsid autogenerated;
42
43create dataset userLocations(userLocation)
44primary key id autogenerated;
45
46create dataset CHPReports(CHPReport)
47primary key rid autogenerated;
48
49
50create function NearbySheltersDuringTornadoDanger($userid) {
51 for $emergency in dataset CHPReports
52 let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
53 where (some $user in dataset userLocations satisfies $user.user-id = $userid
54 and spatial-intersect($dangerzone, $user.location))
55 return
56 { "shelter locations":for $shelter in dataset tornadoShelters return $shelter.location}
57};
58
59create function findShelters($sub){
60 for $result in NearbySheltersDuringTornadoDanger($sub.param0)
61 return { "subscription-id":$sub.subscription-id,"execution-time":current-datetime(),"result":$result }
62};
63
64for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
65for $r in findShelters($sub)
66return $r;