From df3cf8bb7578bdfc4ac79e41d9025994016595fc Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 23 Mar 2026 14:56:40 +0900 Subject: [PATCH] =?UTF-8?q?260323=5F01=5FENH:=20=EB=B6=84=EC=84=9D=20?= =?UTF-8?q?=EB=8F=84=EC=A4=91=20=EB=B9=84=ED=9A=A8=EC=9C=A8=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EC=B6=94=EC=B6=9C=20=EC=A1=B0=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Keps.WinForms/Services/ExcelReportService.cs | 31 +++++++++++++------- Keps.WinForms/Services/SamplingService.cs | 16 ++++++---- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Keps.WinForms/Services/ExcelReportService.cs b/Keps.WinForms/Services/ExcelReportService.cs index de68cf2..5e0a55f 100644 --- a/Keps.WinForms/Services/ExcelReportService.cs +++ b/Keps.WinForms/Services/ExcelReportService.cs @@ -42,13 +42,13 @@ namespace Keps.WinForms.Services List candidateRatioKeys = (result.CandidateRatioKeys ?? new List()).ToList(); NormalizeCandidateLists(candidateNames, candidateVoteKeys, candidateRatioKeys); - WriteExtractedSheet(package.Workbook.Worksheets.Add(areaName + "-추출결과"), electionName, areaName, candidateNames, candidateVoteKeys, result.ExtractedRows ?? new List(), result.PopulationRows ?? new List(), result); + WriteExtractedSheet(package.Workbook.Worksheets.Add(areaName + "-추출결과"), electionName, candidateNames, candidateVoteKeys, result.ExtractedRows ?? new List(), result.PopulationRows ?? new List(), result); WriteVerificationSummarySheet(package.Workbook.Worksheets.Add(areaName + "-자가 검증-요약분석"), electionName, areaName, candidateNames, result.VerificationRows ?? new List(), result.ClusterMax); WriteVerificationDetailSheet(package.Workbook.Worksheets.Add(areaName + "-자가 검증-세부분석"), electionName, areaName, candidateNames, candidateVoteKeys, result.ExtractedRows ?? new List(), result.VerificationRows ?? new List(), result.ClusterMax); WriteFinalStatusSheet(package.Workbook.Worksheets.Add(areaName + "-최종 투표소 추출현황"), electionName, areaName, candidateNames, candidateVoteKeys, result.PopulationRows ?? new List(), result.ClusterMax, adjustList); WriteClusterListSheet(package.Workbook.Worksheets.Add(areaName + "-층별 시군구 리스트"), electionName, areaName, result.PopulationRows ?? new List()); WriteModeSheet(package.Workbook.Worksheets.Add(areaName + "-기준설정 Mode"), electionName, clusterRows ?? new List(), result.PopulationRows ?? new List()); - WriteModeTargetSheet(package.Workbook.Worksheets.Add(areaName + "-기준설정 Mode Target"), clusterRows ?? new List(), result.PopulationRows ?? new List()); + WriteModeTargetSheet(package.Workbook.Worksheets.Add(areaName + "-기준설정 Mode Target"), clusterRows ?? new List(), result.PopulationRows ?? new List(), adjustList); package.SaveAs(new FileInfo(filePath)); } @@ -59,13 +59,12 @@ namespace Keps.WinForms.Services /// /// 대상 워크시트. /// 선거명 또는 연월. - /// 시도명. /// 후보자 표시명 목록(최소 3개로 보정됨). /// 후보자 득표 키 목록(최소 3개로 보정됨). /// 추출 표본 행 목록. /// 모집단 행 목록. /// 추출 실행 메타(정렬/오프셋 등). - private static void WriteExtractedSheet(ExcelWorksheet ws, string electionName, string areaName, List candidateNames, List candidateVoteKeys, List rows, List populationRows, RealExtractionResult result) + private static void WriteExtractedSheet(ExcelWorksheet ws, string electionName, List candidateNames, List candidateVoteKeys, List rows, List populationRows, RealExtractionResult result) { int rowIndex = 1; foreach (IGrouping clusterGroup in rows.GroupBy(x => x.ClusterNo).OrderBy(x => x.Key)) @@ -432,11 +431,12 @@ namespace Keps.WinForms.Services foreach (ExtractionRow row in group.OrderBy(x => x.OriginalOrder)) { - bool isAdjust = adjustList.Any(a => a.ClusterNo == row.ClusterNo && a.AdjustId == row.OriginalOrder); - bool isAdjusted = adjustList.Any(a => a.ClusterNo == row.ClusterNo && a.ExtractId == row.OriginalOrder && a.AdjustId != null); + row.IsAdjustedSelected = adjustList.Any(a => a.ClusterNo == row.ClusterNo && a.AdjustId == row.OriginalOrder); - string autoSelected = (row.IsAutoSelected || row.IsAdjustedSelected) ? "★" : null; - string adjustedSelected = isAdjust ? "★" : autoSelected; + string autoSelected = row.IsAutoSelected ? "★" : null; + string adjustedSelected = row.IsAdjustedSelected ? "★" : autoSelected; + + bool isAdjusted = adjustList.Any(a => a.ClusterNo == row.ClusterNo && a.ExtractId == row.OriginalOrder && a.AdjustId != null); if (isAdjusted) { adjustedSelected = null; @@ -549,7 +549,7 @@ namespace Keps.WinForms.Services /// 대상 워크시트. /// 군집 요약 행 목록. /// 모집단 행 목록. - private static void WriteModeTargetSheet(ExcelWorksheet ws, List clusterRows, List rows) + private static void WriteModeTargetSheet(ExcelWorksheet ws, List clusterRows, List rows, List adjustList) { MergeAndSet(ws, 1, 1, 1, 6, "Target 층별 현황"); ws.Cells[2, 1].Value = "층"; @@ -563,8 +563,19 @@ namespace Keps.WinForms.Services int rowIndex = 3; foreach (ClusterSummaryRow row in clusterRows.OrderBy(x => x.ClusterNo)) { + List finalAdjustList = adjustList + .Where(x => x.ClusterNo == row.ClusterNo) + .Select(x => x.AdjustId ?? x.ExtractId) + .ToList(); + List clusterPopulation = rows.Where(x => x.ClusterNo == row.ClusterNo).OrderBy(x => x.OriginalOrder).ToList(); - string areas = string.Join(string.Empty, clusterPopulation.Where(x => x.IsAutoSelected || x.IsAdjustedSelected).Select(x => x.EupMyeonDong + "-" + x.PollingPlaceNo + "투, ")); + //adjustList. + string areas = string.Join(string.Empty, + clusterPopulation + .Where(x => finalAdjustList.Contains(x.ClusterOrder)) + .Select(x => x.EupMyeonDong + "-" + x.PollingPlaceNo + "투, ") + ); + ws.Cells[rowIndex, 1].Value = row.ClusterNo + " 층"; ws.Cells[rowIndex, 2].Value = row.PollingPlaceCount; ws.Cells[rowIndex, 3].Value = null; diff --git a/Keps.WinForms/Services/SamplingService.cs b/Keps.WinForms/Services/SamplingService.cs index 7f9ee26..19ad60f 100644 --- a/Keps.WinForms/Services/SamplingService.cs +++ b/Keps.WinForms/Services/SamplingService.cs @@ -532,16 +532,20 @@ namespace Keps.WinForms.Services List clusterPopulation = populationRows.Where(x => x.ClusterValue == allocation.ClusterNo).ToList(); List clusterExtracted = extractedRows.Where(x => x.ClusterValue == allocation.ClusterNo).ToList(); - decimal clusterExtracted1 = Round1(ComputeCandidateRatioExact(clusterExtracted, candidateMeta[0].VoteKey)); - decimal clusterExtracted2 = Round1(ComputeCandidateRatioExact(clusterExtracted, candidateMeta[1].VoteKey)); - decimal clusterExtracted3 = Round1(ComputeCandidateRatioExact(clusterExtracted, candidateMeta[2].VoteKey)); + decimal clusterExtractedSource1 = ComputeCandidateRatioExact(clusterExtracted, candidateMeta[0].VoteKey); + decimal clusterExtractedSource2 = ComputeCandidateRatioExact(clusterExtracted, candidateMeta[1].VoteKey); + decimal clusterExtractedSource3 = ComputeCandidateRatioExact(clusterExtracted, candidateMeta[2].VoteKey); + + decimal clusterExtracted1 = Round1(clusterExtractedSource1); + decimal clusterExtracted2 = Round1(clusterExtractedSource2); + decimal clusterExtracted3 = Round1(clusterExtractedSource3); decimal clusterActual1 = Round1(Round2(ComputeCandidateRatioExact(clusterPopulation, candidateMeta[0].VoteKey))); decimal clusterActual2 = Round1(Round2(ComputeCandidateRatioExact(clusterPopulation, candidateMeta[1].VoteKey))); decimal clusterActual3 = Round1(Round2(ComputeCandidateRatioExact(clusterPopulation, candidateMeta[2].VoteKey))); - totalExtractedWeighted1 += allocation.Ratio * ComputeCandidateRatioExact(clusterExtracted, candidateMeta[0].VoteKey); - totalExtractedWeighted2 += allocation.Ratio * ComputeCandidateRatioExact(clusterExtracted, candidateMeta[1].VoteKey); - totalExtractedWeighted3 += allocation.Ratio * ComputeCandidateRatioExact(clusterExtracted, candidateMeta[2].VoteKey); + totalExtractedWeighted1 += allocation.Ratio * clusterExtractedSource1; + totalExtractedWeighted2 += allocation.Ratio * clusterExtractedSource2; + totalExtractedWeighted3 += allocation.Ratio * clusterExtractedSource3; decimal overallError1 = Round1(clusterExtracted1 - totalActual1); decimal overallError2 = Round1(clusterExtracted2 - totalActual2);