Update index.html
Browse files- index.html +22 -10
index.html
CHANGED
|
@@ -47,22 +47,25 @@ function switchTab(idx){
|
|
| 47 |
tabs[idx].classList.add("active");
|
| 48 |
}
|
| 49 |
|
| 50 |
-
//
|
| 51 |
function parseCSV(text) {
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
const rows = [];
|
| 55 |
for(let i=1;i<lines.length;i++){
|
| 56 |
-
const vals = lines[i].split(",");
|
| 57 |
const obj = {};
|
| 58 |
-
headers.forEach((h,idx)=>
|
|
|
|
|
|
|
| 59 |
rows.push(obj);
|
| 60 |
}
|
| 61 |
return rows;
|
| 62 |
}
|
| 63 |
|
| 64 |
function buildTable(title, data, sortKey){
|
| 65 |
-
// 数值降序排序
|
| 66 |
const sorted = [...data].sort((a,b)=> Number(b[sortKey]) - Number(a[sortKey]));
|
| 67 |
let html = `<h3>${title}</h3><table><tr><th>Rank</th><th>Model</th><th>${sortKey}</th></tr>`;
|
| 68 |
sorted.forEach((row,i)=>{
|
|
@@ -76,14 +79,23 @@ function buildTable(title, data, sortKey){
|
|
| 76 |
return html;
|
| 77 |
}
|
| 78 |
|
| 79 |
-
//
|
| 80 |
-
const
|
|
|
|
| 81 |
|
| 82 |
async function loadData(){
|
| 83 |
try {
|
| 84 |
const res = await fetch(csvUrl);
|
|
|
|
| 85 |
const csvText = await res.text();
|
|
|
|
| 86 |
const data = parseCSV(csvText);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
document.getElementById("panel-compile").innerHTML = buildTable(
|
| 89 |
"Ranked by Code Compilation Success",
|
|
@@ -101,8 +113,8 @@ async function loadData(){
|
|
| 101 |
"Correct Coefficient Direction (%)"
|
| 102 |
);
|
| 103 |
} catch(err){
|
| 104 |
-
console.error("
|
| 105 |
-
document.body.insertAdjacentHTML("beforeend",
|
| 106 |
}
|
| 107 |
}
|
| 108 |
loadData();
|
|
|
|
| 47 |
tabs[idx].classList.add("active");
|
| 48 |
}
|
| 49 |
|
| 50 |
+
// 更鲁棒CSV解析,兼容HF返回的换行
|
| 51 |
function parseCSV(text) {
|
| 52 |
+
// 统一换行符
|
| 53 |
+
text = text.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
|
| 54 |
+
const lines = text.trim().split("\n").filter(line=>line.trim()!=='');
|
| 55 |
+
const headers = lines[0].split(",").map(h=>h.trim());
|
| 56 |
const rows = [];
|
| 57 |
for(let i=1;i<lines.length;i++){
|
| 58 |
+
const vals = lines[i].split(",").map(v=>v.trim());
|
| 59 |
const obj = {};
|
| 60 |
+
headers.forEach((h,idx)=>{
|
| 61 |
+
obj[h] = vals[idx];
|
| 62 |
+
});
|
| 63 |
rows.push(obj);
|
| 64 |
}
|
| 65 |
return rows;
|
| 66 |
}
|
| 67 |
|
| 68 |
function buildTable(title, data, sortKey){
|
|
|
|
| 69 |
const sorted = [...data].sort((a,b)=> Number(b[sortKey]) - Number(a[sortKey]));
|
| 70 |
let html = `<h3>${title}</h3><table><tr><th>Rank</th><th>Model</th><th>${sortKey}</th></tr>`;
|
| 71 |
sorted.forEach((row,i)=>{
|
|
|
|
| 79 |
return html;
|
| 80 |
}
|
| 81 |
|
| 82 |
+
// 增加随机参数,绕过HF CDN缓存!非常关键
|
| 83 |
+
const timestamp = Date.now();
|
| 84 |
+
const csvUrl = `https://huggingface.co/datasets/CamoAiLab/Infernet/resolve/main/eval_submissions/results.csv?t=${timestamp}`;
|
| 85 |
|
| 86 |
async function loadData(){
|
| 87 |
try {
|
| 88 |
const res = await fetch(csvUrl);
|
| 89 |
+
if(!res.ok) throw new Error(`HTTP ${res.status}`);
|
| 90 |
const csvText = await res.text();
|
| 91 |
+
console.log("csv raw text:", csvText);
|
| 92 |
const data = parseCSV(csvText);
|
| 93 |
+
console.log("parsed data:", data);
|
| 94 |
+
|
| 95 |
+
if(data.length ===0){
|
| 96 |
+
document.body.insertAdjacentHTML("beforeend",`<p style="color:red">Warning: CSV parsed zero rows</p>`);
|
| 97 |
+
return;
|
| 98 |
+
}
|
| 99 |
|
| 100 |
document.getElementById("panel-compile").innerHTML = buildTable(
|
| 101 |
"Ranked by Code Compilation Success",
|
|
|
|
| 113 |
"Correct Coefficient Direction (%)"
|
| 114 |
);
|
| 115 |
} catch(err){
|
| 116 |
+
console.error("load csv error",err);
|
| 117 |
+
document.body.insertAdjacentHTML("beforeend",`<p style='color:red'>Failed to load ranking data: ${err.message}</p>`);
|
| 118 |
}
|
| 119 |
}
|
| 120 |
loadData();
|