Merge pull request #17 from MieuxVoter/feat-13

Add a `--judges <amount>` parameter to override the guess of the amount of judges
pull/21/head
Dominique Merle 3 years ago committed by GitHub
commit e68f866920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -139,3 +139,8 @@ You can run `upx` on the binary to reduce its size:
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o mj.exe
Sometimes, Go builds for Windows are [falsely detected](https://golang.org/doc/faq#virus) by antiviral software.
## Run tests
go test -v

@ -85,9 +85,11 @@ Gnuplots are meant to be piped as scripts to gnuplot http://www.gnuplot.info
_ = cmd.Help()
return
}
var outputFormatter formatter.Formatter
format := cmd.Flags().Lookup("format").Value.String()
defaultTo := cmd.Flags().Lookup("default").Value.String()
amountOfJudgesStr := cmd.Flags().Lookup("judges").Value.String()
var outputFormatter formatter.Formatter
outputFormatter = &formatter.TextFormatter{}
if "text" == format {
//outputFormatter = &formatter.TextFormatter{}
@ -179,7 +181,19 @@ Gnuplots are meant to be piped as scripts to gnuplot http://www.gnuplot.info
poll := &judgment.PollTally{
Proposals: proposalsTallies,
}
poll.GuessAmountOfJudges()
amountOfJudges, amountOfJudgesErr := strconv.ParseInt(amountOfJudgesStr, 10, 64)
if nil != amountOfJudgesErr || amountOfJudges < 0 {
fmt.Printf("Unrecognized --judges amount `%s`. "+
"Use a positive integer, like so: --judges 42\n", amountOfJudgesStr)
os.Exit(ErrorConfiguring)
}
if amountOfJudges > 0 {
poll.AmountOfJudges = uint64(amountOfJudges)
} else {
poll.GuessAmountOfJudges()
}
var balancerErr error
defaultGradeIndex := indexOf(defaultTo, grades)
@ -252,6 +266,7 @@ func init() {
rootCmd.Flags().StringP("default", "d", "0", "default grade to use when unbalanced")
rootCmd.Flags().StringP("width", "w", "79", "desired width, in characters")
rootCmd.Flags().StringP("chart", "c", "merit", "one of merit, opinion")
rootCmd.Flags().Int64P("judges", "j", 0, "amount of judges participating")
//rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
//rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
rootCmd.Flags().BoolP("sort", "s", false, "sort proposals by Rank")

@ -57,7 +57,9 @@ func (t *GnuplotOpinionFormatter) Format(
for _, proposalResult := range proposalsResults {
proposalTally := pollTally.Proposals[proposalResult.Index]
row = append(row, strconv.FormatUint(proposalTally.Tally[gradeIndex], 10))
row = append(row, strconv.FormatFloat(
float64(proposalTally.Tally[gradeIndex])/options.Scale,
'f', -1, 64))
}
writeErr := writer.Write(row)

@ -3,7 +3,7 @@ module github.com/MieuxVoter/majority-judgment-cli
go 1.17
require (
github.com/mieuxvoter/majority-judgment-library-go v0.3.0
github.com/mieuxvoter/majority-judgment-library-go v0.3.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

Loading…
Cancel
Save