You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@unomi.apache.org by Ben Schiefer <be...@gmail.com> on 2020/04/29 13:04:21 UTC

Proper usage of pastEventCondition

Hello, and thanks for Unomi, its awesome.

I've been wading through the unomi code for the last few days trying to
figure out how to properly use the pastEventCondition type in a segment.  I
am able to register the segment just fine and have it execute against
elastic correctly, but when the "setEventOccurenceCountAction" picks up the
Auto Generated rule to try to increment the count of this event on the
"pastEvents" map on a profile, the action fails with an error because the
eventCondition is null on this line (
https://github.com/apache/unomi/blob/ea1b788ec82b2ad8e404236e21d974a11e68429a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java#L53
)

Here is my segment definition
```
{
  "metadata": {
    "id": "10viewstoday",
    "name": "At least 10 views in last day",
    "scope": "systemscope",
    "description": "Profile with at least 10 views in last 1 day",
    "readOnly": true,
    "enabled": true
  },
  "condition": {
    "type": "pastEventCondition",
    "parameterValues": {
      "eventCondition": {
        "type": "booleanCondition",
        "parameterValues": {
          "operator": "and",
          "subConditions": [
            {
              "type": "eventTypeCondition",
              "parameterValues": {
                "eventTypeId": "view"
              }
            },
            {
              "type": "eventPropertyCondition",
              "parameterValues": {
                "propertyName": "target.itemType",
                "propertyValue": "flow",
                "comparisonOperator": "equals"
              }
            }
          ]
        }
      },
      "numberOfDays": 1,
      "minimumEventCount": 10
    }
  }
}
```


Here is the auto generated rule for that segment
```
{
    "_index": "context",
    "_type": "rule",
    "_id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
    "_version": 1,
    "_score": 1,
    "_source": {
        "itemId": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
        "itemType": "rule",
        "condition": {
            "parameterValues": {
                "eventTypeId": "view"
            },
            "type": "eventTypeCondition"
        },
        "actions": [
            {
                "parameterValues": {
                    "pastEventCondition": {
                        "parameterValues": {
                            "operator": "and",
                            "subConditions": [
                                {
                                    "parameterValues": {
                                        "eventTypeId": "view"
                                    },
                                    "type": "eventTypeCondition"
                                },
                                {
                                    "parameterValues": {
                                        "propertyName": "target.itemType",
                                        "propertyValue": "flow",
                                        "comparisonOperator": "equals"
                                    },
                                    "type": "eventPropertyCondition"
                                }
                            ],
                            "generatedPropertyKey":
"eventTriggered62e083f24cb05e41a2c046c5c4be2086"
                        },
                        "type": "booleanCondition"
                    }
                },
                "type": "setEventOccurenceCountAction"
            }
        ],
        "linkedItems": [
            "10viewstoday"
        ],
        "raiseEventOnlyOnceForProfile": false,
        "raiseEventOnlyOnceForSession": false,
        "priority": 0,
        "metadata": {
            "id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
            "name": "Auto generated rule for At least 10 views in last day",
            "description": "",
            "scope": "systemscope",
            "tags": [],
            "systemTags": [],
            "enabled": true,
            "missingPlugins": false,
            "hidden": true,
            "readOnly": false
        }
    }
}
```



Any help you could provide would be greatly appreciated.  I'm not sure if
i'm using the pastEventCondition improperly in my segment, or if there is a
bug when generating the rule in the segment service (
https://github.com/apache/unomi/blob/27859f99d3b33640b6e6cf62f9b878e56994039d/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java#L728
)


Thanks in advance,
Ben

Re: Proper usage of pastEventCondition

Posted by Ben Schiefer <be...@gmail.com>.
Hi Gary!

Thanks so much for the prompt response.  I have tried switching the booleanCondition to the highest most condition, but am still seeing an error in the karaf logs when the setEventOccurenceAction attempts to apply the past event count to the actual profile.  Any ideas?  (Just to reiterate, the profile shows the segment properly before and after your recommended change, its just seeming to fail to write to the "cached" value on the profile, so it needs to do query elastic for the value every time)

