Time Based¶
Time based MR rule is created when filtering is based on start time and end time of the input JSON data. Here start time and end time parameters under time are provided values in MR rule in the format DD-MON-YYYY HH:mm:ss[.SSS] zzz(eg:23-JUL-2013 15:30:00 IST) or HH:mm:ss zzz(eg:15:30:00 IST) which is supposed to filter time based input data.
Below is the create rule JSON for date and time based filtering:
{
"RuleName": "Data an time based demo rule",
"RuleDescription": "Demo rule for user guide",
"input": {
"DirectExchange": "Direct.Exchange",
"RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf"
},
"params": [
{
"name": "feature",
"value": "room1"
},
{
"name": "sensorID",
"value": "NEXUS1"
},
{
"name": "time",
"value": {
"starttime": "1-JAN-2016 15:30:00 IST",
"endtime": "29-APR-2016 15:30:00 IST"
}
},
{
"name": "expression",
"value": {
"if": "",
"then": "",
"else": ""
}
},
{
"name": "",
"type": "rectangle/circles/polygon",
"geoFencing": "YES/NO",
"value": {
"points": [
{
"x": "",
"y": ""
},
{
"x": "",
"y": ""
}
]
}
},
{
"name": "ObservedProperties",
"value": [
{
"name": "",
"type": "Text/quantity/count",
"value": "",
"operator": ""
}
]
}
],
"output": {
"TopicExchange": "DemoExchange",
"Topic": "demo3"
}
}
As we can see in the above JSON sensor ID, feature and start time and end time value is provided which acts as a filtering condition for input data and routes the input data with sensor NEXUS1, feature as room1 and start time as 1-JAN-2016 15:30:00 IST and end time 29-APR-2016 15:30:00 IST only. In case input data has time value outside the given band pass or the sensor, feature value other than above, it will discard the data. Topic exchange name is DemoExchange which we have already created in the topic exchange section.
In the above create rule JSON combination of time can be used in the following ways:
1) High Pass
If start time is specified and end time is blank then the observations which are started after the mentioned start time will be passed.
{
"name": "time",
"value": {
"starttime": "1-JAN-2016 15:30:00 IST",
"endtime": ""
}
}
2) Low Pass
If end time is specified and start time is blank then the observations which have started before the mentioned end time will be passed.
{
"name": "time",
"value": {
"starttime": "",
"endtime": "29-APR-2016 15:30:00 IST"
}
}
3) Band Pass
If both start time and end time are specified then the observations between the time bound will be passed.
{
"name": "time",
"value": {
"starttime": "1-JAN-2016 15:30:00 IST",
"endtime": "29-APR-2016 15:30:00 IST"
}
}
4) All Pass
If both fields are blank then the passing will not be dependent upon time.
{
"name": "time",
"value": {
"starttime": "",
"endtime": ""
}
}
Band Pass Time¶
Now we will create the band pass rule by mentioning the time parameter as given in Band Pass section above. Rule can be created in the following 2 ways:
Using MR API swagger
Using MR portal
Using MR API swagger¶
Click on POST /routingRules API in swagger, use the above JSON template and hit
Try it out!
button, it will create a new MR rule with time paramter value as shown in the image below:
As we can see in the above image, theMR rule created with rule ID - 1116 will be used to start this rule. You can refer to Start the Routing Channel section to start the rule.
Using MR portal¶
Click on
Create Rule
button in MR rule, fill in all the details as mentioned in the image below and clickCreate Rule
button, it will create a new MR rule with sensor as shown in the image below:
After clicking
Create Rule
button the message mentioned below will be dispalyed at the upper right corner with the rule ID. Here in our case the rule ID is 1117.
As we can see in the above image, MR rule created with rule ID - 1117 will be used to start this rule. You can refer to Start the Routing Channel section to start the rule.
Send Request operation
After the rule is created it needs to be started as mentioned above and then input JSON can be posted to MR rule using send request API. For this we have to configure and start SSE viewer page and send the observation matching to the MR rule.
Below is the input SOS observation JSON
{
"version": "1.0.1",
"observations": [
{
"sensor": "NEXUS1",
"feature": "room1",
"record": [
{
"starttime": "15-JAN-2016 15:30:03 IST",
"output": [
{
"name": "OutsideSensorTemp",
"value": "46.0",
"type": "decimal"
},
{
"name": "temp",
"value": "99",
"type": "quantity"
}
]
}
],
"meta-data": []
}
]
}
Here in input JSON we can see that sensor name is NEXUS1, feature is room1 and starttime is 15-JAN-2016 15:30:03 IST which is in between MR rule start time and end time. We can now use send request API to verify this rule as shown in the images below:
After the data is sent to MR rule we can see that output of MR rule is received in SSE viewer as shown in the image below:
Note
Similarly rule for High Pass Time, Low Pass Time, and All pass time can be created using either MR API swagger or MR portal. Also to send the request and view the output same observation JSON can be used. Based on the time given in the MR rule if the observation satisfies the condition output will be displayed.
Below is the create rule JSON for only time based filtering:
{
"RuleName": "Time based demo rule",
"RuleDescription": "Demo rule for user guide",
"input": {
"DirectExchange": "Direct.Exchange",
"RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf"
},
"params": [
{
"name": "feature",
"value": "room1"
},
{
"name": "sensorID",
"value": "NEXUS1"
},
{
"name": "time",
"value": {
"starttime": "15:30:00 IST",
"endtime": "16:30:00 IST"
}
},
{
"name": "expression",
"value": {
"if": "",
"then": "",
"else": ""
}
},
{
"name": "ObservedProperties",
"value": [
]
}
],
"output": {
"TopicExchange": "DemoExchange",
"Topic": "demo3"
}
}
Time format is [H[H]:m[m]:ss.[SSS] zzz. In case input data time falls in the range specified by starttime and endtime, it will be passed out. Condition will be checked irrespective of day.
In the above create rule JSON combination of time can be used in the following ways:
1) High Pass
If start time is specified and end time is blank then the observations which are started after the mentioned start time will be passed.
{
"name": "time",
"value": {
"starttime": "15:30:00 IST",
"endtime": ""
}
}
2) Low Pass
If end time is specified and start time is blank then the observations which have started before the mentioned end time will be passed.
{
"name": "time",
"value": {
"starttime": "",
"endtime": "16:30:00 IST"
}
}
3) Band Pass
If both start time and end time are specified then the observations between the time bound will be passed.
{
"name": "time",
"value": {
"starttime": "15:30:00 IST",
"endtime": "16:30:00 IST"
}
}
Warning
MR does not have any control on the input JSON data. This should be checked in SOS/DM from where the data should be coming to MR. If the date and time format is correct it will be processed in MR and in case it does not conform to the format it will not be processed. If the time format is (00-MMM-YY) in input JSON, MR will be able to process date data(checking is lenient) as it conforms to the correct format after spill over date & time. As date mentioned with 00 of any month will be treated as the 1st day of the month. Similarly when the hour, minute and second exceeds their maximum value, it will automatically fall in the next value of their time stamp.