Why bufferTime(5000, 10000) shows values that I created after 5000ms - rxjs

Code:
const source = Rx.Observable.fromEvent(document.getElementById('click'), 'click')
const example = source.bufferTime(5000,10000);
const subscribe = example.subscribe(val => console.log('Start Buffer Every 1s:', val));
jsfiddle
I don't understand two things:
Why first value is returned after 5s not 10s
After 10s (as soon as I see empty array in console) I start clicking btn. I do it for 4 seconds, and after 10s there is still empty array. But if I start clicking after 5 seconds since the appearance of an empty array in the console, there is a proper result.
I thought that it will work like "Every 10 seconds, emit the click events from the next 5 seconds". But it doesn't.

bufferTime(bufferTimeSpan: number, bufferCreationInterval: number, ..)
// bufferTimeSpan: The amount of time to fill each buffer array.
// bufferCreationInterval: The interval at which to start new buffers.
bufferTimeSpan < bufferCreationInterval ⟹ gaps between buffer intervals
Example 1: bufferTimer(5000, 10000)
// 1. bufferCreationInterval = 10000
// open the buffer every 10 seconds, start with an open buffer
┌ 5 ┌ 10 ┌ 15 ┌ 20 ┌ 25 ┌ 30 ┌ 35 ┌ 40 ┌ 45 ┌ 50
bufferInterval: [----- -----[----- -----[----- -----[----- -----[----- -----[---
// 2. bufferTimeSpan = 5000
// close the buffer 5 seconds after it was opened
┌ 5 ┌ 10 ┌ 15 ┌ 20 ┌ 25 ┌ 30 ┌ 35 ┌ 40 ┌ 45 ┌ 50
bufferInterval: [~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~
As soon as I see empty array in console I start clicking button, I do
it for 4 seconds.
┌┬┬┬ sounds like you click here, nothing is recorded
││││
bufferInterval: [~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~
If I start clicking after 5 seconds since the appearance of an empty
array in the console, there is a proper result.
┌┬┬┬ sounds like you click here, values are buffered
││││
bufferInterval: [~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~~~]-----[~~~
bufferTimeSpan > bufferCreationInterval ⟹ overlapping buffer intervals
Example 2: bufferTimer(2000, 1000)
// 1. bufferCreationInterval = 1000
// open the buffer every 1 seconds, start with an open buffer
┌ 5 ┌ 10 ┌ 15 ┌ 20
bufferInterval: (- [- {- (- [- {- (- [- {- (- [- {- (- [- {- (- [- {- (- [- {- (-
// 2. bufferTimeSpan = 2000
// close the buffer 2 seconds after it was opened
┌ 5 ┌ 10 ┌ 15 ┌ 20
bufferInterval: (~ [~){~](~}[~){~](~}[~){~](~}[~){~](~}[~){~](~}[~){~](~}[~){~](~}
// split into multiple layers for better view
layer1: (~ ~) - (~ ~) - (~ ~) - (~ ~) - (~ ~) - (~ ~) - (~ ~) - (~
layer2: - [~ ~] - [~ ~] - [~ ~] - [~ ~] - [~ ~] - [~ ~] - [~ ~] -
layer3: - - {~ ~} - {~ ~} - {~ ~} - {~ ~} - {~ ~} - {~ ~} - {~ ~}

Related

Cumulative sum by category with DAX (Without Date dimension)

This is the input data (Let's suppose that I have 14 different products), I need to calculate with DAX, cumulative Total products by Status
ProductID
Days Since LastPurchase
Status
307255900
76
60 - 180 days
525220000
59
30 - 60 days
209500000
20
< 30 days
312969600
151
60 - 180 days
249300000
52
30 - 60 days
210100000
52
30 - 60 days
304851400
150
60 - 180 days
304851600
150
60 - 180 days
314152700
367
> 180 days
405300000
90
60 - 180 days
314692300
90
60 - 180 days
314692400
53
30 - 60 days
524270000
213
> 180 days
524280000
213
> 180 days
Desire ouput:
Status
Cumulative Count
< 30 days
1
> 180 days
4
30 - 60 days
8
60 - 180 days
14
That's trivial: Just take the build in Quick measure "Running total", see screenshot.
The resulting table will look like this:
However, when you think about it, from a data point of view a sort order like the following makes more sense than ordering "status" by alphabet,
and finally you can take it straight away without any crude categorization

How to get hour equally weight average in Amazon QuickSight?

I want to aggregate value as hour equally weight average not general average.
Let's say I have the following dataset.
datetime
HH
value
2022-01-01T14:20
14
100
2022-01-01T14:30
14
80
2022-01-02T14:50
14
30
2022-01-01T15:00
15
60
2022-01-01T15:10
15
60
2022-01-01T15:15
15
60
2022-01-02T15:25
15
0
And I want to get this result.
HH
hour equally weight average
14
60
15
30
Calculation example for HH=14
General average calculation:(100 + 80 + 30)/3 = 70
But I want to get hour equally weight average:(100 + 80)/2 + 30/1 = 60
Calculation example for HH=15
General average calculation: (60 + 60 + 60 + 0)/4 = 45
hour equally weight average: (60 + 60 + 60)/3 + 0/1 = 30
I tried to use avgOver and sumOver, but failed.
Please help

How to calculate which second of song will be playing after x minutes of repeating?

I am not doing pretty well with algorithms, so I need your help :)
Case: I play a song that lasts 3 minutes 40 seconds at 1st August 00:00 (for example). How could I be able to calculate which second of the song will be playing after (again, for expample) 3 days, 7 hours, 3 minutes and 54 seconds or any other time interval?
Sorry if it sounds lame :(
That's a use case for the modulo operator, that gives the remainder of a division.
10 / 3 is 3 * 3 + 1. The +1 is the remainder
It's as simple as :
SecondOfTheSongCurrentlyPlaying = TotalSecondsElapsed % LengthOfTheSongInSeconds
In example, if the song lasts 3 minutes 40 seconds, this is 220 seconds.
3 days, 7 hours, 3 minutes and 54 seconds are 284 634 seconds.
284634 % 220 == 174 seconds

Using Arrays to Calculate Previous and Next Values

Is there a way I can use Clickhouse (Arrays?) to calculate sequential values that are dependent on previously calculated values.
For e.g.
On day 1, I start with 0 -- consume 5 -- Add 100 -- ending up with = 0 - 5 + 100 = 95
My day2, starts with what I ended up on day 1 which is 95 -- again consume 10 -- add 5 -- ending up with 95-10+5=90 (which will be the start for day3)
Given
ConsumeArray [5,10,25]
AddArray [100,5,10]
Calculate EndingPosition and (= StartingPosition for Next day)
-
Day1 Day2 Day3
--------------------------------------------------------------------
StartingPosition (a) = Previous Ending Position | 0 95 90 Calculate
Consumed (b) | 5 10 25
Added (c) | 100 5 10
EdingPosition (d) = a-b+c | 95 90 75 Calculate
Just finish all the add/consume operations first and then do an accumulation.
WITH [5,10,25] as ConsumeArray,
[100,5,10] as AddArray
SELECT
arrayCumSum(arrayMap((c, a) -> a - c, ConsumeArray, AddArray));

How to calculate Total average response time

Below are the results
sampler_label count average median 90%_line min max
Transaction1 2 61774 61627 61921 61627 61921
Transaction2 4 82 61 190 15 190
Transaction3 4 1862 1317 3612 1141 3612
Transaction4 4 1242 915 1602 911 1602
Transaction5 4 692 608 906 423 906
Transaction6 4 2764 2122 4748 1182 4748
Transaction7 4 9369 9029 11337 7198 11337
Transaction8 4 1245 890 2168 834 2168
Transaction9 4 3475 2678 4586 2520 4586
TOTAL 34 6073 1381 9913 15 61921
My question here is how is total average response time is being calculated (which is 6073)?
Like in my result I want to exclude transaction1 response time and then want to calculate Total average response time.
How can I do that?
Total Avg Response time = ((s1*t1) + (s2*t2)...)/s
s1 = No of times transaction 1 was executed
t1 = Avg response time for transaction 1
s2 = No of times transaction 2 was executed
t2 = Avg response time for transaction 2
s = Total no of samples (s1+s2..)
In your case, except transaction1 all other transactions have been executed 4 times. So, simple avg of (82, 1862, 1242...) should give the result you wanted.

Resources