Here is the output from the log.
```
2020-04-29T11:49:54,052 | ERROR | qtp563823312-3093 | ActionExecutorDispatcher         | 184 - org.apache.unomi.services - 1.4.0 | Error executing action with key=setEventOccurenceCount
java.lang.IllegalArgumentException: Condition is null or doesn't have type, impossible to build filter
        at org.apache.unomi.persistence.elasticsearch.conditions.ConditionESQueryBuilderDispatcher.buildFilter(ConditionESQueryBuilderDispatcher.java:61) [173:org.apache.unomi.persistence-elasticsearch-core:1.4.0]
        at org.apache.unomi.plugins.baseplugin.conditions.BooleanConditionESQueryBuilder.buildQuery(BooleanConditionESQueryBuilder.java:55) [175:org.apache.unomi.plugins-base:1.4.0]
        at org.apache.unomi.persistence.elasticsearch.conditions.ConditionESQueryBuilderDispatcher.buildFilter(ConditionESQueryBuilderDispatcher.java:78) [173:org.apache.unomi.persistence-elasticsearch-core:1.4.0]
        at org.apache.unomi.persistence.elasticsearch.conditions.ConditionESQueryBuilderDispatcher.buildFilter(ConditionESQueryBuilderDispatcher.java:56) [173:org.apache.unomi.persistence-elasticsearch-core:1.4.0]
        at org.apache.unomi.persistence.elasticsearch.ElasticSearchPersistenceServiceImpl.queryCount(ElasticSearchPersistenceServiceImpl.java:1339) [173:org.apache.unomi.persistence-elasticsearch-core:1.4.0]
        at Proxy320ead0b_030e_44f0_902c_03348bcbcd61.queryCount(Unknown Source) [?:?]
        at org.apache.unomi.plugins.baseplugin.actions.SetEventOccurenceCountAction.execute(SetEventOccurenceCountAction.java:76) [175:org.apache.unomi.plugins-base:1.4.0]
```

Thanks again, Gary!


