From 8a378923af543309f8ccd0e93f37a44ad71d4906 Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Tue, 21 Dec 2021 04:11:06 +0300 Subject: [PATCH] fix: rate calculation, #14 --- main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index d6f9221..6f43f7a 100644 --- a/main.py +++ b/main.py @@ -166,15 +166,16 @@ async def photo_points(): """Get points with the url of a photo and the rate""" # assume we always have at least some photos # 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( """SELECT images.imgid, resizedpath, GPSLatitude, GPSLongitude, - 100*SUM(marks.mark)/COUNT(marks.mark)/MAX(marks.mark) + 100 * AVG(marks.mark) FROM images LEFT JOIN marks ON images.imgid = marks.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() return [ @@ -183,7 +184,7 @@ async def photo_points(): "url": point["resizedpath"], "lon": point["GPSLongitude"], "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 ]