AA/13 layer validation

This commit is contained in:
Michał Zieliński
2023-11-08 18:59:32 +01:00
parent 51c167d02e
commit 96b710ad82

View File

@@ -62,7 +62,6 @@ namespace WebAPI.dataProcessors
List<Record> newRecords = new List<Record>();
List<Layer> dataSources = new List<Layer>();
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<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
List<Layer> dataSourcesValidation = new List<Layer>();
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<Record> allRecords = dataSources
.SelectMany(x => x.Records!).ToList();
List<Record> allRecordsValidation = dataSources
.SelectMany(x => x.Records!).ToList();
foreach (Record baseRecord in dataSources.Last()?.Records!)
{
List<Record> codeRecords = allRecords.Where(x =>
x.Code!.Substring(1) == baseRecord.Code!.Substring(1))
.ToList();
List<Record> 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);
}