Files
ObsidianHome/小鱼/.cdp/d2a-compare.mjs
T

48 lines
2.3 KiB
JavaScript

import fs from 'node:fs';
const o = JSON.parse(fs.readFileSync('.cdp/out/items-1106.json', 'utf8'));
const v = o.value || o;
const N = s => Number(s) || 0;
const d7 = v.data.recent7d.items, d30 = v.data.recent30d.items;
const m30 = new Map(d30.map(x => [x.id, x]));
// 抓 D2A / Q2A / Q1A / D2 系列
const RE = /D2A|Q2A|Q1A|D2\/|D2表带|D2\b|D2A\/Q2A|D2\/Q1A/;
const rows = d7.filter(x => RE.test(String(x.name))).map(x => {
const a = m30.get(x.id) || {};
return {
id: x.id, name: String(x.name), price: N(x.price), cat: x.c4, days: N(x.days), postDt: x.postDt,
pv7: N(x.pv), uv7: N(x.ipvUv), chat7: N(x.chat), ord7: N(x.ord), amt7: N(x.amt),
pv30: N(a.pv), uv30: N(a.ipvUv), chat30: N(a.chat), ord30: N(a.ord), amt30: N(a.amt),
cvr30: a.cvr || '',
};
}).sort((a, b) => b.pv30 - a.pv30);
const L = [];
L.push('D2A/Q2A 相关链接共 ' + rows.length + ' 条\n');
L.push('| ID | 售价 | 在架天 | 30天曝光 | 30天单 | 30天额 | 30天浏览 | 30天询单 | 转化率 | 7天曝光 | 7天单 | 7天额 |');
L.push('|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|');
for (const r of rows) {
L.push(`| ${r.id} | ¥${r.price} | ${r.days} | ${r.pv30} | ${r.ord30} | ¥${r.amt30} | ${r.uv30} | ${r.chat30} | ${r.cvr30} | ${r.pv7} | ${r.ord7} | ¥${r.amt7} |`);
}
// 价格分布
L.push('');
L.push('=== 价格分布 ===');
const byPrice = {};
for (const r of rows) { byPrice[r.price] = byPrice[r.price] || { n: 0, pv30: 0, ord30: 0, amt30: 0 }; const b = byPrice[r.price]; b.n++; b.pv30 += r.pv30; b.ord30 += r.ord30; b.amt30 += r.amt30; }
L.push('| 售价 | 链接数 | 30天曝光合计 | 30天单合计 | 30天额 | 每万曝光出单 |');
L.push('|---|---:|---:|---:|---:|---:|');
for (const [p, b] of Object.entries(byPrice).sort((a, b) => Number(a[0]) - Number(b[0]))) {
L.push(`| ¥${p} | ${b.n} | ${b.pv30} | ${b.ord30} | ¥${b.amt30.toFixed(2)} | ${b.pv30 ? (b.ord30 / b.pv30 * 10000).toFixed(0) : '-'} |`);
}
// 名称明细,看是否已有套装
L.push('');
L.push('=== 每条的名称(判断是否已存在套装/高配)===');
for (const r of rows) {
const tag = /套装|组合|螺丝刀|工具|钢化膜|膜|保护壳|全套/.test(r.name) ? ' ★可能已是套装' : '';
L.push(`- ${r.id} ¥${r.price} [30天${r.ord30}单] ${r.name}${tag}`);
}
fs.writeFileSync('.cdp/out/d2a-compare.txt', L.join('\n'), 'utf8');