kanglei79 发表于 2022-7-5 22:24:46

如何实现从log中提取关键信息导入到excel中

求助:我有一个log日志文件.txt,需求如下:
1、有1000组实验数据,每组实验数据包含几十行内容(写寄存器、读寄存器等操作),我需要提取其中读到的0x88,0x8a,0x90三个寄存器的data值,但是这三个寄存器每组实验数据要读4次(配置两个芯片,每次配置一片芯片后读两次:分别是0x16寄存器写4和写8);
2、每组实验数据会包含(SUCCESS: cfg)或(FAIL:cmd cfg failed)的关键字,在提取1中的寄存器data值的同时需要同时知道该组实验是success还是fail;
3、将上述数据导入到excel中,格式类似下表格所示


 AFEXXX_DT  AFEXXX_DT 
 0x16 = 40x16 = 8 0x16 = 40x16 = 8 
次数0x880x8a0x900x880x8a0x90 0x880x8a0x900x880x8a0x90result
10xd0xb0xd0xb0xb0xd 0xd0xb0xd0xb0xb0xdPass
20xb0xb0xb0xb0xb0xb 0xb0xb0xb0xb0xb0xbPass
30x90x90x90x90x90x9 0x90x90x90x90x90x9Pass
40xb0xb0xd0xd0xb0xd 0xb0xb0xd0xd0xb0xdPass
50xb0x90xb0x90x90xb 0xb0x90xb0x90x90xbPass
60xb0xb0xb0xb0xb0xb 0xb0xb0xb0xb0xb0xbPass
70xd0xb0xd0xb0xb0xd 0xd0xb0xd0xb0xb0xdPass
80xb0xb0xb0xb0xb0xb 0xb0xb0xb0xb0xb0xbPass
90xd0xb0xd0xb0xb0xd 0xd0xb0xd0xb0xb0xdPass
100xb0xb0xb0xb0xb0xb 0xb0xb0xb0xb0xb0xbfailed


kanglei79 发表于 2022-7-5 22:25:33

这是日志文件success或fail的举例说明,请大神帮忙指点一下
### 测试次数:1 ###(success举例)
afexxxx_2p2 cfg 0 /ram/omu/dif/hw/AFEXXX_DT.bin
SUCCESS: cfg
afexxxx_2p2 cfg 1 /ram/omu/dif/hw/AFEXXX_MT.bin
SUCCESS: cfg
afexxxx_2p2 wr 0 16 4
SUCCESS: wr
afexxxx_2p2 rd 0 88 1
addr=0x88(136), data=0xd
SUCCESS: rd
afexxxx_2p2 rd 0 8a 1
addr=0x8a(138), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 0 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 0 16 8
SUCCESS: wr
afexxxx_2p2 rd 0 88 1
addr=0x88(136), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 0 8a 1
addr=0x8a(138), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 0 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 0 16 0
SUCCESS: wr
afexxxx_2p2 wr 1 16 4
SUCCESS: wr
afexxxx_2p2 rd 1 88 1
addr=0x88(136), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 1 8a 1
addr=0x8a(138), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 1 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 1 16 8
SUCCESS: wr
afexxxx_2p2 rd 1 88 1
addr=0x88(136), data=0xd
SUCCESS: rd
afexxxx_2p2 rd 1 8a 1
addr=0x8a(138), data=0xd
SUCCESS: rd
afexxxx_2p2 rd 1 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 1 16 0
SUCCESS: wr
config AFEXXX done


