How to Design Models for Matches in Django Dating App?

311 views
Skip to first unread message

A Wall

unread,
Dec 23, 2017, 2:30:48 PM12/23/17
to Django users
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!

Jason

unread,
Dec 23, 2017, 2:39:46 PM12/23/17
to Django users
This is an issue where regular tablular database structure really doesn't work well for a number of reasons.  You should look into a graph database for querying matches, and use a regular mysql/postgres for table-related data.

Vijay Khemlani

unread,
Dec 23, 2017, 5:22:20 PM12/23/17
to django...@googlegroups.com
If you have the survey answers for all the people and you are only going to base the matches based on that data, I'd rather use a K Nearest Neighbors implementation


Or some other similar system to suggest the matches.

For 1.000 users it should be extremely fast to determine the closest matches for everyone, so there would be no need to store the intermediate scores, you just need to store the answers to the survey questions.

Problem is, it does well with semantic numeric values ("age", "weight", and so on), so if you just give it model instance IDs it may work well for exact matches but not so much if they start growing apart.

There are ways to solve that, but I'm not sure if this answer works for you.

On Sat, Dec 23, 2017 at 4:39 PM, Jason <jjohn...@gmail.com> wrote:
This is an issue where regular tablular database structure really doesn't work well for a number of reasons.  You should look into a graph database for querying matches, and use a regular mysql/postgres for table-related data.

--
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...@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/4ea4e50e-0214-45f1-b076-a33200828835%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages