blob: 1cb0114746c24b0deb53cf960a523e9302e4f395 [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, "epicenter":point, "radius":double, "message":string, "timestamp":datetime }
create type userLocation as
{ "id":uuid, "user-id":int64, "location":point, "timestamp":datetime }
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 index times on CHPReports(timestamp);
create index times2 on userLocations(timestamp);
create index locs on tornadoShelters(location) type rtree;
create index locs2 on CHPReports(epicenter) type rtree;
create index locs3 on userLocations(location) type rtree;
for $sub in dataset NearbySheltersDuringTornadoDangerChannelSubscriptions
for $emergency in dataset CHPReports
let $dangerzone := create-circle($emergency.epicenter,$emergency.radius)
let $timewindow := day-time-duration("PT10M")
where $emergency.etype = "tornado"
where $emergency.timestamp >= current-datetime()-$timewindow
where (some $user in dataset userLocations satisfies
$user.user-id = $sub.param0
and $user.timestamp >= current-datetime() - $timewindow
and spatial-intersect($dangerzone,$user.location))
return
{ "id":$sub.param0, "message":$emergency.message, "shelter locations":for $shelter in dataset tornadoShelters return $shelter.location }
;