Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FileDelete, votes.txt
- NumBallots = 0
- ; Count ballots
- Loop, Files, ballots\*.txt
- NumBallots += 1
- IfNotExist, master.txt
- MsgBox, 0, Warning, I can't find a list of nominations (master.txt). The votes will be counted, but there might be doubles in the final results.
- Progress, b2 w200,, Processing ballots...
- Loop, Files, ballots\*.txt
- {
- Prog := (A_Index/NumBallots)*100
- Progress, %Prog%
- Loop, Read, %A_LoopFileFullPath%
- {
- Vote := A_LoopReadLine
- /* CALCULATE POINTS
- Change the next uncommented line (Points := 51-A_Index) according to your points system. A_Index is the line number of the current ballot. In this example the first line (where A_Index = 1) gets 50 points (51-1).
- This is what I used for the soul poll. The first 25 albums were weighted (first one 30 points, so 31-A_Index), all the others on the ballot got 5 points.
- Points := (A_Index <= 25) ? (31-A_Index) : 5
- */
- Points := 51-A_Index
- NrOne := (A_Index = 1) ? 1 : 0
- IfNotExist, master.txt
- Gosub, CountVotes
- Else
- {
- ; check for album in master list
- FileRead, Master, master.txt
- IfInString, Master, %Vote%
- Gosub, CountVotes
- Else
- {
- MsgBox, 0, Error in %A_LoopFileName%, Line %A_Index% not in master list:`n%A_LoopReadLine% (%Points% points)
- Run, notepad.exe "%A_LoopFileFullPath%"
- }
- }
- }
- }
- FileRead, Votes, votes.txt
- Votes := SortByColumn(Votes, 2, "N R")
- Votes := RTrim(Votes, "`n`r")
- FileDelete, votes.txt
- FileAppend, %Votes%`n, votes.txt
- Progress, Off
- MsgBox, 0, Ready!, %NumBallots% ballots processed.
- ExitApp
- Esc::ExitApp
- ; -------- Functions and subroutines ---------
- SortByColumn(Str, SortCol, SortOptions="", ColSep="`t", RowSep="`n", RowOmitChars="") {
- IfEqual,SortCol,1,Sort,Str,D%RowSep% %SortOptions%
- IfEqual,SortCol,1,Return Str
- BS:=Chr(8), AA:=BB:=""
- Loop, parse, Str, %RowSep%, %RowOmitChars%
- p:=InStr(A_LoopField,ColSep,false,1,SortCol-1)
- ,AA.=SubStr(A_LoopField,(p=0?1:p+1)) BS A_LoopField RowSep
- Sort, AA, D%RowSep% %SortOptions%
- Loop, parse, AA, %RowSep%
- BB.=SubStr(A_LoopField,InStr(A_LoopField,BS)+1) RowSep
- Return RTrim(BB, RowSep)
- }
- CountVotes:
- ; check for album in votes.txt
- FileRead, Votes, votes.txt
- IfInString, Votes, %Vote%
- {
- ; add Points to votes.txt
- Out =
- Loop, Parse, Votes, `n, `r
- {
- IfInString, A_LoopField, %Vote%
- {
- AlbumArray := StrSplit(A_LoopField, "`t")
- Album := AlbumArray[1]
- Points := Points+AlbumArray[2]
- NumVotes := AlbumArray[3]+1
- NrOne := NrOne+AlbumArray[4]
- Out .= Album . "`t" . Points . "`t" . NumVotes . "`t" . NrOne . "`n"
- }
- Else
- Out .= A_LoopField . "`n"
- }
- FileDelete, votes.txt
- FileAppend, %Out%, votes.txt
- }
- Else
- FileAppend, %Vote%`t%Points%`t1`t%NrOne%`n, votes.txt
- Return
- ; END CountVotes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement