| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| |
| drop dataverse emergencyTest if exists; |
| create dataverse emergencyTest; |
| use dataverse emergencyTest; |
| |
| create type CHPReport as |
| { "rid":uuid, "epicenter":point, "radius":double } |
| |
| create type userLocation as |
| { "id":uuid, "user-id":int64, "location":point } |
| |
| create type tornadoShelter as |
| { "tsid":uuid, "location":point } |
| |
| create type sub as closed |
| { "id":int, "param0":int64 } |
| |
| create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub) |
| primary key id; |
| |
| create dataset tornadoShelters(tornadoShelter) |
| primary key tsid autogenerated; |
| |
| create dataset userLocations(userLocation) |
| primary key id autogenerated; |
| |
| create dataset CHPReports(CHPReport) |
| primary key rid autogenerated; |
| |
| |
| create function NearbySheltersDuringTornadoDanger($userid) { |
| for $emergency in dataset CHPReports |
| let $dangerzone := create-circle($emergency.epicenter,$emergency.radius) |
| where (some $user in dataset userLocations satisfies $user.user-id = $userid |
| and spatial-intersect($dangerzone, $user.location)) |
| return |
| { "shelter locations":for $shelter in dataset tornadoShelters return $shelter.location} |
| }; |
| |
| create function findShelters($sub){ |
| for $result in NearbySheltersDuringTornadoDanger($sub.param0) |
| return { "subscription-id":$sub.subscription-id,"execution-time":current-datetime(),"result":$result } |
| }; |
| |
| for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions |
| for $r in findShelters($sub) |
| return $r; |