Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speeding up lookup of inp sections and bracketed words #116

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions swmmio/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,21 @@ def get_inp_sections_details(inp_path, include_brackets=False):
found_sects = OrderedDict()

with open(inp_path) as f:
for line in f:
sect_not_found = True
for sect_id, data in INP_OBJECTS.items():
# find the start of an INP section
search_tag = format_inp_section_header(sect_id)
if search_tag.lower() in line.lower():
if include_brackets:
sect_id = '[{}]'.format(sect_id.upper())
found_sects[sect_id.upper()] = data
sect_not_found = False
break
if sect_not_found:
if '[' and ']' in line:
h = line.strip()
txt = f.read()
section_dict = {key:txt.find(key) for key in INP_OBJECTS.keys() if txt.find(key) >= 0}

bracketed_words = re.findall(r"\[([A-Za-z0-9_]+)\]",txt)

for sect_id, data in INP_OBJECTS.items():
# find the start of an INP section
if sect_id in section_dict.keys():
if include_brackets:
sect_id = '[{}]'.format(sect_id.upper())
found_sects[sect_id.upper()] = data
else:
if sect_id in bracketed_words:
if not include_brackets:
h = h.replace('[', '').replace(']', '')
h = sect_id.replace('[', '').replace(']', '')
found_sects[h] = OrderedDict(columns=['blob'])

# make necessary adjustments to columns that change based on options
Expand Down