diff --git a/WebAPI/dataProcessors/t3.MultiSourceYearSummary.processor.cs b/WebAPI/dataProcessors/t3.MultiSourceYearSummary.processor.cs index 927cfa2..cb59b4a 100644 --- a/WebAPI/dataProcessors/t3.MultiSourceYearSummary.processor.cs +++ b/WebAPI/dataProcessors/t3.MultiSourceYearSummary.processor.cs @@ -62,7 +62,6 @@ namespace WebAPI.dataProcessors List newRecords = new List(); List dataSources = new List(); - foreach (Record source in sources!) { Layer? dataSource = db.Layers.Where(x => @@ -77,19 +76,44 @@ namespace WebAPI.dataProcessors dataSources.Add(dataSource); } } - if (dataSources.Count == 0) { throw new Exception($"DataSources are empty"); } - List allRecords = dataSources.SelectMany(x => x.Records!).ToList(); + List dataSourcesValidation = new List(); + for (int i = 1; i < 13; i++) + { + Layer? dataSource = db.Layers.Where(x => + x.Type == LayerType.processed + && !x.IsDeleted + && x.Name.Contains($"{year}/{i}-AA-T3")) + .Include(x => x.Records) + .FirstOrDefault(); + if (dataSource != null) + { + dataSourcesValidation.Add(dataSource!); + } + } + if (dataSources.Count == 0) + { + throw new Exception($"DataSourcesValidation are empty"); + } + + + List allRecords = dataSources + .SelectMany(x => x.Records!).ToList(); + List allRecordsValidation = dataSources + .SelectMany(x => x.Records!).ToList(); foreach (Record baseRecord in dataSources.Last()?.Records!) { List codeRecords = allRecords.Where(x => x.Code!.Substring(1) == baseRecord.Code!.Substring(1)) .ToList(); + List codeRecordsValidation = allRecords.Where(x => + x.Code!.Substring(1) == baseRecord.Code!.Substring(1)) + .ToList(); Record processedRecord = new Record { Id = Guid.NewGuid(), @@ -97,10 +121,23 @@ namespace WebAPI.dataProcessors CreatedAt = DateTime.UtcNow, ModifiedAt = DateTime.UtcNow }; + Record validationRecord = new Record(); for (var i = 1; i < 33; i++) { ProcessHelper.setValue(processedRecord, i, codeRecords.Sum(x => ProcessHelper.getValue(x, i))); + + ProcessHelper.setValue(validationRecord, i, + codeRecordsValidation.Sum(x => ProcessHelper.getValue(x, i))); + + if ( + ProcessHelper.getValue(processedRecord,i) != + ProcessHelper.getValue(validationRecord, i)) + { + throw new Exception($"ValidationError: Code {baseRecord.Code!}, " + + $"Value{i} ({ProcessHelper.getValue(processedRecord, i)} | " + + $"{ProcessHelper.getValue(validationRecord, i)})"); + } } newRecords.Add(processedRecord); }