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
488b7db0
Commit
488b7db0
authored
1 year ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Get station code and network code from packet
parent
a6baf296
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
+34
-3
34 additions, 3 deletions
...viewer/model/reftek_data/reftek_reader/log_file_reader.py
with
34 additions
and
3 deletions
sohstationviewer/model/reftek_data/reftek_reader/log_file_reader.py
+
34
−
3
View file @
488b7db0
...
...
@@ -115,7 +115,8 @@ class LogFile:
self
.
file
.
close
()
PACKET_PARSERS
:
Dict
[
Optional
[
LogFileFormat
],
Callable
]
=
{
Parser
=
Callable
[[
List
[
str
]],
Tuple
[
List
[
str
],
List
[
str
]]]
PACKET_PARSERS
:
Dict
[
Optional
[
LogFileFormat
],
Parser
]
=
{
None
:
parse_soh_packet_no_type
,
'
sohstationviewer
'
:
parse_soh_packet_sohstationviewer
,
'
rt2ms
'
:
parse_soh_packet_rt2ms
,
...
...
@@ -123,29 +124,59 @@ PACKET_PARSERS: Dict[Optional[LogFileFormat], Callable] = {
}
def
get_experiment_number
(
soh_lines
:
List
[
str
]):
if
not
soh_lines
[
0
].
startswith
(
'
Station Channel Definition
'
):
return
None
# The experiment number can be in either the first or second line after
# the header. These lines are indented, so we have to strip them of
# whitespace.
if
soh_lines
[
1
].
strip
().
startswith
(
'
Experiment Number =
'
):
experiment_number_line
=
soh_lines
[
1
].
split
()
elif
soh_lines
[
2
].
strip
().
startswith
(
'
Experiment Number =
'
):
experiment_number_line
=
soh_lines
[
2
].
split
()
else
:
return
None
# If the experiment number is not recorded, we know that it will be 0. In
# order to not have too many return statements, we add 0 to the experiment
# line instead of returning it immediately.
if
len
(
experiment_number_line
)
<
4
:
experiment_number_line
.
append
(
'
0
'
)
return
experiment_number_line
[
-
1
]
class
LogFileReader
:
"""
Class that reads a log file.
"""
def
__init__
(
self
,
file_path
:
Path
):
self
.
file_path
=
file_path
self
.
packet_reader
=
None
self
.
log_file_type
:
Optional
[
LogFileFormat
]
=
None
self
.
eh_et_lines
=
[]
self
.
soh_lines
=
[]
self
.
station_code
:
Optional
[
str
]
=
None
self
.
experiment_number
:
Optional
[
str
]
=
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
)
parser
=
PACKET_PARSERS
[
self
.
log_file_type
]
eh_et_lines
,
soh_lines
=
parser
(
packet
)
if
self
.
station_code
is
None
and
soh_lines
:
self
.
station_code
=
soh_lines
[
0
].
split
(
'
'
)[
-
1
].
strip
()
if
self
.
experiment_number
is
None
and
soh_lines
:
found_experiment_number
=
get_experiment_number
(
soh_lines
)
self
.
experiment_number
=
found_experiment_number
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/RT130_9
BB3
_201
6326_2016365
.log
'
))
a
=
LogFileReader
(
Path
(
'
/Users/kle/PycharmProjects/sohstationviewer/
tests/test_data/potato.sdr/LOGS/
RT130_9
2EB
_201
7150_2017150
.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