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
78128dbc
Commit
78128dbc
authored
1 year ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Detect log file format
parent
6931aea8
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
+48
-4
48 additions, 4 deletions
...viewer/model/reftek_data/reftek_reader/log_file_reader.py
with
48 additions
and
4 deletions
sohstationviewer/model/reftek_data/reftek_reader/log_file_reader.py
+
48
−
4
View file @
78128dbc
from
pathlib
import
Path
from
typing
import
List
from
typing
import
List
,
Literal
,
Optional
LogFileFormat
=
Literal
[
'
rt2ms
'
,
'
logpeek
'
,
'
sohstationviewer
'
]
PACKETS
=
[
'
SH
'
,
'
SC
'
,
'
OM
'
,
'
DS
'
,
'
AD
'
,
'
CD
'
,
'
FD
'
,
'
EH
'
,
'
ET
'
]
def
detect_log_file_packet_format
(
packet
:
List
[
str
])
->
LogFileFormat
:
"""
Detect the format of a log file packet. The format can be either rt2ms
'
,
logpeek
'
s, or SOHStationViewer
'
s.
:param packet: a packet extracted from a log file.
:return: the format of packet. Can be either
'
rt2ms
'
,
'
logpeek
'
, or
'
sohstationviewer
'
.
"""
# We want to take advantage of the metadata written by the various programs
# as much as possible.
if
packet
[
0
].
startswith
(
'
logpeek
'
):
return
'
logpeek
'
elif
packet
[
0
].
startswith
(
'
rt2ms
'
):
return
'
rt2ms
'
elif
packet
[
0
].
startswith
(
'
sohstationviewer
'
):
return
'
sohstationviewer
'
packet_start
=
packet
[
0
]
# The first line of a packet in a log file generated by rt2ms starts with
# a 2-letter packet type. That is then followed by an empty space and the
# string 'exp'.
if
packet_start
[:
2
]
in
PACKETS
and
packet_start
[
3
:
6
]
==
'
exp
'
:
return
'
rt2ms
'
# SOHStationViewer stores all events' info at the end of its log file, and
# so if we see the line
# Events:
# at the start of a packet, we know the log file is from SOHStationViewer.
if
packet_start
.
startswith
(
'
Events:
'
):
return
'
sohstationviewer
'
# Logpeek write its events' info right after an SH packet.
packet_end
=
packet
[
-
1
]
packet_end_with_event_info
=
(
packet_end
.
startswith
(
'
DAS
'
)
or
packet_end
.
startswith
(
'
WARNING
'
))
if
(
packet_start
.
startswith
(
'
State of Health
'
)
and
packet_end_with_event_info
):
return
'
logpeek
'
def
detect_log_file_packet_format
(
packet
:
List
[
str
]):
pass
def
read_soh_packet_base
(
packet
:
List
[
str
]):
pass
...
...
@@ -51,11 +93,13 @@ class LogFileReader:
def
__init__
(
self
,
file_path
:
Path
):
self
.
file_path
=
file_path
self
.
packet_reader
=
None
self
.
log_file_type
:
LogFileFormat
self
.
log_file_type
:
Optional
[
LogFileFormat
]
=
None
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
...
...
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