<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ Licensed 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.
  -->
<templateDomain name="TemperatureAnalysis">
    <description>Temperature Analysis Description</description>
    <templates>
        <template name="Maximum Temperature">
            <description>To check maximum room temperature of all rooms</description>
            <executionPlan>
                <![CDATA[
                /* Enter a unique ExecutionPlan */
                @Plan:name('testPlan')
                /* Enter a unique description for ExecutionPlan */
                -- @Plan:description('ExecutionPlan')
                /* define streams and write query here ... */
                @Import('inStream:1.0.0')
                define stream inStream (meta_temperature double, meta_roomNumber int);
                @Export('outStream:1.0.0')
                define stream outStream (meta_temperature double, meta_roomNumber int);
                from inStream[meta_temperature > $maxVal]
                select meta_temperature,meta_roomNumber
                insert into outStream;
                 ]]>
            </executionPlan>
            <parameters>
                <parameter name="maxVal" type="int">
                    <displayName>Maximum Temperature</displayName>
                    <description>Maximum room temperature threshold</description>
                    <defaultValue>75</defaultValue>
                </parameter>
            </parameters>
        </template>

        <template name="Maximum Temperature By Room">
            <description>To check maximum room temperature of specified room</description>
            <executionPlan>
                <![CDATA[
                /* Enter a unique ExecutionPlan */
                @Plan:name('testPlan')
                /* Enter a unique description for ExecutionPlan */
                -- @Plan:description('ExecutionPlan')
                /* define streams and write query here ... */
                @Import('inStream:1.0.0')
                define stream inStream (meta_temperature double, meta_roomNumber int);
                @Export('outStream:1.0.0')
                define stream outStream (meta_temperature double, meta_roomNumber int);
                from inStream[meta_temperature > $maxVal and meta_roomNumber > $roomNo]
                select meta_temperature,meta_roomNumber
                insert into outStream;
                 ]]>
            </executionPlan>
            <parameters>
                <parameter name="maxVal" type="int">
                    <displayName>Maximum Temperature</displayName>
                    <description>Maximum room temperature threshold</description>
                    <defaultValue>75</defaultValue>
                </parameter>


                <parameter name="roomNo" type="int">
                    <displayName>Room Number</displayName>
                    <description>Select one of available rooms</description>
                    <defaultValue>1</defaultValue>
                    <options>1, 2, 3, 4, 5</options>
                </parameter>
            </parameters>
        </template>


        <template name="Average Temperature For Specified Time">
            <description>To check average room temperature within specified time window of all rooms</description>
            <executionPlan>
                <![CDATA[
                /* Enter a unique ExecutionPlan */
                @Plan:name('testPlan')
                /* Enter a unique description for ExecutionPlan */
                -- @Plan:description('ExecutionPlan')
                /* define streams and write query here ... */
                @Import('inStream:1.0.0')
                define stream inStream (meta_temperature double, meta_roomNumber int);
                @Export('outStream:1.0.0')
                define stream outStream (meta_temperature double, meta_roomNumber int);
                from inStream#window.time($timeInterval)
                select avg(meta_temperature) as meta_temperature,meta_roomNumber
                group by meta_roomNumber
				having meta_temperature>= $maxVal
				insert into outStream;
                 ]]>
            </executionPlan>
            <parameters>
                <parameter name="maxVal" type="int">
                    <displayName>Maximum Temperature</displayName>
                    <description>Maximum room temperature threshold</description>
                    <defaultValue>75</defaultValue>
                </parameter>
                <parameter name="timeInterval" type="time">
                    <displayName>Time Interval</displayName>
                    <description>Time can be defined such 5 sec, 1 min and etc</description>
                    <defaultValue>1 min</defaultValue>
                </parameter>
            </parameters>
        </template>

    </templates>
    <streams>
        <stream>
            {
            "streamId": "inStream:1.0.0",
            "name": "inStream",
            "version": "1.0.0",
            "nickName": "",
            "description": "",
            "metaData": [
            {
            "name": "temperature",
            "type": "DOUBLE"
            },
            {
            "name": "roomNumber",
            "type": "INT"
            }
            ],
            "correlationData": [],
            "payloadData": []
            }
        </stream>
        <stream>
            {
            "streamId": "outStream:1.0.0",
            "name": "outStream",
            "version": "1.0.0",
            "nickName": "",
            "description": "",
            "metaData": [
            {
            "name": "temperature",
            "type": "DOUBLE"
            },
            {
            "name": "roomNumber",
            "type": "INT"
            }
            ],
            "correlationData": [],
            "payloadData": []
            }
        </stream>
    </streams>
</templateDomain>