Code to obtain the maximum value out of a list and the three consecutive values after the maximum value - sum

I am writing a model to calculate the maximum production capacity for a machine in a year based on 15-min data. As the maximum capacity is not the sum of the required capacity for all 15-min over the year, I want to write a piece of code that determines the maximum value in the list and then adds this maximum value and the three next consecutive values after this maximum value to a new variable. An simplified example would be:
fifteen_min_capacity = [10, 12, 3, 4, 8, 12, 10, 9, 2, 10, 4, 3, 15, 8, 9, 3, 4, 10]
The piece of code I want to write would be able to determine the maximum capacity in this list (15) and then add this capacity plus the three consecutive ones (8,9,3) to a new variables:
hourly_capacity = 35
Does anyone now the code that would give this output?
I have tried using the max(), the sum() and a combination of both. However, I do not get a working code. Any help would be much appreciated!

Related

Dask aggregate value into fixed range with start and end time?

In dask or even pandas how would you go about grouping an dask data frame that has a 3 columns of time / level / spread into a set of fixed ranges by time.
Time is only used to move one direction. Like a loop counting up. So the end result would be start time and end time with high of level, low of level, first value of level and last value of level over the fixed range? Example
12:00:00, 10, 1
12:00:01, 11, 1
12:00:02, 12, 1
12:00:03, 11, 1
12:00:04, 9, 1
12:00:05, 6, 1
12:00:06, 10, 1
12:00:07, 14, 1
12:00:08, 11, 1
12:00:09, 7, 1
12:00:10, 13, 1
12:00:11, 8, 1
For a fixed level range of (7). So level from start to end can not be more than 7 total distance from start to end for each bin of level. Just because first bin is only 8 difference in time and second is only 2 different in time, this dose not madder one the high to low madders that the total distance from high to low dose not go passed 7 the fixed bin size. The first bin could have been 5 not 8 for first bin and 200 for next bin not 2 in the example below. So the First few rows in dask would look something like this.
First Time, Last Time, High Level, Low Level, First Level, Last Level, Spread
12:00:00, 12:00:07, 13, 6, 10, 13, 1
12:00:07, 12:00:09, 14, 7, 13, 7, 1
12:00:09, X, 13, 7, X, X, X
How could this be aggregated in dask with a fix window of level moving forward in time binning each time level moves above X or equal too high/low with in X or below X?

Hadoop Pig Query

Whenever I try to run this query, it returns zero records even though I know there are records that meet this criteria.
I want to find records where column 10 is equal to 0, 1, 2, or 3 and column 16 is equal to 4, 5, 6, or 7.
Pig Script:
newdata = FILTER data BY ((((($10==0) OR ($10==1)
OR ($10==2)
OR ($10==3)))) AND
(((($16==4) OR ($16==5)
OR ($16==6)
OR ($16==7)))));
Column indexes start from 0, so the 10th column will be $9 and 16th column with me $15.Try this
newdata = FILTER data BY ((($9==0) OR
($9==1) OR
($9==2) OR
($9==3))
AND
(($15==4) OR
($15==5) OR
($15==6) OR
($15==7)));

Alternating threads in JMeter

I have made a selection form a huge amount of ID's, using the following query:
select ID from [tabelname] where id > 0 and id < 31
This gives me 30 ID's to work with.
What I would like to do now, is to use 3 threads, with the first one using ID 1, 4, 7, 10 etc, the second ID 2, 5, 8, 11 etc and the third one ID 3, 6, 9, 12 etc.
Up until now, I have only been able to have all threads use ID 1 through 30 parallel to each other. Would it be at all possible to do this?
Thanks in advance!
JMeter has a build-in operation that you can use in combination with a pre-processor to find the current thread number:
https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html#getThreadNum()
If you now use ctx.getThreadGroup().getNumThreads() to find the number of threads you're using, you can basically divide your testset into subsets and let each thread compute on its own subset (e.g. thread1 computes on 0..10, thread2 on 11..20, thread3 on 21..30, etc..)

How to floor a number in sql based on a range

I would like to know if there is a function or some sort of way to round a number to lowest whole value. Something like floor, but to a specified increment like 10. So for example:
0.766,5.0883, 9, 9.9999 would all be floored to 0
11.84848, 15.84763, 19.999 would all be floored to 10
etc...
I'm basically looking to fit numbers in the ranges of 0, 10, 20, 30, etc
Can I also do it with different ranges? For example 0, 100, 200, 300, etc
Thank you.
You can do this with arithmetic and floor():
select 10*floor(val / 10)
You can replace the 10s with whatever value you want.

Order of insertion for worst case black height of a red black tree

Lets say we are dealing with the keys 1-15. To get the worst case performance of a regular BST, you would insert the keys in ascending or descending order as follows:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
Then the BST would essentially become a linked list.
For best case of a BST you would insert the keys in the following order, they are arranged in such a way that the next key inserted is half of the total range to be inserted, so the first is 15/2 = 8, then 8/2 = 4 etc...
8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15
Then the BST would be a well balanced tree with optimal height 3.
The best case for a red black tree can also be constructed with the best case from a BST. But how do we construct the worst case for a red black tree? Is it the same as the worst case for a BST? Is there a specific pattern that will yield the worst case?
You are looking for a skinny tree, right? This can be produced by inserting [1 ... , 2^(n+1)-2] in reverse order.
You won't be able to. A Red-Black Tree keeps itself "bushy", so it would rotate to fix the imbalance. The length of your above worst case for a Red-Black Tree is limited to two elements, but that's still not a "bad" case; it's what's expected, as lg(2) = 1, and you have 1 layer past the root with two elements. As soon as you add the third element, you get this:
B B
\ / \
R => R R
\
R