Specify arbitrary start and end times for cron job - quartz-scheduler

For Quartz Cron, is it possible at all to specify a cronexpression that corresponds to:
Run every 6 minutes, starting from 9:12 AM until 5:37 PM.
I attempted to write the cronexpression 0 12-37/6 9-17 ? * * but this does only runs once an hour. I also understand that the cronexpression 0 /6 9-17 ? * * corresponds to Run every 6 minutes between the hours of 9 AM and 5 PM.
But is there any way to constrain the starting and ending minutes on that cronexpression? More generally, can I specify an arbitrary start and end time with the job in question running every n intervals of time?

You can do it with 3 cron strings:
0 12-59/6 9 * * *
0 /6 10-16 * * *
0 0-37/6 17 * * *
Give them all the same task to run.

Related

Marking values from the previous N number of days in KDB based on criteria?

Initial Table
company time value
-------------------------
a 00:00:15.000 100
a 00:00:30.000 100
b 00:01:00.000 100
a 00:01:10.000 100
a 00:01:15.000 100
a 00:01:20.000 300
a 00:01:25.000 100
b 00:01:30.000 400
a 00:01:50.000 100
a 00:02:00.000 100
a 00:00:03.000 200
Let t = 1 hour.
For each row, I would like to look back t time.
Entries falling in t will form a time window. I would like to get max(time window) - min (time window) / number of events).
For example, if it is 12:00 now, and there are a total of five events, 12:00, 11:50, 11:40, 11:30, 10:30, four of which falls in the window of t i.e. 12:00, 11:50, 11:40, 11:30, the result will be 12:00 - 11:30 / 4.
Additionally, the window should only account for rows with the same value and company name.
Resultant Table
company time value x
--------------------------------
a 00:00:15.000 100 0 (First event A).
a 00:00:30.000 100 15 (30 - 15 / 2 events).
b 00:01:00.000 100 0 (First event of company B).
a 00:01:10.000 100 55/3 = 18.33 (1:10 - 0:15 / 3 events).
a 00:01:15.000 100 60/4 = 15 (1:15 - 0:15 / 4 events).
a 00:01:20.000 300 0 (Different value).
a 00:01:25.000 100 55/4 = 13.75 (01:25 - 0:30 / 4 events).
b 00:01:30.000 400 0 (Different value and company).
a 00:01:50.000 100 40/4 = 10 (01:50 - 01:10 / 4 events).
a 00:02:00.000 100 50/5 = 10 (02:00 - 01:10 / 5 events).
a 00:03:00.000 200 0 (Different value).
Any help will be greatly appreciated. If it helps, I asked a similar question, which worked splendidly: Sum values from the previous N number of days in KDB?
Table Query
([] company:`a`a`b`a`a`a`a`b`a`a`a; time: 00:00:15.000 00:00:30.000 00:01:00.000 00:01:10.000 00:01:15.000 00:01:20.000 00:01:25.000 00:01:30.000 00:01:50.000 00:02:00.000 00:03:00.000; v: 100 100 100 100 100 300 100 400 100 100 200)
You may wish to use the following;
q)update x:((time-time[time binr time-01:00:00])%60000)%count each v where each time within/:flip(time-01:00:00;time) by company,v from t
company time v x
---------------------------------
a 00:15:00.000 100 0
a 00:30:00.000 100 7.5
b 01:00:00.000 100 0
a 01:10:00.000 100 18.33333
a 01:15:00.000 100 15
a 01:20:00.000 300 0
a 01:25:00.000 100 13.75
b 01:30:00.000 400 0
a 01:50:00.000 100 10
a 02:00:00.000 100 10
a 03:00:00.000 200 0
It uses time binr time-01:00:00 to get the index of the min time for the previous 1 hour of each time.
Then (time-time[time binr time-01:00:00])%60000 gives the respective time range (i.e., time - min time) for each time in minutes.
count each v where each time within/:flip(time-01:00:00;time) gives the number of rows within this range.
Dividing the two and implementing by company,v applies it all only to those that have the same company and v values.
Hope this helps.
Kevin
If your table is ordered by time then below solution will give you the required result. You can also order your table by time if it is not already using xasc.
I have also modified the table to have time with different hour values.
q) t:([] company:`a`a`b`a`a`a`a`b`a`a`a; time: 00:15:00.000 00:30:00.000 01:00:00.000 01:10:00.000 01:15:00.000 01:20:00.000 01:25:00.000 01:30:00.000 01:50:00.000 02:00:00.000 03:00:00.000; v: 100 100 100 100 100 300 100 400 100 100 200)
q) f:{(`int$x-x i) % 60000*1+til[count x]-i:x binr x-01:00:00}
q) update res:f time by company,v from t
Output
company time v res
---------------------------------
a 00:15:00.000 100 0
a 00:30:00.000 100 7.5
b 01:00:00.000 100 0
a 01:10:00.000 100 18.33333
a 01:15:00.000 100 15
a 01:20:00.000 300 0
a 01:25:00.000 100 13.75
b 01:30:00.000 400 0
a 01:50:00.000 100 10
a 02:00:00.000 100 10
a 03:00:00.000 200 0
You can modify the function f to change time window value. Or change f to accept that as an input parameter.
Explanation:
We pass time vector by company, value to a function f. It deducts 1 hour from each time value and then uses binr to get the index of the first time entry within 1-hour window range from the input time vector.
q) i:x binr x-01:00:00
q) 0 0 0 0 1 2 2
After that, it uses the indexes of the output to calculate the total count. Here I am multiplying the count by 60000 as time differences are in milliseconds because it is casting it to int.
q) 60000*1+til[count x]-i
q) 60000 120000 180000 240000 240000 240000 300000
Then finally we subtract the min and max time for each value and divide them by the above counts. Since time vector is ordered(ascending), the input time vector can be used as the max value and min values are at indexes referred by i.
q) (`int$x-x i) % 60000*1+til[count x]-i

Simulink: Creating a repeating irregular square wave

I want to genereate a square wave to represent different uptimes for a lightning installation over a year.
The schedule over a week is the following:
Mon-Thu: 06.00-20.00
Fri: 06.00-18.00
Sat: no uptime
Sun: no uptime
So my wave should repeat every 168 hours (one week) and look like this:
Time Signal
0-6 0
6-20 1
20-30 0
30-44 1
44-54 0
54-68 1
68-78 0
78-94 1
94-104 0
104-116 1
116-168 0
I've tried some with the repeating sequence block using the following:
Time values:[0 6 6.001 20 20.001 30 30.001 44 44.001 54 54.001 68 68.001 78 78.001 94 94.001 104 104.001 116 116.001 168]
Output values: [0 repmat([0 1 1 0],1,5) 0]
But since I'm simulating over 8760 (a year in hours) it seems that the step is f*cking things up.
Is there any better way or good way to make this work?
Thanks a bunch.

groupby functions to get subsequent value

In my data I have stock volumes for order sequence and times, I need to go through each part of the order and find when it ends, by grabbing the next part of the chains time.
I am just starting in python and I would do this by subsetting each stock into its own pool, then adding then do another loop to find the time of the next order for that sequence. Ultimately, in R/Matlab you could go X$time[1:end-1] <- X$time[2:end,]
My question: can I use the df.groupby['sequence'].{for each entry get the time from the subsequent entry}???
I think last() would give me the last value of that entire sequence, I would like the time of that the next sequence starts/ appears
I have a set of type:
sequence time
a 1
b 1
a 3
a 5
b 2
I would like
sequence time nexttime
a 1 3
b 1 2
a 3 5
a 5 999
b 2 999
In [24]: df
Out[24]:
sequence time
0 a 1
1 b 1
2 a 3
3 a 5
4 b 2
In [25]: df['nexttime'] = df.groupby('sequence').time.shift(-1).fillna(999)
In [26]: df
Out[26]:
sequence time nexttime
0 a 1 3
1 b 1 2
2 a 3 5
3 a 5 999
4 b 2 999

Retrieve Month, Day, Hour, Minute, from a number in minute

i want create a counter that retrieve the number of month, day, hour, minute from a given number in minutes, for example i know that:
60 minutes in an hour
24 hours in a day = 60 x 24 = 1440 minutes
31 days per month
1 month = 24 x 60 x 31 = 44,640 minutes
so if i give for example the number 44640 i want have 1 month 0 day 0 hour 0 minute , or for example if i give 44700 i want have 1 month, 0 day 0 hour 60 minute or 1 month 0 day 1 hour 0 minute
any help please?
int total_minutes = 44640;
int total_hours = total_minutes / 60;
int minutes = total_minutes % 60;
int total_days = total_hours / 24;
int hours = total_hours % 24;
int months = total_days / 31;
int days = total_days % 31;
printf("%d months, %d days, %02d:%02d\n", months, days, hours, minutes);
But that's misleading, since months are not all 31 days. On average, a month in the Gregorian calendar is 30.436875 days (43829.1 minutes), so you could use that figure. For many applications, such calculations just assume that a month is always 30 days. But if your time interval is anchored to a specific point in time, it might be better to use the date at both ends to determine how many whole months there are between them.

What is the expression for Quartz cron trigger to run at every day at 00hr?

What is the Quartz cron trigger expression for batch job run at 00hr every day?
To fire at 10:15am every day
0 15 10 * * ?
To fire at 00:00 every day
0 0 0 * * ?
0 0 0 * *
http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger