mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-08 04:56:00 +08:00
✨ 网页控制台的数据模块展示更详细的信息 (#89)
This commit is contained in:
parent
c1f1a563c3
commit
96e9ee0c0f
@ -159,14 +159,20 @@ async def get_global_val(
|
||||
today = datetime.date.today()
|
||||
endday = today - datetime.timedelta(days=day)
|
||||
endday_format = endday.strftime("%Y_%d_%b")
|
||||
_path = global_val_path / bot_id / bot_self_id
|
||||
path = _path / f'GlobalVal_{endday_format}.json'
|
||||
if path.exists():
|
||||
async with aiofiles.open(path, 'rb') as fp:
|
||||
data = json.loads(await fp.read())
|
||||
return data
|
||||
else:
|
||||
return platform_val
|
||||
return await get_sp_val(
|
||||
bot_id,
|
||||
bot_self_id,
|
||||
f'GlobalVal_{endday_format}.json',
|
||||
)
|
||||
|
||||
|
||||
async def get_sp_val(bot_id: str, bot_self_id: str, sp: str) -> PlatformVal:
|
||||
path = global_val_path / bot_id / bot_self_id / sp
|
||||
if not path.exists():
|
||||
return platform_val
|
||||
async with aiofiles.open(path, 'rb') as fp:
|
||||
data = json.loads(await fp.read())
|
||||
return data
|
||||
|
||||
|
||||
async def save_global_val(bot_id: str, bot_self_id: str):
|
||||
|
@ -432,6 +432,101 @@ async def core_log():
|
||||
return StreamingResponse(read_log(), media_type='text/plain')
|
||||
|
||||
|
||||
@app.post('/genshinuid/api/loadData/{bot_id}/{bot_self_id}')
|
||||
@site.auth.requires('root')
|
||||
async def get_history_data(
|
||||
request: Request,
|
||||
data: Dict,
|
||||
bot_id: str,
|
||||
bot_self_id: str,
|
||||
):
|
||||
name = data.get('name', None)
|
||||
a_pie_data = []
|
||||
b_pie_data = []
|
||||
if name is None:
|
||||
seven_day = await gv.get_value_analysis(bot_id, bot_self_id)
|
||||
local_val = seven_day[list(seven_day.keys())[0]]
|
||||
else:
|
||||
local_val = await gv.get_sp_val(bot_id, bot_self_id, name)
|
||||
|
||||
c_data = {}
|
||||
for g in local_val['group']:
|
||||
a_pie_data.append(
|
||||
{"value": sum(list(local_val['group'][g].values())), "name": g}
|
||||
)
|
||||
for u in local_val['user']:
|
||||
for c in local_val['user'][u]:
|
||||
if c not in c_data:
|
||||
c_data[c] = 0
|
||||
c_data[c] += local_val['user'][u][c]
|
||||
|
||||
for c in c_data:
|
||||
b_pie_data.append({"value": c_data[c], "name": c})
|
||||
# l_data.append(c)
|
||||
|
||||
data = {
|
||||
"series": [
|
||||
{
|
||||
"data": a_pie_data,
|
||||
"type": "pie",
|
||||
"name": "群组触发命令",
|
||||
# "selectedMode": "single",
|
||||
"radius": [0, "30%"],
|
||||
"label": {"position": "inner", "fontSize": 14},
|
||||
"labelLine": {"show": False},
|
||||
},
|
||||
{
|
||||
"name": "命令调用次数",
|
||||
"type": "pie",
|
||||
"radius": ["45%", "60%"],
|
||||
"labelLine": {"length": 30},
|
||||
"label": {
|
||||
"formatter": "{a|{a}}{abg|}\n{hr|}\n {b|{b}:}{c} {per|{d}%}", # noqa: E501
|
||||
"backgroundColor": "#F6F8FC",
|
||||
"borderColor": "#8C8D8E",
|
||||
"borderWidth": 1,
|
||||
"borderRadius": 4,
|
||||
"rich": {
|
||||
"a": {
|
||||
"color": "#6E7079",
|
||||
"lineHeight": 22,
|
||||
"align": "center",
|
||||
},
|
||||
"hr": {
|
||||
"borderColor": "#8C8D8E",
|
||||
"width": "100%",
|
||||
"borderWidth": 1,
|
||||
"height": 0,
|
||||
},
|
||||
"b": {
|
||||
"color": "#4C5058",
|
||||
"fontSize": 14,
|
||||
"fontWeight": "bold",
|
||||
"lineHeight": 33,
|
||||
},
|
||||
"per": {
|
||||
"color": "#fff",
|
||||
"backgroundColor": "#4C5058",
|
||||
"padding": [3, 4],
|
||||
"borderRadius": 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
"data": b_pie_data,
|
||||
},
|
||||
],
|
||||
"tooltip": {
|
||||
"trigger": "item",
|
||||
"formatter": "{a} <br/>{b}: {c} ({d}%)",
|
||||
},
|
||||
}
|
||||
return {
|
||||
'status': 0,
|
||||
'msg': 'ok',
|
||||
'data': data,
|
||||
}
|
||||
|
||||
|
||||
@app.get('/genshinuid/api/historyLogs')
|
||||
@site.auth.requires('root')
|
||||
async def get_history_logs(
|
||||
|
@ -1,4 +1,11 @@
|
||||
from gsuid_core.global_val import get_all_bot_dict, get_global_analysis
|
||||
import random
|
||||
import string
|
||||
|
||||
from gsuid_core.global_val import (
|
||||
global_val_path,
|
||||
get_all_bot_dict,
|
||||
get_global_analysis,
|
||||
)
|
||||
from gsuid_core.webconsole.create_base_panel import (
|
||||
get_tab,
|
||||
get_card,
|
||||
@ -15,6 +22,58 @@ def get_chart(api: str):
|
||||
}
|
||||
|
||||
|
||||
def get_detail_chart(bot_id: str, bot_self_id: str):
|
||||
characters = string.ascii_lowercase + string.digits
|
||||
random_string = ''.join(random.choice(characters) for _ in range(12))
|
||||
_p = []
|
||||
path = global_val_path / bot_id / bot_self_id
|
||||
if path.exists():
|
||||
op = [{"label": i.name, "value": i.name} for i in path.iterdir()]
|
||||
_p.append(
|
||||
{
|
||||
"type": "select",
|
||||
"label": "选择日期",
|
||||
"name": "select",
|
||||
"options": op,
|
||||
"id": "u:4cb4efccc603",
|
||||
"multiple": False,
|
||||
"onEvent": {
|
||||
"change": {
|
||||
"weight": 0,
|
||||
"actions": [
|
||||
{
|
||||
"componentId": f"u:{random_string}",
|
||||
"ignoreError": False,
|
||||
"actionType": "reload",
|
||||
"data": {
|
||||
"name": "${event.data.value}",
|
||||
},
|
||||
"dataMergeMode": "merge",
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
_p.append(get_divider())
|
||||
_p.append(
|
||||
{
|
||||
"id": f"u:{random_string}",
|
||||
"type": "chart",
|
||||
"replaceChartOption": True,
|
||||
"api": {
|
||||
"url": f'/genshinuid/api/loadData/{bot_id}/{bot_self_id}',
|
||||
"method": "post",
|
||||
"requestAdaptor": "",
|
||||
"adaptor": "",
|
||||
"messages": {},
|
||||
"dataType": "json",
|
||||
},
|
||||
}
|
||||
)
|
||||
return _p
|
||||
|
||||
|
||||
async def get_analysis_page():
|
||||
AAPI = '/genshinuid/api/getAnalysisData'
|
||||
BAPI = '/genshinuid/api/getAnalysisUserGroup'
|
||||
@ -49,6 +108,8 @@ async def get_analysis_page():
|
||||
get_chart(f'{AAPI}/{bot_id}/{bot_self_id}'),
|
||||
get_divider(),
|
||||
get_chart(f'{BAPI}/{bot_id}/{bot_self_id}'),
|
||||
get_divider(),
|
||||
*get_detail_chart(bot_id, bot_self_id),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user