Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DSI Parser Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
DigitalDynamicMeasurement
DSI Parser Frontend
Commits
e5dce42d
Commit
e5dce42d
authored
8 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added logging for dsiUnits and regEx missmatch
parent
30c055aa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
XMLUnitExtractor.py
+31
-0
31 additions, 0 deletions
XMLUnitExtractor.py
with
31 additions
and
0 deletions
XMLUnitExtractor.py
+
31
−
0
View file @
e5dce42d
import
re
from
dsiUnits
import
dsiUnit
import
logging
import
json
from
regexGenerator
import
generateRegex
dsiregExStr
=
generateRegex
()
# Compile the regex pattern
dsiregExPattern
=
re
.
compile
(
dsiregExStr
)
# Configure logging to log to a file
logging
.
basicConfig
(
filename
=
'
unitValidationLog.log
'
,
level
=
logging
.
DEBUG
,
format
=
'
%(asctime)s %(levelname)s %(message)s
'
)
def
parse_plain_utf8_xml
(
xml_string
):
result
=
{}
...
...
@@ -28,26 +37,48 @@ def parse_plain_utf8_xml(xml_string):
def
process_units
(
unit_dict
):
# Static regex parser function
def
validate_dsi_unit
(
dsi_unit_str
):
return
dsiregExPattern
.
fullmatch
(
dsi_unit_str
)
is
not
None
valid_units
=
{}
invalid_units
=
{}
for
key
,
value
in
unit_dict
.
items
():
try
:
unit
=
dsiUnit
(
value
)
regExresult
=
validate_dsi_unit
(
value
)
if
unit
.
valid
:
valid_units
[
key
]
=
value
# Assuming you want to return the string value
if
not
regExresult
:
discrepancy
=
{
"
type
"
:
"
Regex Error
"
,
"
message
"
:
"
Unit parsed as valid by dsiUnit constructor but invalid by regex
"
,
"
key
"
:
key
,
"
value
"
:
value
}
logging
.
debug
(
json
.
dumps
(
discrepancy
))
else
:
invalid_units
[
key
]
=
{
"
unit
"
:
value
,
"
warnings
"
:
unit
.
warnings
}
print
(
f
"
Warning: Invalid unit at
{
key
}
with value:
{
value
}
"
)
if
regExresult
:
discrepancy
=
{
"
type
"
:
"
Regex Error
"
,
"
message
"
:
"
Unit parsed as invalid by dsiUnit constructor but valid by regex
"
,
"
key
"
:
key
,
"
value
"
:
value
}
logging
.
debug
(
json
.
dumps
(
discrepancy
))
except
Exception
as
e
:
print
(
f
"
Error processing unit at
{
key
}
with value:
{
value
}
. Error:
{
e
}
"
)
invalid_units
[
key
]
=
{
"
unit
"
:
value
,
"
error
"
:
str
(
e
)
}
return
valid_units
,
invalid_units
def
parse_and_process
(
xml_string
):
...
...
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