85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
var $ = a=>document.querySelector(a);
|
|
var seasons = {};
|
|
|
|
fetch("rankings.json").then(r=>r.json())
|
|
.then(res=>{
|
|
seasons = res;
|
|
Object.keys(seasons).forEach(v=>{
|
|
var option = document.createElement("option");
|
|
option.value = v;
|
|
option.innerHTML = v+"-"+(parseInt(v)+1).toString().substring(2);
|
|
$("#season").appendChild(option);
|
|
});
|
|
$("#season").onchange = load;
|
|
$("#season").value = location.hash == '' ? 2024 : location.hash.substring(1);
|
|
load();
|
|
});
|
|
|
|
var API = "/api/summary";
|
|
|
|
function query(d,q)
|
|
{
|
|
var url = new URLSearchParams({
|
|
"isAggregate": true,
|
|
"isGame": true,
|
|
"start": 0,
|
|
"limit": -1,
|
|
"sort": '[{"property":"pointPct","direction":"DESC"},{"property":"wins","direction":"DESC"},{"property":"losses","direction":"ASC"},{"property":"otLosses","direction":"DESC"},{"property":"ties","direction":"DESC"},{"property":"goalsFor","direction":"DESC"},{"property":"goalsAgainst","direction":"ASC"},{"property":"franchiseId","direction":"ASC"}]',
|
|
"cayenneExp": q,
|
|
});
|
|
return fetch(API+"?"+url, {
|
|
method: 'GET',
|
|
})
|
|
.then(res => res.json())
|
|
.then(res => {
|
|
res.div = d;
|
|
return res;
|
|
})
|
|
}
|
|
|
|
function getClass(v,i){
|
|
var year = parseInt($("#season").value);
|
|
var year1 = year+1;
|
|
if(year1 == 2004) year1++;
|
|
var id = v.franchiseId;
|
|
if(seasons[year1])
|
|
{
|
|
var a = seasons[year][0].indexOf(id) >= 0;
|
|
var b = seasons[year][1].indexOf(id) >= 0;
|
|
var c = seasons[year1][0].indexOf(id) >= 0;
|
|
var d = seasons[year1][1].indexOf(id) >= 0;
|
|
if(a==true && d==true) return "down";
|
|
if(b==true && c==true) return "up";
|
|
}
|
|
else
|
|
{
|
|
if(seasons[year][0].indexOf(id) >= 0 && i > seasons[year][0].length - 3) return "down";
|
|
if(seasons[year][1].indexOf(id) >= 0 && i < 2) return "up";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function load()
|
|
{
|
|
var transform = {"tag":"tr","id":"${franchiseId}","class":getClass,"children":[
|
|
{"tag":"td","html":(f,i)=>i+1},
|
|
{"tag":"td","class":"left","html":"${franchiseName}"},
|
|
{"tag":"td","html":"${gamesPlayed}"},
|
|
{"tag":"td","html":"${wins}"},
|
|
{"tag":"td","html":"${losses}"},
|
|
{"tag":"td","html":"${ties}"},
|
|
{"tag":"td","html":"${otLosses}"},
|
|
{"tag":"td","html":"${goalsFor}"},
|
|
{"tag":"td","html":"${goalsAgainst}"},
|
|
{"tag":"td","html":"${points}"},
|
|
{"tag":"td","html":f=>Math.round(f.pointPct*1000)/10+"%"},
|
|
]};
|
|
var year = parseInt($("#season").value);
|
|
var yy = year+""+(year+1);
|
|
location.hash = year;
|
|
for(var d = 0; d < 2; d++)
|
|
query(d,"gameTypeId=2 and franchiseId in ("+seasons[year][d].join(",")+") and opponentFranchiseId in ("+seasons[year][d].join(",")+") and seasonId="+yy)
|
|
.then(res=>{
|
|
$("#div"+res.div).innerHTML = json2html.transform(res.data, transform);
|
|
});
|
|
} |