🐛 Bug: Fix the bug where the channel status is not sorted by success rate.
Browse files- main.py +6 -2
- test/test_matplotlib.py +1 -1
main.py
CHANGED
|
@@ -124,7 +124,9 @@ class StatsMiddleware(BaseHTTPMiddleware):
|
|
| 124 |
percentages[channel] = success_count / total_count * 100
|
| 125 |
else:
|
| 126 |
percentages[channel] = 0
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
|
| 129 |
def calculate_failure_percentages(self):
|
| 130 |
percentages = {}
|
|
@@ -134,7 +136,9 @@ class StatsMiddleware(BaseHTTPMiddleware):
|
|
| 134 |
percentages[channel] = failure_count / total_count * 100
|
| 135 |
else:
|
| 136 |
percentages[channel] = 0
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
async def cleanup_old_data(self):
|
| 140 |
cutoff_time = datetime.now() - timedelta(hours=24)
|
|
|
|
| 124 |
percentages[channel] = success_count / total_count * 100
|
| 125 |
else:
|
| 126 |
percentages[channel] = 0
|
| 127 |
+
|
| 128 |
+
sorted_percentages = dict(sorted(percentages.items(), key=lambda item: item[1], reverse=True))
|
| 129 |
+
return sorted_percentages
|
| 130 |
|
| 131 |
def calculate_failure_percentages(self):
|
| 132 |
percentages = {}
|
|
|
|
| 136 |
percentages[channel] = failure_count / total_count * 100
|
| 137 |
else:
|
| 138 |
percentages[channel] = 0
|
| 139 |
+
|
| 140 |
+
sorted_percentages = dict(sorted(percentages.items(), key=lambda item: item[1], reverse=True))
|
| 141 |
+
return sorted_percentages
|
| 142 |
|
| 143 |
async def cleanup_old_data(self):
|
| 144 |
cutoff_time = datetime.now() - timedelta(hours=24)
|
test/test_matplotlib.py
CHANGED
|
@@ -20,7 +20,7 @@ def create_pic(request_arrivals, key):
|
|
| 20 |
latest_time = max(datetimes)
|
| 21 |
|
| 22 |
# 创建24小时的时间范围
|
| 23 |
-
time_range = [latest_time - timedelta(hours=i) for i in range(
|
| 24 |
# 统计每小时的请求数
|
| 25 |
hourly_counts = defaultdict(int)
|
| 26 |
for dt in datetimes:
|
|
|
|
| 20 |
latest_time = max(datetimes)
|
| 21 |
|
| 22 |
# 创建24小时的时间范围
|
| 23 |
+
time_range = [latest_time - timedelta(hours=i) for i in range(32, 0, -1)]
|
| 24 |
# 统计每小时的请求数
|
| 25 |
hourly_counts = defaultdict(int)
|
| 26 |
for dt in datetimes:
|