Return more data on TopStations endpoints

This commit is contained in:
Marcel Schwarz 2020-12-27 15:52:26 +01:00
parent 3cdfac30bc
commit 8947f9116e
2 changed files with 36 additions and 20 deletions

View File

@ -43,30 +43,44 @@ def get_dashboard(station_id):
def get_dashboard_to(station_id, start_date, end_date):
query = """
SELECT
u.start_station_name AS startStationName,
u.end_station_name AS endStationName,
count(*) AS number,
round(avg(u.duration)) AS avgDuration
FROM usage_stats u
WHERE u.start_station_id = ? AND date(u.start_date, 'unixepoch') BETWEEN ? AND ?
GROUP BY u.end_station_name
ORDER BY number DESC
LIMIT 3"""
topPoints.*,
b.lat AS stationLat,
b.lon AS stationLon
FROM (
SELECT
u.end_station_name AS stationName,
u.end_station_id AS stationId,
count(*) AS number,
round(avg(u.duration)) AS avgDuration
FROM usage_stats u
WHERE u.start_station_id = ? AND date(u.start_date, 'unixepoch') BETWEEN ? AND ?
GROUP BY u.end_station_name
ORDER BY number DESC
LIMIT 3
) as topPoints
JOIN bike_points b ON b.id_num = topPoints.stationId"""
return get_db_connection().execute(query, (station_id, start_date, end_date)).fetchall()
def get_dashboard_from(station_id, start_date, end_date):
query = """
SELECT
u.start_station_name AS startStationName,
u.end_station_name AS endStationName,
count(*) AS number,
round(avg(u.duration)) AS avgDuration
FROM usage_stats u
WHERE u.end_station_id = ? AND date(u.start_date, 'unixepoch') BETWEEN ? AND ?
GROUP BY u.start_station_name
ORDER BY number DESC
LIMIT 3"""
topPoints.*,
b.lat AS stationLat,
b.lon AS stationLon
FROM (
SELECT
u.start_station_name AS stationName,
u.start_station_id AS stationId,
count(*) AS number,
round(avg(u.duration)) AS avgDuration
FROM usage_stats u
WHERE u.end_station_id = ? AND date(u.start_date, 'unixepoch') BETWEEN ? AND ?
GROUP BY u.start_station_name
ORDER BY number DESC
LIMIT 3
) as topPoints
JOIN bike_points b ON b.id_num = topPoints.stationId"""
return get_db_connection().execute(query, (station_id, start_date, end_date)).fetchall()

View File

@ -30,8 +30,10 @@ def get_general_dashboard(station_id: int):
class StationDashboardTopStationsEntry(BaseModel):
startStationName: str
endStationName: str
stationName: str
stationId: int
stationLat: float
stationLon: float
number: int
avgDuration: int