blob: 4386846e5a9c5127263f807b3972c473f2ac5288 [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 dataset tornadoShelters(tornadoShelter)
34primary key tsid autogenerated;
35
36create dataset userLocations(userLocation)
37primary key id autogenerated;
38
39create dataset CHPReports(CHPReport)
40primary key rid autogenerated;
41
42create function NearbySheltersDuringTornadoDanger($userid) {
43for $emergency in dataset CHPReports
44let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
45let $timewindow := day-time-duration("PT1M")
46where (some $user in dataset userLocations satisfies
47$user.user-id = $userid
48)
49return
50{ "shelter locations":for $shelter in dataset tornadoShelters where spatial-intersect( $dangerzone,$shelter.location) return $shelter.location}
51};
52
53create type sub as closed
54{ "id":int, "param0":int64 }
55
56create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
57primary key id;
58
59for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
60for $result in NearbySheltersDuringTornadoDanger($sub.param0)
61return
62{ "result":$result}
63;