Return more data on TopStations endpoints
This commit is contained in:
parent
3cdfac30bc
commit
8947f9116e
@ -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,
|
||||
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"""
|
||||
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,
|
||||
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"""
|
||||
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()
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user