Skip to content

Commit

Permalink
Merge branch 'master' into holding-down-move-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Dec 11, 2024
2 parents b14dbce + 23fbeb3 commit 74337a1
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 128 deletions.
10 changes: 4 additions & 6 deletions modules/recap/src/main/Recap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ case class Recap(
def userIds = games.opponents.map(_.value)

case class RecapGames(
nb: NbAndStreak,
nbs: NbWin,
nbWhite: Int,
moves: Int,
openings: Recap.Openings,
firstMoves: List[Counted[SanStr]],
results: Results,
timePlaying: FiniteDuration,
sources: Map[Source, Int],
opponents: List[Counted[UserId]],
perfs: List[Recap.Perf]
):
def significantPerfs: List[Recap.Perf] = perfs.filter: p =>
(p.games > (nb.nb / 20)) || (p.seconds > (timePlaying.toSeconds / 20))
(p.games > (nbs.total / 20)) || (p.seconds > (timePlaying.toSeconds / 20))

case class RecapPuzzles(nb: NbAndStreak, results: Results, votes: PuzzleVotes)
case class RecapPuzzles(nbs: NbWin, votes: PuzzleVotes)

object Recap:

Expand All @@ -51,6 +50,5 @@ object Recap:
case Available(data: JsObject)
case Queued(data: JsObject)

case class Results(win: Int = 0, draw: Int = 0, loss: Int = 0)
case class NbAndStreak(nb: Int, streak: Days)
case class NbWin(total: Int = 0, win: Int = 0)
case class PuzzleVotes(up: Int = 0, down: Int = 0, themes: Int = 0)
30 changes: 12 additions & 18 deletions modules/recap/src/main/RecapBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ private final class RecapBuilder(

private def makePuzzleRecap(scan: PuzzleScan): RecapPuzzles =
RecapPuzzles(
nb = NbAndStreak(scan.nb, Days(scan.streak.max)),
results = scan.results,
nbs = scan.nbs,
votes = scan.votes
)

Expand All @@ -47,17 +46,16 @@ private final class RecapBuilder(
.monSuccess(_.recap.puzzles)

private case class PuzzleScan(
nb: Int = 0,
results: Results = Results(),
streak: Streak = Streak(),
nbs: NbWin = NbWin(),
votes: PuzzleVotes = PuzzleVotes()
):
def addRound(r: PuzzleRound): PuzzleScan =
val win = r.firstWin
copy(
nb = nb + 1,
results = results.copy(win = results.win + win.so(1), loss = results.loss + (!win).so(1)),
streak = streak.add(r.date),
nbs = NbWin(
total = nbs.total + 1,
win = nbs.win + win.so(1)
),
votes = votes.copy(
up = votes.up + r.vote.exists(_ > 0).so(1),
down = votes.down + r.vote.exists(_ < 0).so(1),
Expand All @@ -67,14 +65,13 @@ private final class RecapBuilder(

private def makeGameRecap(scan: GameScan): RecapGames =
RecapGames(
nb = NbAndStreak(scan.nb, Days(scan.streak.max)),
nbs = scan.nbs,
nbWhite = scan.nbWhite,
moves = scan.nbMoves,
openings = scan.openings.map:
_.toList.sortBy(-_._2).headOption.fold(Recap.nopening)(Recap.Counted.apply)
,
firstMoves = scan.firstMoves.toList.sortBy(-_._2).take(5).map(Recap.Counted.apply),
results = scan.results,
timePlaying = scan.secondsPlaying.seconds,
sources = scan.sources,
opponents = scan.opponents.toList.sortBy(-_._2).take(5).map(Recap.Counted.apply),
Expand All @@ -98,11 +95,10 @@ private final class RecapBuilder(
.monSuccess(_.recap.games)

private case class GameScan(
nb: Int = 0,
nbs: NbWin = NbWin(),
nbWhite: Int = 0,
nbMoves: Int = 0,
secondsPlaying: Int = 0,
results: Results = Results(),
streak: Streak = Streak(),
openings: ByColor[Map[SimpleOpening, Int]] = ByColor.fill(Map.empty),
firstMoves: Map[SanStr, Int] = Map.empty,
Expand All @@ -119,15 +115,13 @@ private final class RecapBuilder(
OpeningDb.search(g.sans).map(_.opening).flatMap(SimpleOpening.apply)
val durationSeconds = g.hasClock.so(g.durationSeconds) | 30 // ?? :shrug:
copy(
nb = nb + 1,
nbs = NbWin(
total = nbs.total + 1,
win = nbs.win + winner.exists(_.is(userId)).so(1)
),
nbWhite = nbWhite + player.color.fold(1, 0),
nbMoves = nbMoves + g.playerMoves(player.color),
secondsPlaying = secondsPlaying + durationSeconds,
results = results.copy(
win = results.win + winner.exists(_.is(userId)).so(1),
draw = results.draw + winner.isEmpty.so(1),
loss = results.loss + winner.exists(_.isnt(userId)).so(1)
),
streak = streak.add(g.createdAt),
openings = opening.fold(openings): op =>
openings.update(player.color, _.updatedWith(op)(_.fold(1)(_ + 1).some)),
Expand Down
3 changes: 1 addition & 2 deletions modules/recap/src/main/RecapJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ private final class RecapJson(lightUserApi: LightUserApi)(using Executor):
"pgn" -> o.ref.pgn
)

given Writes[NbAndStreak] = Json.writes
given Writes[Results] = Json.writes
given Writes[NbWin] = Json.writes
given Writes[PuzzleVotes] = Json.writes
given Writes[RecapPuzzles] = Json.writes
given Writes[Recap.Perf] = Json.writes
Expand Down
3 changes: 1 addition & 2 deletions modules/recap/src/main/RecapRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ private final class RecapRepo(colls: RecapColls)(using Executor):
private given BSONHandler[FiniteDuration] =
BSONIntegerHandler.as[FiniteDuration](_.seconds, _.toSeconds.toInt)

private given BSONDocumentHandler[NbAndStreak] = Macros.handler
private given BSONDocumentHandler[Results] = Macros.handler
private given BSONDocumentHandler[NbWin] = Macros.handler
private given [A: BSONHandler]: BSONHandler[Recap.Counted[A]] = Macros.handler
private given BSONDocumentHandler[Recap.Perf] = Macros.handler

Expand Down
1 change: 0 additions & 1 deletion modules/web/src/main/ui/DevUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ announce 10 minutes Lichess will restart!
announce cancel
change asset version
fishnet client create {username}
gdpr erase {username} forever
msg multi {sender} {recipient1,recipient2} {message}
team members add {teamId} {username1,username2,username3}
notify url users {username1,username2,username3} {url} {link title} | {link description}
Expand Down
14 changes: 7 additions & 7 deletions ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,13 @@ export default class AnalyseCtrl {
this.evalCache = new EvalCache({
variant: this.data.game.variant.key,
canGet: this.canEvalGet,
canPut: () =>
!!(
this.ceval?.isCacheable &&
this.canEvalGet() &&
// if not in study, only put decent opening moves
(this.opts.study || (!this.node.ceval!.mate && Math.abs(this.node.ceval!.cp!) < 99))
),
canPut: () => true,
// !!(
// this.ceval?.isCacheable &&
// this.canEvalGet() &&
// // if not in study, only put decent opening moves
// (this.opts.study || (!this.node.ceval!.mate && Math.abs(this.node.ceval!.cp!) < 99))
// ),
getNode: () => this.node,
send: this.opts.socketSend,
receive: this.onNewCeval,
Expand Down
30 changes: 15 additions & 15 deletions ui/analyse/src/evalCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export interface EvalCacheOpts {
upgradable: boolean;
}

const evalPutMinDepth = 20;
const evalPutMinNodes = 3e6;
// const evalPutMinDepth = 20;
// const evalPutMinNodes = 3e6;
const evalPutMaxMoves = 10;

function qualityCheck(ev: Tree.ClientEval): boolean {
// quick mates may never reach the minimum nodes or depth
if (Math.abs(ev.mate ?? 99) < 15) return true;
// below 500k nodes, the eval might come from an imminent threefold repetition
// and should therefore be ignored
return ev.nodes > 500000 && (ev.depth >= evalPutMinDepth || ev.nodes > evalPutMinNodes);
}
// function qualityCheck(ev: Tree.ClientEval): boolean {
// // quick mates may never reach the minimum nodes or depth
// if (Math.abs(ev.mate ?? 99) < 15) return true;
// // below 500k nodes, the eval might come from an imminent threefold repetition
// // and should therefore be ignored
// return ev.nodes > 500000 && (ev.depth >= evalPutMinDepth || ev.nodes > evalPutMinNodes);
// }

// from client eval to server eval
function toPutData(variant: VariantKey, ev: Tree.ClientEval): EvalPutData {
Expand Down Expand Up @@ -81,13 +81,13 @@ export default class EvalCache {
onLocalCeval = throttle(500, () => {
const node = this.opts.getNode(),
ev = node.ceval;
const fetched = this.fetchedByFen.get(node.fen);
// const fetched = this.fetchedByFen.get(node.fen);
if (
ev &&
!ev.cloud &&
this.fetchedByFen.has(node.fen) &&
(!fetched || fetched.depth < ev.depth) &&
qualityCheck(ev) &&
// !ev.cloud &&
// this.fetchedByFen.has(node.fen) &&
// (!fetched || fetched.depth < ev.depth) &&
// qualityCheck(ev) &&
this.opts.canPut()
) {
this.opts.send('evalPut', toPutData(this.opts.variant, ev));
Expand All @@ -109,7 +109,7 @@ export default class EvalCache {
};
if (this.opts.variant !== 'standard') obj.variant = this.opts.variant;
if (multiPv > 1) obj.mpv = multiPv;
if (this.upgradable()) obj.up = true;
if (true || this.upgradable()) obj.up = true;
this.opts.send('evalGet', obj);
};

Expand Down
2 changes: 1 addition & 1 deletion ui/lobby/src/lobby.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function layout() {
cols = newCols;
document
.querySelector<HTMLElement>(cols > 2 ? '.lobby__side' : '.lobby')
?.append(document.querySelector('.lobby__timeline')!);
?.append(document.querySelector('.lobby__timeline') ?? '');
}

layout();
Expand Down
19 changes: 19 additions & 0 deletions ui/recap/css/_recap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body {
left: 1vw;
right: 1vw;
height: 100%;
text-align: center;
}

.recap a {
Expand Down Expand Up @@ -188,3 +189,21 @@ body {
transform: rotate(-90deg);
}
}

.animated-pulse {
animation: pulse 1s 1;
}

@keyframes pulse {
0% {
transform: scale(1);
}

50% {
transform: scale(1.2);
}

100% {
transform: scale(1);
}
}
15 changes: 4 additions & 11 deletions ui/recap/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
interface NbStreak {
nb: number;
streak: number;
}
export interface Results {
interface NbWin {
total: number;
win: number;
draw: number;
loss: number;
}
export interface Opening {
key: string;
Expand All @@ -25,8 +20,7 @@ export interface Recap {
year: number;
createdAt: number;
puzzles: {
nb: NbStreak;
results: Results;
nbs: NbWin;
votes: {
up: number;
down: number;
Expand All @@ -41,7 +35,7 @@ export interface Recap {
}[];
moves: number;
openings: ByColor<Counted<Opening>>;
nb: NbStreak;
nbs: NbWin;
nbWhite: number;
opponents: Counted<LightUser>[];
timePlaying: number;
Expand All @@ -53,6 +47,5 @@ export interface Recap {
arena: number;
};
firstMoves: Counted<string>[];
results: Results;
};
}
47 changes: 36 additions & 11 deletions ui/recap/src/swiper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'swiper/css';
import 'swiper/css/bundle';
import { Recap } from './interfaces';
import { animateNumber } from './ui';
import { get } from 'common/data';
import { formatDuration } from './util';

export const makeSwiper =
(_recap: Recap) =>
Expand All @@ -13,7 +15,7 @@ export const makeSwiper =
const progressContent = element.querySelector('.autoplay-progress span') as HTMLSpanElement;
const options: SwiperOptions = {
modules: [mod.Pagination, mod.Navigation, mod.Keyboard, mod.Mousewheel, mod.Autoplay],
initialSlide: 0,
initialSlide: window.location.hash ? parseInt(window.location.hash.slice(1)) : 0,
direction: 'horizontal',
loop: false,
cssMode: false,
Expand All @@ -30,23 +32,46 @@ export const makeSwiper =
},
autoplay: {
delay: 5000,
disableOnInteraction: true,
disableOnInteraction: false,
},
on: {
autoplayTimeLeft(_s, time, progress) {
progressCircle.style.setProperty('--progress', (1 - progress).toString());
progressContent.textContent = `${Math.ceil(time / 1000)}s`;
},
slideChange() {
setTimeout(
() =>
element
.querySelectorAll('.swiper-slide-active .animated-number')
.forEach((counter: HTMLElement) => {
animateNumber(counter);
}),
200,
);
setTimeout(() => {
element
.querySelectorAll('.swiper-slide-active .animated-number')
.forEach((counter: HTMLElement) => {
animateNumber(counter, {});
});
element
.querySelectorAll('.swiper-slide-active .animated-time')
.forEach((counter: HTMLElement) => {
animateNumber(counter, { duration: 1000, render: formatDuration });
});
element
.querySelectorAll('.swiper-slide-active .animated-pulse')
.forEach((counter: HTMLElement) => {
counter.classList.remove('animated-pulse');
setTimeout(() => {
counter.classList.add('animated-pulse');
}, 100);
});
element.querySelectorAll('.swiper-slide-active .lpv').forEach((el: HTMLElement) => {
const lpv = get(el, 'lpv')!;
lpv.goTo('first');
const next = () => {
if (!lpv.canGoTo('next')) return;
setTimeout(() => {
lpv.goTo('next');
next();
}, 500);
};
next();
});
}, 200);
},
},
};
Expand Down
Loading

0 comments on commit 74337a1

Please sign in to comment.