Skip to main content

LLD: Fix Invalidly Audited TCs

Problem

32 TCs have lossPercentage set but are missing tcConsumption (31) or installationConsumption (1) — the fields required to compute lossPercentage. These were incorrectly marked as AUDITED.

Script

transformer_fixInvalidAuditedTCs

Step 1 — Find and log affected TCs

Query transformer collection:

filter: {
lossPercentage: { $exists: true, $ne: null },
$or: [
{ tcConsumption: null },
{ tcConsumption: { $exists: false } },
{ installationConsumption: null },
{ installationConsumption: { $exists: false } },
],
}

Project: id, number, month, tcConsumption, installationConsumption, lossPercentage

Log every matched TC so we have a record of what was changed.

Step 2 — Bulk update all matched TCs

// Uses native driver (collection.updateMany) to bypass Mongoose timestamps
$set: { auditStatus: "AUDIT_FAILED" }
$unset: { lossPercentage, auditedOn, revenueParams.atc, revenueParams.arr }

Fields touched

FieldActionReason
auditStatusSet to AUDIT_FAILEDCan't be audited without source data
lossPercentageRemoveComputed from missing inputs — invalid
auditedOnRemoveWas never validly audited
revenueParams.atcRemoveDepends on valid loss computation
revenueParams.arrRemoveDepends on valid loss computation

Fields NOT touched

  • tcConsumption, meterConstant, installationConsumption — left as-is
  • billingCount, revenueParams.demand, revenueParams.collection, revenueParams.billingEfficiency, revenueParams.collectionEfficiency — unchanged
  • overloaded, remark, auditedByAI — unchanged
  • updatedAt, createdAt — bypassed by using native driver instead of Mongoose

Affected TCs (32)

Executed on: 2026-03-29

#idnumbermonthtcConsumptioninstallationConsumptionlossPercentage
1cTNpkNXhpbh4z9eBH0E_P11F10052025-09111111MISSING1
2X7yWYW4PmEn2R0YVPGQqF21180482025-09MISSING6556-446.3
3_XIsOfz_3rqfWTXPPd9JQ21180472025-09MISSING7087-1376
4FMa6wdAxK9jJk9fJy2cGc21180502025-09MISSING6373-563.9
5CRVtJm-zo0iyR57WAZKbV21190112025-09MISSING13539.011
6bEMD85ybhHjzabNTcvXWc21190032025-09MISSING4145-0.2176
7WyhCGCyShx85_pEHbtJyM21190552025-09MISSING104012.97
8fEOrYWdEN-sJCLn0m0J98211B0382025-09MISSING332921.36
9VJO_9xHE6Ol0F3_LiRa7j21180072025-09MISSING12382150.5
10-yTHKwAEq_9G9yNPewoA-21180642025-09MISSING1491-0.4717
11LPkeYWzHNhELPOXImckFQ21180722025-09MISSING744822.3
12Xn3Ip1RioROI3hCsnqvzu21180522025-09MISSING882-9.838
13oWJTIijsXR6jzsgQN42aa21180252025-09MISSING12520-2.346
14gHLgPC2yz2Gq2O6yqGin_21180782025-09MISSING1340-52.27
15FMRndD5IygBn9y7iYBIVS21180702025-09MISSING5326-31230
16s_xKUVC2gcSDMD44-Sm9K21180442025-09MISSING28786-210.5
17rAbgziafRG9q9RiS4spos21180262025-09MISSING4669-3.114
18LPUqz--3CFa6T8JDQRrbo21180282025-09MISSING721999.5
19LWauYLPyxfl2S5VB_oZHU21190092025-09MISSING1674-1.763
20iKp6ae1GO-kqsOc9o3jQ921190012025-09MISSING10364-117.5
21w4OwcPDFcUVaAwmRjE1n221180112025-09MISSING23458-268.3
22JBXn1iQKsgV6JuGYvoYgH21180132025-09MISSING16550-54.38
23TJPe5QPMXYEbxBEyVtoWk21180382025-09MISSING28584-255.5
24BBh0_D5yQNiX08hfsUjwI21180392025-09MISSING15943-195.2
25NQtwBaz3gT4WKbYd_9ynz21180092025-09MISSING7745315.9
264ROKjDJ98uytALjTwXnpq21180182025-09MISSING9044-2.25
27ETNGqGL94O4uf9h8ILWY0211B0062025-09MISSING10528-10.82
28wT3AxWNU2tBXjNnPyis-G444B0092025-09MISSING1092100
29UUf_jEAe_2R9BaDGtK1bz444B0472025-09MISSING53100
306NbaOf8bSn3vp1WOCzl8P14830842025-10MISSING22373.04
31islYATLasaZ24AiQtIiUo14420272025-10MISSING3656100.4
32YUL8cD38N12j1Hid9dpsu161502025-11MISSING421195.04

Summary: 29 in 2025-09, 2 in 2025-10, 1 in 2025-11. 31 missing tcConsumption, 1 missing installationConsumption.

AuditSummary impact

These TCs may affect section/MESCOM-level audit summaries (counts, loss buckets). A separate auditSummary recomputation may be needed after this script runs.