代码之家  ›  专栏  ›  技术社区  ›  Mongus Pong

在日期范围内分配约会

  •  2
  • Mongus Pong  · 技术社区  · 15 年前

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

    假设我有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;
        }
    

    它返回在给定日期的特定日期分配的天数。 它处理分配到每个月的事务,处理四舍五入溢出,但它并不十分完美,它在最后一天的分配已经用光了天,但现在已经足够好了,我已经没有时间来完善它了。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Henrik    15 年前

    第一天有X个约会,最后一天有2个约会,平均为1.5倍。 当有y个工作日时,x为1000/(1.5y)。 所以第一天是667/y,最后一天是1333/y,这两天之间