Conversation
|
There are still grammar mistakes, BTW: "rounds with less than N competitors..." should be "with fewer than N competitors..." Also, just a suggestion, why not use the actual rule text which is subtly different, even if semantically the same as yours: |
|
I've updated the text to use the regulation text. The original code had a check for having at least 8 competitors in the previous round which was formatted in the same way I wrote them, which was my reasoning for keeping it in the same format. (I also find "fewer than 100" more understandable than "99 or fewer", but its probably better to use the actual regulation text). |
| Enum.to_list(1..round.number - 1 // 1) | ||
| |> Enum.map( | ||
| fn round_offset -> | ||
| Round |> Round.where_sibling(round, -round_offset) |> Repo.one() |> Repo.preload(:results) |
There was a problem hiding this comment.
Instead of querying each round separately, let's add list_previous_rounds. It should return rounds ordered by round number, and here we can reverse for the check.
| 0 -> "Rounds with 7 or fewer competitors must not have subsequent rounds" | ||
| 1 -> "Rounds with 15 or fewer competitors must have at most one subsequent round" | ||
| 2 -> "Rounds with 99 or fewer competitors must have at most two subsequent rounds" | ||
| _ -> :nil |
There was a problem hiding this comment.
The only other value we expected is nil (not found), so let's be explicit:
| _ -> :nil | |
| nil -> nil |
(also, nil is an atom, but you don't need : because it's special, same with true and false :))
| 0 -> "Rounds with 7 or fewer competitors must not have subsequent rounds" | ||
| 1 -> "Rounds with 15 or fewer competitors must have at most one subsequent round" | ||
| 2 -> "Rounds with 99 or fewer competitors must have at most two subsequent rounds" |
There was a problem hiding this comment.
Usually we keep {:error, _} messages lowercased. We transform to uppercase in other places as needed.
| 0 -> "Rounds with 7 or fewer competitors must not have subsequent rounds" | |
| 1 -> "Rounds with 15 or fewer competitors must have at most one subsequent round" | |
| 2 -> "Rounds with 99 or fewer competitors must have at most two subsequent rounds" | |
| 0 -> "rounds with 7 or fewer competitors must not have subsequent rounds" | |
| 1 -> "rounds with 15 or fewer competitors must have at most one subsequent round" | |
| 2 -> "rounds with 99 or fewer competitors must have at most two subsequent rounds" |
| message = validate_previous_rounds(round) | ||
| if message do |
There was a problem hiding this comment.
To avoid nesting you can do this:
cond do
Round.open?(round) ->
{:error, ...}
message = validate_previous_rounds(round) ->
{:error, error}
true ->
Multi.new()
|> ...
end|
@mckeenicholas thanks, a couple small comments. Also, please add one more test similar to this one: wca-live/test/wca_live/scoretaking_test.exs Lines 524 to 534 in 66b1ab6 |
Closes #186
I've only implemented the check on the server side as of now. I can add a client side check as well if necessary.