尝试针对魅族20系设计新的计算逻辑

This commit is contained in:
2026-07-05 23:23:30 +08:00
parent 14416be48e
commit 20e29f3043
13 changed files with 1423 additions and 1036 deletions
+41
View File
@@ -0,0 +1,41 @@
/// 容量提取工具
/// 支持两种日志格式:
/// 1. learned_cap21 系列):单位 µAh,除以 1000 得到 mAh
/// 2. remaining_cap20 系列):单位 mAh,直接使用(但 21 系列的 remaining_cap 也是 µAh,需判断)
class CapacityExtractor {
static int? extractCapacity(List<String> lines) {
final validLines = lines.where((line) => line.contains('tbat=')).toList();
if (validLines.isEmpty) return null;
// 模式一:learned_cap21 系列)
final learnedReg = RegExp(r'learned_cap=(\d+)');
for (String line in validLines.reversed) {
final match = learnedReg.firstMatch(line);
if (match != null) {
return int.parse(match.group(1)!) ~/ 1000;
}
}
// 模式二:remaining_cap 最大值
final remainingReg = RegExp(r'remaining_cap=(\d+)');
int? maxRemaining;
for (String line in validLines) {
final match = remainingReg.firstMatch(line);
if (match != null) {
final value = int.parse(match.group(1)!);
if (maxRemaining == null || value > maxRemaining) {
maxRemaining = value;
}
}
}
if (maxRemaining == null) return null;
// 🟢 判断单位:如果数值大于 100000(约 100 mAh),则认为是 µAh,需除以 1000
// 否则认为是 mAh,直接使用
if (maxRemaining > 100000) {
return maxRemaining ~/ 1000;
} else {
return maxRemaining;
}
}
}