Exemplo n.º 1
0
        /// <summary>
        /// Возвращает приблизительное количество дней, за которое наберется ресурс remains с заданной среднестатистической наработкой
        /// </summary>
        /// <param name="from"></param>
        /// <param name="remains"></param>
        /// <param name="average"></param>
        /// <param name="conditionType"></param>
        /// <returns></returns>
        public static Double?GetApproximateDays(DateTime from,
                                                Lifelength remains, AverageUtilization average,
                                                ThresholdConditionType conditionType = ThresholdConditionType.WhicheverFirst)
        {
            //
            if (remains == null || average == null)
            {
                return(null);
            }

            if (remains.CalendarValue != null && remains.CalendarValue != 0)
            {
                DateTime to = from.AddCalendarSpan(remains.CalendarSpan);
                return((to - from).Days);
            }

            Double?d1 = average.CyclesPerMonth != 0 && remains.Cycles != null ? new Double?(remains.Cycles.Value / (average.Hours / average.Cycles)) : null;
            Double?d2 = average.HoursPerMonth != 0 && remains.Hours != null ? remains.Hours * 30 / average.HoursPerMonth : null;
            Double?d3 = remains.Days;

            // Whichever First vs. Whichever Later
            if (conditionType == ThresholdConditionType.WhicheverFirst)
            {
                // Выбираем минимум
                Double?min = null;
                if (d1 != null)
                {
                    min = d1;
                }
                if (d2 != null && (min == null || d2 < min))
                {
                    min = d2;
                }
                if (d3 != null && (min == null || d3 < min))
                {
                    min = d3;
                }
                // Возвращаем результат
                return(min);
            }

            // Выбираем максимум
            Double?max = null;

            if (d1 != null)
            {
                max = d1;
            }
            if (d2 != null && (max == null || d2 > max))
            {
                max = d2;
            }
            if (d3 != null && (max == null || d3 > max))
            {
                max = d3;
            }
            // Возвращаем результат
            return(max);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Представляет условие выполения директивы в виде строки
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 private string ThresholdConditionToString(ThresholdConditionType type)
 {
     if (type == ThresholdConditionType.WhicheverFirst)
     {
         return("w.f.");
     }
     if (type == ThresholdConditionType.WhicheverLater)
     {
         return("w.l.");
     }
     throw new Exception("1525: Failed to specify directive threshold condition type");
 }
Exemplo n.º 3
0
        /// <summary>
        /// Возвращает дату, когда наберется ресурс remains с заданной среднестатистической наработкой
        /// </summary>
        /// <param name="remains"></param>
        /// <param name="average"></param>
        /// <param name="conditionType"></param>
        /// <returns></returns>
        public static DateTime?GetApproximateDate(Lifelength remains, AverageUtilization average, ThresholdConditionType conditionType = ThresholdConditionType.WhicheverFirst)
        {
            //
            if (remains == null || average == null)
            {
                return(null);
            }

            // расчитываем количество дней
            Double?days = GetApproximateDays(DateTime.Today, remains, average, conditionType);

            if (days == null)
            {
                return(null);
            }

            // возвращаем дату
            return(DateTime.Today.AddDays(days.Value));
        }