forked from mieqq/mieqq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruleMatchingTime.js
34 lines (31 loc) · 971 Bytes
/
ruleMatchingTime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
let initial = {
numberOfRequests: 0,
totalMatchingTime: 0,
latestRecordTime: 0,
};
let history = JSON.parse(
$persistentStore.read("RULEMATCHINGTIME") || JSON.stringify(initial)
);
$httpAPI("GET", "/v1/requests/recent", null, (body) => {
body.requests.forEach((request) => {
if (
request.timingRecords &&
request.setupCompletedDate > history.latestRecordTime &&
request.timingRecords[0].name == "Rule Evaluating"
) {
history.totalMatchingTime += request.timingRecords[0].duration;
history.numberOfRequests += 1;
}
});
history.latestRecordTime = body.requests[0].setupCompletedDate;
$persistentStore.write(JSON.stringify(history), "RULEMATCHINGTIME");
let avgMatchingTime = (
(history.totalMatchingTime * 1000) /
history.numberOfRequests
).toFixed(2);
$done({
title: "Rule Matching Time",
content: `统计数量: ${history.numberOfRequests}\n平均时间: ${avgMatchingTime} ms`,
icon: "bolt.horizontal.circle.fill",
});
});