Skip to content
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

Autocomplete for mentors and participants #209

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

Conversation

aayush19saxena
Copy link
Contributor

@aayush19saxena aayush19saxena commented Feb 25, 2017

Hi guys @mattharris5 @mitchellharper12 ,

This is an improved version of searching. I used Josue's last pull request and did most of the computational work in the person.rb.

It's been a while pushing something, I'll start working towards DreamSIS more once as the spring quarter gets closer!

Copy link
Contributor

@mitchellharper12 mitchellharper12 left a comment

Choose a reason for hiding this comment

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

This whole new change review system in Github is nice, letting you put all the comments together at once.

Overall, the underlying purpose of this code is pretty good, I'm just not sure if there are any more performant options for performing these types of searches. Also, the cases where multiple strings being passed need approval from @mattharris5 to whether the behavior is correct.

As a last note, we aren't in a good habit of committing test code with each feature PR, probably because we don't have a good unit test framework. That's one of my goals to set up, and in the future I think it would make sense to require tests with newly merged features and make a habit of it.

@@ -136,7 +136,7 @@
<div class="git branch">Customer <strong><%= Customer.name_label rescue nil %></strong></div>
<div class="git branch">Tenant <strong><%= Apartment::Tenant.current_tenant rescue nil %></strong></div>
<div id="dev-inspector" style="display:none">
<div class="session-info"><pre><%= session.to_yaml %></pre></div>
<div class="session-info"><pre><%#= session.to_yaml %></pre></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason this is commented out now?

@@ -131,6 +131,51 @@ def self.object_filters
[]
end

def self.find_by_name(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method name is confusing. Generally, if there's a method on a model named find_by_..., I expect the method will return an instance of that model. For example, if the method was named find_by_id, I would expect the method would take an integer and return the object that has the associated ID.

However, this method does not return Person objects. It returns an array of 4 strings.

I would rename this to make it more clear that the method is not doing any "finding", but is instead parsing a name and returning some relevant data. I would also add a comment above the method stating what the method takes and what it returns, because it is not immediately clear on its own.

name = name.downcase
args = name.split(" ")
conditions = generate_conditions(args, name)
return conditions
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines above can be combined, no need for the assignment to conditions.

first = ""
middle = ""
last = ""
args = args.each { |s| s.strip! }
Copy link
Contributor

Choose a reason for hiding this comment

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

This line ends up doing the right thing, but not in the way you expect...

The assignment is actually redundant. Because you are using the in-place strip! method, each string in the args array will already be stripped. When you call .each, the original array is returned, so the original array is being set to itself here. It just so happens that by calling the in-place search, you are stripping each string directly in the args array.

So if this line were changed to only read args.each { |s| s.strip! }, the behavior would be the same. The more standard way of writing this would be to say

args = args.collect { |s| s.strip }

which does not use an in-place strip. Additionally, as a Ruby trick, whenever you have a block that takes one argument and calls a method on that one argument, you can rewrite the method to take a Proc instead:

args = args.collect(&:strip)

end
conditions = ["(LOWER(firstname) LIKE :firstname AND LOWER(lastname) LIKE :lastname AND LOWER(middlename) LIKE :middlename)", first, middle, last]
end
return conditions
Copy link
Contributor

Choose a reason for hiding this comment

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

It may make more sense to return an object rather than an array, that way you don't have to remember what each array index represents. For example, this could be what's returned:

{ firstname: "Keisha", middlename: "Test", lastname: "Test", sql_where: "SQL LIKE(STUFF) WHERE STUFF ETC" }

first = args[0]
middle = args[1]
end
conditions = ["(LOWER(firstname) LIKE :firstname AND LOWER(lastname) LIKE :lastname AND LOWER(middlename) LIKE :middlename)", first, middle, last]
Copy link
Contributor

Choose a reason for hiding this comment

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

Of all of the SQL statements, this one seems like the most likely to exhibit incorrect, or at least imperfect, behavior.

Sometimes middlenames are stored with first names for UW mentors because that's how data is returned from the student database. Also, sometimes people have two-word first or last names. I'm also not sure the best way to handle this case, as by doing straight SQL like this there are a number of edge cases depending on how you structure the query.

first = generated_conditions[1]
middle = generated_conditions[2]
last = generated_conditions[3]

conditions << "high_school_id = :high_school_id" if params[:high_school_id]
conditions << "grad_year = :grad_year" if params[:grad_year]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these two lines above work together? There are no spaces at the start or end of lines, so I'm wondering if there's a chance that the string won't have spaces where it needs them.

:conditions => [conditions,
{:firstname => "%#{first}",
:lastname => "%#{last}",
:middlename => "%#{middle}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need wildcard characters after the names? Here, they are only before, which may not be the behavior we want.

@@ -1,7 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
CFPropertyList (2.3.5)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we have strict guidelines as to whether or not you should commit your Gemfile.lock with feature PRs, but to me it makes more sense to add it in a separate commit instead. Not a huge deal either way though.

last = args[1]
middle = args[1]
end
conditions = ["(LOWER(firstname) LIKE :firstname AND(LOWER(lastname) LIKE :lastname OR LOWER(middlename) LIKE :middlename))", first, middle, last]
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also be the case where a person has two letter first name or last name. It's just a decision whether or not we want to gracefully handle this case.

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.

2 participants