# HG changeset patch # User Sean E. Russell # Date 1614107040 21600 # Tue Feb 23 13:04:00 2021 -0600 # Node ID de49936d6214bd00473621442b11aee96eace27d # Parent d355806b0e224ba7a1037fe10423b3adeed9a63b If cycle, determine winner by pure score diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Using the example data in the repository: ``` -10235(hg:default)» go run main.go < input-1.csv ~/workspace/sbb +10235(hg:default)» go run main.go < input-1.csv Total votes in input: 15 Summary of distributions # A B C @@ -80,8 +80,14 @@ ``` You'll get a program called `MARS` in your `$GOPATH/bin`, usually -`~/go/bin`. Alternatively, check out the repository and run it on the -command line: +`~/go/bin`. Compiled or downloaded, you would then either download an input +file from the repository, or create your own, and run it with: + +``` +MARS < inputdataset.csv +``` + +Alternatively, check out the repository and run it on the command line: ``` hg clone https://hg.sr.ht/~ser/MARS diff --git a/main.go b/main.go --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -// score-better-balance calculator +// MARS (Mixed Absolute Relative Score) // from https://www.reddit.com/r/EndFPTP/comments/lil4zz/scorebetterbalance_a_proposal_to_fix_some/ import ( @@ -12,6 +12,7 @@ "strings" ) +// FIXME: detect tie func main() { /**************************/ /* Process the input data */ @@ -64,11 +65,12 @@ // then we're looping; dump the cycle list and exit. for _, cand := range past { if w2 == cand { - fmt.Print("Cycle found in ") + fmt.Print("Cycle found in adjusted scoring ") for _, c := range past { fmt.Printf("%s => ", lines[0][c]) } fmt.Printf("%s => ...\n", lines[0][w2]) + printScoreDetails(w, lines, badVotes, ints, diffs, ttl) return } } @@ -78,7 +80,8 @@ wc = w2 } - printDetails(wc, lines, badVotes, ints, diffs, ttl) + printScoreDetails(wc, lines, badVotes, ints, diffs, ttl) + printAdjustDetails(wc, lines, badVotes, ints, diffs, ttl) } // getRange finds the maximum and minimum score values in the entire file. @@ -191,7 +194,7 @@ // printDetails cut out from main() to keep main terse; nothing here is // relevant to the voting calculation, and is only output. -func printDetails(wc int, hlines, badVotes [][]string, ints [][]int, diffs [][]int, ttl []int) { +func printScoreDetails(wc int, hlines, badVotes [][]string, ints [][]int, diffs [][]int, ttl []int) { header := hlines[0] lines := hlines[1:] // The rest of this is just dumping out the calculations. @@ -201,6 +204,10 @@ printWithCandidates("Subtotals", false, header, subttl) subWc := max(subttl) fmt.Printf("Winner by score: %s with %d\n", header[subWc], subttl[subWc]) +} + +func printAdjustDetails(wc int, hlines, badVotes [][]string, ints [][]int, diffs [][]int, ttl []int) { + header := hlines[0] printWithCandidates("Summary of diffs", true, header, uniq(toString(diffs))) printWithCandidates("Modifiers", false, header, subtotal(diffs)) printWithCandidates("Totals", false, header, ttl) diff --git a/tie.csv b/tie.csv new file mode 100644 --- /dev/null +++ b/tie.csv @@ -0,0 +1,9 @@ +A,B,C +5,1,0 +5,1,0 +5,1,0 +5,1,0 +0,1,5 +0,1,5 +0,1,5 +0,1,5