25 lines
1.5 KiB
JavaScript
25 lines
1.5 KiB
JavaScript
import fs from 'node:fs';
|
||
const dir = '.cdp/out/search';
|
||
const files = fs.readdirSync(dir).filter(f => f.endsWith('.json'));
|
||
const L = []; const say = s => L.push(s);
|
||
for (const f of files) {
|
||
const v = JSON.parse(fs.readFileSync(dir + '/' + f, 'utf8'));
|
||
const cards = v.cards || [];
|
||
const prices = cards.map(c => Number((c.price || '').replace(/[^\d.]/g, ''))).filter(x => x > 0);
|
||
prices.sort((a, b) => a - b);
|
||
const wants = cards.map(c => {
|
||
const m = String(c.want || '').replace(/万/, '0000');
|
||
return Number(m) || 0;
|
||
}).filter(x => x > 0).sort((a, b) => b - a);
|
||
const med = prices.length ? prices[Math.floor(prices.length / 2)] : 0;
|
||
say(`\n${'='.repeat(96)}`);
|
||
say(`### 买家搜索词「${f.replace('.json','')}」 抓到 ${cards.length} 张卡,带价格 ${prices.length},带想要数 ${wants.length}`);
|
||
say(` 价格带:¥${prices[0]} ~ ¥${prices[prices.length-1]} 中位 ¥${med} 均值 ¥${(prices.reduce((a,b)=>a+b,0)/(prices.length||1)).toFixed(2)}`);
|
||
say(` 想要数 Top8:${wants.slice(0,8).join(' / ')}`);
|
||
say(` 想要数 >=100 的卡片:${wants.filter(x=>x>=100).length} / ${wants.length} >=500:${wants.filter(x=>x>=500).length}`);
|
||
say(` ---- 前 18 张卡 ----`);
|
||
cards.slice(0, 18).forEach((c, i) => say(
|
||
` ${String(i+1).padStart(2)}. ¥${String(c.price||'?').padEnd(8)} 想要${String(c.want||'-').padStart(6)} | ${(c.title||c.text||'').slice(0,58)}`));
|
||
}
|
||
fs.writeFileSync('.cdp/out/search-summary.md', L.join('\n'), 'utf8');
|