Skip to content
Snippets Groups Projects
Commit e5dce42d authored by Benedikt's avatar Benedikt
Browse files

added logging for dsiUnits and regEx missmatch

parent 30c055aa
No related branches found
No related tags found
No related merge requests found
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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment