Get platform statistics within the specified offset in seconds and group by platform_id.
(self, offset_sec: int = 86400)
| 178 | return count if count is not None else 0 |
| 179 | |
| 180 | async def get_platform_stats(self, offset_sec: int = 86400) -> list[PlatformStat]: |
| 181 | """Get platform statistics within the specified offset in seconds and group by platform_id.""" |
| 182 | async with self.get_db() as session: |
| 183 | session: AsyncSession |
| 184 | now = datetime.now() |
| 185 | start_time = now - timedelta(seconds=offset_sec) |
| 186 | result = await session.execute( |
| 187 | text(""" |
| 188 | SELECT * FROM platform_stats |
| 189 | WHERE timestamp >= :start_time |
| 190 | GROUP BY platform_id |
| 191 | ORDER BY timestamp DESC |
| 192 | """), |
| 193 | {"start_time": start_time}, |
| 194 | ) |
| 195 | return list(result.scalars().all()) |
| 196 | |
| 197 | async def insert_provider_stat( |
| 198 | self, |