简体   繁体   中英

Distributing appointments over a date range

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..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM