Skip to content

Implementação do teste técnico #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Implementação do teste técnico #24

wants to merge 27 commits into from

Conversation

alessandroasac
Copy link

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.

Copy link

@nandooliveira nandooliveira left a comment

Choose a reason for hiding this comment

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

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")
)

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Bad indentation.

self
end

def create_kill(killed_at:, killer:, killed:, weapon:)

Choose a reason for hiding this comment

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

Would be good to extract this method to its own service.

self
end

def create_suicide(killed_at:, killed:)

Choose a reason for hiding this comment

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

Would be good to extract this method to its own service.

@@ -0,0 +1,44 @@
class Match::Builder

Choose a reason for hiding this comment

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

This class is doing too much.

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

Choose a reason for hiding this comment

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

Bad indentation.

end

def message(players_qty)
"Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players."

Choose a reason for hiding this comment

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

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?

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Bad indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants