Skip to content

Instantly share code, notes, and snippets.

Last active March 16, 2018 00:24
Show Gist options
  • Save ciacci1234/74322157533928d38ccae7546bf696a1 to your computer and use it in GitHub Desktop.
Save ciacci1234/74322157533928d38ccae7546bf696a1 to your computer and use it in GitHub Desktop.
I created a very basic matching algorithm during a hackathon.

Lessons Learned

  • For Hackathons, emphasizing how a proposed app/product solves a given pain point can be as valuable if not more valuable than the specific details of the technical implementation.
  • I discovered a handy way in Ruby to perform Array Intersection with the & operator.


At the end of my bootcamp, we had a small internal hackathon. My team was assigned the hypothetical task of improving AirBnB's site to address issues of racial discrimination by hosts towards guests. Our team decided to utilize IBM Watson's Personality Insights API to analyze AirBnB users' bio descriptions (which our team proposed adding as a requirement upon signup).

The Watson analysis would quantify a user's personality and these values would help inform the matching of hosts with guests. Initially, we wanted to come up with a more involved matching algorithm, but given the short amount of time we had, I suggested a basic matching algorithm, which is what is written above.

#Emotional Analysis Helpers
#This method stores the traits for a particular user.
def traits(user)
traits = []
# byebug
traits << emo_analysis(user.openness, "open")
# byebug
traits << emo_analysis(user.conscientiousness, "conscientious")
traits << emo_analysis(user.extraversion, "extraverted")
traits << emo_analysis(user.agreeableness, "agreeable")
traits << emo_analysis(user.emotional_range, "neurotic")
#This method converts the numerical data obtained from Watson Personality Insights API
#into simple string values for a user's personality traits
def emo_analysis(emo_val, emo_name)
if emo_val <= 0.2
"not very #{emo_name}"
elsif 0.3 <= emo_val && emo_val <= 0.6
elsif emo_val >= 0.7
"very #{emo_name}"
#These methods check to see if travelers and hosts have three or more personality traits in common.
def recommend(traveler)
hosts = Host.all
matches = []
hosts.each do |host|
if (traits(host) & traits(traveler)).length >= 3
matches << host
def host_recommendations(host)
travelers = Traveler.all
matches = []
travelers.each do |traveler|
if (traits(host) & traits(traveler)).length >= 3
matches << traveler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment