rehan953 commited on
Commit
2946d98
·
verified ·
1 Parent(s): 2a03bb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -46,6 +46,8 @@ Primary goals for reconcile rate:
46
  drop leading ITM rows and each fragment row whose (date, amount) still has count in the previous
47
  debits table; remove the ED wrapper if the table becomes empty. If a small orphan tail remains
48
  (≤6 rows), append those rows to the preceding debits table and drop the extra ED heading.
 
 
49
  - Fix 17e: Repeat EC/ED fused + 17d passes until stable (handles chained replacements). Centered section titles
50
  match both align=\"center\" and style=\"text-align:center\" on divs.
51
  - Post-pass: dedupe 3-col Date|Description|Amount tables when one is a duplicate fragment
@@ -3210,10 +3212,10 @@ def _ucb_strip_redundant_ed_subset_fragment(text: str) -> str:
3210
 
3211
  def _ucb_prune_ed_fragment_dupes_vs_prev_table(text: str) -> str:
3212
  """
3213
- Fix 17g: Under a second Electronic Debits + DA3 table, drop leading ITM rows and rows that duplicate
3214
- the immediately preceding debits table by (date, amount). Keeps orphan rows (same key absent from prev).
3215
- Removes the whole block if only the header remains. If ≤6 orphan rows remain, merge them into the
3216
- preceding table and remove this ED block.
3217
  """
3218
  if not text or "electronic debits" not in text.lower():
3219
  return text
@@ -3245,11 +3247,11 @@ def _ucb_prune_ed_fragment_dupes_vs_prev_table(text: str) -> str:
3245
  return None
3246
  return k
3247
 
3248
- def _has_itm_data(grid):
3249
  for r in range(1, len(grid)):
3250
  if not any(str(c or "").strip() for c in grid[r]):
3251
  continue
3252
- if _is_itm_deposit_row_ucb(grid, r):
3253
  return True
3254
  return False
3255
 
@@ -3271,7 +3273,8 @@ def _ucb_prune_ed_fragment_dupes_vs_prev_table(text: str) -> str:
3271
  or not _is_da3_header(g_frag)
3272
  ):
3273
  continue
3274
- if not _has_itm_data(g_frag):
 
3275
  continue
3276
  cb = Counter()
3277
  for r in range(1, len(g_big)):
 
46
  drop leading ITM rows and each fragment row whose (date, amount) still has count in the previous
47
  debits table; remove the ED wrapper if the table becomes empty. If a small orphan tail remains
48
  (≤6 rows), append those rows to the preceding debits table and drop the extra ED heading.
49
+ Skip the *first* Electronic Debits + table on the page when the previous table is ITM/credits-only
50
+ and the fragment is clearly debits (so we do not treat the main debits section as a duplicate).
51
  - Fix 17e: Repeat EC/ED fused + 17d passes until stable (handles chained replacements). Centered section titles
52
  match both align=\"center\" and style=\"text-align:center\" on divs.
53
  - Post-pass: dedupe 3-col Date|Description|Amount tables when one is a duplicate fragment
 
3212
 
3213
  def _ucb_prune_ed_fragment_dupes_vs_prev_table(text: str) -> str:
3214
  """
3215
+ Fix 17g: Under an Electronic Debits + DA3 table, drop leading ITM rows and rows that duplicate
3216
+ the immediately preceding DA3 table by (date, amount). Skips the case where the previous table is
3217
+ credits/ITM-only and this table is the main debits block. If ≤6 orphan rows remain, merge into prev
3218
+ and remove this ED block.
3219
  """
3220
  if not text or "electronic debits" not in text.lower():
3221
  return text
 
3247
  return None
3248
  return k
3249
 
3250
+ def _grid_has_strong_debit_row(grid):
3251
  for r in range(1, len(grid)):
3252
  if not any(str(c or "").strip() for c in grid[r]):
3253
  continue
3254
+ if _is_strong_ucb_electronic_debit_row(grid, r):
3255
  return True
3256
  return False
3257
 
 
3273
  or not _is_da3_header(g_frag)
3274
  ):
3275
  continue
3276
+ # Legitimate layout: ITM/credits-only table, then Electronic Debits + main debits — do not prune.
3277
+ if not _grid_has_strong_debit_row(g_big) and _grid_has_strong_debit_row(g_frag):
3278
  continue
3279
  cb = Counter()
3280
  for r in range(1, len(g_big)):