2
2
import re
3
3
from pathlib import Path
4
4
5
+ import chess
5
6
from django .core .management import BaseCommand
6
7
from django .db .models .functions import Substr
7
8
8
9
from apps .daily_challenge .models import DailyChallenge
9
10
11
+ THEMES_TO_IGNORE = {
12
+ "oneMove" ,
13
+ "mateIn1" ,
14
+ "mateIn2" ,
15
+ }
16
+
10
17
11
18
class Command (BaseCommand ):
12
19
def add_arguments (self , parser ):
@@ -18,20 +25,20 @@ def add_arguments(self, parser):
18
25
parser .add_argument (
19
26
"--batch-size" ,
20
27
type = int ,
21
- default = 1000 ,
28
+ default = 10 , # low batch size to avoid OOM on low-end Fly.io plan
22
29
help = "DailyChallenges creation batch size." ,
23
30
)
24
31
parser .add_argument (
25
32
"--min-popularity" ,
26
33
type = int ,
27
- default = 85 ,
34
+ default = 90 ,
28
35
help = "Only consider puzzles that have at least that Popularity." ,
29
36
)
30
37
parser .add_argument (
31
38
"--rating-range" ,
32
39
type = rating_range ,
33
40
dest = "rating_min_max" ,
34
- default = (800 , 1300 ),
41
+ default = (900 , 1100 ),
35
42
help = "Only consider puzzles that have a Rating in this 'min-max' range." ,
36
43
)
37
44
parser .add_argument (
@@ -63,6 +70,10 @@ def handle(
63
70
with csv_file_path .open (newline = "" ) as csv_file :
64
71
reader = csv .DictReader (csv_file )
65
72
for row in reader :
73
+ themes : set [str ] = set (row .get ("Themes" , "" ).split ())
74
+ if themes & THEMES_TO_IGNORE :
75
+ self .stdout .write ("Skipping too short puzzle" )
76
+ continue
66
77
if (popularity := int (row ["Popularity" ])) < min_popularity :
67
78
self .stdout .write (f"Skipping puzzle with Popularity { popularity } " )
68
79
continue
@@ -80,6 +91,10 @@ def handle(
80
91
f"Creating DailyChallenge for puzzle '{ puzzle_id } ' with Popularity { popularity } , rating { rating } , FEN '{ fen } '"
81
92
)
82
93
94
+ if " b " in fen : # quick and dirty way to detect if black is to move
95
+ self .stdout .write ("Mirroring puzzle with black to move" )
96
+ fen = chess .Board (fen ).mirror ().fen ()
97
+
83
98
current_batch .append (
84
99
DailyChallenge (
85
100
source = f"lichess-{ puzzle_id } " ,
0 commit comments