|
3 | 3 | from collections import deque |
4 | 4 | from dataclasses import dataclass |
5 | 5 | import io |
6 | | -import json |
7 | 6 | import os |
8 | 7 | from pathlib import Path |
9 | 8 | import socket |
10 | | -from typing import Any, Optional |
| 9 | +from typing import Optional |
11 | 10 |
|
12 | 11 | import aiohttp |
13 | 12 | import psutil |
14 | 13 |
|
15 | | -from core import cache, cluster, config, logger |
| 14 | +from core import cluster, config, logger |
16 | 15 |
|
17 | 16 | from . import utils |
18 | 17 |
|
|
23 | 22 | ) |
24 | 23 | from aiohttp import web |
25 | 24 |
|
| 25 | +from . import database as db |
| 26 | + |
26 | 27 | @dataclass |
27 | 28 | class CollectionUsage: |
28 | 29 | total: int |
@@ -125,6 +126,24 @@ async def _(request: web.Request): |
125 | 126 | async def _(request: web.Request): |
126 | 127 | return web.json_response(counter.get_json()) |
127 | 128 |
|
| 129 | +@route.get("/api/count") |
| 130 | +async def _(request: web.Request): |
| 131 | + # statistics of the cluster hits and bytes |
| 132 | + session = db.SESSION.get_session() |
| 133 | + current_hour = db.get_hour() |
| 134 | + hour_of_day = (current_hour // 24) * 24 |
| 135 | + next_hour = hour_of_day + 24 |
| 136 | + q = session.query(db.ClusterStatisticsTable).filter( |
| 137 | + db.ClusterStatisticsTable.hour >= hour_of_day, |
| 138 | + db.ClusterStatisticsTable.hour < next_hour |
| 139 | + ).all() |
| 140 | + print(hour_of_day, next_hour) |
| 141 | + return web.json_response({ |
| 142 | + "hits": sum([int(item.hits) for item in q]), |
| 143 | + "bytes": sum([int(item.bytes) for item in q]) |
| 144 | + }) |
| 145 | + |
| 146 | + |
128 | 147 | @route.get("/api/openbmclapi/rank") |
129 | 148 | async def _(request: web.Request): |
130 | 149 | async with aiohttp.ClientSession( |
|
0 commit comments