From 4502f73dad9e40dcb40fe42798bd283bf8828a39 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 24 Oct 2024 13:55:59 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=AB=99=E7=82=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 6 +++--- plugins.v2/sitestatistic/__init__.py | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/package.v2.json b/package.v2.json index 9f7df6f..f311cd1 100644 --- a/package.v2.json +++ b/package.v2.json @@ -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": { diff --git a/plugins.v2/sitestatistic/__init__.py b/plugins.v2/sitestatistic/__init__.py index 86fbc5c..b2bd3a2 100644 --- a/plugins.v2/sitestatistic/__init__.py +++ b/plugins.v2/sitestatistic/__init__.py @@ -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()] # 今日下载数据