views:

62

answers:

1

I am trying to generate some test data.

Say I have 1000 appointments that I need to allocate over a date range.

Now I need to distribute these appointments such that there are twice as many appointments per day at the end of the month as there are at the start of the month. The increase in appointments needs to increase with a consistent velocity.

So for example if there are 5 appointments on the 1st day of the month, by the end of the month we will be getting 10 appointments per day.

An appointment can only occur on a weekday.

Is there a decent algorithm that would help me to distribute these dates in this fashion?

Edit

This is the best I got so far, inspired by Henriks solution :

    private int GetNumForCurrentDate (DateTime date)
    {
        int daysInMonth = DateTime.DaysInMonth ( date.Year, date.Month );

        // x is the number of appointments on the first day
        double firstDay = this._NumPerMonth / ( ( ( ratio + 1 ) / 2 ) * daysInMonth );

        // x * ratio is the number of appointments on the last day.
        double lastDay = firstDay * ratio;

        // Interpolate a value between the first and last days
        double exactNumOnThisDay = firstDay + ( lastDay - firstDay ) * ( (double)date.Day / (double)daysInMonth );
        int numOnThisDay = Convert.ToInt32 ( Math.Truncate ( exactNumOnThisDay ) );

        // Accumulate any overflow
        this._Overflow += exactNumOnThisDay - numOnThisDay;
        if ( this._Overflow > 1 )
        {
            // Shove the overflow into our number when it gets into whole number teritory
            numOnThisDay++;
            this._Overflow--;
        }

        return numOnThisDay;
    }

It returns the number of days to allocate on a particular day given the date. It deals with separating out the allocations to each month and handles rounding overflow, but its not quite perfect, it runs out of days to allocate on the last day, but it is good enough for now and Ive run out of time to perfect it..

+1  A: 

x appointments on the first day, 2x the last day, so 1.5x on average. When there are y weekdays, x is 1000 / (1.5y). So 667/y on the first day, 1333/y on the last, interpolate for the days in between

Henrik
I think you forgot one requirement: "The increase in appointments needs to increase with a consistent velocity (not linearly)." This is f''(x) = c. Yours is f(x) = cx, f'(x) = c, f''(x) = 0.
Thomas Jung
@Thomas: maybe you're right. I misread the "increase in increase".
Henrik
@Thomas: But with this interpretation the problem is underdetermined an my solution is still correct, as f'' = 0 = const. :)
Henrik
@Henrik, this increase in increase is more of a nice to have really. Im just trying to get my head around the mathematics and implement your solution (too many years of db programming have played havoc with my mathematical brain!)
Mongus Pong