使用python解析MML日志

时间:2016-08-13 00:30:45

标签: python algorithm parsing telecommunication

我想解析一个文本文件以将信息提取到电子表格程序中,问题是输入文本文件通常有多个分隔符,分隔符和文本字符,如下所示。

Script Task : dd_new
==========Summary==========
Success Num : 2690
Fail Num : 2342
===========================

==========Fail MML Command==========
MML Command-----LST RACHCFG:;
NE : 042249
Report : Ne is not connected.

MML Command-----LST RACHCFG:;
NE : 073196
Report : +++    073196        2016-08-11 16:01:00 DST
O&M    #22638
%%/*327033029*/LST RACHCFG:;%%
RETCODE = 939589973  Invalid Command.


---    END

MML Command-----LST RACHCFG:;
NE : 236263
Report : +++    236263        2016-08-11 16:00:59 DST
O&M    #807456706
%%/*325939762*/LST RACHCFG:;%%
RETCODE = 0  Operation succeeded.

Display RACHCfg
---------------
Local cell ID  Power ramping step(dB)  Preamble initial received target power(dBm)  Message size of select group A(bit)  PRACH Frequency Offset  Indication of PRACH Configuration Index  PRACH Configuration Index  Maximum number of preamble transmission  Timer for contention resolution(subframe)  Maximum number of Msg3 HARQ transmissions

1              2dB                     -104dBm                                      56bits                               6                       Not configure                            NULL                       10times                                  64                                         5                                        
2              2dB                     -104dBm                                      56bits                               6                       Not configure                            NULL                       10times                                  64                                         5                                        
3              2dB                     -104dBm                                      56bits                               6                       Not configure                            NULL                       10times                                  64                                         5                                        
(Number of results = 3)


---    END



MML Command-----LST RACHCFG:;
NE : 236264
Report : +++    236264        2016-08-11 16:01:00 DST
O&M    #807445026
%%/*325939772*/LST RACHCFG:;%%
RETCODE = 0  Operation succeeded.

Display RACHCfg
---------------
                              Local cell ID  =  1
                     Power ramping step(dB)  =  2dB
Preamble initial received target power(dBm)  =  -104dBm
        Message size of select group A(bit)  =  56bits
                     PRACH Frequency Offset  =  6
    Indication of PRACH Configuration Index  =  Not configure
                  PRACH Configuration Index  =  NULL
    Maximum number of preamble transmission  =  10times
  Timer for contention resolution(subframe)  =  64
  Maximum number of Msg3 HARQ transmissions  =  5
(Number of results = 1)


---    END

方法:

我们用line.split(':')中的“:”分隔行的部分是构建字典的一种明确方法,但是我需要一种方法来让程序扼杀所有的决策一路上。

  • 这是一个有效的块吗? (标题脚本任务:dd new可以丢弃)。
  • 无法连接NE和无效命令的MML命令失败需要使用相应的类型提取到dict中: {NE:'042249',状态:'Ne未连接'},{NE:'07316',状态:'无效命令'}
  • 当遇到Display RACH Cfg的两个输出格式中的任何一个时,成功的MML命令应该能够成功地解析为嵌套字典。两者应该产生(每个NE的本地单元格ID,然后是每个参数的嵌套键值字典。

{NE:236263,{Local Cell Id: '1' : {Power ramping Step :'2dB',,Preamble initial received target power:-104dBm,........},Local Cell Id: '2' : {Power ramping Step :'2dB',,Preamble initial received target power:-104dBm,........}Local Cell Id: '3' : {Power ramping Step :'2dB',,Preamble initial received target power:-104dBm,........}

和类似的(第二种情况下有一个Local Cell Id)

{NE :236264 ,{Local Cell Id : '1' { Power ramping Step :'2dB',Preamble initial received target power:-104dBm,.....}

我搜索了论坛,看过正则表达式的例子以及用开始/结束标记和阅读块替换'==='的想法但是如果有更多的pythonic方式或已经存在的库来处理这些东西,它会让我的生活变得轻而易举。

对于那些想知道它是什么的人来说,这些是来自电信设备的MML日志,列出了它的配置。

0 个答案:

没有答案