Difference between revisions of "Event Condition Action"
Jump to navigation
Jump to search
Line 29: | Line 29: | ||
heatOff : function(context) { context.heaterOn=false; }, |
heatOff : function(context) { context.heaterOn=false; }, |
||
heat : function(context) { context.indoortemp+=1; }, |
heat : function(context) { context.indoortemp+=1; }, |
||
− | //cool : function(context) { context.indoortemp-=1; }, |
||
}; |
}; |
||
− | var ruleSet = [ |
+ | var ruleSet = [ |
− | |||
{ name: 'heatOn', |
{ name: 'heatOn', |
||
condition: function (context) { return context.indoortemp <= minTemp && context.heaterOn==false; }, |
condition: function (context) { return context.indoortemp <= minTemp && context.heaterOn==false; }, |
||
Line 51: | Line 49: | ||
breakFlow: true, |
breakFlow: true, |
||
}, |
}, |
||
− | |||
− | |||
− | { name: 'cool', |
||
− | condition: function (context) { return context.indoortemp > context.outdoortemp; }, |
||
− | action: function (context) { context.indoortemp-=0.5; }, |
||
− | breakFlow: true, |
||
− | }, |
||
− | |||
− | { name: 'hot', |
||
− | condition: function (context) { return context.indoortemp < context.outdoortemp; }, |
||
− | action: function (context) { context.indoortemp+=0.5; }, |
||
− | breakFlow: true, |
||
− | }, |
||
]; |
]; |
||
var rulesEngine = new JSRulez.RulesEngine(ruleSet), |
var rulesEngine = new JSRulez.RulesEngine(ruleSet), |
||
+ | |||
context = { indoortemp: 10, outdoortemp: 10, heaterOn : false}; |
context = { indoortemp: 10, outdoortemp: 10, heaterOn : false}; |
||
+ | |||
rulesEngine.runAll(context); |
rulesEngine.runAll(context); |
||
for(i=1;i<100;i++) { |
for(i=1;i<100;i++) { |
||
Line 74: | Line 61: | ||
}; |
}; |
||
}); |
}); |
||
+ | </pre> |
||
+ | |||
+ | <pre> |
||
+ | npm install requirejs |
||
+ | node hysteresis.js |
||
</pre> |
</pre> |
Revision as of 23:59, 11 March 2013
Le paradigme Event Condition Action (ECA) consiste à déclencher des actions sur réception d'un événement quand la condition (en général, une expression booléenne sur la valeur de l'événement).
Rules engines
SQL
- Triggers SQL
Java
- JBoss Drools
Javascript
- JSON Rules http://bpt.hpi.uni-potsdam.de/pub/Public/EmilianPascalau/JSONRulesSlides.pdf
- JSRuleZ pour Node.js
Exemples
Hystérésis pour un chauffage avec JSRuleZ pour Node.js
var requirejs = require('requirejs'); requirejs([ "JSRulez" ], function (JSRulez) { var maxTemp=21; var minTemp=19; var heater = { heatOn : function(context) { context.heaterOn=true; }, heatOff : function(context) { context.heaterOn=false; }, heat : function(context) { context.indoortemp+=1; }, }; var ruleSet = [ { name: 'heatOn', condition: function (context) { return context.indoortemp <= minTemp && context.heaterOn==false; }, action: function (context) { heater.heatOn(context); }, breakFlow: true, }, { name: 'heatOff', condition: function (context) { return context.indoortemp >= maxTemp && context.heaterOn==true; }, action: function (context) { heater.heatOff(context); }, breakFlow: true, }, { name: 'heater', condition: function (context) { return context.heaterOn==true; }, action: function (context) { heater.heat(context); }, breakFlow: true, }, ]; var rulesEngine = new JSRulez.RulesEngine(ruleSet), context = { indoortemp: 10, outdoortemp: 10, heaterOn : false}; rulesEngine.runAll(context); for(i=1;i<100;i++) { console.log("indoortemp: " + context.indoortemp); rulesEngine.runAll(context); }; });
npm install requirejs node hysteresis.js