mirror of
https://github.com/lichess-org/mobile.git
synced 2026-05-26 13:50:52 +00:00
update chess openings db (#2404)
* update chess openings db * bump chess openings db version
This commit is contained in:
committed by
GitHub
parent
85b33668a8
commit
09da70b636
Binary file not shown.
@@ -8,7 +8,7 @@ import 'package:sqflite/sqflite.dart';
|
|||||||
// The dataset is from https://github.com/lichess-org/chess-openings
|
// The dataset is from https://github.com/lichess-org/chess-openings
|
||||||
// It can be updated by running the script at scripts/update_openings_db.py
|
// It can be updated by running the script at scripts/update_openings_db.py
|
||||||
|
|
||||||
const _kDatabaseVersion = 3;
|
const _kDatabaseVersion = 4;
|
||||||
const _kDatabaseName = 'chess_openings$_kDatabaseVersion.db';
|
const _kDatabaseName = 'chess_openings$_kDatabaseVersion.db';
|
||||||
|
|
||||||
/// A provider for the openings database.
|
/// A provider for the openings database.
|
||||||
|
|||||||
@@ -21,15 +21,28 @@ subprocess.run(["make", "all"], cwd=path_to_chess_openings, check=True)
|
|||||||
db_path = os.path.join(os.path.dirname(__file__), '../assets/chess_openings.db')
|
db_path = os.path.join(os.path.dirname(__file__), '../assets/chess_openings.db')
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
|
|
||||||
|
old_openings = set()
|
||||||
|
new_openings = set()
|
||||||
|
|
||||||
|
openings_sql = 'SELECT eco || " " || name || " " || pgn FROM openings ORDER BY eco, name, pgn;'
|
||||||
|
|
||||||
with open(os.path.join(path_to_chess_openings, 'dist/all.tsv'), 'r') as f:
|
with open(os.path.join(path_to_chess_openings, 'dist/all.tsv'), 'r') as f:
|
||||||
dr = csv.DictReader(f, delimiter='\t')
|
dr = csv.DictReader(f, delimiter='\t')
|
||||||
to_db = [(i['eco'], i['name'], i['pgn'], i['uci'], i['epd']) for i in dr]
|
to_db = [(i['eco'], i['name'], i['pgn'], i['uci'], i['epd']) for i in dr]
|
||||||
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
old_openings = set(row[0] for row in cur.execute(openings_sql))
|
||||||
cur.execute('DELETE FROM openings;')
|
cur.execute('DELETE FROM openings;')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
cur.executemany('INSERT INTO openings (eco, name, pgn, uci, epd) VALUES (?, ?, ?, ?, ?);', to_db)
|
cur.executemany('INSERT INTO openings (eco, name, pgn, uci, epd) VALUES (?, ?, ?, ?, ?);', to_db)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
new_openings = set(row[0] for row in cur.execute(openings_sql))
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
print(f"Opening changes:")
|
||||||
|
print("```diff")
|
||||||
|
[print(f"- {o}") for o in sorted(old_openings - new_openings)]
|
||||||
|
[print(f"+ {o}") for o in sorted(new_openings - old_openings)]
|
||||||
|
print("```")
|
||||||
|
|||||||
Reference in New Issue
Block a user