260512_01_ENH: 조정 ID로 2차 추출 및 검증 적용, 조정 ID 복붙 기능 추가 및 복수개의 층은 탭으로 분리
This commit is contained in:
@@ -182,13 +182,16 @@ namespace Keps.WinForms.Services
|
||||
List<ClusterSummaryRow> workingRows,
|
||||
int signedOffset,
|
||||
string offsetDescription,
|
||||
bool isAutoAllocation)
|
||||
bool isAutoAllocation,
|
||||
List<AdjustmentRow> adjustmentRows = null)
|
||||
{
|
||||
List<PollingPlaceRecord> allRows = LoadRealPollingRows(electionName, areaName, clusterMax);
|
||||
List<CandidateMeta> candidateMeta = LoadCandidateMeta(electionName, allRows);
|
||||
List<ExtractionRow> extractedRows = new List<ExtractionRow>();
|
||||
List<ExtractionRow> populationRows = new List<ExtractionRow>();
|
||||
List<PollingPlaceRecord> extractedSourceRows = new List<PollingPlaceRecord>();
|
||||
Dictionary<string, int> adjustmentMap = BuildAdjustmentMap(adjustmentRows);
|
||||
bool hasAdjustments = adjustmentMap.Count > 0;
|
||||
|
||||
foreach (ClusterSummaryRow workingRow in workingRows.OrderBy(x => x.ClusterNo))
|
||||
{
|
||||
@@ -201,25 +204,46 @@ namespace Keps.WinForms.Services
|
||||
int startPosition;
|
||||
List<int> extractIds = SelectLegacyExtractIds(clusterRows.Count, workingRow.SampleCount, signedOffset, out interval, out startPosition);
|
||||
HashSet<int> selectedPositions = new HashSet<int>(extractIds);
|
||||
HashSet<int> adjustedPositions = new HashSet<int>();
|
||||
List<int> finalExtractIds = new List<int>();
|
||||
foreach (int extractId in extractIds)
|
||||
{
|
||||
int finalExtractId;
|
||||
if (adjustmentMap.TryGetValue(BuildAdjustmentKey(workingRow.ClusterNo, extractId), out finalExtractId))
|
||||
{
|
||||
if (finalExtractId < 1 || finalExtractId > clusterRows.Count)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
string.Format("{0}층 조정ID {1}이 유효한 범위를 벗어났습니다. 1부터 {2} 사이로 입력하세요.", workingRow.ClusterNo, finalExtractId, clusterRows.Count));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalExtractId = extractId;
|
||||
}
|
||||
|
||||
finalExtractIds.Add(finalExtractId);
|
||||
adjustedPositions.Add(finalExtractId);
|
||||
}
|
||||
|
||||
for (int i = 0; i < clusterRows.Count; i++)
|
||||
{
|
||||
int originalOrder = i + 1;
|
||||
PollingPlaceRecord row = clusterRows[i];
|
||||
populationRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, originalOrder, originalOrder, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), selectedPositions.Contains(originalOrder), selectedPositions.Contains(originalOrder)));
|
||||
populationRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, originalOrder, originalOrder, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), selectedPositions.Contains(originalOrder), hasAdjustments ? adjustedPositions.Contains(originalOrder) : selectedPositions.Contains(originalOrder)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < extractIds.Count; i++)
|
||||
for (int i = 0; i < finalExtractIds.Count; i++)
|
||||
{
|
||||
int extractId = extractIds[i];
|
||||
if (extractId < 1 || extractId > clusterRows.Count)
|
||||
int finalExtractId = finalExtractIds[i];
|
||||
if (finalExtractId < 1 || finalExtractId > clusterRows.Count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PollingPlaceRecord row = clusterRows[extractId - 1];
|
||||
PollingPlaceRecord row = clusterRows[finalExtractId - 1];
|
||||
extractedSourceRows.Add(row);
|
||||
extractedRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, i + 1, extractId, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), true, true));
|
||||
extractedRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, i + 1, finalExtractId, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), selectedPositions.Contains(finalExtractId), true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +258,7 @@ namespace Keps.WinForms.Services
|
||||
CandidateRatioKeys = candidateRatioKeys,
|
||||
ExtractedRows = extractedRows.OrderBy(x => x.ClusterNo).ThenBy(x => x.ClusterOrder).ToList(),
|
||||
PopulationRows = populationRows.OrderBy(x => x.ClusterNo).ThenBy(x => x.OriginalOrder).ToList(),
|
||||
AdjustmentRows = BuildAdjustmentRows(extractedRows),
|
||||
AdjustmentRows = hasAdjustments ? CloneAdjustmentRows(adjustmentRows) : BuildAdjustmentRows(extractedRows),
|
||||
VerificationRows = BuildVerificationRows(allRows, extractedSourceRows, workingRows, candidateMeta),
|
||||
ClusterMax = clusterMax,
|
||||
TotalSampleCount = workingRows.Sum(x => x.SampleCount),
|
||||
@@ -245,6 +269,51 @@ namespace Keps.WinForms.Services
|
||||
};
|
||||
}
|
||||
|
||||
private static Dictionary<string, int> BuildAdjustmentMap(List<AdjustmentRow> adjustmentRows)
|
||||
{
|
||||
Dictionary<string, int> result = new Dictionary<string, int>();
|
||||
if (adjustmentRows == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (AdjustmentRow row in adjustmentRows)
|
||||
{
|
||||
if (row == null || row.AdjustId == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[BuildAdjustmentKey(row.ClusterNo, row.ExtractId)] = row.AdjustId.Value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string BuildAdjustmentKey(int clusterNo, int extractId)
|
||||
{
|
||||
return clusterNo.ToString() + ":" + extractId.ToString();
|
||||
}
|
||||
|
||||
private static List<AdjustmentRow> CloneAdjustmentRows(List<AdjustmentRow> adjustmentRows)
|
||||
{
|
||||
if (adjustmentRows == null)
|
||||
{
|
||||
return new List<AdjustmentRow>();
|
||||
}
|
||||
|
||||
return adjustmentRows
|
||||
.OrderBy(x => x.ClusterNo)
|
||||
.ThenBy(x => x.ExtractId)
|
||||
.Select(x => new AdjustmentRow
|
||||
{
|
||||
ClusterNo = x.ClusterNo,
|
||||
ExtractId = x.ExtractId,
|
||||
AdjustId = x.AdjustId
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 실 데이터 테이블에서 투표구 행들을 조회하여 도메인 모델로 변환합니다.
|
||||
/// </summary>
|
||||
@@ -638,7 +707,6 @@ namespace Keps.WinForms.Services
|
||||
return (vote / total) * 100m;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 소수점 둘째 자리에서 반올림(away from zero)합니다.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user