-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d52f2
commit 548c8e4
Showing
11 changed files
with
576 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: API | ||
--- | ||
|
||
<div id="app"></div> | ||
|
||
<script src="sketch.js"></script> | ||
|
||
<script> | ||
|
||
const urlParams = new URLSearchParams(window.location.search) | ||
const tid = parseInt(urlParams.get("tid")) | ||
const pid = parseInt(urlParams.get("pid").toString()) | ||
|
||
const api_t = 'https://member.schack.se/public/api/v1/tournamentresults/table/id/' | ||
const api_r = 'https://member.schack.se/public/api/v1/tournamentresults/roundresults/id/' | ||
|
||
Promise.all([ | ||
fetch(api_t + tid).then(response => response.json()), | ||
fetch(api_r + tid).then(response => response.json()) | ||
]) | ||
.then(([data_t, data_r]) => { | ||
process(data_t,data_r,pid) | ||
}) | ||
.catch(error => console.error('Fel vid hämtning av filer:', error)); | ||
|
||
</script> |
58 changes: 58 additions & 0 deletions
58
content/Klubben/Medlemmar/christer-nilsson/API/sketch.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
table = (s) -> "<table>\n" + s + "</table>" | ||
td = (s,attrs="") -> "<td #{attrs}>" + s + "</td>" | ||
tr = (s,attrs="") -> "<tr #{attrs}>" + s + "</tr>\n" | ||
th = (s,attrs="") -> "<th #{attrs}>" + s + "</th>" | ||
|
||
process = (data_t, data_r, pid) -> | ||
|
||
console.log data_t | ||
console.log data_r | ||
|
||
players = {} | ||
for p in data_t | ||
pi = p.playerInfo | ||
players[p.contenderId] = pi.elo.rating + ' ' + pi.lastName.toUpperCase() + ' ' + pi.firstName | ||
|
||
stable = "" | ||
stable += th "datum" | ||
stable += th "rond" | ||
stable += th "bord" | ||
stable += th "färg" | ||
stable += th "mot" | ||
stable += th "resultat" | ||
stable = tr stable | ||
good = 0 | ||
n = 0 | ||
center = 'style="text-align: center"' | ||
grå = 'style="color:#444444"' | ||
now = new Date() | ||
nu = now.toLocaleDateString "sv-SE" | ||
|
||
for r in data_r | ||
g = r.games[0] | ||
if r.finalized | ||
n += 1 | ||
if r.homeResult != 0 or r.awayResult != 0 then good += 1 | ||
console.log r.awayId,r.homeId | ||
if r.awayId == pid or r.homeId == pid | ||
färg = if r.homeId==pid then "vit" else "svart" | ||
s = "" | ||
s += td r.date | ||
s += td r.roundNr,center | ||
s += td r.board,center | ||
s += td färg,center | ||
opp = if färg=='vit' then r.awayId else r.homeId | ||
res = if färg=='vit' then r.homeResult else r.awayResult | ||
if opp < 1000 | ||
s += td "w.o." | ||
else | ||
s += td players[opp.toString()] | ||
if g.result==-3 then res += " w.o." | ||
s += td res,center | ||
col = if r.date < nu or r.finalized then grå else "" | ||
stable += tr s,col | ||
|
||
app = document.getElementById('app') | ||
console.log table stable | ||
app.innerHTML = table stable | ||
console.log "#{good} of #{n} games played (#{(100*good/n).toFixed 1}%)", |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.