Skip to content

Commit 0e545bd

Browse files
authored
修复终止翻页逻辑,测算模式调整,压缩log (#3058)
修复终止翻页逻辑,测算模式调整,压缩log
1 parent a250685 commit 0e545bd

10 files changed

Lines changed: 126 additions & 85 deletions

File tree

repo/js/背包材料统计/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 背包材料统计 v2.62
1+
# 背包材料统计 v2.68
22
作者:吉吉喵
33

44
<!-- 新增:全局图片样式,控制连续图片同行显示 -->
@@ -208,21 +208,21 @@ A:记录文件夹位于 `BetterGI\User\JsScript\背包材料统计\` 下,各
208208
| v1.3 | 优化:加速材料寻找(新增前位材料识别) |
209209
| v1.31 | 调整本地记录存储逻辑 |
210210
| v1.32 | 新增后位材料识别功能 |
211-
| v2.0 | 开发版:支持多组材料、多个分类;移除前/后位材料识别 |
211+
| v2.0 | 开发版:支持多组材料、多个分类;移除前/后位材料识别 |
212212
| v2.1 | 新增CD管理功能 |
213213
| v2.2 | 优化路径顺序、材料数量判断逻辑 |
214214
| v2.21 | 修改路径储存路径 |
215215
| v2.22 | 精简日志输出内容 |
216216
| v2.23 | 优化部分函数性能 |
217217
| v2.24 | 修复“空路径无法使用背包统计”等bug |
218-
| v2.25 | 恢复前/后位材料识别(加速扫描);新增“仅扫描路径材料”选项(降低内存占用) |
218+
| v2.25 | 恢复前/后位材料识别(加速扫描);新增“仅扫描路径材料”选项(降低内存占用)|
219219
| v2.26 | 修复材料时间读取错误;新增路径材料时间成本计算功能 |
220220
| v2.27 | 修复“材料数计算错误”“目标数量临界值异常”“3识别成三”等bug |
221221
| v2.28 | 材料变更时自动更新初始数量;排除0位移/0数量路径记录;新增材料名0后缀本地记录;新增背包弹窗识别 |
222-
| v2.29 | 新增排除提示;调整平均时间成本计算逻辑;过滤异常值记录 |
223-
| v2.30 | 更改路径专注模式默认值;增加日志提示;移除调试日志 |
222+
| v2.29 | 新增排除提示;调整平均时间成本计算逻辑;过滤异常值记录 |
223+
| v2.30 | 更改路径专注模式默认值;增加日志提示;移除调试日志 |
224224
| v2.40 | 优化背包识别时的内存占用;新增通知功能 |
225-
| v2.41 | 修复“勾选分类的本地记录”bug;新增“仅背包统计”选项;补充记录损坏处理说明 |
225+
| v2.41 | 修复“勾选分类的本地记录”bug;新增“仅背包统计”选项;补充记录损坏处理说明 |
226226
| v2.42 | 新增“无路径间扫描”“noRecord模式”(适合成熟路径);新增怪物材料CD文件 |
227227
| v2.50 | 新增独立名单拾取、弹窗模块;支持怪物名识别 |
228228
| v2.51 | 自定义设置新增“拖动距离/拖动点”;新增月卡弹窗识别;路径材料超量自动上黑名单;修复怪物0收获记录 |
@@ -240,4 +240,5 @@ A:记录文件夹位于 `BetterGI\User\JsScript\背包材料统计\` 下,各
240240
| v2.64 | 移除位移检测模块 |
241241
| v2.65 | 修复测算模式、0记录检测码等bug,优化汇总日志,调整默认目标数量至1000 |
242242
| v2.66 | 修复翻页兜底逻辑,增加材料数量模板匹配,材料数量OCR失败后截图保存,【扫描额外的分类】联动超量材料 |
243-
| v2.67 | 修复怪物材料映射斜杠逻辑,更新OCR错字映射表,优先级材料按自定义顺序,修复怪物材料过滤bug |
243+
| v2.67 | 修复怪物材料映射斜杠逻辑,更新OCR错字映射表,优先级材料按自定义顺序,修复怪物材料过滤bug |
244+
| v2.68 | 修复终止翻页逻辑,测算模式调整,压缩log |

repo/js/背包材料统计/lib/autoPick.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function readtargetTextCategories(targetTextDir) {
3939
let availablePickCategories = [];
4040
try {
4141
availablePickCategories = targetTextFilePaths.map(filePath => basename(filePath).replace('.txt', ''));
42-
log.info(`可用识别名单:${availablePickCategories.join(', ')}`);
42+
if (debugLog) log.info(`可用识别名单:${availablePickCategories.join(', ')}`);
4343
} catch (e) {
4444
log.error(`扫描识别名单目录失败: ${e.message}`);
4545
}
4646

4747
if (pickTextNames.length === 0) {
48-
log.info("未指定识别名单,将加载所有文件");
48+
if (debugLog) log.info("未指定识别名单,将加载所有文件");
4949
} else {
5050
const invalidCategories = pickTextNames.filter(name => !availablePickCategories.includes(name));
5151
if (invalidCategories.length > 0) {
@@ -54,7 +54,7 @@ function readtargetTextCategories(targetTextDir) {
5454
}
5555
}
5656

57-
log.info(`筛选名单状态:${pickTextNames.length === 0 ? '未指定(空),将加载所有文件' : '指定了:' + pickTextNames.join(',')}`);
57+
if (debugLog) log.info(`筛选名单状态:${pickTextNames.length === 0 ? '未指定(空),将加载所有文件' : '指定了:' + pickTextNames.join(',')}`);
5858

5959
for (const filePath of targetTextFilePaths) {
6060
if (state.cancelRequested) break;
@@ -76,7 +76,7 @@ function readtargetTextCategories(targetTextDir) {
7676

7777
materialCategories[sourceCategory] = parseCategoryContent(content);
7878
}
79-
log.info(`完成读取,加载的分类:${Object.keys(materialCategories).join(',')}`);
79+
if (debugLog) log.info(`完成读取,加载的分类:${Object.keys(materialCategories).join(',')}`);
8080
return materialCategories;
8181
}
8282

@@ -196,7 +196,9 @@ async function alignAndInteractTarget(targetTextsOrFunc, fDialogueRo, textxRange
196196
for (const res of ocrResults) {
197197
const centerY = res.y + res.height / 2;
198198
const yDiff = Math.abs(centerY - fCenterY);
199-
log.debug(`未匹配: "${res.text}" Y中心: ${centerY.toFixed(1)}, F图标Y中心: ${fCenterY.toFixed(1)}, 差值: ${yDiff.toFixed(1)}, 容忍度: ${texttolerance}`);
199+
const logText = `未匹配: "${res.text}" Y中心: ${centerY.toFixed(1)}, F图标Y中心: ${fCenterY.toFixed(1)}, 差值: ${yDiff.toFixed(1)}, 容忍度: ${texttolerance}`;
200+
log.debug(logText);
201+
writeFile("user/OCR未匹配记录.txt", logText);
200202
}
201203
}
202204
await keyMouseScript.runFile(`assets/滚轮下翻.json`);

repo/js/背包材料统计/lib/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function safeReadTextSync(filePath, defaultValue = "") {
116116
try {
117117
// 第一步:校验文件是否存在
118118
if (!fileExists(filePath)) {
119-
log.debug(`${CONSTANTS.LOG_MODULES.RECORD}文件不存在,跳过读取: ${filePath}`);
119+
// log.debug(`${CONSTANTS.LOG_MODULES.RECORD}文件不存在,跳过读取: ${filePath}`);
120120
return defaultValue;
121121
}
122122
// 第二步:读取文件(捕获读取异常)
@@ -226,7 +226,7 @@ function matchImageAndGetCategory(resourceName, imagesDir) {
226226
const processedName = (MATERIAL_ALIAS[resourceName] || resourceName).toLowerCase();
227227

228228
if (!imageMapCache.has(imagesDir)) {
229-
log.debug(`${CONSTANTS.LOG_MODULES.MATERIAL}初始化图像分类缓存:${imagesDir}`);
229+
// log.debug(`${CONSTANTS.LOG_MODULES.MATERIAL}初始化图像分类缓存:${imagesDir}`);
230230
imageMapCache.set(imagesDir, createImageCategoryMap(imagesDir));
231231
}
232232

repo/js/背包材料统计/lib/imageClick.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ async function imageClickBackgroundTask() {
264264

265265
// 打印资源检测结果
266266
log.info("\n==================== 现有弹窗加载结果 ====================");
267-
log.info("1. 一级弹窗(共" + firstLevelDirs.length + "个):");
268-
firstLevelDirs.forEach((res, idx) => log.info(` ${idx+1}. 【${res.dirName}】`));
267+
const firstLevelNames = firstLevelDirs.map(res => res.dirName).join('、');
268+
log.info("1. 一级弹窗(共" + firstLevelDirs.length + "个):" + firstLevelNames);
269269
const secondLevelResources = preloadedResources.filter(res => !res.isFirstLevel);
270-
log.info("\n2. 二级弹窗(共" + secondLevelResources.length + "个):");
271-
secondLevelResources.forEach((res, idx) => log.info(` ${idx+1}. 【${res.dirName}】`));
270+
const secondLevelNames = secondLevelResources.map(res => res.dirName).join('、');
271+
log.info("2. 二级弹窗(共" + secondLevelResources.length + "个):" + secondLevelNames);
272272
log.info("=============================================================\n");
273273

274274
// 核心逻辑:外循环遍历所有一级弹窗

repo/js/背包材料统计/lib/pathProcessor.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async function processMonsterPathEntry(entry, context) {
366366
if (startTime) {
367367
const endTime = new Date().toLocaleString();
368368
runTime = (new Date(endTime) - new Date(startTime)) / 1000;
369-
await handlePathError(error, pathingFilePath, pathName, monsterName, startTime, endTime, runTime, shouldRunAsNoRecord, false);
369+
await handlePathError(error, pathingFilePath, pathName, monsterName, startTime, endTime, runTime, shouldRunAsNoRecord, state.cancelRequested);
370370
}
371371
throw error;
372372
}
@@ -589,7 +589,8 @@ async function processAllPaths(allPaths, CDCategories, materialCategoryMap, time
589589
noRecordDir,
590590
isFood,
591591
pathRecordCache,
592-
pathingFilePath
592+
pathingFilePath,
593+
true
593594
);
594595

595596
const isTimeCostOk = perTime === null || isTimeCostQualified(
@@ -655,17 +656,6 @@ async function processAllPaths(allPaths, CDCategories, materialCategoryMap, time
655656
}
656657
}
657658

658-
log.info(`${CONSTANTS.LOG_MODULES.PATH}\n===== 测算模式分析结果 =====`);
659-
log.info(`${CONSTANTS.LOG_MODULES.PATH}时间成本:${timeCost}%`);
660-
log.info(`${CONSTANTS.LOG_MODULES.PATH}总路径数:${totalPaths}`);
661-
log.info(`${CONSTANTS.LOG_MODULES.PATH}未通过(CD未刷新):${failedCD}条`);
662-
log.info(`${CONSTANTS.LOG_MODULES.PATH}未通过(0记录超限):${failedFrequency}条`);
663-
log.info(`${CONSTANTS.LOG_MODULES.PATH}未达标(时间成本不合格):${failedTimeCost}条`);
664-
log.info(`${CONSTANTS.LOG_MODULES.PATH}直通达标(记录不足):${insufficientRecords}条`);
665-
log.info(`${CONSTANTS.LOG_MODULES.PATH}达标路径数:${totalQualifiedPaths}条(同时通过三个校验)`);
666-
log.info(`${CONSTANTS.LOG_MODULES.PATH}达标占比:${totalPaths > 0 ? ((totalQualifiedPaths / totalPaths) * 100).toFixed(1) : 0}%`);
667-
log.info(`${CONSTANTS.LOG_MODULES.PATH}预计耗时:${formatTime(totalEstimatedTime)}`);
668-
669659
log.info(`${CONSTANTS.LOG_MODULES.PATH}\n各材料平均时间成本及达标情况:`);
670660
for (const [resourceKey, data] of Object.entries(resourceAnalysis)) {
671661
const avgThresholdPerTime = data.thresholdPerTimeCount > 0 ? (data.thresholdPerTimeSum / data.thresholdPerTimeCount).toFixed(4) : '无记录';
@@ -675,7 +665,6 @@ async function processAllPaths(allPaths, CDCategories, materialCategoryMap, time
675665
const avgThresholdPercentile = thresholdPercentileTimes.length > 0
676666
? (thresholdPercentileTimes.reduce((sum, t) => sum + t, 0) / thresholdPercentileTimes.length).toFixed(4)
677667
: '无达标';
678-
const qualifiedRatio = data.thresholdPerTimeCount > 0 ? ((data.qualified / data.thresholdPerTimeCount) * 100).toFixed(1) : '0.0';
679668
const totalEstimatedTime = formatTime(data.estimatedTimeSum);
680669
const avgQualifiedPerTime = data.qualified > 0 ? (data.qualifiedPerTimeSum / data.qualified).toFixed(4) : '无达标';
681670

@@ -687,15 +676,21 @@ async function processAllPaths(allPaths, CDCategories, materialCategoryMap, time
687676
} else if (isMonster) {
688677
unit = '秒/中位材料';
689678
}
679+
const totalPassedPaths = data.qualified;
680+
const totalPathsForMaterial = data.total;
681+
const directPassPaths = totalPassedPaths;
682+
const displayRatio = `${totalPassedPaths}/${totalPathsForMaterial}`;
690683

691684
log.info(`${CONSTANTS.LOG_MODULES.PATH} --------------------------------------`);
692685
log.info(`${CONSTANTS.LOG_MODULES.PATH} ${resourceKey}:`);
693686
log.info(`${CONSTANTS.LOG_MODULES.PATH} 达标平均:${avgQualifiedPerTime}${unit}`);
694687
log.info(`${CONSTANTS.LOG_MODULES.PATH} 所有记录平均(排除0记录超限):${avgThresholdPerTime}${unit}`);
695688
log.info(`${CONSTANTS.LOG_MODULES.PATH} 设置的${timeCost}%分位阈值:${avgThresholdPercentile}${unit}`);
696-
log.info(`${CONSTANTS.LOG_MODULES.PATH} 达标:${qualifiedRatio}% (${data.qualified}/${data.thresholdPerTimeCount}),总耗时:${totalEstimatedTime}`);
689+
log.info(`${CONSTANTS.LOG_MODULES.PATH} 达标:${displayRatio},总耗时:${totalEstimatedTime}`);
697690
}
698-
log.info(`${CONSTANTS.LOG_MODULES.PATH}=============================\n`);
691+
692+
const qualifiedRatio = totalPaths > 0 ? ((totalQualifiedPaths / totalPaths) * 100).toFixed(1) : 0;
693+
log.info(`${CONSTANTS.LOG_MODULES.PATH}===== 测算模式分析结果 =====\n时间成本:${timeCost}%,总路径:${totalPaths}\nCD冷却中:${failedCD},0记录超限:${failedFrequency},cost不达标:${failedTimeCost}\n达标:${totalQualifiedPaths}(${qualifiedRatio}%),预计耗时:${formatTime(totalEstimatedTime)}\n`);
699694

700695
if (notify) {
701696
const estimateMsg = `【测算模式】分析完成\n总路径数:${totalPaths}\n达标路径数:${totalQualifiedPaths}\n达标占比:${totalPaths > 0 ? ((totalQualifiedPaths / totalPaths) * 100).toFixed(1) : 0}%\n预计耗时:${formatTime(totalEstimatedTime)}`;

repo/js/背包材料统计/lib/recordManager.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function checkPathNameFrequency(resourceName, pathName, recordDir, isFood = fals
138138
if (line.startsWith('路径名: ')) {
139139
currentPathName = line.split('路径名: ')[1];
140140
} else if (line.startsWith('内容检测码: ')) {
141-
recordContentCode = line.split('内容检测码: ')[1];
141+
recordContentCode = line.split('内容检测码: ')[1].trim();
142142
} else if (line === '' && currentPathName && recordContentCode) {
143143
if (hasValidContentCode) {
144144
if (recordContentCode === currentContentCode) {
@@ -266,11 +266,11 @@ function getLastRunEndTime(resourceName, pathName, recordDir, noRecordDir, pathi
266266

267267
blockLines.forEach(line => {
268268
if (line.startsWith('路径名: ')) {
269-
blockPathName = line.split('路径名: ')[1];
269+
blockPathName = line.split('路径名: ')[1].trim();
270270
} else if (line.startsWith('内容检测码: ')) {
271-
blockContentCode = line.split('内容检测码: ')[1] || '00000000';
271+
blockContentCode = line.split('内容检测码: ')[1].trim() || '00000000';
272272
} else if (line.startsWith('结束时间: ')) {
273-
blockEndTime = line.split('结束时间: ')[1];
273+
blockEndTime = line.split('结束时间: ')[1].trim();
274274
}
275275
});
276276

@@ -308,7 +308,7 @@ function getLastRunEndTime(resourceName, pathName, recordDir, noRecordDir, pathi
308308
* @param {Object} cache - 缓存对象(单次路径处理周期内有效)
309309
* @returns {Array<Object>} 结构化记录列表(含runTime、quantityChange)
310310
*/
311-
function getHistoricalPathRecords(resourceKey, pathName, recordDir, noRecordDir, isFood = false, cache = {}, pathingFilePath) {
311+
function getHistoricalPathRecords(resourceKey, pathName, recordDir, noRecordDir, isFood = false, cache = {}, pathingFilePath, filterExcessMaterials = false) {
312312
const contentCode = pathingFilePath ? generatePathContentCode(pathingFilePath) : null;
313313
const hasValidContentCode = contentCode && contentCode !== "00000000";
314314

@@ -353,14 +353,14 @@ function getHistoricalPathRecords(resourceKey, pathName, recordDir, noRecordDir,
353353

354354
blockLines.forEach(line => {
355355
if (line.startsWith('路径名: ')) {
356-
const recordPathName = line.split('路径名: ')[1];
356+
const recordPathName = line.split('路径名: ')[1].trim();
357357
const cleanRecordPathName = recordPathName.replace(/_[0-9a-fA-F]{8}\.json$/, '.json');
358358
if (cleanRecordPathName === cleanPathName) {
359359
isTargetPath = true;
360360
}
361361
}
362362
if (line.startsWith('内容检测码: ')) {
363-
recordContentCode = line.split('内容检测码: ')[1] || "00000000";
363+
recordContentCode = line.split('内容检测码: ')[1].trim() || "00000000";
364364
}
365365
if (line.startsWith('运行时间: ')) {
366366
runTime = parseInt(line.split('运行时间: ')[1].split('秒')[0], 10) || 0;
@@ -391,6 +391,35 @@ function getHistoricalPathRecords(resourceKey, pathName, recordDir, noRecordDir,
391391

392392
cache[cacheKey] = records;
393393
if (debugLog) log.debug(`${CONSTANTS.LOG_MODULES.RECORD}读取记录并缓存:${cacheKey}${records.length}条)`);
394+
395+
if (filterExcessMaterials && excessMaterialNames.length > 0) {
396+
const filteredRecords = records.filter(record => {
397+
const { quantityChange } = record;
398+
399+
if (isFood) {
400+
return true;
401+
}
402+
403+
if (monsterToMaterials[resourceKey]) {
404+
const monsterMaterials = monsterToMaterials[resourceKey];
405+
const allExcess = monsterMaterials.every(mat => excessMaterialNames.includes(mat));
406+
return !allExcess;
407+
}
408+
409+
if (quantityChange[resourceKey] !== undefined) {
410+
return !excessMaterialNames.includes(resourceKey);
411+
}
412+
413+
return true;
414+
});
415+
416+
if (debugLog && filteredRecords.length !== records.length) {
417+
log.debug(`${CONSTANTS.LOG_MODULES.RECORD}过滤超量材料记录:${records.length}条 -> ${filteredRecords.length}条`);
418+
}
419+
420+
return filteredRecords;
421+
}
422+
394423
return records;
395424
}
396425

0 commit comments

Comments
 (0)