How do I achieve the same effect of Spark Streaming sliding window, which runs at X sliding interval over the last Y window length.
Looking at Esper, it should be win:time and win:time_batch, where win:time >= win:time_batch.
I managed to solve this problem in less customizable but easier way (at least for me), by using win:time with OUTPUT EVERY x
SELECT value
FROM Entry.win:time(10 sec)
OUTPUT EVERY 5 sec
Works as I intended - every 5 seconds I get results from the last 10 seconds.
In esper the equivalent is to declare a context.
create context BucketOf10Sec start #now end after 10 seconds;
context BucketOf10Sec select sum(price) from MyEvent;
Related
I have the following script running with the intention of closing a trade after it has been open for a period of 4 days since the trade was taken.
TimeDiff = time - time[1]
MinutesPerBar = TimeDiff / 60000
//calcuates how long one bar is in minutes
BarsSinceSwingLongCondition = barssince(SwingLongCondition)
// Calculates how many bars have passed since open of trade
CurrentSwingTradeDuration = BarsSinceSwingLongCondition * MinutesPerBar
//calculates the duration that the trade has been opened for (minutes*number of bars)
MaximumSwingTradeDuration = 4*1440
// Sets maximum trade duration. Set at 4 Days in minutes
SwingLongCloseLogic3 = CurrentSwingTradeDuration > MaximumSwingTradeDuration
// Closes trade when trade duration exceeds maximum duration set (4days)
The close logic however isn't executing when I run the strategy as i have trades open for longer than the maximum duration.
Is there any way to see what value each element of the formula is calculating so that I can see where the error is (i suspect it could be the time element). Or can anyone see where I am going wrong in the code?
The fastest way to achieve that is using the plotchar function, which would show the values in the data-window on mouse-over on each bar. The user manual contains several other techniques available for debugging.
my issue is that I want to be able to get two time stamps and compare if the second (later taken) one is less than 59 minutes away from the first one.
Following this thread Compare two dates with JavaScript
the date object may do the job.
but first thing i am not happy with is that it takes the time from my system.
is it possible to get the time from some public server or something?
cause there always is a chance that the system clock gets manipulated within the time stamps, so that would be too unreliable.
some outside source would be great.
then i am not too sure how to get the difference between 2 times (using 2 date objects).
many issue that may pop up:
time being something like 3:59 and 6:12
so just comparing minutes would give the wrong idea.
so we consider hours too.
biut there the issue with the modulo 24.
day 3 23:59 and day 4 0:33 wouldnt be viewed proper either.
so including days too.
then the modulo 30 thing, even though that on top changes month for month.
so month and year to be included as well.
so we would need the whole date, everything from current year to second (because second would be nice too, for precision)
and comparing them would require tons of if clauses for year, month, etc.
do the date objects have some predfeined date comparision function that actually keeps all these things in mind (havent even mentioned leap years yet, have I)?
time would be very important cause exactly at the 59 minutes mark (+-max 5 seconds wouldnt matter but getting rmeitely close to 60 is forbidden)
a certain function would have to be used that without fail closes a website.
script opens website at mark 0 min, does some stuff rinse and repeat style and closes page at 59 min mark.
checking the time like every few seconds would be smart.
Any good ideas how to implement such a time comparision that doesnt take too more computer power yet is efficient as in new month starting and stuff doesnt mess it up?
You can compare the two Date times, but when creating a date time there is a parameter of DateTime(value) which you can use.
You can use this API to get the current UTC time which returns a example JSON array like this:
{
"$id":"1",
"currentDateTime":"2019-11-09T21:12Z",
"utcOffset":"00:00:00",
"isDayLightSavingsTime":false,
"dayOfTheWeek":"Saturday",
"timeZoneName":"UTC",
"currentFileTime":132178075626292927,
"ordinalDate":"2019-313",
"serviceResponse":null
}
So you can use either the currentFileTime or the currentDateTime return from that API to construct your date object.
Example:
const date1 = new Date('2019-11-09T21:12Z') // time when I started writing this answer
const date2 = new Date('2019-11-09T21:16Z') // time when I finished writing this answer
const diff = new Date(date2-date1)
console.log(diff.toTimeString()) // time it took me to write this
Please keep in mind that due to network speeds, the time API will be a little bit off (by a few milliseconds)
For Each drow As DataGridViewRow In DgvItemList.Rows
drow.Cells("strSrNo").Value = drow.Index + 1
Next
I have more than 3500 records in DgvItemList. I just give to numbering to that records but it tool 9 to 10 minutes for that.
How to reduce this time ?
Two things. Each time you change the value, it could cause the DataGridView to update, so just before your loop, add
DgvItemList.SuspendLayout
and after the loop, add
DgvItemList.ResumeLayout
You could also change the loop to a Parallel.For loop, so your final code would be something like
DgvItemList.SuspendLayout
Parallel.For(0, DgvItemList.Rows.Count, Sub(index As Integer)
DgvItemList.Rows(index).Cells("strSrNo").Value = DgvItemList.Rows(index).Index + 1
End Sub)
DgvItemList.ResumeLayout
Try it with just the Suspend and Resume layout first. You may not get a vast amount of improvement from the parallelization. Worth a go though.
I am trying out WSO2 CEP for our new requirement. Currently i have written a query to find timedout events.
from InputStream#window.time(5 minutes)
select *
insert into TimeoutRequest for expired-events.
But my requirement is, the 5 minutes mentioned in time window will vary from each request. Some request should get timeout in 5 mins and some in 10 minutes. How to pass dynamic value for window.time(n minutes). If we can do via Custom Transformer or Custom Window, i am not getting the right context on how to do this.
There can be different approaches to implement this:
Custom window - you can write you own window (extending the time window) which looks for a specific attribute in events to determine their timeout durations.
If there is only a limited set of time durations, you can simply define a window for each duration and point the incoming events to the relevant window using a filter.
e.g:
from InputStream[timeoutValue == 5]#window.time(5 minutes) select * insert into TimeoutRequest for expired-events
from InputStream[timeoutValue == 10]#window.time(10 minutes) select * insert into TimeoutRequest for expired-events
I have a timer that ticks every 3 seconds.
If the timer found something a messagebox will show.
Then the timer should wait 30 seconds, before he show again the messagebox (the user of course must have time to react).
How can I handle this?
I tried a Thread.Sleep(30000), but the GUI blocks of course.
My other Idea is a second timer that will be activated after the first ticks and reactivate the first timer in the tick-method.
So: t1 tick -> msg box -> after click -> t2 enable (30 sec tick) -> t2 tick, enable t1
But I think thats not a good idea, is there a better way?
Depends on the Language.
In any case you have to create a second Thread that does the waiting and checking.
In case of .NET you might want to look into the "BackgroundWorker"
Use System.Windows.Forms.Timer