fix: merge
This commit is contained in:
@@ -15,7 +15,7 @@ from app.models.transaction import TransactionRecord
|
||||
from app.models.transaction_cluster import TransactionCluster
|
||||
from app.repositories.transaction_repo import TransactionRepository
|
||||
from app.rules.dedup_rules import is_duplicate_pair
|
||||
from app.rules.transit_rules import is_self_transfer, is_fee_tolerant_transit_pair
|
||||
from app.rules.transit_rules import mark_transit_transactions
|
||||
|
||||
|
||||
async def run_matching(case_id: UUID, self_accounts: list[str], db: AsyncSession) -> None:
|
||||
@@ -34,8 +34,6 @@ async def run_matching(case_id: UUID, self_accounts: list[str], db: AsyncSession
|
||||
|
||||
# ── Layer 1 & 2: dedup ──
|
||||
matched: set[UUID] = set()
|
||||
clusters: list[TransactionCluster] = []
|
||||
|
||||
for i, tx_a in enumerate(transactions):
|
||||
if tx_a.id in matched:
|
||||
continue
|
||||
@@ -61,23 +59,9 @@ async def run_matching(case_id: UUID, self_accounts: list[str], db: AsyncSession
|
||||
tx.cluster_id = cluster.id
|
||||
if tx.id != primary.id:
|
||||
tx.is_duplicate = True
|
||||
clusters.append(cluster)
|
||||
|
||||
# ── Layer 3: transit detection ──
|
||||
for tx in transactions:
|
||||
if tx.is_duplicate:
|
||||
continue
|
||||
if is_self_transfer(tx, self_accounts):
|
||||
tx.is_transit = True
|
||||
|
||||
# Rule extension: if an in/out pair occurs within 2 minutes and
|
||||
# amount difference is within 2% (e.g. fee), mark both as transit.
|
||||
non_duplicate = [tx for tx in transactions if not tx.is_duplicate]
|
||||
for i, tx_a in enumerate(non_duplicate):
|
||||
for tx_b in non_duplicate[i + 1 :]:
|
||||
if is_fee_tolerant_transit_pair(tx_a, tx_b):
|
||||
tx_a.is_transit = True
|
||||
tx_b.is_transit = True
|
||||
mark_transit_transactions(transactions, self_accounts)
|
||||
|
||||
await db.flush()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user