AA/13 layer validation
This commit is contained in:
@@ -62,7 +62,6 @@ namespace WebAPI.dataProcessors
|
|||||||
List<Record> newRecords = new List<Record>();
|
List<Record> newRecords = new List<Record>();
|
||||||
|
|
||||||
List<Layer> dataSources = new List<Layer>();
|
List<Layer> dataSources = new List<Layer>();
|
||||||
|
|
||||||
foreach (Record source in sources!)
|
foreach (Record source in sources!)
|
||||||
{
|
{
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
Layer? dataSource = db.Layers.Where(x =>
|
||||||
@@ -77,19 +76,44 @@ namespace WebAPI.dataProcessors
|
|||||||
dataSources.Add(dataSource);
|
dataSources.Add(dataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataSources.Count == 0)
|
if (dataSources.Count == 0)
|
||||||
{
|
{
|
||||||
throw new Exception($"DataSources are empty");
|
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!)
|
foreach (Record baseRecord in dataSources.Last()?.Records!)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Record> codeRecords = allRecords.Where(x =>
|
List<Record> codeRecords = allRecords.Where(x =>
|
||||||
x.Code!.Substring(1) == baseRecord.Code!.Substring(1))
|
x.Code!.Substring(1) == baseRecord.Code!.Substring(1))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
List<Record> codeRecordsValidation = allRecords.Where(x =>
|
||||||
|
x.Code!.Substring(1) == baseRecord.Code!.Substring(1))
|
||||||
|
.ToList();
|
||||||
Record processedRecord = new Record
|
Record processedRecord = new Record
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
@@ -97,10 +121,23 @@ namespace WebAPI.dataProcessors
|
|||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
ModifiedAt = DateTime.UtcNow
|
ModifiedAt = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
|
Record validationRecord = new Record();
|
||||||
for (var i = 1; i < 33; i++)
|
for (var i = 1; i < 33; i++)
|
||||||
{
|
{
|
||||||
ProcessHelper.setValue(processedRecord, i,
|
ProcessHelper.setValue(processedRecord, i,
|
||||||
codeRecords.Sum(x => ProcessHelper.getValue(x, 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);
|
newRecords.Add(processedRecord);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user