Archived
1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
citybike/top.py

43 lines
767 B
Python
Raw Permalink Normal View History

2016-10-27 12:40:58 +02:00
cache = {}
2016-10-05 14:25:28 +02:00
topSQL = {
"shortestConnections": """
SELECT
id,
s.name,
g.name,
length
FROM connections
LEFT JOIN stationen AS s ON start = s.ref
LEFT JOIN stationen AS g ON goal = g.ref
WHERE start != goal
ORDER BY length ASC
2016-10-27 12:40:58 +02:00
LIMIT %s OFFSET %s
2016-10-05 14:25:28 +02:00
""",
"farAway": """
SELECT *
FROM (SELECT
name,
length,
ref
FROM connections
LEFT JOIN stationen ON (start = ref OR goal = ref)
WHERE start != goal
ORDER BY length ASC) AS x
GROUP BY ref
2016-10-27 12:40:58 +02:00
ORDER BY length DESC
LIMIT %s OFFSET %s
"""
2016-10-05 14:25:28 +02:00
}
2016-10-27 12:40:58 +02:00
def helloworld(cursor, args):
2016-10-05 14:25:28 +02:00
2016-10-27 12:40:58 +02:00
sql = topSQL[args["type"]]
limit = int(args["pageSize"])
offset = (int(args["pageNumber"]) - 1) * limit
cursor.execute(sql, (limit, offset))
2016-10-05 14:25:28 +02:00
return cursor.fetchall()