Event Condition Action: Difference between revisions
Jump to navigation
Jump to search
(Created page with "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 v…") |
|||
| Line 10: | Line 10: | ||
* JSON Rules http://bpt.hpi.uni-potsdam.de/pub/Public/EmilianPascalau/JSONRulesSlides.pdf |
* JSON Rules http://bpt.hpi.uni-potsdam.de/pub/Public/EmilianPascalau/JSONRulesSlides.pdf |
||
* [https://github.com/giacecco/JSRulez JSRuleZ] pour [[Node.js]] |
* [https://github.com/giacecco/JSRulez JSRuleZ] pour [[Node.js]] |
||
==Exemples== |
|||
[http://fr.wikipedia.org/wiki/Hyst%C3%A9r%C3%A9sis Hystérésis] pour un chauffage avec [https://github.com/giacecco/JSRulez JSRuleZ] pour [[Node.js]] |
|||
<pre> |
|||
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; }, |
|||
//cool : 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, |
|||
}, |
|||
{ 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), |
|||
context = { indoortemp: 10, outdoortemp: 10, heaterOn : false}; |
|||
rulesEngine.runAll(context); |
|||
for(i=1;i<100;i++) { |
|||
console.log("indoortemp: " + context.indoortemp); |
|||
rulesEngine.runAll(context); |
|||
}; |
|||
}); |
|||
</pre> |
|||
Revision as of 21:55, 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; },
//cool : 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,
},
{ 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),
context = { indoortemp: 10, outdoortemp: 10, heaterOn : false};
rulesEngine.runAll(context);
for(i=1;i<100;i++) {
console.log("indoortemp: " + context.indoortemp);
rulesEngine.runAll(context);
};
});