blob: 7fc67ea6da56165824d9affe059b854dd9338001 [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;
22
23use dataverse emergencyTest;
24
25create type CHPReport as
26{ "rid":uuid, "etype":string, "timestamp":datetime, "epicenter":point, "radius":double, "message":string }
27
28create type userLocation as
29{ "id":uuid, "user-id":int64, "timestamp":datetime, "location":point }
30
31create type tornadoShelter as
32{ "tsid":uuid, "name":string, "location":point }
33
34create dataset tornadoShelters(tornadoShelter)
35primary key tsid autogenerated;
36
37create dataset userLocations(userLocation)
38primary key id autogenerated;
39
40create dataset CHPReports(CHPReport)
41primary key rid autogenerated;
42
43create index reportTimes on CHPReports(timestamp);
44create index userTimes on userLocations(timestamp);
45create index shelterloc on tornadoShelters(location) type rtree;
46
47create function NearbySheltersDuringTornadoDanger($userid) {
48for $emergency in dataset CHPReports
49let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
50let $timewindow := day-time-duration("PT1M")
51where (some $user in dataset userLocations satisfies
52$user.user-id = $userid
53)
54return
55{ "shelter locations":for $shelter in dataset tornadoShelters where spatial-intersect( $dangerzone,$shelter.location) return $shelter.location}
56};
57
58create type sub as closed
59{ "id":int, "param0":int64 }
60
61create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
62primary key id;
63
64create type result as open
65{ "id": uuid }
66
67create dataset NearbySheltersDuringTornadoDangerChannelResults(result)
68primary key id autogenerated;
69
70insert into dataset NearbySheltersDuringTornadoDangerChannelResults (
71for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
72for $result in NearbySheltersDuringTornadoDanger($sub.param0)
73return
74{ "result":$result}
75);