INTERVAL duration literals in TDEngine - intervals

I am not able to find duration literals used by INTERVAL keyword in TDEngine. E.g. select count(*) from mytable interval(1m); works for 1-minute intervals, but I don't know what letter should be used for 1-month interval. I would like to know all possible duration intervals available.

Let's see source code. It seems TDEngine supports these duration intervals:
/*
* b - nanoseconds;
* u - microseconds;
* a - Millionseconds
* s - Seconds
* m - Minutes
* h - Hours
* d - Days (24 hours)
* w - Weeks (7 days)
* n - Months (30 days)
* y - Years (365 days)
*/

Related

How calculate working time in Oracle PLSQL

How calculate working time eg.
7.5 = 7h and 30 min (working hours)
0.75 = 45 min (pause)
8 = 8h (Planing hours)
How get result eg. (-15 min) below query return 00:15 is it possible get in minus or use have better example?
Select
to_char(time'0:0:0'+numtodsinterval((7.5 + 0.75 - 8 ),'hour'),'hh24:mi')
from dual
You have the arithmetic backwards and to get a negative number you want 8 - (7.5 + 0.75).
Don't use a time and just use the interval (and extract the sign, hour and minute components using string functions if you want a different format):
SELECT numtodsinterval(8 - (7.5 + 0.75),'hour') AS interval,
REGEXP_REPLACE(
numtodsinterval(8 - (7.5 + 0.75),'hour'),
'([+-]?)(\d+) (\d+):(\d+):(\d+\.?\d*)',
'\1\3:\4'
) AS hhmm
FROM DUAL;
Outputs:
INTERVAL
HHMM
-000000000 00:15:00.000000000
-00:15
fiddle

How do I get the counter clockwise value using the modulo operator?

Let's say we have a 24 hour clock where all time is represented in minutes. That gives us 24 * 60 possible time points from 0 hours to 24 hours. The clockwise distance between two time points T1, T2 is simply |T1 - T2| since the time is represented in minutes.
Now, how do I obtain the counter clockwise distance between T1 and T2 ? Would I do something like
(-|T1 - T2|) % 1440?
have you considered:
24 * 60 - |T1 - T2|

Configure schedule in spring boot range hour [duplicate]

This question already has answers here:
Spring Scheduling - Cron expression for everyday at midnight not working?
(5 answers)
Closed 3 years ago.
Hello guys
I want to work my schedule at every minute between 8am - 10pm.
I tried that code.
#Scheduled(cron = "0 */1 8-22 * * MON-FRI")
But it doesn't work! I am confused. Help me!
you can find out crontab information StackOverflow link
These are valid formats for cron expressions:
0 0 * * * * = the top of every hour of every day.
*/10 * * * * * = every ten seconds.
0 0 8-10 * * * = 8, 9 and 10 o'clock of every day.
0 0 6,19 * * * = 6:00 AM and 7:00 PM every day.
0 0/30 8-10 * * * = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day.
0 0 9-17 * * MON-FRI = on the hour nine-to-five weekdays
0 0 0 25 12 ? = every Christmas Day at midnight
The pattern is:
second, minute, hour, day, month, weekday

Scheduling: advance deadline for implicit-deadline rate monotonic algorithm

Given a set of tasks:
T1(20,100) T2(30,250) T3(100,400) (execution time, deadline=peroid)
Now I want to constrict the deadlines as Di = f * Pi where Di is new deadline for ith task, Pi is the original period for ith task and f is the factor I want to figure out. What is the smallest value of f that the tasks will continue to meet their deadlines using rate monotonic scheduler?
This schema will repeat (synchronize) every 2000 time units. During this period
T1 must run 20 times, requiring 400 time units.
T2 must run 8 times, requiring 240 time units.
T3 must run 5 times, requiring 500 time units.
Total is 1140 time units per 2000 time unit interval.
f = 1140 / 2000 = 0.57
This assumes long-running tasks can be interrupted and resumed, to allow shorter-running tasks to run in between. Otherwise there will be no way for T1 to meet it's deadline once T3 has started.
The updated deadlines are:
T1(20,57)
T2(30,142.5)
T3(100,228)
These will repeat every 1851930 time units, and require the same time to complete.
A small simplification: When calculating factor, the period-time cancels out. This means you don't really need to calculate the period to get the factor:
Period = 2000
Required time = (Period / 100) * 20 + (Period / 250) * 30 + (Period / 400) * 100
f = Required time / Period = 20 / 100 + 30 / 250 + 100 / 400 = 0.57
f = Sum(Duration[i] / Period[i])
To calculate the period, you could do this:
Period(T1,T2) = lcm(100, 250) = 500
Period(T1,T2,T3) = lcm(500, 400) = 2000
where lcm(x,y) is the Least Common Multiple.

Progressive non-linear algorithm for increasing discount

A system has to support 100 users and the price for support is 3
A system has to support 10 000 users and the price for support is 1
I have to devise an algorithm to give me the price in between so it will gradually rise with the number of users.
I tried to multiply the number of users by 0.0002 to get the discount value and I got
300 users * 0.0002 = 0.06 discount, so price for support = 2.94
total income = 300 * 2.94 = 882
5000 users * 0.0002 = 1 discount, so price for support = 2
total income = 5000 * 2 = 10 000
8000 users * 0.0002 = 1.6 discount, so price for support = 1.4
total income = 8000 * 1.4 = 11 200
10 000 users * 0.0002 = 2 discount, so price for support = 1
total income = 8000 * 1.4 = 10 000
So you see after a given point I am actually having more users but receiving less payment.
I am not a mathematician and I now this is not really a programming question, but I don't know where else to ask this. I will appreciate if someone can help me with any information. Thanks!
price = n * (5 - log10(n)) will work for 100 < n < 10000.
Just make sure you're using base-10 log and not natural (base-e) log. If your language doesn't have base-10 log normally, you can calculate it like this:
function log10(x) { return log(x)/log(10); }.
For 100 users, that's 100 * (5 - log10(100)), which gives 100 * (5 - 2), which is 300.
For 1000 users, that's 1000 * (5 - log10(1000)), which gives 1000 * (5 - 3), which is 2000.
For 10000 users, that's 10000 * (5 - log10(10000)), which gives 10000 * (5 - 4), which is 10000.
Let's pick some more random figures.
2500 users: 2500 * (5 - log10(2500)) gives us 2500 * (5 - 3.39794), which is 4005.
6500 users: 6500 * (5 - log10(6500)) gives us 6500 * (5 - 3.81291), which is 7716.
8000 users: 8000 * (5 - log10(8000)) gives us 8000 * (5 - 3.90309), which is 8775.
Should work out about right for what you're modelling.
Scaling the price per user linearly didn't work as you showed, but you can try scaling the total income linearly instead.
total income for 100 users = 300
total income for 10000 users = 10000
total income for n users = (n-100) / (10000-100) * (10000-300) + 300
You know that the total income for n users is the price for support per user times the number of users, that means, now you have to find the function f(n) such that f(n) * n = (n-100) / (10000-100) * (10000-300) + 300.
And if you have to show that as the total income always increase, the price for support always decrease, just show that f'(n) ≤ 0 when 100 ≤ n ≤ 10000.

Resources