Skip to content

Commit

Permalink
Merge pull request #7 from sdobber/sd_majorityfix
Browse files Browse the repository at this point in the history
Fix multiple majority calculations
  • Loading branch information
sdobber authored Aug 25, 2022
2 parents d7b7f0f + c08bca0 commit 84e301b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BallroomSkatingSystem"
uuid = "8aed41a2-23bd-4167-baf7-1f33f6c22702"
authors = ["Sören Dobberschütz <[email protected]> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
9 changes: 5 additions & 4 deletions src/skating_single_dance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ function skating_single_dance(results::DataFrame, majority_from::Int; initial_pl
append_sum = false
remove!(idx, id)
else
idy = idx[findall(==(maximum(calculation[idx, tmp_col+1])), calculation[idx, tmp_col+1])]
# equal majority
# look at sum of evaluations up to current column
if length(findall(==(minimum(sum_of_eval[idx, tmp_col+1])), sum_of_eval[idx, tmp_col+1])) == 1
if length(findall(==(minimum(sum_of_eval[idy, tmp_col+1])), sum_of_eval[idy, tmp_col+1])) == 1
# @info "Single sum minority"
id = findfirst(==(minimum(sum_of_eval[idx, tmp_col+1])), sum_of_eval[idx, tmp_col+1])
write_result!(calculation, calculation_text, sum_of_eval, idx[id], current_place, current_col, tmp_col, max_cols; append_sum=true)
id = findfirst(==(minimum(sum_of_eval[idy, tmp_col+1])), sum_of_eval[idy, tmp_col+1])
write_result!(calculation, calculation_text, sum_of_eval, idy[id], current_place, current_col, tmp_col, max_cols; append_sum=true)
current_place += 1
append_sum = true
remove!(idx, idx[id])
remove!(idx, idy[id])
else
# @info "Multiple equal sums"
calculation_text[idx, (tmp_col+1)] = string.(calculation[idx, (tmp_col+1)]) .* "*" .* "(" .* string.(sum_of_eval[idx, (tmp_col+1)]) .* ")"
Expand Down
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,26 @@ end
JudgeE=[2, 3, 4, 4, 6, 1])
calculation, places = skating_single_dance(results)
@test places[:, :Place] == [2.0, 3.0, 4.5, 4.5, 6.0, 1.0]

results = DataFrame(Number=[11, 12, 13, 14, 15, 16, 17],
JudgeA=[6, 3, 5, 1, 7, 4, 2],
JudgeB=[1, 2, 4, 3, 5, 7, 6],
JudgeC=[1, 2, 4, 3, 5, 6, 7],
JudgeD=[7, 6, 5, 4, 3, 2, 1],
JudgeE=[3, 2, 1, 4, 5, 6, 7],
JudgeF=[2, 4, 3, 1, 5, 6, 7],
JudgeG=[4, 3, 2, 1, 5, 6, 7])
calculation, places = skating_single_dance(results)
@test places[:, :Place] == [3.0, 2.0, 4.0, 1.0, 5.0, 6.0, 7.0]

results = DataFrame(Number=[11, 12, 13, 14, 15, 16, 17],
JudgeA=[1, 2, 3, 7, 6, 4, 5],
JudgeB=[7, 6, 5, 4, 1, 2, 3],
JudgeC=[7, 6, 1, 2, 3, 4, 5],
JudgeD=[1, 2, 3, 7, 6, 5, 4],
JudgeE=[7, 7, 7, 4, 3, 2, 1],
JudgeF=[1, 2, 3, 4, 5, 7, 7],
JudgeG=[4, 5, 6, 1, 2, 3, 7])
calculation, places = skating_single_dance(results)
@test places[:, :Place] == [5.0, 7.0, 2.0, 4.0, 1.0, 3.0, 6.0]
end

2 comments on commit 84e301b

@sdobber
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/67074

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 84e301befe00aca6cbbdb6e32094deeb12edb120
git push origin v0.1.2

Please sign in to comment.