Saturday, December 23, 2017

How to Design Models for Matches in Django Dating App?

I'm working on a dating app for a hackathon project.  We have a series of questions that users fill out, and then every few days we are going to send suggested matches.  If anyone has a good tutorial for these kinds of matching algorithms, it would be very appreciated. One idea is to assign a point value for each question and then to do a
    def comparison(person_a, person_b) function where you iterate through these questions, and where there's a common answer, you add in a point. So the higher the score, the better the match.  I understand this so far, but I'm struggling to see how to save this data in the database.

In python, I could take each user and then iterate through all the other users with this comparison function and make a dictionary for each person that lists all the other users and a score for them.  And then to suggest matches, I iterate through the dictionary list and if that person hasn't been matched up already with that person, then make a match.

    person1_dictionary_of_matches = {'person2': 3,  'person3': 5,  'person4': 10,  'person5': 12, 'person6': 2,……,'person200':10}
    person_1_list_of_prior_matches = ['person3', 'person4']

I'm struggling on how to represent this in django.  I could have a bunch of users and make a Match model like:
   
    class Match(Model):
         person1 = models.ForeignKey(User)
         person2 = models.ForeignKey(User)
         score = models.PositiveIntegerField()

Where I do the iteration and save all the pairwise scores.

and then do 
    person_matches = Match.objectsfilter(person1=sarah, person2!=sarah).order_by('score').exclude(person2 in list_of_past_matches)

But I'm worried with 1000 users, I will have 1000000 rows in my table if do this.  Will this be brutal to have to save all these pairwise scores for each user in the database? Or does this not matter if I run it at like Sunday night at 1am or just cache these responses once and use the comparisons for a period of months?  Is there a better way to do this than matching everyone up pairwise?  Should I use some other data structure to capture the people and their compatibility score? Thanks so much for any guidance!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1709763b-baeb-4f75-b6e4-d6e9ac634092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment