blob: 4386846e5a9c5127263f807b3972c473f2ac5288 [file] [log] [blame]
/*
* 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, "etype":string, "timestamp":datetime, "epicenter":point, "radius":double, "message":string }
create type userLocation as
{ "id":uuid, "user-id":int64, "timestamp":datetime, "location":point }
create type tornadoShelter as
{ "tsid":uuid, "name":string, "location":point }
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)
let $timewindow := day-time-duration("PT1M")
where (some $user in dataset userLocations satisfies
$user.user-id = $userid
)
return
{ "shelter locations":for $shelter in dataset tornadoShelters where spatial-intersect( $dangerzone,$shelter.location) return $shelter.location}
};
create type sub as closed
{ "id":int, "param0":int64 }
create dataset NearbySheltersDuringTornadoDangerChannelSubscriptions(sub)
primary key id;
for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
for $result in NearbySheltersDuringTornadoDanger($sub.param0)
return
{ "result":$result}
;