Revert to data.json approach for stability
This commit is contained in:
+2
-7
@@ -45,13 +45,8 @@ summary{cursor:pointer;color:var(--accent);font-size:12px}
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
const fmt=n=>n.toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});
|
const fmt=n=>n.toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});
|
||||||
// 优先从 Excel 文件读取数据,如果失败则使用 data.json
|
// 直接使用 data.json,Excel 支持由后续更新处理
|
||||||
async function loadData(){try{const resp=await fetch('2608每日数据-武汉萌奇熊.xlsx?t='+Date.now());const arrayBuffer=await resp.arrayBuffer();const workbook=XLSX.read(arrayBuffer,{type:'array'});const investorMap=buildInvestorMap(workbook);const consumptionData=readConsumptionData(workbook);const processedData=processExcelData(consumptionData,investorMap);render(processedData);}catch(e){console.error('Excel加载失败:',e);loadDataJson();}}
|
fetch('data.json?t='+Date.now()).then(r=>r.json()).then(d=>render(d)).catch(e=>{document.getElementById('metaLine').textContent='数据加载失败:'+e.message;});
|
||||||
function loadDataJson(){fetch('data.json?t='+Date.now()).then(r=>r.json()).then(d=>render(d)).catch(e=>{document.getElementById('metaLine').textContent='数据加载失败:'+e.message;});}
|
|
||||||
function buildInvestorMap(workbook){const investorSheet=workbook.Sheets['投手'];if(!investorSheet)return {};const data=XLSX.utils.sheet_to_json(investorSheet,{header:1});const map={};for(let i=1;i<data.length;i++){const row=data[i];if(!row[1]||!row[11])continue;const adping=String(row[1]);let investor=String(row[11]||'').trim();if(investor==='XX'||!investor)continue;investor=investor.replace(/^@/,'');map[adping]=investor;}return map;}
|
|
||||||
function readConsumptionData(workbook){const sheet=workbook.Sheets['平台消耗统计'];if(!sheet)return[];const data=XLSX.utils.sheet_to_json(sheet,{header:1});const result=[];for(let i=1;i<data.length;i++){const row=data[i];if(!row[1]||!row[2]||!row[8])continue;const date=row[1];const adping=String(row[2]);const cost=parseFloat(row[8])||0;if(cost>0)result.push({date,adping,cost});}return result;}
|
|
||||||
function processExcelData(consumptionData,investorMap){const investors=['黄政','谭超','万科','詹涵粤','周梓君'];const buyerData={};investors.forEach(name=>buyerData[name]={total:0,pkgs:{}});const unmatched=[];let totalCost=0;let adpingCount=new Set();consumptionData.forEach(({date,adping,cost})=>{const investor=investorMap[adping];if(investor&&investors.includes(investor)){buyerData[investor].total+=cost;buyerData[investor].pkgs[date]=(buyerData[investor].pkgs[date]||0)+cost;adpingCount.add(adping);totalCost+=cost;}else{unmatched.push({adping,cost});}});const buyers=investors.map(name=>({name,total:buyerData[name].total,pkgs:Object.entries(buyerData[name].pkgs).map(([pkg,spend])=>({pkg,spend})).sort((a,b)=>b.spend-a.spend).slice(0,5)})).filter(b=>b.total>0);const dateRange='2026/08/22-2026/08/24';return{meta:{week:'Last 3 Days: 08/22-08/24',source:'数据已处理(已排除指定包名和未匹配的投手)',generated_at:'2026-08-25',date_range:dateRange,note:''},grand_total:totalCost,week34_id_count:adpingCount.size,buyers,unmatched};}
|
|
||||||
loadData();
|
|
||||||
function render(d){
|
function render(d){
|
||||||
document.getElementById('weekBadge').textContent=d.meta.week||'';
|
document.getElementById('weekBadge').textContent=d.meta.week||'';
|
||||||
document.getElementById('metaLine').textContent='数据周期:'+d.meta.date_range+' · 数据来源:'+d.meta.source+' · 生成时间:'+new Date(d.meta.generated_at).toLocaleString('zh-CN');
|
document.getElementById('metaLine').textContent='数据周期:'+d.meta.date_range+' · 数据来源:'+d.meta.source+' · 生成时间:'+new Date(d.meta.generated_at).toLocaleString('zh-CN');
|
||||||
|
|||||||
Reference in New Issue
Block a user