Skip to content

Conversation

@balos1
Copy link
Member

@balos1 balos1 commented Jan 14, 2026

Parses stats that were printed in the table format instead of csv.

@balos1 balos1 changed the base branch from main to develop January 14, 2026 22:52
@balos1 balos1 added the tools label Jan 14, 2026
Comment on lines +44 to +50
try:
if "." in value:
value = float(value)
else:
value = int(value)
except ValueError:
pass # Keep value as string if conversion fails
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar parsing is done at

def num(s):
"""Try to convert a string to an int or float"""
try:
return int(s)
except ValueError:
try:
return float(s)
except ValueError:
return s

Could consider making this into a shared function that both files can use.

Args:
data (str): Multiline string containing repeated key-value tables.
Returns:
list: A dictionary, where each key is a list of the values.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
list: A dictionary, where each key is a list of the values.
stats: A dictionary, where each key is a list of the values.

Calling the output list when it is a dict is a bit confusing

Comment on lines +35 to +38
lines = data.splitlines()
for line in lines:
# Extract key-value pairs
match = re.match(r"^(.*?)\s+=\s+(.*)$", line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lines = data.splitlines()
for line in lines:
# Extract key-value pairs
match = re.match(r"^(.*?)\s+=\s+(.*)$", line)
lines = data.splitlines()
regexp = re.compile(r"^(.*?)\s+=\s+(.*)$")
for line in lines:
# Extract key-value pairs
match = regexp.match(line)

Untested, but should be a bit more efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants