Heng2004 commited on
Commit
ad8bcc2
·
verified ·
1 Parent(s): a2877a1

Update loader.py

Browse files
Files changed (1) hide show
  1. loader.py +26 -4
loader.py CHANGED
@@ -109,13 +109,35 @@ def load_manual_qa() -> None:
109
  qa_store.NEXT_MANUAL_ID = max_num + 1 if max_num > 0 else 1
110
 
111
 
 
 
112
  def generate_new_manual_id() -> str:
113
  """
114
- Generate a new manual entry ID and increment the counter.
 
 
115
  """
116
- new_id = f"manual_{qa_store.NEXT_MANUAL_ID:04d}"
117
- qa_store.NEXT_MANUAL_ID += 1
118
- return new_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
 
121
  def save_manual_qa_file() -> None:
 
109
  qa_store.NEXT_MANUAL_ID = max_num + 1 if max_num > 0 else 1
110
 
111
 
112
+ # loader.py
113
+
114
  def generate_new_manual_id() -> str:
115
  """
116
+ Generate the smallest free manual_XXXX ID based on the
117
+ current MANUAL_QA_LIST (so gaps like 11 after delete
118
+ are reused).
119
  """
120
+ import re as _re
121
+
122
+ used_nums = set()
123
+
124
+ # collect all numbers that are already used in IDs
125
+ for e in qa_store.MANUAL_QA_LIST:
126
+ raw_id = str(e.get("id") or "")
127
+ m = _re.search(r"(\d+)$", raw_id)
128
+ if m:
129
+ used_nums.add(int(m.group(1)))
130
+
131
+ # find the smallest positive integer that is not used
132
+ i = 1
133
+ while i in used_nums:
134
+ i += 1
135
+
136
+ # keep the global counter roughly in sync (optional)
137
+ qa_store.NEXT_MANUAL_ID = i + 1
138
+
139
+ return f"manual_{i:04d}"
140
+
141
 
142
 
143
  def save_manual_qa_file() -> None: