25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
6.9KB

  1. <%
  2. Class PurpleEnvelopeReportHelper_Class
  3. Public Function FormatElectionLabel(ByVal rawValue)
  4. FormatElectionLabel = Trim(rawValue & "")
  5. If Len(FormatElectionLabel) = 0 Then Exit Function
  6. On Error Resume Next
  7. dim parsedDate : parsedDate = CDate(rawValue)
  8. If Err.Number = 0 Then
  9. FormatElectionLabel = MonthName(Month(parsedDate), True) & "-" & CStr(Year(parsedDate))
  10. Else
  11. Err.Clear
  12. End If
  13. On Error GoTo 0
  14. End Function
  15. Public Function SortPrecinctColorRows(ByVal rs)
  16. dim list : set list = new LinkedList_Class
  17. If rs.EOF Then
  18. set SortPrecinctColorRows = list
  19. Exit Function
  20. End If
  21. dim items()
  22. dim itemCount : itemCount = -1
  23. Do Until rs.EOF
  24. itemCount = itemCount + 1
  25. ReDim Preserve items(itemCount)
  26. dim row : set row = new PrecinctColorRow_ViewModel_Class
  27. row.PRECINCT = rs("PRECINCT")
  28. If IsNull(rs("ColorId")) Then
  29. row.ColorId = ""
  30. Else
  31. row.ColorId = rs("ColorId")
  32. End If
  33. Set items(itemCount) = row
  34. rs.MoveNext
  35. Loop
  36. SortPrecinctItems items
  37. dim i
  38. For i = 0 To UBound(items)
  39. list.Push items(i)
  40. Next
  41. set SortPrecinctColorRows = list
  42. End Function
  43. Public Function SortPrecinctBallotRangeRows(ByVal rs)
  44. dim list : set list = new LinkedList_Class
  45. If rs.EOF Then
  46. set SortPrecinctBallotRangeRows = list
  47. Exit Function
  48. End If
  49. dim items()
  50. dim itemCount : itemCount = -1
  51. Do Until rs.EOF
  52. itemCount = itemCount + 1
  53. ReDim Preserve items(itemCount)
  54. dim row : set row = new PrecinctBallotRangeRow_ViewModel_Class
  55. row.PRECINCT = rs("PRECINCT")
  56. row.LowBallotNumber = rs("LowBallotNumber")
  57. row.HighBallotNumber = rs("HighBallotNumber")
  58. Set items(itemCount) = row
  59. rs.MoveNext
  60. Loop
  61. SortPrecinctItems items
  62. dim i
  63. For i = 0 To UBound(items)
  64. list.Push items(i)
  65. Next
  66. set SortPrecinctBallotRangeRows = list
  67. End Function
  68. Public Function BuildBallotRangesWithMissing(ByVal rs)
  69. ' Groups raw PRECINCT/BALLOT_NUMBER rows by precinct, extracts last 4 digits of
  70. ' the numeric portion (matching the PowerShell InkjetRecords analysis script),
  71. ' computes min/max and any missing numbers in that range, then returns rows
  72. ' sorted by precinct in descending order.
  73. dim precinctNums : set precinctNums = CreateObject("Scripting.Dictionary")
  74. dim precinct, rawNum, digits, i, ch, last4Str
  75. Do Until rs.EOF
  76. precinct = Trim(rs("PRECINCT") & "")
  77. rawNum = rs("BALLOT_NUMBER") & ""
  78. digits = ""
  79. For i = 1 To Len(rawNum)
  80. ch = Mid(rawNum, i, 1)
  81. If ch >= "0" And ch <= "9" Then digits = digits & ch
  82. Next
  83. If Len(digits) >= 4 Then
  84. last4Str = Mid(digits, Len(digits) - 3, 4)
  85. If precinctNums.Exists(precinct) Then
  86. precinctNums(precinct) = precinctNums(precinct) & "," & last4Str
  87. Else
  88. precinctNums.Add precinct, last4Str
  89. End If
  90. End If
  91. rs.MoveNext
  92. Loop
  93. If precinctNums.Count = 0 Then
  94. set BuildBallotRangesWithMissing = new LinkedList_Class
  95. Exit Function
  96. End If
  97. dim keys : keys = precinctNums.Keys
  98. dim itemCount : itemCount = precinctNums.Count - 1
  99. dim items()
  100. ReDim items(itemCount)
  101. dim k, j, n
  102. dim numStrs, numArr, minVal, maxVal, presenceDict, missingList, missingCount, row
  103. For k = 0 To itemCount
  104. precinct = keys(k)
  105. numStrs = Split(precinctNums(precinct), ",")
  106. ReDim numArr(UBound(numStrs))
  107. For j = 0 To UBound(numStrs)
  108. numArr(j) = CLng(numStrs(j))
  109. Next
  110. minVal = numArr(0)
  111. maxVal = numArr(0)
  112. For j = 1 To UBound(numArr)
  113. If numArr(j) < minVal Then minVal = numArr(j)
  114. If numArr(j) > maxVal Then maxVal = numArr(j)
  115. Next
  116. set presenceDict = CreateObject("Scripting.Dictionary")
  117. For j = 0 To UBound(numArr)
  118. If Not presenceDict.Exists(numArr(j)) Then
  119. presenceDict.Add numArr(j), True
  120. End If
  121. Next
  122. missingList = ""
  123. missingCount = 0
  124. For n = minVal To maxVal
  125. If Not presenceDict.Exists(n) Then
  126. missingCount = missingCount + 1
  127. If Len(missingList) > 0 Then missingList = missingList & ", "
  128. missingList = missingList & CStr(n)
  129. End If
  130. Next
  131. set row = new PrecinctBallotRangeRow_ViewModel_Class
  132. row.PRECINCT = precinct
  133. row.LowBallotNumber = minVal
  134. row.HighBallotNumber = maxVal
  135. row.MissingCount = missingCount
  136. row.MissingNumbers = missingList
  137. Set items(k) = row
  138. Next
  139. SortPrecinctItems items
  140. dim list : set list = new LinkedList_Class
  141. ' Iterate in reverse for descending precinct order
  142. For k = UBound(items) To 0 Step -1
  143. list.Push items(k)
  144. Next
  145. set BuildBallotRangesWithMissing = list
  146. End Function
  147. Private Sub SortPrecinctItems(ByRef items)
  148. If Not IsArray(items) Then Exit Sub
  149. dim i, j
  150. For i = 0 To UBound(items) - 1
  151. For j = i + 1 To UBound(items)
  152. If PrecinctSortsBefore(items(j).PRECINCT, items(i).PRECINCT) Then
  153. dim temp : set temp = items(i)
  154. Set items(i) = items(j)
  155. Set items(j) = temp
  156. End If
  157. Next
  158. Next
  159. End Sub
  160. Private Function PrecinctSortsBefore(ByVal leftPrecinct, ByVal rightPrecinct)
  161. dim leftType, leftNumber, leftSuffix, leftNormalized
  162. dim rightType, rightNumber, rightSuffix, rightNormalized
  163. ParsePrecinctSortParts leftPrecinct, leftType, leftNumber, leftSuffix, leftNormalized
  164. ParsePrecinctSortParts rightPrecinct, rightType, rightNumber, rightSuffix, rightNormalized
  165. If leftType <> rightType Then
  166. PrecinctSortsBefore = (leftType < rightType)
  167. Exit Function
  168. End If
  169. If leftType = 0 Then
  170. If leftNumber <> rightNumber Then
  171. PrecinctSortsBefore = (leftNumber < rightNumber)
  172. Exit Function
  173. End If
  174. If leftSuffix <> rightSuffix Then
  175. PrecinctSortsBefore = (leftSuffix < rightSuffix)
  176. Exit Function
  177. End If
  178. End If
  179. If leftNormalized <> rightNormalized Then
  180. PrecinctSortsBefore = (leftNormalized < rightNormalized)
  181. Else
  182. PrecinctSortsBefore = (UCase(Trim(leftPrecinct & "")) < UCase(Trim(rightPrecinct & "")))
  183. End If
  184. End Function
  185. Private Sub ParsePrecinctSortParts(ByVal precinct, ByRef precinctType, ByRef numericPart, ByRef suffixPart, ByRef normalizedText)
  186. dim rawPrecinct : rawPrecinct = Trim(precinct & "")
  187. dim leadingDigits : leadingDigits = ""
  188. dim i, currentChar
  189. For i = 1 To Len(rawPrecinct)
  190. currentChar = Mid(rawPrecinct, i, 1)
  191. If currentChar >= "0" And currentChar <= "9" Then
  192. leadingDigits = leadingDigits & currentChar
  193. Else
  194. Exit For
  195. End If
  196. Next
  197. If Len(leadingDigits) > 0 Then
  198. precinctType = 0
  199. numericPart = CLng(leadingDigits)
  200. suffixPart = UCase(Trim(Mid(rawPrecinct, Len(leadingDigits) + 1)))
  201. normalizedText = CStr(numericPart) & "|" & suffixPart
  202. Else
  203. precinctType = 1
  204. numericPart = 0
  205. suffixPart = UCase(rawPrecinct)
  206. normalizedText = suffixPart
  207. End If
  208. End Sub
  209. End Class
  210. dim PurpleEnvelopeReportHelper__Singleton
  211. Function PurpleEnvelopeReportHelper()
  212. If IsEmpty(PurpleEnvelopeReportHelper__Singleton) Then
  213. set PurpleEnvelopeReportHelper__Singleton = new PurpleEnvelopeReportHelper_Class
  214. End If
  215. set PurpleEnvelopeReportHelper = PurpleEnvelopeReportHelper__Singleton
  216. End Function
  217. %>

Powered by TurnKey Linux.