js:采集,锄地,性能测试更新 (#2840)

* js:性能测试

加入新项目,优化打分逻辑

* Update manifest.json

修正错误的保留文件夹

* js:采集cd管理

将优先采集移出高级配置

* 茜芙爱万策略应用ready

* js:采集cd管理更新readme

* 更新readme
This commit is contained in:
mno
2026-02-04 07:33:12 +08:00
committed by GitHub
parent 0879849668
commit dfc0199d8b
18 changed files with 278 additions and 144 deletions

View File

@@ -1,26 +1,29 @@
// 主函数
(async function () {
operationMode = settings.operationMode || "综合测试";
let xRange = parseInt(+settings.xRange || 1920, 10);
let yRange = parseInt(+settings.yRange || 1080, 10);
let interval = +settings.interval || 1000;
let timeout = +settings.timeout || 60;
let dispose = settings.dispose;
const imagePath = "assets/流放.png";
let template = file.ReadImageMatSync(imagePath);
let xRange = 1651;
let yRange = 1051;
let whidth = 1920 - 1651;
let height = 1080 - 1051;
let interval = 1000;
let timeout = 10;
dispose = true;
let template = file.ReadImageMatSync("assets/0.png");
let template2 = file.ReadImageMatSync("assets/1.png");
let roTM = RecognitionObject.TemplateMatch(template, xRange, yRange, whidth, height);
let ro2TM = RecognitionObject.TemplateMatch(template2);
let roOCR = RecognitionObject.ocr(xRange, yRange, whidth, height);
let captureRegionScore = 0;
let tempalteMatchScore = 0;
let tempalteMatch2Score = 0;
let calculateScore = 0;
let ocrScore = 0;
let tpScore = 0;
await genshin.tpToStatueOfTheSeven();
if (operationMode === "综合测试") {
log.info("开始综合测试,预计用时约30秒");
log.info("开始综合测试,预计用时约120秒");
dispose = true;
timeout = 11;
xRange = 1920;
yRange = 1080;
interval = 1000;
}
@@ -28,7 +31,7 @@
let startTime = Date.now();
let count = 0;
let loopCount = 0;
while (Date.now() - startTime <= timeout * 1000) {
while (loopCount < timeout) {
try {
let GameRegion = captureGameRegion();
if (dispose) GameRegion.dispose();
@@ -49,20 +52,20 @@
log.info(`截图测试完成,得分${captureRegionScore.toFixed(2)}`);
}
if (operationMode === "模板匹配" || operationMode === "综合测试") {
if (operationMode === "模板匹配1" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
let loopCount = 0;
let GameRegion = captureGameRegion();
while (Date.now() - startTime <= timeout * 1000) {
while (loopCount < timeout) {
try {
let recognitionObject = RecognitionObject.TemplateMatch(template, 0, 0, xRange, yRange);
let result = GameRegion.find(recognitionObject);
let result = GameRegion.find(roTM);
count++;
if (Date.now() - startTime >= interval * (loopCount + 1)) {
loopCount++;
await sleep(1);
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次模板匹配`);
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次模板匹配1`);
tempalteMatchScore += count;
count = 0;
}
@@ -72,8 +75,35 @@
}
}
if (dispose) GameRegion.dispose();
tempalteMatchScore = Math.round(((tempalteMatchScore * 10 / loopCount) / 3.5) * 100) / 100;
log.info(`模板匹配测试完成,得分${tempalteMatchScore.toFixed(2)}`);
tempalteMatchScore = Math.round(((tempalteMatchScore * 10 / loopCount) / 250) * 100) / 100;
log.info(`模板匹配1测试完成,得分${tempalteMatchScore.toFixed(2)}`);
}
if (operationMode === "模板匹配2" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
let loopCount = 0;
let GameRegion = captureGameRegion();
while (loopCount < timeout) {
try {
let result = GameRegion.find(ro2TM);
count++;
if (Date.now() - startTime >= interval * (loopCount + 1)) {
loopCount++;
await sleep(1);
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次模板匹配2`);
tempalteMatch2Score += count;
count = 0;
}
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
break;
}
}
if (dispose) GameRegion.dispose();
tempalteMatch2Score = Math.round(((tempalteMatch2Score * 10 / loopCount) / 0.85) * 100) / 100;
log.info(`模板匹配2测试完成,得分${tempalteMatch2Score.toFixed(2)}`);
}
if (operationMode === "ocr" || operationMode === "综合测试") {
@@ -81,12 +111,9 @@
let count = 0;
let loopCount = 0;
let GameRegion = captureGameRegion();
while (Date.now() - startTime < timeout * 1000) {
while (loopCount < timeout) {
try {
let result = GameRegion.findMulti(RecognitionObject.ocr(
0, 0,
xRange, yRange
));
let result = GameRegion.find(roOCR);
count++;
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
@@ -101,17 +128,106 @@
}
}
if (dispose) GameRegion.dispose();
ocrScore = ocrScore;
ocrScore = Math.round((ocrScore * 2 * 10 / loopCount) * 100) / 100;
ocrScore = Math.round((ocrScore * 2 * 10 / loopCount) * 100 / 3.5) / 100;
log.info(`ocr测试完成,得分${ocrScore.toFixed(2)}`);
}
if (operationMode === '纯运算' || operationMode === '综合测试') {
const startTime = Date.now();
const timeoutMs = timeout * 1000;
const CHECK_EVERY = 1000_000; // ★ 每 100 万次看一次表
let x = 1.23456789;
let count = 0; // 当前 interval 计数
let loopCount = 0; // 已完成的 interval 个数
let totalIter = 0; // 总迭代次数(用于分段时间判断)
while (true) {
// 一次性批跑 CHECK_EVERY 次浮点
for (let i = 0; i < CHECK_EVERY; i++) {
x = Math.sqrt(x + 1) * 1.000001;
}
count++;
totalIter += CHECK_EVERY;
// 批跑完再看时间
const elapsed = Date.now() - startTime;
if (elapsed >= timeoutMs) break;
// 是否到达日志/统计点
if (elapsed >= interval * (loopCount + 1)) {
loopCount++;
log.info(`${loopCount}${interval}ms 内执行了约 ${count}百万 次纯运算`);
calculateScore += count;
count = 0;
}
}
const R60 = 6000; // 60 分基准点
const k = 0.2; // 曲率系数
const R = calculateScore; // 原始累加值(百万次)
const score = 100 * Math.log1p(k * R) / Math.log1p(k * R60);
calculateScore = Math.round(score * 100) / 100; // 保留两位小数
log.info(`浮点运算测试完成,得分 ${calculateScore.toFixed(2)}`);
}
if (operationMode === "传送" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
while (Date.now() - startTime < 45 * 1000) {
try {
await genshin.tp(-876.73, 2277.07);
await genshin.tp(9452.18, 1660.94);
count++;
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
break;
}
}
log.info(`在45秒内执行了${count * 2}次传送`);
tpScore += count;
count = 0;
tpScore = Math.round((tpScore * 2 * 10) * 100) / 100;
log.info(`传送测试完成,得分${tpScore.toFixed(2)}`);
}
if (operationMode === "综合测试") {
log.info("综合测试结束");
finalScore = (captureRegionScore + tempalteMatchScore + ocrScore) / 3;
// squash 函数
const squash = x => x <= 100 ? x : 100 + Math.log1p(x - 100);
// 原始六项
const src = [
captureRegionScore,
tempalteMatchScore,
calculateScore,
tempalteMatch2Score,
ocrScore,
tpScore
];
// 1. 先 squash2. 再升序3. 按序号加权
const w = [0.1, 0.2, 0.2, 0.2, 0.2, 0.1];
let finalScore = src
.map(squash) // ① 压制 100+ 分数
.sort((a, b) => a - b) // ② 排序1最小…6最大
.reduce((s, v, i) => s + v * w[i], 0); // ③ 加权
// 可选保留两位小数
finalScore = Math.round(finalScore * 100) / 100;
log.info(`截图评分为${captureRegionScore.toFixed(2)}`);
log.info(`模板匹配评分为${tempalteMatchScore.toFixed(2)}`);
log.info(`模板匹配2评分为${tempalteMatch2Score.toFixed(2)}`);
log.info(`浮点运算评分为${calculateScore.toFixed(2)}`);
log.info(`ocr评分为${ocrScore.toFixed(2)}`);
log.info(`传送评分为${tpScore.toFixed(2)}`);
log.info(`综合评分为${finalScore.toFixed(2)}`)
}
})();