English 中文(简体)
分配预约在一个日期范围内
原标题:Distributing appointments over a date range

我正在尝试生成一些测试数据。

假设我有1000个约会需要安排在一段日期范围内。

现在我需要安排这些约会,使得月底每天的约会数量是月初的两倍。预约的增加速度需要保持一致。

举个例子,如果某月的第一天有5个约会,到月底时我们每天将会收到10个约会。

预约只能在工作日进行。

有没有一个合适的算法可以帮助我以这种方式分配这些日期?

编辑

这是我迄今为止在亨利克斯解决方案的激励下最出色的:

    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

问题回答

暂无回答




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签