blob: e8d57a6da1686c4007ddcdb028f1fad7e386d225 [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.
*/
/*
* Description : Disasters with friends
* Expected Res : Success
* Date : May 17
* Author : Steven Jacobs
*/
drop dataverse channels if exists;
create dataverse channels;
use channels;
create type UserLocation as {
recordId: uuid,
latitude: double,
longitude: double,
user_id: int,
timestamp: datetime
};
create type EmergencyShelter as {
name: string,
location: point
};
create type EmergencyReport as {
reportId: uuid,
impactZone: circle,
timestamp: datetime,
emergencyType: string
};
//create datasets
create dataset EmergencyReports(EmergencyReport) primary key reportId autogenerated;
create dataset UserLocations(UserLocation) primary key recordId autogenerated;
create dataset EmergencyShelters(EmergencyShelter) primary key name;
create broker brokerA at "http://www.notifyA.com";
create function EmergenciesNearMe(emergencyType, uid){
(with tenMinutesAgo as current_datetime() - day_time_duration("PT10S")
select report as report, shelters as shelters
from EmergencyReports report, UserLocations user
let shelters = (select * from EmergencyShelters shelter
where spatial_intersect(report.impactZone,shelter.location))
where user.user_id = uid
and report.timestamp >= tenMinutesAgo
and user.timestamp >= tenMinutesAgo
and report.emergencyType = emergencyType
and spatial_intersect(report.impactZone,create_point(user.latitude,user.longitude)))
};
create repetitive channel EmergenciesNearMeChannel using EmergenciesNearMe@2 period duration("PT5S");