I'm new in Esper. Can anyone help me define the EPL statement to catch the event when the following situation occurs:
Assumming that there are events with 3 attributes - (string)Symbol, (boolean)Value, (datetime)Timestamp. For example event1 (Symbol-apple, Value-true, Timestamp- 2020.10.07 14:00:00), event2 (Symbol-orange, Value-true, Timestamp- 2020.10.07 14:00:00) and event3 (Symbol-banana, Value-false, Timestamp- 2020.10.07 14:00:00). If they have same (or almost the same) Timestamp only one of them can have attribute - Value as true. In this example event2 matchs the requirement and should be captured.
How can I define the statement to catch it?
Thanks for any help.
Narsu
The "window" is an aggregation function (see manual) returns the events. The enumeration methods (selectfrom, countof, see manual) are for filtering and selecting. Something like this.
select window(*).selectFrom(v => v.value=true) as eventWithTrueFlag
from Event#length(3)
having window(*).countOf(v => v.value=true)=1 and
prev(1, timestamp)=timestamp and prev(2, timestamp)=timestamp
"Event" is your event type. You didn't say what your event type is named.
"Prev" is the previous function (see manual).
Related
I'm trying to using SyncWithoutDetaching() to update a pivot table (active_pest) but am getting a "Call to a member function active_pest() on array" error message.
The background here is that I have 8 tables: products, pests, actives (i.e active ingredients), crops, active_product, pest_product, crop_product, and active_pest. My form collects information about a selected (agrichemical) product - in that form, the user selects the pests, actives, and crops associated with that product. When submitted, my existing code is saving the expected information in the products table and, through a set of "belongsToMany" relationships, the active_product, pest_product, and crop_product pivot tables are also correctly updated.
For any given product there are typically 1 or 2 actives and 3-8 pests and it is those id values that I want to add to the active_pest pivot table.
My code is:
// ProductController
public function update(UpdateRequest $request)
{
$actives = $request->get('active');
$actives->active_pest()->SyncWithoutDetaching( $request->get('pest'));
...
}
// pest model
public function active_pest()
{
return $this->belongsToMany('App\Models\Pest', 'active_pest', 'active_id', 'pest_id');
}
Answers to other questions about this type of error message indicate that there is something wrong with the active_pest() relationship - but I got the same error message after making a typo there (active_pestr). Regardless, I don't understand what I'm doing wrong.
Insight appreciated. Thanks, Tom
$actives = $request->get('active');
Just return array, so you are trying something like this [1,2,3]->active_pest().
Which is exactly what it says. Call to a member function active_pest() on array.
You need to work with eloquent instance to perform ->active_pest()->SyncWithoutDetaching( $request->get('pest'));
So you can find you instances like this:
$actives = Active::whereIn('col_name', $request->get('active'))->get();
This will return you collection of instances, to save pest for each of them you need to iterate with foreach like this:
foreach($actives as $active){
$active->active_pest()->SyncWithoutDetaching( $request->get('pest'));
}
Here am having multiple Rules in a .drl file. They are updating 6 different JSONArray. These updates are happening in the "then" section of the Drools. Rather than having the similar logic inside the rule, am trying to write a function which will update the 6 JSONArray. How would that be possible ?
declare USER1_LIST
querysetUser1 :JSONArray
end
declare USER2_LIST
querysetUser2 :JSONArray
end
......
......
......
The initialization is happening in a "Set Up" rule with highest Salience -
rule "setUp"
salience 25
when
then
USER1_LIST user1_list = new USER1_LIST();
user1_list.setQuerysetUser1(new JSONArray());
insert(user1_list);
....
In the rule am using one of the list based on the logic -
rule "RULE_XYZ"
salience 5
when
USER1_LIST($querysetUser1 :querysetUser1)
...<Some code>
then
...<Some code>
$querysetUser1.add(...);
Here I want to perform the operation "$querysetUser1.add(...);" inside a function. These JSONArray are updated by different rules. So my aim is to move the logic of selecting the JSONArray and updating it in a function, so that only this function would be called from different rules.
Declared types can be accessed in declared functions. However, from your example, it sounds like you just need to be able to do work against the JSONArray objects contained within the declared types.
The function would look something like this:
function void addToQuerySet(JSONArray querySet, JSONObject object) {// I have guessed the type of 'object'
querySet.add(object);
}
And you would invoke it from the then clause:
rule "RULE_XYZ"
when
USER1_LIST($querysetUser1 :querysetUser1)
// ...<Some code>
someObject: JSONObject() // the thing to insert
then
addToQuerySet($querysetUser1, someObject);
end
What you cannot do is write a generic method that will take any of your USER1_LIST, USER2_LIST, etc declared types because they're all unique and unrelated types, even if they all share the same structure.
Note that the fact that your declared types sharing the same structure is indicative of poor design -- it is likely they should all be instances of a single type, with somet other way of identifying which user it belongs to. For example, something like this:
declare UserList
querySet: JSONArray
userNum: int
end
Where userNum would indicate which user this is for. Then you could write a function that takes a UserList and a JSONObject (or whatever the type is of that thing is you're adding to the query set) like so:
function void addToQuerySet(UserList userList, JSONObject object) {
userList.getQuerySet().add(object);
}
And invoke it in a then clause like so:
rule "RULE XYZ version 2"
when
$user1List: UserList( userNum == 1, querySet != null)
// more code
$someObject: JSONObject() // to insert
then
addToQuerySet( $user1List, $someObject );
end
Please refer to the documentation here. I have linked to the Drools 7.11.0.Final documentation, specifically the section on functions; the section on declared types is the following section and quite extensive.
I need help in understanding that algorithm:
[[Call]]
When the [[Call]] internal method for a Function object F is called with a this value and a list of arguments, the following steps are taken:
Let funcCtx be the result of establishing a new execution context for function code using the value of F's [[FormalParameters]] internal property, the passed arguments List args, and the this value as described in 10.4.3.
Let result be the result of evaluating the FunctionBody that is the value of F's [[Code]] internal property. If F does not have a [[Code]] internal property or if its value is an empty FunctionBody, then result is (normal, undefined, empty).
Exit the execution context funcCtx, restoring the previous execution context.
If result.type is throw then throw result.value.
If result.type is return then return result.value.
Otherwise result.type must be normal. Return undefined.
https://www.ecma-international.org/ecma-262/5.1/#sec-13.2.1
Exactly I need in explanation in 2,4,5,6 clauses.
About 2: First, what does the result of the FunctionBody calculation mean? How is it calculated? What does it mean there is no [[Code]] property when this happens? And most importantly, what does this record mean (normal, undefined, empty).
About 4,5,6: What does result.type mean, result.value? Where does this value come from? Explain for each point
P.S If you vote down, explain why you do that!
First, the [[Call]] is propabily about Function.prototype.call(), so it's better to understand call() first because it's easier than algorithm.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
I get this sample code from the MDN, and try to answer the question roughly. (If you want to understand in detail, you and I have to understand the whole specification, but I don't!)
function greet() {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
}
var obj = {
person: 'Douglas Crockford', role: 'Javascript Developer'
};
greet.call(obj); // Douglas Crockford Is An Awesome Javascript Developer
About 2
First, what does the result of the FunctionBody calculation mean?
FunctionBody is function's code. From the sample, FunctionBody is below.
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
the result of the FunctionBody calculation is the result of the code execution. The result is expressed by Completion Specification Type(explain below). It includes the function return value, but has more wider information.
What does it mean there is no [[Code]] property when this happens?
It's mean empty function as below.
function greet() {
// empty
}
And most importantly, what does this record mean (normal, undefined, empty).
It's Completion Specification Type. This is an expression for value or statement in specification.
Values of the Completion type are triples of the form (type, value, target).
About 4,5,6
What does result.type mean, result.value? Where does this value come from? Explain for each point
result is Completion Specification Type, and the form is (type, value, target).
I'm using a date object to keep track of the current date in an application.
In my view I have a one way binding like this:
<h3>{{ currentDate | date }}</h3>
And in the component, I have functions to change this date, like this:
previousMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() - 1);
}
nextMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() + 1);
}
But when these functions are triggered, the currentDate value doesn't update on the view.
I made sure the date object is being updated, just not on the view.
Whenever I remove the date pipe, it works.
Anyone has any idea how to fix this?
Thanks!
The value is not updating in the view because the pipes in angular are so called pure (or, stateless) by default. That means that the input will not be re-evaluated if the input object changes, but only if it's replaced.
From the documentation (see section Pure and Impure pipes):
Angular executes a pure pipe only when it detects a pure change to the
input value. A pure change is either a change to a primitive input
value (String, Number, Boolean, Symbol) or a changed object reference
(Date, Array, Function, Object).
Try the following code instead:
previousMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() - 1);
this.currentDate = new Date(this.currentDate);
}
nextMonth(){
this.currentDate.setMonth(this.currentDate.getMonth() + 1);
this.currentDate = new Date(this.currentDate);
}
I am in the process of learning RX and have run across a sample on the Intro to Rx site that I have a question about. Here is the example which implements the same functionality as the Window with count extension method:
public static IObservable<IObservable<T>> MyWindow<T>(
this IObservable<T> source,
int count)
{
var shared = source.Publish().RefCount();
var windowEdge = shared
.Select((i, idx) => idx % count)
.Where(mod => mod == 0)
.Publish()
.RefCount();
return shared.Window(windowEdge, _ => windowEdge);
}
I understand the purpose of the var shared = source.Publish().RefCount() line to 'share' the source with the window edge query. What I don't understand is why the windowEdge query was also defined with the .Publish().RefCount()? Can someone please help me understand why this would be necessary?
Good Question!
Long Answer
Aside from performance reasons, the reason windowEdge is ref-counted has to do with the use of Select.
In this example, Select is using the index argument (idx), who's value is determined uniquely for each new subscriber. Therefore, if we did not ref-count windowEdge, each new subscriber would receive an event upon the next item yielded, since mod == 0 will always be true.
This means without ref-counting that each window would consist of exactly two values (assuming no other race conditions are introduced). Example:
When the first event fires, we create a new window and feed in the event, at which point we also use the window-closing selector to obtain an observable which will yield when the window should close. The next event fires, and is sent to the current window. That event also happens to be the first event that is sent to our window-closing observable (because mod == 0 is always true). The window-closing observable has now fired, and the window is closed, leaving us with a window which contains exactly two elements. Repeat.
TLDR
The use of ref-count for windowEdge is necessary to ensure we're only incrementing idx once per "MyWindow" observable.