Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The system shall accept one measurement every second. The system shall present 6 real-time plots:
last minute
last hour
last day
last week
last month
last year.
For example, here is a beautiful yearly plot of the measurement presenting the average temperature for every month of the year(suppose the plot consists of 12 datapoints, connected with straight lines). When and how should I update it? The worst case is to re-calcucate the average temperature for each month at every measurement (once per second), then redraw the plot.
The plot of last minute we solve with a circular buffer - the new measurement is simply pushed to the deque eveyr second.
What about the other plots? How do we minimize the re-calculations for each one?
Solution
Keep averages of all vectors. Whe a new event happens, check which vectors to update (time % vector_sample_period). For the chosen vectors, ask the previous vector for it's average and push it in own circular buffer.
You minimize re-calculation by calculating only when needed. For example when you start over on the circular buffers.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Let's say I want to write a Rate limiter.
By Rate limiter, I mean that suppose we want that our server should entertain only 5 requests per user in the last 5 minutes.
We have to write a function that returns a boolean that if we can accept the current requests or not?
Which data structure will be used for this? How will we update entries that are more than the last 5 minutes older?
You need a FIFO queue holding a maximum of 5 times.
Upon a request, purge the times older than 5 minutes. Then if there is room left, accept the request and push the current time.
Update:
To handle the multiple users, it does not seem foolish to hold one queue per user (ring buffer), given that they are short.
Otherwise, you can store all times in a single array and organize them as doubly linked lists, with pointers to the start of the lists, per user.
You need queue with size 5, containing timestamps of requests.
With every request you check if last timestamp younger then 5 min.
If it does, you fail the request.
If it doesn't, you remove last element and push new timestamp.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So i have an opera houses with 10 rows and 10 columns of seats (Total :100). Each seat is allocated a preference value Aij. The preference value is halved if the group do not get seats in same row. Eg: If a reservation in opera house is for 5 people and only 2 can be accommodated in top row and 3 in next row, the preference value is actually halved for each seat. There are total of n reservations with 'n' > 100 seats. What will the best way to maximize the customer preference (n *Aij).If it can be done by linear programming, how should the equation look like.
I think this is not trivial to model as a MIP.
I gave it a try using a main binary variable x(i,j,g,r) where (i,j) is the row and column of the seat assigned to group g. The set r is {singlerow,multiplerows} to indicate whether the group is sitting in the same row.
Not sure if this is a particular good formulation, but it seems to work. Below are the equations I used:
I assumed that there are a number of groups g that each have a size. A group gets all seats it needs or it is not getting any seats.
I suspect that a constraint programming approach could be easier.
Conclusion: it can be done using a MIP formulation but it is somewhat cumbersome.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am working on task http://poj.org/problem?id=1884. I didn't understand just one part of it:
Adjacent stations on each route are far enough apart to allow a train to accelerate to its maximum velocity before beginning to decelerate.
Does it mean that train is accelerating and then going in constant speed/velocity before it goes to deaccelrate or it is accelerating for longer period, and when it comes to max velocity, it is immediately going to deaccelerate?
The fist one, yes, "train is accelerating and then going in constant speed/velocity before it goes to deaccelrate".
Basically the train accelerates as much as it can, then maintains maximum speed for the journey, then brakes as approaches the station.
What they meant was: if the station were too close, trains would have to accelerate then brake before reaching peak speed to be able to stop in the next station, but you don't have this problem.
from the text:
It remains at that maximum velocity until it begins to decelerate (at
the same constant rate) as it approaches the next station.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When you use slow shutter speed of the SLR camera to take photo . You can get special effect. for example http://img.photobucket.com/albums/v157/Oilfan94/Rocky%20Mountains%20-%202007/5856-FR-web.jpg.
Are there any possibilities that I use mutil-images to simulate these result. I mean take a series of photos from the same scene. Then merge these photos. I have tried to merge these images . but the effect is so bad
Since a pixel value in a photograph corresponds to the amount of light that reached that point on the sensor while the shutter was open, I'd assume you could just do (pseudocode)
out(i, j) = sum(frame_n(i, j) for each n) / n
to get the average over the time interval.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
The above image represents an article's page views over time. I'm looking for a decent, not to complex either physics or statistical calculation that would be able to give me (based on the history of the page views) what the current trending of the page views is for the past n days (which is represented by the blue box).
So basically, in the past 5 days is this link trending unusually higher than it usually does and if so by what degree/magnitude?
Ideally the accepted answer would provide an algorithm class that applies to this problem as well as some example of that using the data provided from this chart above.
thanks!
One approach could be to perform a least squares fit of the points within the blue box. Trends could then measured by the difference between the points and the least squares fit approximation value.
It sounds like you want to compare a short term (5-day) moving average to a longer-term moving average (e.g., something like 90 days).
As a refinement, you might want to do a least-squares linear regression over the longer term, and then compare the shorter term average to the projection you get from that.