/// <summary> /// Calculates forecast object value column's values. /// </summary> /// <param name="parameters">Parameters.</param> /// <returns> /// Parameters with calculated cells. /// </returns> public ForecastCalcParams Calculate(ForecastCalcParams parameters) { InitData(parameters); var objectValueColumns = GetObjectValueColumns(); List <Cell> cells = new List <Cell>(); if (objectValueColumns.IsNotEmpty()) { CellRepository.DeleteCells(ForecastSheet, Periods, objectValueColumns); } _log.Info($"Forecast object value calculation. " + $"Columns to count: {objectValueColumns.Count()}"); foreach (ForecastColumn column in objectValueColumns) { var settings = ColumnSettingsMapper.GetForecastColumnSettingsData(UserConnection, column); if (settings == null) { _log.Info($"Settings for forecast {ForecastSheet.Name} - {ForecastSheet.Id} " + $"column {column.Name} - {column.Id} does not exists"); continue; } _log.Info($"Forecast object value calculation. " + $"Periods to count: {Periods.Count()}"); foreach (Period period in Periods) { var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, settings.SourceEntityName); esq.IgnoreDisplayValues = true; string columnPath = GetEntityInCellColumnPath(settings); var refColumnName = esq.AddColumn(settings.ReferenceColumnName); var rowIdColumnName = esq.AddColumn($"{columnPath}.Row"); var valueColumn = esq.AddColumn(esq.CreateAggregationFunction( GetCalcFunction(settings.FuncCode), settings.FuncColumnName)); AddSettingsFilter(settings, esq); AddPeriodFilter(period, settings.PeriodColumnName, esq); AddEntitiesFilter(columnPath, esq); List <Cell> periodCells = new List <Cell>(); Select select = esq.GetSelectQuery(UserConnection); select.ExecuteReader((reader) => { decimal value = reader.GetColumnValue <decimal>(valueColumn.ValueQueryAlias); value = CalcValue(settings, value); periodCells.Add(new Cell { Value = value, ColumnId = column.Id, EntityId = reader.GetColumnValue <Guid>(refColumnName.ValueQueryAlias), RowId = reader.GetColumnValue <Guid>(rowIdColumnName.ValueQueryAlias), PeriodId = period.Id }); }); if (periodCells.Any()) { cells.AddRange(periodCells); _log.Info($"Forecast object value calculation. " + $"Has {periodCells.Count()} cells data for period {period.Name}"); } } } SaveCells(cells); parameters.Cells.AddRange(cells); return(parameters); }
/// <summary> /// Compares two opening times for equality. /// </summary> /// <param name="OpeningTimes">An opening time to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(OpeningTime OpeningTimes) => Periods.Count().Equals(OpeningTimes.Periods.Count()) && Periods.All(period => OpeningTimes.Periods.Contains(period)) && On.Equals(OpeningTimes.On) && ((!UnstructuredText.IsNullOrEmpty() && !OpeningTimes.UnstructuredText.IsNullOrEmpty()) || (UnstructuredText.IsNullOrEmpty() && OpeningTimes.UnstructuredText.IsNullOrEmpty() && UnstructuredText.Equals(OpeningTimes.UnstructuredText)));