Fix small group naming bug
This commit is contained in:
1 parent
bd1964ffcd
commit
698ac4240c
2 files changed
+16
-9
No files matched your search
@@ -234,15 +234,17 @@ def _unique_prefixes(groups: list[list[str]]) -> list[tuple[str, list[str]]]:
|
|||||||
candidate = f"{safe_labels[0]}+"
|
candidate = f"{safe_labels[0]}+"
|
||||||
if natural_key(candidate) > natural_key(previous):
|
if natural_key(candidate) > natural_key(previous):
|
||||||
base = candidate
|
base = candidate
|
||||||
prefix = base.removesuffix("i")
|
base = base.removesuffix("i")
|
||||||
|
# Keep related groups under the same short stem (I), I)-2, ...).
|
||||||
|
# Normalize before allocating a suffix so no later rewrite can collide.
|
||||||
|
if previous and base.startswith(previous):
|
||||||
|
base = previous
|
||||||
|
prefix = base
|
||||||
counter = 2
|
counter = 2
|
||||||
while prefix in used:
|
while prefix in used:
|
||||||
prefix = f"{base}-{counter}"
|
prefix = f"{base}-{counter}"
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter == 2 and previous and previous in prefix:
|
previous = base
|
||||||
prefix = f"{previous}-{counter}"
|
|
||||||
elif counter == 2:
|
|
||||||
previous = prefix
|
|
||||||
used.add(prefix)
|
used.add(prefix)
|
||||||
result.append((prefix, labels))
|
result.append((prefix, labels))
|
||||||
return result
|
return result
|
||||||
@@ -250,14 +252,16 @@ def _unique_prefixes(groups: list[list[str]]) -> list[tuple[str, list[str]]]:
|
|||||||
|
|
||||||
def _existing_group_state(
|
def _existing_group_state(
|
||||||
output_root: Path,
|
output_root: Path,
|
||||||
prefix: str,
|
prefix: str | None = None,
|
||||||
) -> tuple[set[tuple[str, str]], int]:
|
) -> tuple[set[tuple[str, str]], int]:
|
||||||
existing_items: set[tuple[str, str]] = set()
|
existing_items: set[tuple[str, str]] = set()
|
||||||
maximum_group = 0
|
maximum_group = 0
|
||||||
if not output_root.is_dir():
|
if not output_root.is_dir():
|
||||||
return existing_items, maximum_group
|
return existing_items, maximum_group
|
||||||
for directory in output_root.iterdir():
|
for directory in output_root.iterdir():
|
||||||
if not directory.is_dir() or not directory.name.startswith(f"{prefix} G"):
|
if not directory.is_dir():
|
||||||
|
continue
|
||||||
|
if prefix is not None and not directory.name.startswith(f"{prefix} G"):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
maximum_group = max(maximum_group, int(directory.name.split(" G")[-1]))
|
maximum_group = max(maximum_group, int(directory.name.split(" G")[-1]))
|
||||||
@@ -318,8 +322,11 @@ def _generate_groups(
|
|||||||
) -> tuple[int, bool]:
|
) -> tuple[int, bool]:
|
||||||
generated = 0
|
generated = 0
|
||||||
problems = False
|
problems = False
|
||||||
|
# Resume by answer identity across all prefixes, including legacy names.
|
||||||
|
# Changing the naming scheme must not regenerate already reviewed PDFs.
|
||||||
|
existing_items = _existing_group_state(output_root)[0] if resume else set()
|
||||||
for prefix, labels in _unique_prefixes(groups):
|
for prefix, labels in _unique_prefixes(groups):
|
||||||
existing_items, maximum_group = (
|
_, maximum_group = (
|
||||||
_existing_group_state(output_root, prefix) if resume else (set(), 0)
|
_existing_group_state(output_root, prefix) if resume else (set(), 0)
|
||||||
)
|
)
|
||||||
items = [
|
items = [
|
||||||
|
|||||||
@@ -716,7 +716,7 @@ def process_exam(
|
|||||||
|
|
||||||
with io.StringIO() as f, io.StringIO() as f_full:
|
with io.StringIO() as f, io.StringIO() as f_full:
|
||||||
|
|
||||||
header = "# Edit labels. Modify groups (---). Ensure label uniqueness (XX). Duplicate CONTEXT.\n\n"
|
header = "# Edit labels. Modify groups (---). Ensure label uniqueness (XX). Duplicate/modify CONTEXT.\n\n"
|
||||||
f.write(header)
|
f.write(header)
|
||||||
f_full.write(header)
|
f_full.write(header)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user