I'm trying to maximize attendance to a event given a list of busy times for each person. The event can be scheduled anytime between a certain date and hours (Ex. March 1st to March 8th from 9-5) and that attendance is maximized.
So far I've tried using a sliding window approach, and a counting approach described here (https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/) however I only managed to get the sliding window approach working with a time complexity of O(n^3) which unfortunately is not good enough for my use case. The counting approach does not work because I can find the maximum interval but not for a certain timeframe.
A worst case scenario use case would be ~500 people and a month timespan.
Any help would be much appreciated.
Solved using a Interval Tree (https://en.wikipedia.org/wiki/Interval_tree)
Related
I am making a player movement with applyForce using matter.js.
I am checking for pressed keys and applying force to my character in my game loop, which is normally called 60 times per second. But the problem begins when FPS drops. If the loop is called only 30 times per second, how can I applyForce the same amount when FPS was 60?
Is there any analog of FixedUpdate like in Unity?
This is a classic problem in game development. One way you can solve this problem is instead of applying the same amount of force in every update, you can check a clock to see how much time has passed since the last update (e.g. call performance.now() in every update). Then multiply the amount of force you want to add by the amount of time that has passed.
I don't think this will work perfectly in all situations. Especially if you have small, fast moving objects, you might find objects clipping through each other. But I think this will be good enough for most cases, and you should be able to code it by hand.
I'm working on an RPG chat coded in old php-mysql and javascript (at the time there was no jquery), and the playing story is about vampires (not a twilight style, I assure you :P).
And I need to set a time watch visible, that doesn't have the real time, but only a night time, extended throughout all day.
For example, at real time 6 AM, must correspond a in-game time of 20PM, and so on, until a real time 5:59AM, which must correspond to a in-game time of 5AM.
So that through the whole real-life day, the in game time span goes only from 20PM to 5AM, only the night, in short.
Is it possible? It's ok to use php and mysql, or even jquery or javascript (even though I think it would be easier done with the last two).
PHP writing is in the old procedural style, not object oriented, just to specify.
Thanks for the replies!
Interesting problem. I would think the algorithm would go something like this:
Calculate what percentage of an actual day has passed.
Use that to calculate how much time has passed in a virtual day (multiply times 32400 to get the number of seconds, probably).
Add that number of seconds to a date object that has been set to 20:00PM on today's date.
How would you chart something like pageviews over time using Highcharts?
Given that page views take place at sporadic irregular intervals, how could you chart this as accurately and legibly as possible?
One way is to group pageviews into time intervals (like days), and then sum up all pageviews on any given day.
The obvious issue here is that if you are only looking at data for a few days, the intervals are too large, and the data fits basically into a few buckets (not really showing any trends).
Another solution I thought of is to have a minimum interval (say, 7 steps) and when less than 7 days of data are requested, (say 3) I could divide that time period into 7 intervals.
However this seems like too much fuss, especially on the backend, for the purpose of simply showing data.
Given that the underlying data does not change, only the manner in which it's rendered, I figured there must be a general solution to this problem.
It depends on what you are trying to discover in the data. If you want to compare it with another data set then use the same scheme it does ("pageviews per day" or whatever). If you want to spot trends over time you need to decide on your horizon and use an appropriate time period (so, for example, if you are trying to justify the purchase of a larger server then perhaps quarterly data comparing this year to last would be good). Designing visualizations for datasets is a huge topic.
So, in other words, I think you pretty much answered your own question.
It looks like the answer is forced Data Grouping
http://api.highcharts.com/highstock/#plotOptions.series.dataGrouping
forced: Boolean
When data grouping is forced, it runs no matter how small the
intervals are. This can be handy for example when the sum should be
calculated for values appearing at random times within each hour.
Defaults to false.
I'll try this and see if it works well
This could work for highstock, but it's not part of highcharts...
Currently, if I click the button, the map will start to animate. But it never stops, it animates infinitely. If there is a map/file is from 2004-2008, I just want that it stops on 2008-12-31 automatically. How can I do that?
I tried
var timeSpan = ge.createTimeSpan('');
timeSpan.getBegin().set('2004');
timeSpan.getEnd().set('2008');
ge.getTime().setTimePrimitive(timeSpan);
But it does not work, I think it may not work for my purpose.
So please help me, I am so strugling....
There's a few things you can do, and it's hard to know what to recommend without know more what you are trying to build. One suggestion:
Don't use the default time slider UI, but rather hide it away and create your own button
On clicking the button, set the time for the plugin to 2004.
Decide upon whatever virtual clock rate you want (e.g. one virtual month per real second, or whatever)
Calculate how long it would take, in real seconds, to get to 2008
do a setTimeout that sets the clock rate to 0 after the appropriate amount of real time has passed (e.g. when the virtual plugin clock makes it to 2008)
This way a user can'd be fiddling with the UI (e.g. dragging the slider around) in a way that interferes with the story you are probably trying to tell...
You can see examples of much of the code mentioned above at http://code.google.com/apis/ajax/playground/#internal_clock_rate and some additional documentation at http://code.google.com/apis/earth/documentation/time.html
I want to show some effect (animate) with the help of jQuery during the time that should be calculated based on how many results are found for a particular needle. The rule is that the effect should continue no longer than 5 minutes and at the very least be 5 seconds long.
So, here's what I do in particular. I search a database for a particular word the user inputs and count the results. Then I search a myself defined word in the same database and count the results. If there are more the latter results than the former results, I need to calculate how long to show the effect. The more the latter results found, the shorter the time the effect should continue. Plus, I need to obey the rule: no longer than 5 minutes, no less than 5 seconds.
I need that to be accurate at best.
That may be a stupid question but I cannot figure out on my own how to calculate the time! :)
jQuery is really well documented; you should be sure to look up documentation before asking questions! http://api.jquery.com/animate/
To answer your question, jQuery's .animation() function takes in a "duration" parameter.
For instance:
$myElement = $("#animatedObject");
$myElement.animate({"width": 500}, 6000); // would animate the width of the object to be 500 pixels over 6000 milliseconds (i.e. 6 seconds).
Just pass in the duration as the second parameter.
If you are asking how to actually calculating that duration, you really need to figure that out yourself or be more clear about where you are facing problems. As it stands it sounds like you haven't attempted to solve this one on your own. As a good starting point, though you will probably want to communicate with some server side scripts using AJAX (http://api.jquery.com/category/ajax/)