← back to Dw Color Image Audit
scripts/audit-shard.js
34 lines
'use strict';
// Audit one vendor shard. Reads TSV lines on stdin, classifies each, writes JSON results to stdout.
// Columns: vendor, handle, dwsku, mfrsku, title, hex, image_url
const { classify } = require('./color-classify.js');
const readline = require('readline');
// Extract the declared color phrase from a DW title "Pattern Name - Colorway MaterialType | Brand".
// We feed the whole left segment (before the pipe) to the name mapper; nameToFamily() then
// isolates the colorway after the last " - ", resolves multi-word colorways, and ignores pure
// material/finish words so a trailing "Vegan Leather" can't hijack the family.
function declaredFrom(title){
if(!title) return '';
const left = title.split('|')[0].trim();
return left;
}
const rl = readline.createInterface({ input: process.stdin });
const out = [];
const counts = { OK:0, REVIEW:0, HIGH:0, UNKNOWN:0 };
rl.on('line', (line)=>{
if(!line.trim()) return;
const [vendor,handle,dwsku,mfrsku,title,hex,image_url] = line.split('\t');
const declared = declaredFrom(title);
const r = classify(declared, hex);
counts[r.verdict] = (counts[r.verdict]||0)+1;
if (r.verdict==='HIGH' || r.verdict==='REVIEW'){
out.push({ vendor, handle, dwsku, mfrsku, title, declared, hex, image_url,
verdict:r.verdict, declaredFamily:r.declaredFamily, imageFamily:r.imageFamily, reason:r.reason });
}
});
rl.on('close', ()=>{
process.stdout.write(JSON.stringify({ counts, findings: out })+'\n');
});