rules
rules copied to clipboard
JSON syntax for timer evaluation
Hello:
Thanks so much for your time, and this project.
Is there a general way to generate JSON syntax for a given ruleset?
I'm having a little trouble understanding how to evaluate JSON timers. Specifically, how can we evaluate the timer ($t) JSON value into the 'startTimer' syntax?
Is there something similar to the h.getAction for the 'run' syntax evaluation? The JSON examples also have clearTimer, restartTimer, but it's not obvious to me how I should evaluate these.
{
"risk$state": {
"start": {
"t_0": {
"to": "meter"
}
},
"meter": {
"t_0": {
"count": 3,
"all": [
{
"message": {
"$gt": {
"amount": 100
}
}
}
],
"to": "fraud",
"run": "logFraud"
},
"t_1": {
"all": [
{
"m": {
"$t": "RiskTimer"
}
}
],
"to": "exit",
"run": "logExit"
}
},
"fraud": {},
"exit": {}
}
}
In the above, how do we translate the 'RiskTimer'?
Hello,
I just wanted to follow up on this request to see if there are some examples (such as h.getAction) for timers define in JSON syntax.
Thanks.
Hi, thanks for posting the question. I'm not sure I understand what you are looking for. Let me try to answer: The json syntax for a timer requires looking for an event with a property of the form "$t": "timer_name". To start a timer you should call the function startTimer("timer_name", duration)
inside an action. Does this help?
Hello, thanks for the response. Please take a look at the below example from the documentation. I'm trying to get the JSON syntax and actions to trigger the timer, but I'm not getting it right. Any suggestions would be appreciated.
I've tried both startTimer and c.startTimer.
var ruleset = {
"risk$state": {
"start": {
"t_0": {
"to": "meter",
"run": "startRiskTimer"
}
},
"meter": {
"t_0": {
"count": 3,
"all": [
{
"message": {
"$gt": {
"amount": 100
}
}
}
],
"to": "fraud",
"run": "logFraud"
},
"t_1": {
"all": [
{
"m": {
"$t": "RiskTimer"
}
}
],
"to": "exit",
"run": "logExit"
}
},
"fraud": {},
"exit": {}
}
}
var h = d.getHost()
h.getAction = function(actionName) {
return function(c) {
if(actionName === 'startRiskTimer') {
startRiskTimer(c)
}
if(actionName === 'logExit') {
logExit(c)
}
if(actionName === 'logFraud') {
logFraud(c)
}
}
}
h.setRulesets(ruleset, function(err, res) {
if(err) {
console.log("ERROR: ", err)
}
})
function startRiskTimer(c) {
console.log('inside startRisk function')
startTimer('RiskTimer', 5)
}
function logExit(c) {
console.log('risk exit for ', c.s.sid)
}
function logFraud(c) {
console.log('inside the logFraud function')
}
d.post('risk', { amount: 200 });
d.post('risk', { amount: 300 });
d.post('risk', { sid: 1, amount: 500 });
d.post('risk', { sid: 1, amount: 600 });
I have the same questions.
For you, did startTimer work ? I have tried c.startTimer("timer_name", duration) but It did work for me and I got exception: 'Error: Could not start timer, error code: 1'