Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
PASSOFT
SOHViewer
Commits
a6baf296
Commit
a6baf296
authored
1 year ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Parse log file packets
parent
78128dbc
No related branches found
No related tags found
1 merge request
!191
Read log files generated by users
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sohstationviewer/model/reftek_data/reftek_reader/log_file_reader.py
+51
-9
51 additions, 9 deletions
...viewer/model/reftek_data/reftek_reader/log_file_reader.py
with
51 additions
and
9 deletions
sohstationviewer/model/reftek_data/reftek_reader/log_file_reader.py
+
51
−
9
View file @
a6baf296
from
pathlib
import
Path
from
typing
import
List
,
Literal
,
Optional
from
typing
import
List
,
Literal
,
Optional
,
Dict
,
Callable
,
Tuple
LogFileFormat
=
Literal
[
'
rt2ms
'
,
'
logpeek
'
,
'
sohstationviewer
'
]
PACKETS
=
[
'
SH
'
,
'
SC
'
,
'
OM
'
,
'
DS
'
,
'
AD
'
,
'
CD
'
,
'
FD
'
,
'
EH
'
,
'
ET
'
]
...
...
@@ -47,16 +47,45 @@ def detect_log_file_packet_format(packet: List[str]) -> LogFileFormat:
return
'
logpeek
'
def
read_soh_packet_base
(
packet
:
List
[
str
]):
pass
def
parse_soh_packet_no_type
(
packet
:
List
[
str
]):
eh_et_lines
=
[]
soh_lines
=
packet
return
eh_et_lines
,
soh_lines
def
read_soh_packet_rt2ms
(
packet
:
List
[
str
]):
pass
def
parse_soh_packet_logpeek
(
packet
:
List
[
str
]):
eh_et_lines
=
[]
soh_lines
=
[]
for
line
in
packet
:
if
line
.
startswith
(
'
DAS:
'
):
eh_et_lines
.
append
(
line
)
else
:
soh_lines
.
append
(
line
)
return
eh_et_lines
,
soh_lines
def
parse_soh_packet_rt2ms
(
packet
:
List
[
str
]):
eh_et_lines
=
[]
soh_lines
=
[]
if
packet
[
0
].
startswith
(
'
EH
'
)
or
packet
[
0
].
startswith
(
'
ET
'
):
# The event info is summarized in the last line of an event info packet
eh_et_lines
=
[
packet
[
-
1
]]
else
:
soh_lines
=
packet
[
1
:]
return
eh_et_lines
,
soh_lines
def
parse_soh_packet_sohstationviewer
(
packet
:
List
[
str
]):
eh_et_lines
=
[]
soh_lines
=
[]
if
packet
[
0
].
startswith
(
'
Events:
'
):
eh_et_lines
=
packet
[
1
:]
else
:
soh_lines
=
packet
return
eh_et_lines
,
soh_lines
def
read_soh_packet_rt2ms
(
packet
:
List
[
str
]):
pass
class
LogFile
:
...
...
@@ -86,6 +115,14 @@ class LogFile:
self
.
file
.
close
()
PACKET_PARSERS
:
Dict
[
Optional
[
LogFileFormat
],
Callable
]
=
{
None
:
parse_soh_packet_no_type
,
'
sohstationviewer
'
:
parse_soh_packet_sohstationviewer
,
'
rt2ms
'
:
parse_soh_packet_rt2ms
,
'
logpeek
'
:
parse_soh_packet_logpeek
}
class
LogFileReader
:
"""
Class that reads a log file.
...
...
@@ -94,16 +131,21 @@ class LogFileReader:
self
.
file_path
=
file_path
self
.
packet_reader
=
None
self
.
log_file_type
:
Optional
[
LogFileFormat
]
=
None
self
.
eh_et_lines
=
[]
self
.
soh_lines
=
[]
def
read
(
self
):
log_file
=
LogFile
(
self
.
file_path
)
for
packet
in
log_file
:
if
self
.
log_file_type
is
None
:
self
.
log_file_type
=
detect_log_file_packet_format
(
packet
)
pass
parser
=
PACKET_PARSERS
[
self
.
log_file_type
]
eh_et_lines
,
soh_lines
=
parser
(
packet
)
self
.
eh_et_lines
.
extend
(
eh_et_lines
)
self
.
soh_lines
.
extend
(
soh_lines
)
if
__name__
==
'
__main__
'
:
pass
a
=
LogFileReader
(
Path
(
'
/Users/kle/PycharmProjects/sohstationviewer/
9BB3
.log
'
))
a
=
LogFileReader
(
Path
(
'
/Users/kle/PycharmProjects/sohstationviewer/
RT130_9BB3_2016326_2016365
.log
'
))
a
.
read
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment