Open ghost opened 9 years ago
Data model and DB:
Emergency#code
, and your foreign key in Responders#emergency_id
, so having Responders#emergency_code
is a problem because it could potentially get out of sync with Emergency#code
. So, you'll want to remove that from your data model.Emergency#resolved_at
is nil
, then you already know that unresolved
is true
, and if it's not nil
, then unresolved
is false
. It's better to add a dash of business logic to figure that out than to add unnecessary columns to your data model that need to be kept in sync, adding future maintenance.annotate
gem since it duplicates information that's already in your db/schema.rb
file. It's just documentation that's likely to get out of sync if you forget to run the rake task to update it, which most developers eventually do. Even if you're perfect at remembering to do it it's one more application dependency to keep up-to-date, which I personally think is unnecessary for the value it provides.Emergency#call_off_responders
method's implementation with the following code, which (a) avoids iterating over the associated objects unnecessarily, and (b) avoids putting logic in two models instead of one:def call_off_responders responders = [] save! end
Responder#return_to_base
should be able to be removed entirely.Emergency::count_resolved
with a scope, something like:scope :resolved, -> { where.not(:resolved_at, nil) } # untested code
...and then call it like this:
Emergency.resolved.count
Controllers
slug
thing now. It means you add code to both your model and your EmergenciesController
. Seems unnecessary when you could do@emergency = Emergency.find_by_code(params[:id])
...or alter your route to convert the id
parameter to code
instead. Another judge might have more to say on this point, maybe not.
@railschallenge-judge04 thanks for the input. It seems I need to up my DRY skills :)
First of all, I didn't thought about using emergency_code as an virtual attribute. It's in the spec, but I see the benefit of not saving it into DB directly.
Secondly, I'm not sure about Emergency#resolved_at being a good spot to check for full_response, as it is possible to set it via request without dispatching any Responder. I used Emergency#unresolved as a numeric counter to measure if ResponderDipatcher was abble to bring all Severity to 0 (it's a numeric field with sum of remainig Severity). I will have to think about it.
About the slug. my logic was as follows:
About the rest - great ideas.
I'll see if I can circle back to this sometime tomorrow. I know that doesn't leave you much time for further changes, but we have many more repos to cover this weekend with early feedback, and right now I'm working to make sure everyone gets at least one round with a judge.
Thanks again for your participation!
Verified score of 114 points
on the automated scoring, based on the current master branch.
After much consideration, I have removed the slugs
...I'm not sure about Emergency#resolved_at being a good spot to check for full_response, as it is possible to set it via request without dispatching any Responder
This should not be the case. This test ensures that you cannot set Emergency#resolved_at
during creation, and these other tests ensure that dispatch happens on creation. So it should not be possible, if you have all tests passing, to set Emergency#resolved_at
without the proper Responders having already been dispatched.
Ok, I get it. I tried to keep the starting values of severities and that is not required by spec. Updated
Sounds good.
Your score breakdown (you placed 19th):
174 points total:
2
0
0
1
1
I wanted to say a special thank you to you for the conversations on Twitter. Was really cool to see the engagement, and I enjoyed interacting with you online (says the faceless, robot-like general @railschallenge account :tongue: ).
Keep your eye out for our post on what judges thought were the best solutions. We're hoping there's a lot of learning to be had. The plan is the following:
Writeup on the following:
The article summarizing the code, we're hoping, provides a lot of insight into how other programmers think, and our goal is to spread that knowledge to everyone who took the time to participate.
Thanks a million @michalsapka for participating!
Placeholder issue for judge's feedback.