Reactive.jl fps which only runs for N frames - julia

The fps function in Reactive.jl allows for creating a signal that activates at the given frequency.
Is it possible to create something similar, but which terminates after a given duration or number of activations?

Fengyang is right. You can do this with fpswhen
switch = Signal(true)
#async (sleep(10); push!(switch, false))
ticks = fpswhen(switch, 60)
Here ticks will update at 60 fps for 10 seconds.

Related

How to detect the start and end of pieces in a stitched video?

I am trying to figure out how to process a special video for an application that I trying to build. After days of research, I cannot figure out how to achieve what I am trying to build:
The user passes in a video that is X minutes long. The video was produced was stitching together multiple videos of variable length(with a maximum length per video of K seconds, say 60). The purpose of the app is to detect when each video starts and ends within the larger video of X minutes.
For example, the user passes in a video that is 25(this is X) minutes long. We know that a single video cannot be more than 10(this is K) minutes. So the maximum number of videos that the user could have stitched together to produce the input video is 3 videos(Two ten minute videos and one 5 minute video). But this is not always case, another possible combination is(Five 5 minute videos, etc).
I've been researching this for days and cannot come up with any way mathematically to solve this(very possibly due to my limited math knowledge). Is it possible to solve this problem(where each of the stitched videos begin and end)?
Thank you for any help! It's sincerely appreciated.
If you want to use only integer units (munutes, seconds), then calculate two values
R = X % K - integer modulo 7 % 3 = 1, residue
M = X / K -integer division 7 / 3 = 2
If residue R is zero, then overall number of video segments is M, else M + 1.
Start time of i-th video segment is Ts[i] = i * K
End time of i-th video segment is Te[i] = (i + 1) * K for all but the last segment Te[last] = X
I hope it is very basic math.

R : Display plot while calculating [duplicate]

This question already has answers here:
Plotting during a loop in RStudio
(7 answers)
Closed 8 years ago.
I wrote an R script which does a lot of heavy calculation. The script enters a while loop and proceeds it around 16 times (which lasts between 3 and 5 minutes a loop in average).
I would like to be able to "track" the calculation progresses: be able to see how much has been done and how much remains to be done. So I just printed the number of the iteration and the calculation time for a finished loop.
What I would like to add is a kind of a "progression bar", which I represent by a ggplot2 histogram. Every time a calculation is finished, I update the plot (the "finished" area grows bigger and the "remaining" area subsequently diminishes), and I print it. But, no plot shows in the "plot" area of R studio while the function is still executing. All plots appears once the overall calculation (of the 16 loops) is finished.
So my question is: Is it possible to display a plot at the end of a while loop, even if the "overall" calculation is not over?
If I am not being clear, please tell me.
Thank you in advance for your answers.
EDIT: Sys.sleep() works very well for what I intended.
If anyone is interested in the code, here follows:
# Big calculation
iter <- iter + 1
d <- data.frame(x1 = c(1,1), x2 = c(iter/maxIt, 1 - iter/maxIt),
x3 = c("finished", "remaining"))
print(qplot(d$x1, d$x2, fill = factor(d$x3), geom = "histogram", stat = "identity"))
Sys.sleep(1)
# Preparing the next loop
timearray <- NULL # array of time used by each iteration
for (wait in c(3,2,5,4,6)) {
s <- Sys.time() # iteration time start
Sys.sleep(3) # do your calculation -- I just wait here
s <- Sys.time() - s # now s is last iteration time
timearray <- c(timearray, s) # add this new value to array
plot(timearray, type='h', main='Iteration time') # plot the array
}
Could it be something like that?

Calculate the max samples with ramp up

I got this math problem. I am trying to calculate the max amount of samples when the response time is zero. My test has 3 samples (HTTP Request). The total test wait time is 11 seconds. The test is run for 15 minutes and 25 seconds. The ramp up is 25 seconds, this means that for every second 2 users are created till we reach 50.
Normally you have to wait for the server to respond, but I am trying to calculate the max amount of samples (this means response time is zero.) How do i do this. I can't simply do ((15 * 60 + 25) / 11) * 50. Because of the ramp up.
Any ideas?
EDIT:
Maybe I should translate this problem into something generic and not specific to JMeter So consider this (maybe it will make sense to me aswel ;)).
50 people are walking laps around the park. Each lap takes exactly 11 seconds to run. We got 15 minutes and 25 seconds to walk as many as possible laps. We cannot start all at the sametime but we can start 2 every second (25seconds till we are all running). How many laps can we run?
What i end up doing was manually adding it all up...
Since it takes 25s to get up to full speed, only 2 people can walk for 900s and 2 people can walk for 901s and 2 people can walk for 902s all the way to total of 50 people..
Adding that number together should give me my number i think.
If I am doing something wrong or based on wrong conclusion I like to hear your opinion ;). Or if somebody can see a formula.
Thanks in advance
I have no idea about jmeter, but I do understand your question about people running round the park :-).
If you want an exact answer to that question which ignores partial laps round the park, you'll need to do (in C/java terminology) a for loop to work it out. This is because to ignore partial laps it's necessary to round down the number of possible laps, and there isn't a simple formula that's going to take the rounding down into account. Doing that in Excel, I calculate that 4012 complete laps are possible by the 50 people.
However, if you're happy to include partial laps, you just need to work out the total number of seconds available (taking account of the ramp up), then divide by the number of people starting each second, and finally divide by how many seconds it takes to run the lap. The total number of seconds available is an arithmetic progression.
To write down the formula that includes partial laps, some notation is needed:
T = Total number of seconds (i.e. 900, given that there are 15 minutes)
P = number of People (i.e. 50)
S = number of people who can start at the Same time (i.e. 2)
L = time in seconds for a Lap (i.e. 11)
Then the formula for the total number of laps, including partial laps is
Number of Laps = P * (2 * T - (P/S - 1)) / (2*L)
which in this case equals 4036.36.
Assume we're given:
T = total seconds = 925
W = walkers = 50
N = number of walkers that can start together = 2
S = stagger (seconds between starting groups) = 1
L = lap time = 11
G = number of starting groups = ceiling(W/N) = 25
Where all are positive, W and N are integers, and T >= S*(G-1) (i.e. all walkers have a chance to start). I am assuming the first group start walking at time 0, not S seconds later.
We can break up the time into the ramp period:
Ramp laps = summation(integer i, 0 <= i < G, N*S*(G-i-1)/L)
= N*S*G*(G-1)/(2*L)
and the steady state period (once all the walkers have started):
Steady state laps = W * (T - S*(G-1))/L
Adding these two together and simplifying a little, we get:
Laps = ( N*S*G*(G-1)/2 + W*(T-S*(G-1)) ) / L
This works out to be 4150 laps.
There is a closed form solution if you're only interested in full laps. If that's the case, just let me know.

Simple Steering Behaviour: Explain This Line

I am reading the book Programming Game AI by Example, and he gives code for
a steering behaviour which causes the entity to decelerate so that it arrives
gracefully at a target. After calculating dist, the distance from target to
source he then (essentially) does this
double speed = dist/deceleration;
I just cannot understand where this comes from however, am I just missing something
really obvious? It is not listed as a known error in the book so I am guessing it
is correct.
If there was some physical truth to this, the units would have match up on either side.
From what I understand, this is akin to Zeno's paradoxes where you are trying to reach something, but you never get there because you always only travel one nth of the remaining distance.
Suppose
the simulation proceeds at intervals of one second at a time.
deceleration = 5
distance = 1000 meters
With these initial conditions, speed will be set to 200 meters per second. Because the simulation proceeds at intervals of one second, we will travel exactly 200 meters (i.e. one fifth of the remaining distance), and end up at a distance of 800 meters from the target. The new speed is determined to be: 160 meters per second
Here is what happens in the first 30 seconds:
The last 30 seconds:
The last 10 seconds:
Observations
Within the first 30 seconds, we travel roughly 998 meters
Within the first 50 seconds, we cover 999.985 meters
Within the last 10 seconds, we cover only ~1.2cm
As you can see, you get almost there very quickly, but it takes a long time to get close.
Plots by WolframAlpha
Maybe there is something missing in your calculation. For a constant accelaration (or decelleration), and ignoring initial condictions, the speed is
v = a * t
and the distance is
d = a * t^2 / 2
If you eliminate t in both equations you get
v = a * sqrt(2 * d / a)

Constant Pointer / structs

In my programming class, we have
struct Time {
int hours, min, sec;
}
We are to create a method to compute the difference between two times:
Time *timeDiff(const Time *t1, const Time *t2)
I thought I could create the time difference by getting everything in seconds, and then subtracting the two values, but it seems like extra work to do something like
long hour1 = t1->hours;
long min1 = t1->min;
long sec1 = t1->sec;
And then using these values to get the time in seconds, do something similar for the second time, and then subtract. Any thoughts? Thanks!
The way you've described it sounds exactly right. I might do something like
int sec = t1->sec + 60*(t1->min + 60*t1->hours);
Then similarly for t2, then subtract one from the other and break the result down into minutes and hours.

Resources