public bool TryGetCurrentPeriodOrFindForTotalIndexHh(int totalHalfhourIndex, out IPeriodBase <T> currentCoeff, int discreteType = 30) { if ((_isTotalPeriodCoeffFound || _isCurrentDayCoeffFound) && _currentCoeff != null) { currentCoeff = _currentCoeff; return(true); } if (_coeffs != null) { var currHhDateTime = _dtStart.AddMinutes(totalHalfhourIndex * discreteType); _currentCoeff = currentCoeff = _coeffs .LastOrDefault(t => t.PeriodValue != null && currHhDateTime >= t.StartDateTime && currHhDateTime <= t.FinishDateTime); _isCurrentDayCoeffFound = currentCoeff != null && (!currentCoeff.FinishDateTime.HasValue || currentCoeff.FinishDateTime.Value >= _dtEnd); return(currentCoeff != null); } currentCoeff = null; return(false); }
public void GoNextPeriodIfNotTotal(DateTime periodStart, DateTime periodEnd) { if (_isTotalPeriodCoeffFound && _currentCoeff != null) { return; //Найден коэфф. на весь период, нет смысла снова искать } //Пытаемся найти коэфф на указанный период _isCurrentDayCoeffFound = _currentCoeff != null && periodStart >= _currentCoeff.StartDateTime && (!_currentCoeff.FinishDateTime.HasValue || periodEnd <= _currentCoeff.FinishDateTime); if (!_isCurrentDayCoeffFound && _coeffs != null) { _isCurrentDayCoeffFound = (_currentCoeff = _coeffs.FirstOrDefault(t => t.PeriodValue != null && periodStart >= t.StartDateTime && (!t.FinishDateTime.HasValue || periodEnd <= t.FinishDateTime))) != null; _baseDate = periodStart.Date; } }
public bool TryGetForDateTime(DateTime dt, out IPeriodBase <T> currentCoeff) { if (_isTotalPeriodCoeffFound && _currentCoeff != null) { currentCoeff = _currentCoeff; return(true); } if (_coeffs != null) { currentCoeff = _coeffs .LastOrDefault(t => t.PeriodValue != null && dt >= t.StartDateTime && dt <= t.FinishDateTime); return(currentCoeff != null); } currentCoeff = null; return(false); }
public PeriodCoeffWorker(IEnumerable <IPeriodBase <T> > coeffs, DateTime dtStart, DateTime dtEnd, IPeriodBase <T> defaultValue) { _coeffs = coeffs; _dtEnd = dtEnd; _dtStart = dtStart; if (_coeffs == null) { _currentCoeff = defaultValue; _isTotalPeriodCoeffFound = true; return; } //Попытка найти коэфф на весь период _currentCoeff = _coeffs.FirstOrDefault(t => t.PeriodValue != null && _dtStart >= t.StartDateTime && (!t.FinishDateTime.HasValue || _dtEnd <= t.FinishDateTime)); _isTotalPeriodCoeffFound = _currentCoeff != null && _currentCoeff.PeriodValue.HasValue; }
public bool TryGetCurrentPeriodOrFindForHalfhour(int hhIndx, out IPeriodBase <T> currentCoeff, int discreteType = 30) { if ((_isTotalPeriodCoeffFound || _isCurrentDayCoeffFound) && _currentCoeff != null) { currentCoeff = _currentCoeff; return(true); } if (_coeffs != null && _baseDate.HasValue) { var currHhDateTime = _baseDate.Value.AddMinutes(hhIndx * discreteType); _currentCoeff = currentCoeff = _coeffs .LastOrDefault(t => t.PeriodValue != null && currHhDateTime >= t.StartDateTime && currHhDateTime <= t.FinishDateTime); return(currentCoeff != null); } currentCoeff = null; return(false); }
/// <summary> /// Наполнение списка архива отсутствующими значений /// </summary> /// <param name="discreteType">Период дискретизации</param> /// <param name="archivesList">Архивы, которые наполняем</param> public void FillVoidHalfHours(List <TVALUES_DB> archivesList, enumTimeDiscreteType discreteType, VALUES_FLAG_DB mask, ref VALUES_FLAG_DB totalPrimaryFlag) { var totalFlag = totalPrimaryFlag; var totalHalfhourIndex = 0; foreach (var numbersHalfHoursInOurPeriod in _intervalTimeList) { var periodFlag = VALUES_FLAG_DB.None; var periodValue = 0.0; for (var hhIndex = 0; hhIndex <= numbersHalfHoursInOurPeriod; hhIndex++) { VALUES_FLAG_DB flag; double value; var isNotWorkedHalfHour = _isExistsNotWorkedPeriod && _notWorkedRange.Any(r => (hhIndex >= r.Item1) && (!r.Item2.HasValue || hhIndex <= r.Item2)); if (isNotWorkedHalfHour) { flag = VALUES_FLAG_DB.IsNotWorkedPeriod; value = 0; } else { flag = VALUES_FLAG_DB.DataNotFull | mask; #region Акт недоучета, обработка ручного ввода КА //Прибавляем по акту недоучета if (_isActUndercountExists) { IPeriodBase <double> currentCoeff = null; IPeriodBase <double> currentLossesCoeff = null; if (_calculateCoeffs) { #region Коэфф. трансформации IPeriodBase <bool> isDisabledPeriod; var haveDisabledPeriod = _coeffTransformationDisabledWorker.TryGetCurrentPeriodOrFindForTotalIndexHh(totalHalfhourIndex, out isDisabledPeriod); if ((!haveDisabledPeriod && !_isCoeffTransformationDisabledByDefault) || (haveDisabledPeriod && !isDisabledPeriod.PeriodValue.Value) ) //Если нет заблокированного периода, или период разрешен { //Не нашли один коэфф для данного часа или нет общего коэфф, значит ищем по каждой получасовке _coeffTranformationWorker.TryGetCurrentPeriodOrFindForTotalIndexHh(totalHalfhourIndex, out currentCoeff); } #endregion #region Коэфф. потерь if (_useLossesCoeff) { _coeffLossesWorker.TryGetCurrentPeriodOrFindForHalfhour(totalHalfhourIndex, out currentLossesCoeff); } #endregion } EnumActMode actMode; var av = _actUndercountValues.CalculateUndercountValues(totalHalfhourIndex, out actMode, currentCoeff, currentLossesCoeff); if (av.HasValue) { value = Math.Round(av.Value, 8) / _unitDigit; if (actMode == EnumActMode.Замещение) { flag &= ~(VALUES_FLAG_DB.DataNotFull | VALUES_FLAG_DB.NotCorrect | VALUES_FLAG_DB.DataNotComplete); } flag |= VALUES_FLAG_DB.ActUndercountExists; } else { value = 0; } } else { value = 0; } #endregion } periodValue += value; periodFlag |= flag; totalHalfhourIndex++; } totalFlag |= periodFlag; archivesList.Add(new Servers.Calculation.DBAccess.Interface.Data.TVALUES_DB(periodFlag, periodValue)); } totalPrimaryFlag = totalFlag; }