On 2020/04/29 13:20:14, Gary Thayer <ga...@10up.com> wrote: 
> Hi Ben!
> 
> I think that you are close, but you have the segment conditions inverted.
> You'd want the highest most condition to be the `booleanCondition`. (Does
> the user, or does the user not meet this condition.)
> 
> Inside of that is where you'd use the `pastEventCondition`. Below is an
> example from a project I am working on. Hopefully this will help you get a
> better sense of the structure.
> 
> ```
> 
> >     "condition": {
> >         "parameterValues": {
> >             "subConditions": [
> >                 {
> >                     "type": "pastEventCondition",
> >                     "parameterValues": {
> >                         "numberOfDays": 10,
> >                         "minimumEventCount": 1,
> >                         "eventCondition": {
> >                             "type": "eventPropertyCondition",
> >                               "parameterValues" : {
> >                                 "propertyName" :
> > "target.properties.pageInfo.taxonomies.category",
> >                                 "comparisonOperator" : "contains",
> >                                 "propertyValue" : "arrangement"
> >                               }
> >                         }
> >                     }
> >                 }
> >             ],
> >             "operator": "and"
> >         },
> >         "type": "booleanCondition"
> >     }
> 
> ```
> 
> On Wed, Apr 29, 2020 at 9:04 AM Ben Schiefer <be...@gmail.com> wrote:
> 
> > Hello, and thanks for Unomi, its awesome.
> >
> > I've been wading through the unomi code for the last few days trying to
> > figure out how to properly use the pastEventCondition type in a segment.  I
> > am able to register the segment just fine and have it execute against
> > elastic correctly, but when the "setEventOccurenceCountAction" picks up the
> > Auto Generated rule to try to increment the count of this event on the
> > "pastEvents" map on a profile, the action fails with an error because the
> > eventCondition is null on this line (
> > https://github.com/apache/unomi/blob/ea1b788ec82b2ad8e404236e21d974a11e68429a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java#L53
> > )
> >
> > Here is my segment definition
> > ```
> > {
> >   "metadata": {
> >     "id": "10viewstoday",
> >     "name": "At least 10 views in last day",
> >     "scope": "systemscope",
> >     "description": "Profile with at least 10 views in last 1 day",
> >     "readOnly": true,
> >     "enabled": true
> >   },
> >   "condition": {
> >     "type": "pastEventCondition",
> >     "parameterValues": {
> >       "eventCondition": {
> >         "type": "booleanCondition",
> >         "parameterValues": {
> >           "operator": "and",
> >           "subConditions": [
> >             {
> >               "type": "eventTypeCondition",
> >               "parameterValues": {
> >                 "eventTypeId": "view"
> >               }
> >             },
> >             {
> >               "type": "eventPropertyCondition",
> >               "parameterValues": {
> >                 "propertyName": "target.itemType",
> >                 "propertyValue": "flow",
> >                 "comparisonOperator": "equals"
> >               }
> >             }
> >           ]
> >         }
> >       },
> >       "numberOfDays": 1,
> >       "minimumEventCount": 10
> >     }
> >   }
> > }
> > ```
> >
> >
> > Here is the auto generated rule for that segment
> > ```
> > {
> >     "_index": "context",
> >     "_type": "rule",
> >     "_id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
> >     "_version": 1,
> >     "_score": 1,
> >     "_source": {
> >         "itemId": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
> >         "itemType": "rule",
> >         "condition": {
> >             "parameterValues": {
> >                 "eventTypeId": "view"
> >             },
> >             "type": "eventTypeCondition"
> >         },
> >         "actions": [
> >             {
> >                 "parameterValues": {
> >                     "pastEventCondition": {
> >                         "parameterValues": {
> >                             "operator": "and",
> >                             "subConditions": [
> >                                 {
> >                                     "parameterValues": {
> >                                         "eventTypeId": "view"
> >                                     },
> >                                     "type": "eventTypeCondition"
> >                                 },
> >                                 {
> >                                     "parameterValues": {
> >                                         "propertyName": "target.itemType",
> >                                         "propertyValue": "flow",
> >                                         "comparisonOperator": "equals"
> >                                     },
> >                                     "type": "eventPropertyCondition"
> >                                 }
> >                             ],
> >                             "generatedPropertyKey":
> > "eventTriggered62e083f24cb05e41a2c046c5c4be2086"
> >                         },
> >                         "type": "booleanCondition"
> >                     }
> >                 },
> >                 "type": "setEventOccurenceCountAction"
> >             }
> >         ],
> >         "linkedItems": [
> >             "10viewstoday"
> >         ],
> >         "raiseEventOnlyOnceForProfile": false,
> >         "raiseEventOnlyOnceForSession": false,
> >         "priority": 0,
> >         "metadata": {
> >             "id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
> >             "name": "Auto generated rule for At least 10 views in last
> > day",
> >             "description": "",
> >             "scope": "systemscope",
> >             "tags": [],
> >             "systemTags": [],
> >             "enabled": true,
> >             "missingPlugins": false,
> >             "hidden": true,
> >             "readOnly": false
> >         }
> >     }
> > }
> > ```
> >
> >
> >
> > Any help you could provide would be greatly appreciated.  I'm not sure if
> > i'm using the pastEventCondition improperly in my segment, or if there is a
> > bug when generating the rule in the segment service (
> > https://github.com/apache/unomi/blob/27859f99d3b33640b6e6cf62f9b878e56994039d/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java#L728
> > )
> >
> >
> > Thanks in advance,
> > Ben
> >
> 
> 
> -- 
> *Gary Thayer* • Lead Web Engineer, 10up <http://10up.com/>
> 

Re: Proper usage of pastEventCondition

Posted by Gary Thayer <ga...@10up.com>.
Hi Ben!

I think that you are close, but you have the segment conditions inverted.
You'd want the highest most condition to be the `booleanCondition`. (Does
the user, or does the user not meet this condition.)

Inside of that is where you'd use the `pastEventCondition`. Below is an
example from a project I am working on. Hopefully this will help you get a
better sense of the structure.

```

>     "condition": {
>         "parameterValues": {
>             "subConditions": [
>                 {
>                     "type": "pastEventCondition",
>                     "parameterValues": {
>                         "numberOfDays": 10,
>                         "minimumEventCount": 1,
>                         "eventCondition": {
>                             "type": "eventPropertyCondition",
>                               "parameterValues" : {
>                                 "propertyName" :
> "target.properties.pageInfo.taxonomies.category",
>                                 "comparisonOperator" : "contains",
>                                 "propertyValue" : "arrangement"
>                               }
>                         }
>                     }
>                 }
>             ],
>             "operator": "and"
>         },
>         "type": "booleanCondition"
>     }

```

