Skip to content

Commit

Permalink
Only show people with a photo as a guess. Fixes #37.
Browse files Browse the repository at this point in the history
Co-authored-by: Jaryn Colbert <jaryn.colbert@gmail.com>
  • Loading branch information
blinry and jaryncolbert committed Apr 26, 2019
1 parent 1ef9d8a commit 379a8dd
Showing 1 changed file with 67 additions and 10 deletions.
77 changes: 67 additions & 10 deletions faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,27 @@ def get_random_person_from_all_batches(cursor, current_user):
last_name,
image_url
FROM people
WHERE person_id != %s
WHERE person_id != %s AND NOT image_url LIKE '%%no_photo_%%'
ORDER BY random()
LIMIT 4""",
LIMIT 1""",
[current_user])
return [x for x in cursor.fetchall()]

person = cursor.fetchall()

cursor.execute("""SELECT person_id,
first_name,
middle_name,
last_name,
image_url
FROM people
WHERE person_id != %s AND person_id != %s
ORDER BY random()
LIMIT 3""",
[current_user, person[0][0]])

hints = cursor.fetchall()

return person + hints

def get_random_overlapping(cursor, current_user):
"""Find a random person from the database that was at RC at the same time as
Expand All @@ -126,11 +142,27 @@ def get_random_overlapping(cursor, current_user):
last_name,
image_url
FROM batch_mates
WHERE querent_person_id = %s
WHERE querent_person_id = %s AND NOT image_url LIKE '%%no_photo_%%'
ORDER BY random()
LIMIT 4""",
LIMIT 1""",
[current_user])
return [x for x in cursor.fetchall()]

person = cursor.fetchall()

cursor.execute("""SELECT person_id,
first_name,
middle_name,
last_name,
image_url
FROM batch_mates
WHERE querent_person_id = %s AND person_id != %s
ORDER BY random()
LIMIT 3""",
[current_user, person[0][0]])

hints = cursor.fetchall()

return person + hints

def get_random_in_batch(cursor, current_user):
"""Find a random person from the database that is in (one of) the current
Expand All @@ -150,11 +182,36 @@ def get_random_in_batch(cursor, current_user):
ON people.person_id = stints.person_id
INNER JOIN user_batch
ON stints.batch_id = user_batch.batch_id
WHERE people.person_id != %s
WHERE people.person_id != %s AND NOT image_url LIKE '%%no_photo_%%'
ORDER BY random()
LIMIT 4""",
[current_user,current_user])
return [x for x in cursor.fetchall()]
LIMIT 1""",
[current_user, current_user])

person = cursor.fetchall()

cursor.execute("""WITH user_batch AS (
SELECT batch_id
FROM stints
WHERE person_id = %s
)
SELECT people.person_id,
people.first_name,
people.middle_name,
people.last_name,
people.image_url
FROM people
INNER JOIN stints
ON people.person_id = stints.person_id
INNER JOIN user_batch
ON stints.batch_id = user_batch.batch_id
WHERE people.person_id != %s AND people.person_id != %s
ORDER BY random()
LIMIT 3""",
[current_user, current_user, person[0][0]])

hints = cursor.fetchall()

return person + hints

@app.route('/api/people/random')
@needs_authorization
Expand Down

0 comments on commit 379a8dd

Please sign in to comment.