|
|
|
|
@ -145,36 +145,30 @@ async def rate_picture(cookie: str, picture_id: int, mark: int):
|
|
|
|
|
|
|
|
|
|
return {"status": "success"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/photo_points")
|
|
|
|
|
def photo_points():
|
|
|
|
|
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
|
|
|
|
|
cur.execute(
|
|
|
|
|
"""SELECT images.imgid, resizedpath, GPSLatitude, GPSLongitude,
|
|
|
|
|
100*SUM(marks.mark)/COUNT(marks.mark)/MAX(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 [
|
|
|
|
|
{
|
|
|
|
|
"id": 0,
|
|
|
|
|
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/JPEG_example_down.jpg/350px-JPEG_example_down.jpg",
|
|
|
|
|
"lon": 37.34542,
|
|
|
|
|
"lat": 55.12323,
|
|
|
|
|
"rate": 36 # percentage of likes
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"id": 1,
|
|
|
|
|
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/JPEG_example_down.jpg/350px-JPEG_example_down.jpg",
|
|
|
|
|
"lon": 37.34342,
|
|
|
|
|
"lat": 55.12423,
|
|
|
|
|
"rate": 62 # percentage of likes
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"id": 2,
|
|
|
|
|
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/JPEG_example_down.jpg/350px-JPEG_example_down.jpg",
|
|
|
|
|
"lon": 37.34642,
|
|
|
|
|
"lat": 55.12223,
|
|
|
|
|
"rate": 43 # percentage of likes
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"id": 3,
|
|
|
|
|
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/JPEG_example_down.jpg/350px-JPEG_example_down.jpg",
|
|
|
|
|
"lon": 37.34342,
|
|
|
|
|
"lat": 55.12923,
|
|
|
|
|
"rate": 90 # percentage of likes
|
|
|
|
|
"id": point["imgid"],
|
|
|
|
|
"url": point["resizedpath"],
|
|
|
|
|
"lon": point["GPSLongitude"],
|
|
|
|
|
"lat": point["GPSLatitude"],
|
|
|
|
|
"rate": point["100*SUM(marks.mark)/COUNT(marks.mark)/MAX(marks.mark)"],
|
|
|
|
|
}
|
|
|
|
|
for point in points
|
|
|
|
|
]
|