Skip to content

Instantly share code, notes, and snippets.

@goplayerjuggler
Last active August 27, 2020 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goplayerjuggler/f9aba0aed7e294058c6e69f93614836c to your computer and use it in GitHub Desktop.
Save goplayerjuggler/f9aba0aed7e294058c6e69f93614836c to your computer and use it in GitHub Desktop.
Some javascript to produce statistics on wins/losses for toroidal go, in LittleGolem
/*
# Purpose
This script produces some statistics on wins/losses for toroidal go, for a given player (A), in LittleGolem.
Part of the info copied to the clipboard is the list of players (B) where B has either (1) beaten A at least once,
(2) has played at least 3 games against A (by default, players B with 0 wins against A are not included)
The output format of this list is:
```
[player B's name]([player B's rank]): [nb of losses against B (games won by B and lost by A)]/[nb of wins against B (games won by A and lost by B)] (percentage)
```
Sample output:
```
---------
Statistics for: Malcolm Schonfield
total wins/losses: 137/11 (92.6 %)
played against 48 opponents
List of main opponents:
gamesorry(4.3d): 0/2 (0.0 %)
goblade(19.1k): 0/1 (0.0 %)
Crelo ★(6.4d): 1/2 (33.3 %)
SiroWirdo(13.0k): 3/1 (75.0 %)
William Fraser(5.6k): 4/1 (80.0 %)
Bernhard Herwig(3.3k): 8/2 (80.0 %)
drToma(4.3k): 7/1 (87.5 %)
Pascal Huybers(3.6k): 12/1 (92.3 %)
---------
```
# Usage
1. In the browser(*), open the list of games for a given player in littleGolem, for the game Go.
The address is the following URL below + the player ID as a suffix:
http://littlegolem.net/jsp/info/player_game_list.jsp?gtid=go19&plid=playerId_goes_here
eg:
http://littlegolem.net/jsp/info/player_game_list.jsp?gtid=go19&plid=31707
(*) This will probably work for Chrome or Edge or any other modern browser, but it was only tested/developed in Firefox.
2. Paste this script into the Console section of the “F12/Developer tools” browser feature; and then press Enter in order to run the script.
3. the output is then copied in to the clipboard.
## Other remarks
* This script does not handle draws.
# Log
2020-05-18 created
2020-05-21 tweaks
2020-05-22 add percentages and total number of opponents
*/
(() => {
const
// # Configuration: change the following, in order to change some behaviour
filter = 'Toroid' // filter for games where the tournament contains this string
, minGamesToShow = 3 // need to have played at least `minGamesToShow` against someone for them to be displayed
, includePlayersWithNoLosses = false // set to true to have opponents that never won a game
, newLine = '\r\n'
, parsed = []
Array.from(document.querySelectorAll('.portlet-body tr')).forEach(
(tr, i) => {
if (i === 0) {
return
}
const vals = Array.from(tr.querySelectorAll('td')).map(td => td.innerText)
, vals2 = {
player: vals[1], result: vals[5].trim(), rating: vals[2]
}
if (!vals2.result || vals[3].indexOf(filter) < 0) {
return
}
parsed.push(vals2)
}
)
//copy(parsed)
const parsed2 = {}
for (let index = 0; index < parsed.length; index++) {
const element = parsed[index];
if (!parsed2[element.player]) {
parsed2[element.player] = {
[element.result]: 1
, rating: element.rating
}
}
else {
let newVal = parsed2[element.player][element.result]
if (Number(newVal))
parsed2[element.player][element.result] = newVal + 1
else
parsed2[element.player][element.result] = 1
}
}
const parsed3 = Object.keys(parsed2)
.map(x => {
const r = { player: x, rating: parsed2[x].rating }
r.win = parsed2[x].win ? parsed2[x].win : 0
r.lost = parsed2[x].lost ? parsed2[x].lost : 0
return r
})
.sort((x, y) => {
if (x.win === 0) return y.win === 0 ? (x.lost < y.lost ? 1 : -1) : -1
if (y.win === 0) return 1
if (x.lost === 0) return y.lost === 0 ? (x.win > y.win ? 1 : -1) : 1
if (y.lost === 0) return -1
return (x.win / x.lost < y.win / y.lost) ? -1 : 1
}
)
const opponents = [], stats = { win: 0, lost: 0 }
for (let index = 0; index < parsed3.length; index++) {
const element = parsed3[index];
stats.win = stats.win + element.win
stats.lost = stats.lost + element.lost
if (element.lost > 0
|| (includePlayersWithNoLosses && (element.win + element.lost) >= minGamesToShow)
) {
const perc = (100 * element.win / (element.win + element.lost)).toFixed(1)
opponents.push(`${element.player}(${element.rating}): ${element.win}/${element.lost} (${perc} %)`)
}
}
//get the player's name
const
text = document.querySelector('div.caption').innerText,
regex = /\[([^\]]+)\]/,
player = regex.exec(text)[1],
perc = (100 * stats.win / (stats.win + stats.lost)).toFixed(1)
//we're done; copy the output to the clipboard
copy(`---------` + newLine
+ `Statistics for: ${player}` + newLine
+ `total wins/losses: ${stats.win}/${stats.lost} (${perc} %)` + newLine
+ `played against ${parsed3.length} opponents` + newLine
+ `List of main opponents:` + newLine
+ opponents.join(newLine) + newLine
+ `---------`)
console.log('The statistics were generated successfully and were copied to the clipboard.')
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment