Add 6-week limit to stat pulls
This commit is contained in:
parent
a080ba4d9b
commit
9bf5ef70a0
36
main.py
36
main.py
@ -1817,18 +1817,20 @@ async def v1_battingstats_get(
|
||||
|
||||
all_stats = all_stats.where(BattingStat.player == this_player)
|
||||
|
||||
start = 0
|
||||
end = Schedule.select(fn.MAX(Schedule.week)).scalar()
|
||||
if week_start:
|
||||
start = 1
|
||||
end = Current.get(Current.season == season).week
|
||||
if week_start is not None:
|
||||
start = week_start
|
||||
|
||||
if week_end:
|
||||
end = week_end
|
||||
if week_end is not None:
|
||||
end = min(week_end, end)
|
||||
|
||||
if start > end:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404,
|
||||
detail=f'Start week {start} is after end week {end} - cannot pull stats')
|
||||
if start + 5 < end:
|
||||
start = end - 5
|
||||
|
||||
logging.info(f'\n\nweek_start: {week_start} / week_end: {week_end} / game_num: {game_num} / '
|
||||
f'start: {start} / end: {end}')
|
||||
@ -2271,18 +2273,20 @@ async def v1_pitchingstat_get(
|
||||
|
||||
all_stats = all_stats.where(PitchingStat.player == this_player)
|
||||
|
||||
start = 0
|
||||
end = Schedule.select(fn.MAX(Schedule.week)).scalar()
|
||||
if week_start:
|
||||
start = 1
|
||||
end = Current.get(Current.season == season).week
|
||||
if week_start is not None:
|
||||
start = week_start
|
||||
|
||||
if week_end:
|
||||
end = week_end
|
||||
if week_end is not None:
|
||||
end = min(week_end, end)
|
||||
|
||||
if start > end:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404,
|
||||
detail=f'Start week {start} is after end week {end} - cannot pull stats')
|
||||
if start + 5 < end:
|
||||
start = end - 5
|
||||
|
||||
all_stats = all_stats.where(
|
||||
(PitchingStat.week >= start) & (PitchingStat.week <= end)
|
||||
@ -2629,18 +2633,20 @@ async def v1_fieldingstats_get(
|
||||
|
||||
all_stats = all_stats.where(BattingStat.player == this_player)
|
||||
|
||||
start = 0
|
||||
end = Schedule.select(fn.MAX(Schedule.week)).scalar()
|
||||
if week_start:
|
||||
start = 1
|
||||
end = Current.get(Current.season == season).week
|
||||
if week_start is not None:
|
||||
start = week_start
|
||||
|
||||
if week_end:
|
||||
end = week_end
|
||||
if week_end is not None:
|
||||
end = min(week_end, end)
|
||||
|
||||
if start > end:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404,
|
||||
detail=f'Start week {start} is after end week {end} - cannot pull stats')
|
||||
if start + 5 < end:
|
||||
start = end - 5
|
||||
|
||||
all_stats = all_stats.where(
|
||||
(BattingStat.week >= start) & (BattingStat.week <= end)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user