Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

258 linhas
6.7KB

  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, strips non-digits from each
  70. ' ballot number, computes min/max and any missing numbers in that range, then
  71. ' returns rows sorted by precinct in descending order.
  72. dim precinctNums : set precinctNums = CreateObject("Scripting.Dictionary")
  73. dim precinct, rawNum, digits, i, ch
  74. Do Until rs.EOF
  75. precinct = Trim(rs("PRECINCT") & "")
  76. rawNum = rs("BALLOT_NUMBER") & ""
  77. digits = ""
  78. For i = 1 To Len(rawNum)
  79. ch = Mid(rawNum, i, 1)
  80. If ch >= "0" And ch <= "9" Then digits = digits & ch
  81. Next
  82. If Len(digits) > 0 Then
  83. If precinctNums.Exists(precinct) Then
  84. precinctNums(precinct) = precinctNums(precinct) & "," & digits
  85. Else
  86. precinctNums.Add precinct, digits
  87. End If
  88. End If
  89. rs.MoveNext
  90. Loop
  91. If precinctNums.Count = 0 Then
  92. set BuildBallotRangesWithMissing = new LinkedList_Class
  93. Exit Function
  94. End If
  95. dim keys : keys = precinctNums.Keys
  96. dim itemCount : itemCount = precinctNums.Count - 1
  97. dim items()
  98. ReDim items(itemCount)
  99. dim k, j, n
  100. dim numStrs, numArr, minVal, maxVal, presenceDict, missingList, missingCount, row
  101. For k = 0 To itemCount
  102. precinct = keys(k)
  103. numStrs = Split(precinctNums(precinct), ",")
  104. ReDim numArr(UBound(numStrs))
  105. For j = 0 To UBound(numStrs)
  106. numArr(j) = CLng(numStrs(j))
  107. Next
  108. minVal = numArr(0)
  109. maxVal = numArr(0)
  110. For j = 1 To UBound(numArr)
  111. If numArr(j) < minVal Then minVal = numArr(j)
  112. If numArr(j) > maxVal Then maxVal = numArr(j)
  113. Next
  114. set presenceDict = CreateObject("Scripting.Dictionary")
  115. For j = 0 To UBound(numArr)
  116. If Not presenceDict.Exists(numArr(j)) Then
  117. presenceDict.Add numArr(j), True
  118. End If
  119. Next
  120. missingList = ""
  121. missingCount = 0
  122. For n = minVal To maxVal
  123. If Not presenceDict.Exists(n) Then
  124. missingCount = missingCount + 1
  125. If Len(missingList) > 0 Then missingList = missingList & ", "
  126. missingList = missingList & CStr(n)
  127. End If
  128. Next
  129. set row = new PrecinctBallotRangeRow_ViewModel_Class
  130. row.PRECINCT = precinct
  131. row.LowBallotNumber = minVal
  132. row.HighBallotNumber = maxVal
  133. row.MissingCount = missingCount
  134. row.MissingNumbers = missingList
  135. Set items(k) = row
  136. Next
  137. SortPrecinctItems items
  138. dim list : set list = new LinkedList_Class
  139. ' Iterate in reverse for descending precinct order
  140. For k = UBound(items) To 0 Step -1
  141. list.Push items(k)
  142. Next
  143. set BuildBallotRangesWithMissing = list
  144. End Function
  145. Private Sub SortPrecinctItems(ByRef items)
  146. If Not IsArray(items) Then Exit Sub
  147. dim i, j
  148. For i = 0 To UBound(items) - 1
  149. For j = i + 1 To UBound(items)
  150. If PrecinctSortsBefore(items(j).PRECINCT, items(i).PRECINCT) Then
  151. dim temp : set temp = items(i)
  152. Set items(i) = items(j)
  153. Set items(j) = temp
  154. End If
  155. Next
  156. Next
  157. End Sub
  158. Private Function PrecinctSortsBefore(ByVal leftPrecinct, ByVal rightPrecinct)
  159. dim leftType, leftNumber, leftSuffix, leftNormalized
  160. dim rightType, rightNumber, rightSuffix, rightNormalized
  161. ParsePrecinctSortParts leftPrecinct, leftType, leftNumber, leftSuffix, leftNormalized
  162. ParsePrecinctSortParts rightPrecinct, rightType, rightNumber, rightSuffix, rightNormalized
  163. If leftType <> rightType Then
  164. PrecinctSortsBefore = (leftType < rightType)
  165. Exit Function
  166. End If
  167. If leftType = 0 Then
  168. If leftNumber <> rightNumber Then
  169. PrecinctSortsBefore = (leftNumber < rightNumber)
  170. Exit Function
  171. End If
  172. If leftSuffix <> rightSuffix Then
  173. PrecinctSortsBefore = (leftSuffix < rightSuffix)
  174. Exit Function
  175. End If
  176. End If
  177. If leftNormalized <> rightNormalized Then
  178. PrecinctSortsBefore = (leftNormalized < rightNormalized)
  179. Else
  180. PrecinctSortsBefore = (UCase(Trim(leftPrecinct & "")) < UCase(Trim(rightPrecinct & "")))
  181. End If
  182. End Function
  183. Private Sub ParsePrecinctSortParts(ByVal precinct, ByRef precinctType, ByRef numericPart, ByRef suffixPart, ByRef normalizedText)
  184. dim rawPrecinct : rawPrecinct = Trim(precinct & "")
  185. dim leadingDigits : leadingDigits = ""
  186. dim i, currentChar
  187. For i = 1 To Len(rawPrecinct)
  188. currentChar = Mid(rawPrecinct, i, 1)
  189. If currentChar >= "0" And currentChar <= "9" Then
  190. leadingDigits = leadingDigits & currentChar
  191. Else
  192. Exit For
  193. End If
  194. Next
  195. If Len(leadingDigits) > 0 Then
  196. precinctType = 0
  197. numericPart = CLng(leadingDigits)
  198. suffixPart = UCase(Trim(Mid(rawPrecinct, Len(leadingDigits) + 1)))
  199. normalizedText = CStr(numericPart) & "|" & suffixPart
  200. Else
  201. precinctType = 1
  202. numericPart = 0
  203. suffixPart = UCase(rawPrecinct)
  204. normalizedText = suffixPart
  205. End If
  206. End Sub
  207. End Class
  208. dim PurpleEnvelopeReportHelper__Singleton
  209. Function PurpleEnvelopeReportHelper()
  210. If IsEmpty(PurpleEnvelopeReportHelper__Singleton) Then
  211. set PurpleEnvelopeReportHelper__Singleton = new PurpleEnvelopeReportHelper_Class
  212. End If
  213. set PurpleEnvelopeReportHelper = PurpleEnvelopeReportHelper__Singleton
  214. End Function
  215. %>

Powered by TurnKey Linux.