### 测试次数:2 ###(fail举例1)
afexxxx_2p2 cfg 0 /ram/omu/dif/hw/AFEXXX_DT.bin
[../src/device/Afe79xx/Src/basicFunctions.c]INFO:addr, lsb, msb, data not matching with expected value
ERR:position mode, addr data lsb msb
ERR:cmd cfg failed
args_count, usage: afe79xx cfg
afexxxx_2p2 cfg 1 /ram/omu/dif/hw/AFEXXX_MT.bin
SUCCESS: cfg
afexxxx_2p2 wr 0 16 4
SUCCESS: wr
afexxxx_2p2 rd 0 88 1
addr=0x88(136), data=0x13
SUCCESS: rd
afexxxx_2p2 rd 0 8a 1
addr=0x8a(138), data=0x13
SUCCESS: rd
afexxxx_2p2 rd 0 90 1
addr=0x90(144), data=0x13
SUCCESS: rd
afexxxx_2p2 wr 0 16 8
SUCCESS: wr
afexxxx_2p2 rd 0 88 1
addr=0x88(136), data=0x13
SUCCESS: rd
afexxxx_2p2 rd 0 8a 1
addr=0x8a(138), data=0x13
SUCCESS: rd
afexxxx_2p2 rd 0 90 1
addr=0x90(144), data=0x13
SUCCESS: rd
afexxxx_2p2 wr 0 16 0
SUCCESS: wr
afexxxx_2p2 wr 1 16 4
SUCCESS: wr
afexxxx_2p2 rd 1 88 1
addr=0x88(136), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 1 8a 1
addr=0x8a(138), data=0xd
SUCCESS: rd
afexxxx_2p2 rd 1 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 1 16 8
SUCCESS: wr
afexxxx_2p2 rd 1 88 1
addr=0x88(136), data=0xb
SUCCESS: rd
afexxxx_2p2 rd 1 8a 1
addr=0x8a(138), data=0xd
SUCCESS: rd
afexxxx_2p2 rd 1 90 1
addr=0x90(144), data=0xd
SUCCESS: rd
afexxxx_2p2 wr 1 16 0
SUCCESS: wr
config AFEXXX done

阿奇_o 发表于 2022-7-6 01:23:53

问题1:log日志文件里都是包括像 【### 测试次数:2 ###】 这样的固定字符吗? 还是你自己在这里加的?
问题2:一定要那样子的Excel格式吗?不能变通一下?(合并单元这种格式,看到头皮就有点麻{:10_277:})

为了更好地了解背景和你的需求,最好把txt日志和想要的效果Excel文件,打包发上来。

ps: 另外可以加Q3130137034沟通细聊

kanglei79 发表于 2022-7-6 20:41:09

阿奇_o 发表于 2022-7-6 01:23
问题1:log日志文件里都是包括像 【### 测试次数:2 ###】 这样的固定字符吗? 还是你自己在这里加的?
...

感谢解答,问题回复如下:
问题1:日志里每次开头都会有测试次数统计;
问题2:可以变通,只要能体现次数、三个寄存器的data值、pass或fail就行

kanglei79 发表于 2022-7-6 20:43:14

不知道怎么打包附件{:5_96:}

阿奇_o 发表于 2022-7-6 21:41:29

暂时这样给你看看 这样的效果:
import pandas as pd
import numpy as np
import re
with open('test_log.txt', encoding='utf-8') as f:
    result = re.split('### 测试次数:\d+ ###\n', ''.join(f), re.MULTILINE)
    print(result)
    print(len(result))
data =

df = pd.DataFrame(data, ).T
df.columns=['t1', 't2']
df

#
df1 = df[['t1']].reset_index(drop=True)
df1['第次'] = 1
df1['结果'] = 'pass' if len(df) == 0 else '未知'
df1.columns = ['data', '第次', '结果']
df1

# --
df2 = df[['t2']].reset_index(drop=True)
df2['第次'] = 2
df2['结果'] = 'fail' if len(df) >= 1 else '未知'
df2.columns = ['data', '第次', '结果']
df2


kanglei79 发表于 2022-7-9 14:56:57

阿奇_o 发表于 2022-7-6 21:41
暂时这样给你看看 这样的效果:

第一段的result运行出来是空的
页: [1]
查看完整版本: 如何实现从log中提取关键信息导入到excel中