fix 站点数据统计

This commit is contained in:
jxxghp
2024-10-24 13:55:59 +08:00
parent ad4f71e997
commit 4502f73dad
2 changed files with 20 additions and 8 deletions

View File

@@ -3,13 +3,13 @@
"name": "站点数据统计",
"description": "站点统计数据图表。",
"labels": "站点,仪表板",
"version": "1.0.3",
"version": "1.1",
"icon": "statistic.png",
"author": "lightolly,jxxghp",
"level": 2,
"history": {
"v1.0.3": "修复增量数据统计问题",
"v1.0.2": "MoviePilot V2 版本站点数据统计插件"
"v1.1": "修复增量数据统计问题",
"v1.0": "MoviePilot V2 版本站点数据统计插件"
}
},
"BrushFlow": {

View File

@@ -32,7 +32,7 @@ class SiteStatistic(_PluginBase):
# 插件图标
plugin_icon = "statistic.png"
# 插件版本
plugin_version = "1.0.3"
plugin_version = "1.1"
# 插件作者
plugin_author = "lightolly,jxxghp"
# 作者主页
@@ -234,6 +234,18 @@ class SiteStatistic(_PluginBase):
return 0
return round(float(value) / 1024 / 1024 / 1024, 1)
def __is_digit(value: any) -> bool:
"""
判断是否为数字
"""
if value is None:
return False
if isinstance(value, float) or isinstance(value, int):
return True
if isinstance(value, str):
return value.isdigit()
return False
def __sub_data(d1: dict, d2: dict) -> dict:
"""
计算两个字典相同Key值的差值如果值为数字返回新字典
@@ -242,8 +254,8 @@ class SiteStatistic(_PluginBase):
return {}
if not d2:
return d1
d = {k: int(d1.get(k)) - int(d2.get(k)) for k in d1
if k in d2 and str(d1.get(k)).isdigit() and str(d2.get(k)).isdigit()}
d = {k: d1.get(k) - d2.get(k) for k in d1
if k in d2 and __is_digit(d1.get(k)) and __is_digit(d2.get(k))}
# 把小于0的数据变成0
for k, v in d.items():
if str(v).isdigit() and int(v) < 0:
@@ -554,7 +566,7 @@ class SiteStatistic(_PluginBase):
if inc:
inc_data[data.name] = inc
# 今日上传
uploads = {k: v for k, v in inc_data.items() if v.get("upload")}
uploads = {k: v for k, v in inc_data.items() if v.get("upload") if v.get("upload") > 0}
# 今日上传站点
upload_sites = [site for site in uploads.keys()]
# 今日上传数据
@@ -562,7 +574,7 @@ class SiteStatistic(_PluginBase):
# 今日上传总量
today_upload = round(sum(upload_datas), 2)
# 今日下载
downloads = {k: v for k, v in inc_data.items() if v.get("download")}
downloads = {k: v for k, v in inc_data.items() if v.get("download") if v.get("download") > 0}
# 今日下载站点
download_sites = [site for site in downloads.keys()]
# 今日下载数据