Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cum vars #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions ingest_lichess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,36 @@
from ingester import ingest_lichess_data


def main(start, end, pq_dir, months=None, include_moves=False, restart_counter_games=True):
def main(start, end, pq_dir, months=None, include_moves=False, restart_counter_games=True, dir_ndjson=None, ndjson_size=1e6):
"""Download data with a check for existing parquet files."""
pq_dir = Path(pq_dir)
pq_dir.mkdir(parents=True, exist_ok=True)

if dir_ndjson is not None:
dir_ndjson = Path(dir_ndjson)
dir_ndjson.mkdir(parents=True, exist_ok=True)

years = range(start, end)
if months is None:
months = range(1, 13)
arguments = [(y, m, pq_dir, include_moves) for y in years for m in months]
arguments = [(y, m, pq_dir, include_moves, dir_ndjson, ndjson_size) for y in years for m in months]

for arg in arguments:
if (Path(pq_dir) / f"{arg[0]}_{arg[1]:02}.parquet").exists():
print(f"{arg[0]}_{arg[1]:02} exists. Skipping...")
continue
ingest_lichess_data(*arg)

if restart_counter_games:
# Remove the counter file
counter_file = Path(pq_dir) / "cum_files.json.zst"
if counter_file.exists():
counter_file.unlink()

if __name__ == "__main__":

parser=argparse.ArgumentParser()
parser.add_argument('--start', type=int, default=2013)
parser.add_argument('--end', type=int, default=datetime.date.today().year)
parser.add_argument('--months', nargs='+', type=int)
parser.add_argument('--include-moves', action='store_true', default=False)
parser.add_argument('--debug', action='store_true', default=False)
parser.add_argument('--restart-counter-games', action='store_true', default=True)
parser.add_argument('--parquet-dir', type=Path, default="./lichess_parquet")
parser.add_argument('--dir-ndjson', type=str, default=None)
parser.add_argument('--ndjson-size', type=int, default=1e6)
args=parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
Expand All @@ -47,4 +46,6 @@ def main(start, end, pq_dir, months=None, include_moves=False, restart_counter_g
months=args.months,
include_moves=args.include_moves,
pq_dir=args.parquet_dir,
restart_counter_games=args.restart_counter_games)
dir_ndjson=args.dir_ndjson,
ndjson_size=args.ndjson_size
)
Loading