Vue.js 代码优化:分析日志数据并提取关键信息
function tempfunction(val) { const allinfo = {}; const info = [ {'2023-02-22': {'3014': {'Num': 2, 'Maxnumber': 33}}}, {'2023-02-23': {'3014': {'Num': 2, 'Maxnumber': 33}}} ]; const Jsoninfo = { '1000': '刷新视野耗时', '1001': '拾取触发耗时', '1003': '穿戴装备触发', '1004': '脱下装备触发', '1006': '吃物品触发', '1011': '点击NPC执行耗时', '5016': '小精灵拾取', '3014': '攻击触发', '10101': '攻击触发', '10049': '加经验' };
for (let i = 0; i < val.length; i++) { const textinfo = val[i].substring(26); const LogTime = val[i].substring(1, 11);
if (textinfo.indexOf('MsgTime') !== -1) {
const SubTextList = textinfo.split(' ');
for (let j = 0; j < SubTextList.length; j++) {
const SubText = SubTextList[j];
const lastIndexOfDash = SubText.lastIndexOf('-');
if (lastIndexOfDash !== -1 && SubText.includes('MsgTime')) {
const OutTime = SubText.substr(lastIndexOfDash + 1, SubText.length);
const MsgTimeId = SubText.substring(7, lastIndexOfDash);
const Remarks = Jsoninfo[MsgTimeId] || '未知行为';
if (OutTime > 31) {
if (!allinfo[LogTime]) {
allinfo[LogTime] = {};
}
if (!allinfo[LogTime][MsgTimeId]) {
allinfo[LogTime][MsgTimeId] = {
Num: 1,
Maxnumber: OutTime
};
} else {
const objt = allinfo[LogTime][MsgTimeId];
objt.Num += 1;
objt.Maxnumber = Math.max(objt.Maxnumber, OutTime);
allinfo[LogTime][MsgTimeId] = objt;
}
}
}
}
}
}
const lastDate = Object.keys(allinfo).pop(); const members = allinfo[lastDate] || {}; console.log(lastDate, members);
return temp; }
原文地址: https://www.cveoy.top/t/topic/m1IA 著作权归作者所有。请勿转载和采集!