合并相同属地的IP统计
This commit is contained in:
@@ -632,7 +632,7 @@ async def get_ip_locations(
|
||||
)
|
||||
)
|
||||
result = await db.execute(_apply_monitoring_scope_to_log_query(query, scope))
|
||||
buckets: dict[tuple[str, str, str, str], dict] = {}
|
||||
buckets: dict[tuple[str, str, str], dict] = {}
|
||||
all_ip_addresses: set[str] = set()
|
||||
all_user_ids: set[uuid.UUID] = set()
|
||||
total_count = 0
|
||||
@@ -641,15 +641,16 @@ async def get_ip_locations(
|
||||
|
||||
for ip_address, user_id, allowed in result.all():
|
||||
ip_info = resolve_ip_location(ip_address)
|
||||
key = (ip_info.country, ip_info.province, ip_info.city, ip_info.isp)
|
||||
key = (ip_info.country, ip_info.province, ip_info.city)
|
||||
location = " / ".join(part for part in [ip_info.country, ip_info.province, ip_info.city] if part) or ip_info.location or "未知"
|
||||
bucket = buckets.setdefault(
|
||||
key,
|
||||
{
|
||||
"country": ip_info.country,
|
||||
"province": ip_info.province,
|
||||
"city": ip_info.city,
|
||||
"isp": ip_info.isp,
|
||||
"location": ip_info.location,
|
||||
"isp": "",
|
||||
"location": location,
|
||||
"total_count": 0,
|
||||
"allowed_count": 0,
|
||||
"denied_count": 0,
|
||||
|
||||
Reference in New Issue
Block a user