On Wed, Apr 29, 2020 at 9:04 AM Ben Schiefer <be...@gmail.com> wrote:

> Hello, and thanks for Unomi, its awesome.
>
> I've been wading through the unomi code for the last few days trying to
> figure out how to properly use the pastEventCondition type in a segment.  I
> am able to register the segment just fine and have it execute against
> elastic correctly, but when the "setEventOccurenceCountAction" picks up the
> Auto Generated rule to try to increment the count of this event on the
> "pastEvents" map on a profile, the action fails with an error because the
> eventCondition is null on this line (
> https://github.com/apache/unomi/blob/ea1b788ec82b2ad8e404236e21d974a11e68429a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java#L53
> )
>
> Here is my segment definition
> ```
> {
>   "metadata": {
>     "id": "10viewstoday",
>     "name": "At least 10 views in last day",
>     "scope": "systemscope",
>     "description": "Profile with at least 10 views in last 1 day",
>     "readOnly": true,
>     "enabled": true
>   },
>   "condition": {
>     "type": "pastEventCondition",
>     "parameterValues": {
>       "eventCondition": {
>         "type": "booleanCondition",
>         "parameterValues": {
>           "operator": "and",
>           "subConditions": [
>             {
>               "type": "eventTypeCondition",
>               "parameterValues": {
>                 "eventTypeId": "view"
>               }
>             },
>             {
>               "type": "eventPropertyCondition",
>               "parameterValues": {
>                 "propertyName": "target.itemType",
>                 "propertyValue": "flow",
>                 "comparisonOperator": "equals"
>               }
>             }
>           ]
>         }
>       },
>       "numberOfDays": 1,
>       "minimumEventCount": 10
>     }
>   }
> }
> ```
>
>
> Here is the auto generated rule for that segment
> ```
> {
>     "_index": "context",
>     "_type": "rule",
>     "_id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
>     "_version": 1,
>     "_score": 1,
>     "_source": {
>         "itemId": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
>         "itemType": "rule",
>         "condition": {
>             "parameterValues": {
>                 "eventTypeId": "view"
>             },
>             "type": "eventTypeCondition"
>         },
>         "actions": [
>             {
>                 "parameterValues": {
>                     "pastEventCondition": {
>                         "parameterValues": {
>                             "operator": "and",
>                             "subConditions": [
>                                 {
>                                     "parameterValues": {
>                                         "eventTypeId": "view"
>                                     },
>                                     "type": "eventTypeCondition"
>                                 },
>                                 {
>                                     "parameterValues": {
>                                         "propertyName": "target.itemType",
>                                         "propertyValue": "flow",
>                                         "comparisonOperator": "equals"
>                                     },
>                                     "type": "eventPropertyCondition"
>                                 }
>                             ],
>                             "generatedPropertyKey":
> "eventTriggered62e083f24cb05e41a2c046c5c4be2086"
>                         },
>                         "type": "booleanCondition"
>                     }
>                 },
>                 "type": "setEventOccurenceCountAction"
>             }
>         ],
>         "linkedItems": [
>             "10viewstoday"
>         ],
>         "raiseEventOnlyOnceForProfile": false,
>         "raiseEventOnlyOnceForSession": false,
>         "priority": 0,
>         "metadata": {
>             "id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a",
>             "name": "Auto generated rule for At least 10 views in last
> day",
>             "description": "",
>             "scope": "systemscope",
>             "tags": [],
>             "systemTags": [],
>             "enabled": true,
>             "missingPlugins": false,
>             "hidden": true,
>             "readOnly": false
>         }
>     }
> }
> ```
>
>
>
> Any help you could provide would be greatly appreciated.  I'm not sure if
> i'm using the pastEventCondition improperly in my segment, or if there is a
> bug when generating the rule in the segment service (
> https://github.com/apache/unomi/blob/27859f99d3b33640b6e6cf62f9b878e56994039d/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java#L728
> )
>
>
> Thanks in advance,
> Ben
>


-- 
*Gary Thayer* • Lead Web Engineer, 10up <http://10up.com/>