-
Notifications
You must be signed in to change notification settings - Fork 26
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
Simplify and refactor SiteData
, removing unused code
#1989
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking so much better!
app/classes/site_data.rb
Outdated
# !(obs.specimen && obs.notes.to_s.length >= 10 && | ||
# obs.thumb_image_id.to_i.positive?) | ||
# end | ||
# }.freeze | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to erase these completely, they'd be easy to reconstruct anyway.
app/classes/site_data.rb
Outdated
case mode | ||
when :del | ||
-weight | ||
when :chg | ||
get_weight_change(obj, field) | ||
0 # get_weight_change(obj, field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this case for? Do we ever actually use it?
app/classes/site_data.rb
Outdated
# def self.get_weight_change(obj, new_field) | ||
# old_field = new_field | ||
# FIELD_WEIGHTS[new_field] - FIELD_WEIGHTS[old_field] | ||
# end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good riddance!!!!
app/classes/site_data.rb
Outdated
# end | ||
|
||
@user_id = id.to_i | ||
user = User.find(id) | ||
|
||
# Prime @user_data structure. | ||
@user_data = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fishy. Either this is never called on multiple users, in which case @user_data doesn't need to be a hash, or it is called on multiple users, in which case shouldn't this is @user_data ||= {}
? As it is, it clobbers the hash each time and sticks a single user in it.
# Add some extra stats. | ||
@site_data[:observed_taxa] = Observation.distinct.count(:name_id) | ||
@site_data[:listed_taxa] = Name.count | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into SiteData
Trying to get a handle on the confusing logic of this class, prior to writing a table to store the data.
observations_with_voucher
andobservations_without_voucher
. These cases required SiteData to account for much more complex logic. The logic somehow was implemented, but is always bypassed in code execution. I'm getting rid of it; it makes the code harder to read and refactor. Those fields can be rebuilt when the code here is simpler, if desired.