I've been asked to build a prize giveaway web page with the following competition parameters:
A user can only enter the competition once per day
It's an instant win competition, the user will know if they have won or not when they enter
We want to give away on average 1 prize per hour
My first thought was at the start of each hour, to select a random second within that hour for the prize to be given away. The first user who enters after that second is the winner. If a hour goes past where no one actually enters, a new time will be chosen somewhere in the next 12 hours to give away that hours prize (this is to stop the late night prizes all being given away in the morning).
I can't tell if this will be random enough for a fair competition. Also, there is a slight security risk in that if someone were to view the upcoming prize draw database record, they could enter at the right time and win the prize.
Is there a better way to achieve this?
Related
I am running a Tennis Website in behalf of a friend of mine because she's not that really passionate about technology and computers.
When we create a tournament subscription page, users and amateur tennis players fill out a form to subscribe to that tournament.
There is a field in the form where the user can describe their availability based on their needs.
Basically, users write when they can play matches, and most of the times they are time costraints, like for example:
"I can play all the evenings after 9.00 PM",
"only in the weekdays",
"because of work, I can play only in the weekends",
"Always, except not after 10.00 PM every evening because I have to wake up early".
I call them time costraints.
Yesterday I found a new costraint, and it is like so:
"Me (UserA) and my friend (userB) will share the car in order to partecipate in the tournament, because we live far from you, and we have to travel long miles and we would like to come together in order to save fuel.
As long as my friend is not eliminated in the tournament, I'd prefer to play in similar times with my friend (userB).
If my friend is eliminated, I can always play everytime"
My question now is if there is an algorithm to satisfy all these costraints, or a precooked solution my friend can use even if she's not a techie or a geek.
I undertand that this algorithm should run after every day, because of course match winners are not known in advance and hence user time costraints vary.
I also understand it is an operations research problem, but I haven't got experience and I'm not a professional programmer.
Please leave any pointer you may have on specific literature or software.
Thanks
There is no precooked solution to such problems AFAIK. Somebody will have to build a model and an application for that.
As suggested, Constraint Programming is one technique that solves this kind of problem and proposes solutions that satisfy all given constraints. Choco is a very handy open source tool.
However, you may want to formulate it as an optimization problem. You want the algorithm to place each pair UserA/UserB in the same day/time slot when scheduling the next round. How many such pairs are there? What if it is not possible to place all such pairs?
Go for the largest number of pairs would be doable using MILP. Maybe take history into account and average out the number of times each pair comes together ? Such a model is definitely more complex...
I'm building a calendar scheduling application for, let's say a plumbing company. The company has one or more plumbers, who each have a schedule of appointments at different times throughout the day. So Josh's schedule on May 30th might include a 30-minute appointment at 10 AM, a 45-minute appointment at 1 PM, and an hour-long appointment at 3 PM, while Maria has a completely different schedule that day. Now say a customer wants to book an appointment with this company, and my program has already calculated the time this new appointment will take. I want my program to return a list of possible appointment times for any plumber(s). Is there a standard algorithm for this type of problem?
I'd prefer language-agnostic, general steps just to be more helpful to anyone who might be in a similar situation with a different language, though I'm using PHP and PostgreSQL if there's a specific language feature suited to this.
Here's what I've tried so far:
Get all available shifts for every plumber on the requested day
Get all appointments already made on that day
Do a sort of boolean subtraction to cut the appointments out of the shifts, leaving gaps in each plumber's schedule
Get rid of all schedule gaps that are smaller than the requested appointment length (I also calculate drive times here so I know how far appointments need to be from one another)
Return those gaps to the customer, trimmed to the appointment length, as appointment possibilities
I've learned that the problem with this approach is that it doesn't understand what to do with a gap much larger than the requested appointment. If you have a gap from 10 AM to 6 PM but you want an hour-long appointment, it will only suggest 10 AM to 11 AM. This approach doesn't allow for time-of-day choices, either. In that same scenario, what if the customer wants a morning appointment? Then it should only suggest 10-11 and 11-12. Or if they want an evening appointment, it should only suggest 5-6 PM. This approach also doesn't consider two plumbers working together. If we assume that two workers = half the time, then maybe the algorithm should look for the same 30 minutes available in both Josh and Maria's schedules along with 60-minute gaps in either plumber's schedule. Lastly, this algorithm feels very inefficient.
By the way, I've looked at several other questions here and around the Internet about how to solve similar situations, but I'm finding that most (if not all) of those questions involve optimizing a schedule. That might be valuable for other parts of this program, but for now, let's assume that the existing appointments are fixed and unchangeable. We're just looking to fit a new appointment into an existing schedule. I know this is possible because applications like Calendly have similar inputs and outputs.
In short, is there a better way of meeting these goals:
Suggest available gaps in one plumber's schedule given a time interval
If possible, only return appointment possibilities in the given time of day (morning = 4-12, afternoon = 12-5, evening = 5-10, night = 10-4, or any), and if not possible, continue with the algorithm as if no time of day had been specified
Suggest smaller gaps where n plumbers might do the job in 1/n time (there aren't that many plumbers, so setting a limit on this isn't necessary). This isn't as important as the other criteria, so if this isn't possible or would make the algorithm far more complex, then don't worry about it.
Split big appointment gaps into smaller gaps so we can suggest 4 hour-long gaps in between 10 AM and 2 PM. Obviously we can't suggest all possible hour-long segments of that gap because they'd be infinite
Thank you in advance.
There is no need for any sophisticated algorithm. There is only a small number of possible appointment times throughout a day, let's say every 30 minutes or so. Iterate over all possible times: 06:00, 06:30, 07:00, ... 20:00. Check each time if it matches the requirements, that check can either return a yes/no result, or a number that say how good a match that time is. You end up with a list of possible appointment times, pick the best one or all of them.
In TFS, the Remaining Wokrk field is a Double.
How can I set minutes for it?
For quarters of hours this is "easy" (or less difficult)
1h30 = 1,5
1h45 = 1,75
But, Ex:
10min = 0,17
20min = 0,33
It's hard!
Suggestions? Or am I overreacting?
Why would you need such a level of precision? I personally only deal in hours, although I know people who do deal in half hours.
I rarely have any task in development that will take less than 30 minutes, and if I did, I would just round it up. I would not expect anyone to have a lot of tasks taking under 30 minutes, if you do, perhaps your tasks are too granular. My tasks are often 2/3 hours in size and I just change them to 0, when complete, or update remaining hours at the end of the day, or if I realise I have underestimated and need to add more on. I do not perform periodic updates through the day because they don't really benefit anyone.
Remaining work in TFS is expected to be used as part of the burn down chart to show the estimated number of hours remaining, so long as you are tracking on the line it doesn't really matter.
I all comes down to how you have to work, if you are free to adopt the agile principles, then just stick with hours/halves, if you have management that require to the minute remaining, then you will have to go with the way you have in your question.
I agree with Dave, no need to track at the minute granularity.
And if for some reason you really do need to track at that level, there is nothing saying that Remaining Work has to be entered in hours. It's just a numeric field, you could enter hours, minutes, days, whatever, so long as everybody consistently uses the same unit (I think there may be a couple reports that show it as hours, but as far as TFS is concerned it doesn't have to be hours if you don't want it to be).
I live in Split,Croatia, and a city bus company recently accuired a new piece of software, and what it does is this: if I am a passenger and am awaiting a bus on a bus station, there is a huge monitor on which I can see the bus code and the time it will take for him to get to my station. The problem is, that in two years of having the software, not once have I seen that the time of the arrival is even remotley accurate. I am aware that GPS data can be inaccurate but this.... And that makes me so frustrated, that I decided that I will try to write a similar application for my final exam in CS in college. The problem is that I searched the web extensively in the last few days, and I cannot find good starting points. So my question is: have you ever been involved in such a project, and if so could you give me some pointers be it tutorials, or books regarding the subject? I appreciate any kind of input.
If I made a mistake regarding the question itself feel free to close it.
Thanks!
You will probably have:
Vehicle object containing each vehicles position, assigned route, direction of travel on route, and next scheduled stop, previous scheduled stop, arrival time at previous scheduled stop
Array of routes which comprises a list of stops and a data structure holding historic transit times between stops on each route
Now, updates to a vehicle's location push to the vehicle's object.
When you want to update a display at a station, find all routes passing through that station and for each route display the estimated arrival time of the next vehicle on that route.
The estimated arrival time structure is at the heart of this. Seed it by assuming some distance between stops and an average travel speed.
Now, every time a vehicle arrives at a stop, calculate the real time it took to get there from its last stop and use this to update an average transit time binned by half-hour increments (or what have you), you could also bin by season and/or day of week. The purpose of the binning is to implicitly account for varying traffic congestion by time of day, day of week, and/or season. Assuming otherwise homogeneous conditions, you'll eventually converge on a decent estimate of the transit time between each station.
You may find it useful to employ a Kalman filter.
Estimates of travel times between more distant stations may be more accurate than travel times between adjacent stations, if you feel like looking into that. Higher-order Markov chains may also help describe the underlying statistics of transit times.
Just ideas.
I'm currently working on an application that allows people to schedule "Shows" for an online radio station.
I want the ability for the user to setup a repeated event, say for example:-
"Manic Monday" show - Every Monday From 9-11
"Mid Month Madness" - Every Second Thursday of the Month
"This months new music" - 1st of every month.
What, in your opinion, is the best way to model this (based around an MVC/MTV structure).
Note: I'm actually coding this in Django. But I'm more interested in the theory behind it, rather than specific implementation details.
Ah, repeated events - one of the banes of my life, along with time zones. Calendaring is hard.
You might want to model this in terms of RFC2445. However, that may well give you far more flexibility - and complexity than you really want.
A few things to consider:
Do you need any finer granularity than a certain time on given dates? If you need to repeat based on time as well, it becomes trickier.
Consider date corner cases such as "the 30th of every month" and what that means for leap years
Consider time corner cases such as "1.30am every day" - sometimes 1.30am may happen twice, and sometimes it may not happen at all, due to daylight saving time
Do you need to share the schedule with people in other time zones? That makes life trickier again
Do you need to represent the number of times an event occurs, or a final date on which it occurs? ("Count" or "until" basically.) You may not need either, or you may need one or both.
I realise this is a list of things to think about more than a definitive answer, but I think it's important to define the parameters of your problem before you try to work out a solution.
From reading other posts, Martin Fowler describes recurring events the best.
http://martinfowler.com/apsupp/recurring.pdf
Someone implemented these classes for Java.
http://www.google.com/codesearch#vHK4YG0XgAs/src/java/org/chronicj/DateRange.java
I've had a thought that repeated events should be generated when the original event is saved, with a new model. This means I'm not doing random processing every time the calendar is loaded (and means I can also, for example, cancel one "Show" in a series) but also means that I have to limit this to a certain time frame, so if someone went say, a year into the future, they wouldn't see these repeated shows. But at some point, they'd have to (potentially) be re-generated.