diff --git a/package.v2.json b/package.v2.json index 354f18e..b48a851 100644 --- a/package.v2.json +++ b/package.v2.json @@ -3,11 +3,12 @@ "name": "站点数据统计", "description": "站点统计数据图表。", "labels": "站点,仪表板", - "version": "1.7.1", + "version": "1.7.2", "icon": "statistic.png", "author": "lightolly,jxxghp", "level": 2, "history": { + "v1.7.2": "修复站点数据增量处理逻辑", "v1.7.1": "优化内存占用", "v1.6": "优化了站点数据获取失败时的回退逻辑", "v1.5": "修复了发送增量通知失败等一些问题", diff --git a/plugins.v2/sitestatistic/__init__.py b/plugins.v2/sitestatistic/__init__.py index 93f4aef..ea42b09 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.7.1" + plugin_version = "1.7.2" # 插件作者 plugin_author = "lightolly,jxxghp" # 作者主页 @@ -229,9 +229,17 @@ class SiteStatistic(_PluginBase): download = int(today_data_dict[site].download or 0) updated_date = today_data_dict[site].updated_day - if self._notify_type == "inc" and yesterday_data_dict.get(site): - upload -= int(yesterday_data_dict[site].upload or 0) - download -= int(yesterday_data_dict[site].download or 0) + if self._notify_type == "inc": + # 增量数据模式:只有当有昨天数据时才计算增量 + if yesterday_data_dict.get(site): + upload -= int(yesterday_data_dict[site].upload or 0) + download -= int(yesterday_data_dict[site].download or 0) + # 确保增量不为负数 + upload = max(0, upload) + download = max(0, download) + else: + # 没有昨天数据时,跳过该站点 + continue if updated_date and updated_date != today_date: updated_date = f"({updated_date})" @@ -354,7 +362,8 @@ class SiteStatistic(_PluginBase): if not d1: return {} if not d2: - return d1 + # 如果没有昨天数据,返回空字典,表示无增量数据 + return {} d = {k: __to_numeric(d1.get(k)) - __to_numeric(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 @@ -658,14 +667,15 @@ class SiteStatistic(_PluginBase): # 计算增量数据集 inc_data = {} for data in stattistic_data: - yesterday_datas = [yd for yd in yesterday_sites_data if yd.domain == data.domain] + # 修复:使用name进行匹配,保持一致性 + yesterday_datas = [yd for yd in yesterday_sites_data if yd.name == data.name] if yesterday_datas: yesterday_data = yesterday_datas[0] - else: - yesterday_data = None - inc = __sub_data(data.to_dict(), yesterday_data.to_dict() if yesterday_data else None) - if inc: - inc_data[data.name] = inc + # 只有当有昨天数据时才计算增量 + inc = __sub_data(data.to_dict(), yesterday_data.to_dict()) + if inc: + inc_data[data.name] = inc + # 如果没有昨天数据,不添加到inc_data中 # 今日上传 uploads = {k: v for k, v in inc_data.items() if v.get("upload") if v.get("upload") > 0} # 今日上传站点