fix: rate calculation, #14

pull/15/head
rrr-marble 4 years ago
parent 4b5a20a109
commit 8a378923af

@ -166,15 +166,16 @@ async def photo_points():
"""Get points with the url of a photo and the rate""" """Get points with the url of a photo and the rate"""
# assume we always have at least some photos # assume we always have at least some photos
# fetch them all # fetch them all
# if frontend uses 1 and 0 to represent like and dislike
# we can just take the average and turn it into %
# 100 * AVG(marks.mark)
cur.execute( cur.execute(
"""SELECT images.imgid, resizedpath, GPSLatitude, GPSLongitude, """SELECT images.imgid, resizedpath, GPSLatitude, GPSLongitude,
100*SUM(marks.mark)/COUNT(marks.mark)/MAX(marks.mark) 100 * AVG(marks.mark)
FROM images FROM images
LEFT JOIN marks ON images.imgid = marks.imgid LEFT JOIN marks ON images.imgid = marks.imgid
GROUP BY images.imgid; GROUP BY images.imgid;
""", # 100 * SUM(marks.mark)/COUNT(marks.mark)/MAX(marks.mark) """,
# is an ad-hoc percentage of likes without know how front end defined like/dislike
# returns None with no marks (sqlite handles division by 0 gracefully)
) )
points = cur.fetchall() points = cur.fetchall()
return [ return [
@ -183,7 +184,7 @@ async def photo_points():
"url": point["resizedpath"], "url": point["resizedpath"],
"lon": point["GPSLongitude"], "lon": point["GPSLongitude"],
"lat": point["GPSLatitude"], "lat": point["GPSLatitude"],
"rate": point["100*SUM(marks.mark)/COUNT(marks.mark)/MAX(marks.mark)"], "rate": point["100 * AVG(marks.mark)"],
} }
for point in points for point in points
] ]

Loading…
Cancel
Save