Implementação do teste técnico#24
Open
alessandroasac wants to merge 27 commits intohusky-misc:masterfrom
alessandroasac:master
Open
Implementação do teste técnico#24alessandroasac wants to merge 27 commits intohusky-misc:masterfrom alessandroasac:master
alessandroasac wants to merge 27 commits intohusky-misc:masterfrom
alessandroasac:master
Conversation
…ranking (the <WORLD> case). Now world will be ignored.
Killer and weapon made optional.
nandooliveira
suggested changes
May 4, 2021
nandooliveira
left a comment
There was a problem hiding this comment.
I left some comments, but the biggest problem is the lack of tests.
Comment on lines
+7
to
+15
| @match.kills | ||
| .joins("INNER JOIN players ON players.id = kills.killer_id OR players.id = kills.killed_id") | ||
| .group("players.id","players.name") | ||
| .order("frag DESC, deaths") | ||
| .pluck( | ||
| "players.name", | ||
| Arel.sql("SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE 0 END) AS frag"), | ||
| Arel.sql("SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths") | ||
| ) |
There was a problem hiding this comment.
Suggested change
| @match.kills | |
| .joins("INNER JOIN players ON players.id = kills.killer_id OR players.id = kills.killed_id") | |
| .group("players.id","players.name") | |
| .order("frag DESC, deaths") | |
| .pluck( | |
| "players.name", | |
| Arel.sql("SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE 0 END) AS frag"), | |
| Arel.sql("SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths") | |
| ) | |
| @match.kills.joins(:killer) | |
| .group('players.id', 'players.name') | |
| .order(frag: :desc, deaths: :asc) | |
| .select('players.name, '\ | |
| 'SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE | |
| 0 END) AS frag, '\ | |
| 'SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths') |
Comment on lines
+37
to
+43
| def find_or_initialize_player(name:) | ||
| @players[name] ||= Player.find_or_initialize_by(name: name) | ||
| end | ||
|
|
||
| def find_or_initialize_weapon(name:) | ||
| @weapons[name] ||= Weapon.find_or_initialize_by(name: name) | ||
| end |
| self | ||
| end | ||
|
|
||
| def create_kill(killed_at:, killer:, killed:, weapon:) |
There was a problem hiding this comment.
Would be good to extract this method to its own service.
| self | ||
| end | ||
|
|
||
| def create_suicide(killed_at:, killed:) |
There was a problem hiding this comment.
Would be good to extract this method to its own service.
| @@ -0,0 +1,44 @@ | |||
| class Match::Builder | |||
Comment on lines
+19
to
+30
| def validate_match | ||
| players_qty = players.size | ||
| raise PlayersLimitExceededError, message(players_qty) if players_qty > PLAYERS_LIMIT | ||
| end | ||
|
|
||
| def players | ||
| (match.kills.map(&:killer) | match.kills.map(&:killed)).compact | ||
| end | ||
|
|
||
| def message(players_qty) | ||
| "Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." | ||
| end |
| end | ||
|
|
||
| def message(players_qty) | ||
| "Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." |
There was a problem hiding this comment.
Suggested change
| "Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." | |
| "Exceeded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." |
|
|
||
| def each_match | ||
| @file.each_line do |line| | ||
| next if line.blank? |
There was a problem hiding this comment.
Add a new line after guard clauses.
Suggested change
| next if line.blank? | |
| next if line.blank? | |
Comment on lines
+20
to
+30
| case captures | ||
| in { started_at: started_at, code: code } => params | ||
| @match_builder = Match::Builder.new | ||
| @match_builder.start_match(**params) | ||
| in { ended_at: ended_at, code: code } => params | ||
| yield @match_builder.end_match(**params).build | ||
| in { killed_at: killed_at, killer: killer, killed: killed, weapon: weapon } => params | ||
| @match_builder.create_kill(**params) | ||
| in { killed_at: killed_at, killed: killed } => params | ||
| @match_builder.create_suicide(**params) | ||
| end |
There was a problem hiding this comment.
This is the second time that I see someone using a case statement in Ruby, and I don't like it.. 😢 hahaha
It is hard to read. I also like to use regular expressions when it is essentially necessary; they are computationally costly.
Comment on lines
+36
to
+41
| def extract_captures(match) | ||
| captures = match.named_captures | ||
| captures.compact! | ||
| captures.transform_keys!(&:to_sym) | ||
| captures | ||
| end |
luxu
approved these changes
Oct 7, 2022
luxu
approved these changes
Oct 7, 2022
luxu
approved these changes
Oct 7, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fiz da maneira mais simples possível. Algumas soluções poderiam ser melhoradas, mas foi o que consegui fazer no tempo proposto.
A implementação do importador do arquivo foi feita usando PORO e depois com serviços, isso consta no histórico dos commits.