Python web scraper.
Created for HSYLC with public data.
A small pipeline that gathers Genshin Impact gacha (wish) data into CSVs and a sqlite database. There are two separate datasets because they come from two different kinds of sources:
| Dataset | Granularity | Source | Output |
|---|---|---|---|
| Individual | one row per pull | UIGF wish-history exports | csv/pulls.csv |
| Aggregated | community-wide totals | paimon.moe | csv/aggregate/*.csv |
Why two sources? paimon.moe only publishes aggregate statistics. It has no per-pull rows, timestamps, or per-pull pity. So the individual columns (date, time, region, result, rarity, pity, banner) cannot come from paimon.moe.
scripts/ pipeline that builds the datasets
csv/ pipeline output (pulls.csv, banners.csv, aggregate/)
raw/ raw downloads (paimon snapshots, reference lookups)
database/ genshin.db -- all CSVs loaded into sqlite
data/ standalone CSVs used by the notebooks
notebooks/ HSYLC course notebooks (D1-D5) + the NLP notebook
Notebooks read data with repo-relative paths (../data/...), so run them from
inside notebooks/.
pip install -r requirements.txtEvery script reads its paths from scripts/paths.py, so you can run them from
the scripts/ folder or the repo root.
Columns: date, time, location, result, rarity, pity, banner (plus
player_id, banner_type, pity_4).
locationis the account server region, derived from the UID's first digit (America / Europe / Asia / TW-HK-MO / China).pityis computed by walking each player's pulls in time order and resetting after each 5★ (4★ pity is tracked independently inpity_4). Pity is grouped byuigf_gacha_type, so the two parallel character banners share a pool, while standard / weapon / chronicled are independent.- UIDs are replaced with a salted hash (
player_id). SetPULLS_SALTin the environment to keep IDs stable across runs. (UIDs are a small space, so this is a pseudonym, not perfect anonymisation.)
Three ways to get UIGF data into raw/uigf/:
-
Bundled sample —
raw/uigf/sample_uigf.jsonships in the repo, so the pipeline runs with zero setup. -
Your own files — drop any UIGF
.jsonexport intoraw/uigf/. -
GitHub scrape — searches public repos for UIGF exports. GitHub code search needs a token:
export GITHUB_TOKEN=ghp_your_token_here # public-search scope is enough python3 scripts/download_uigf.py
Then build the dataset:
python3 scripts/parse_uigf.py # -> csv/pulls.csvPrivacy: raw UIGF exports contain real, plaintext account UIDs, so
raw/uigf/*is gitignored (only the synthetic sample is committed).csv/pulls.csvis safe to share — UIDs are replaced with salted hashes.
The scrape has four tunable levers, in scripts/download_uigf.py, weakest to
strongest:
- More depth per query by raising
MAX_RESULTS_PER_QUERY(200 → up to 1000). - More breadth by adding exporter signatures to
SEARCH_QUERIES. Each distinct query reaches files the others miss. - Targeted scope by adding
repo:owner/nameoruser:someoneto a query to focus on a known source. - Full-repo harvest by adding
"owner/repo"entries to theREPOSlist. Code search only returns a capped subset per repo, but an aggregator repo can hold hundreds of exports; harvesting walks the repo's entire file tree and grabs every UIGF export (and bypasses code search's 384 KB file-size limit). The repos shown in a scrape's output are good harvest candidates. (Note: most public UIGF repos are single-player, so true UIGF aggregators are rare — for bulk data see the OneBST import below.)
OneBST/GI_gacha_dataset is the one
large public corpus of real, voluntarily-shared wish histories — but it's stored
as CSV, not UIGF JSON, so the scraper can't read it. import_onebst.py
normalises those CSVs into the same pulls.csv schema (reusing the pity / region
/ anonymisation logic) and appends them, deduping by player.
python3 scripts/download_reference.py # recommended first: enables CN->slug names
python3 scripts/import_onebst.py # dataset_02 (~100 accounts, ~200k pulls) over HTTP
python3 scripts/import_onebst.py --accounts 20 # ...or cap how many accounts- dataset_02 (the default) is plain CSV in the repo and downloads directly — no token, no extraction.
- dataset_03 (~16k accounts / 15.6M pulls) ships as a password-protected 7z
(
OneBST). This environment can't extract 7z, so download + extract it yourself, then point the importer at the extracted folder:ONEBST_03_DIR=/path/to/player_data python3 scripts/import_onebst.py --mode 03
- OneBST CSVs carry no UID, so
locationisUnknown(the account is a folder number, anonymised intoplayer_idlike everything else).
Name normalisation: real exports use whatever language the player's client was set to (the scraped Chinese players' UIGF and OneBST are in Chinese).
download_reference.pybuildsname_lookup.json(Chinese/English → English slug) soparse_uigf.pyandimport_onebst.pyemit one consistentresultslug that joins across sources and to the aggregate data.
python scripts/download_paimon.py # downloads ~190 banners -> raw/paimon/
python scripts/download_reference.py # optional: name->rarity lookup
python scripts/build_banner_metadata.py # -> csv/banners.csv
python scripts/parse_paimon.py # -> csv/aggregate/*.csv (+ csv/all_items.csv)Aggregate outputs: banner_summary.csv, item_popularity.csv,
pity_distribution.csv, pull_by_day.csv, constellation.csv.
python scripts/build_database.py # loads every CSV present -> database/genshin.db
python scripts/query_database.py # example queries over both datasetspython scripts/analyze.py # top-20 pulled characters (aggregate)
python scripts/build_five_star_distribution.py # filter a few 5★ for comparison| Script | Track | Purpose |
|---|---|---|
paths.py |
shared | path constants (import these, don't hardcode ../) |
download_paimon.py |
aggregate | download all banners from paimon.moe |
download_reference.py |
shared | build name → rarity + name → slug lookups (optional) |
build_banner_metadata.py |
aggregate | csv/banners.csv |
parse_paimon.py |
aggregate | aggregate CSVs |
download_uigf.py |
individual | fetch UIGF exports (needs GITHUB_TOKEN) |
parse_uigf.py |
individual | csv/pulls.csv with computed pity |
import_onebst.py |
individual | bulk-import the OneBST CSV dataset into pulls.csv |
build_database.py |
shared | load all CSVs into sqlite |
query_database.py |
shared | example queries |
analyze.py, build_five_star_distribution.py |
aggregate | small chart helpers |
| Notebook | Topic |
|---|---|
[HSYLC]_D1_Python.ipynb |
Python basics |
[HSYLC]_D2_PandasNumpy.ipynb |
pandas / numpy on the enemy stat CSVs |
[HSYLC]_D3_Visualization.ipynb |
plotting |
[HSYLC]_D4_Modeling.ipynb |
linear regression on abyss usage; gacha pity curve |
[HSYLC]_D5_Neural_Nets.ipynb |
neural net predicting abyss usage % |
[HSYLC]_D6_NLP.ipynb |
sentiment models over the review text |
The notebook predicts a character's average Spiral Abyss usage % from their stats. Two things are worth knowing before trusting any number it prints:
- A single train/test split is not meaningful here. With 122 characters, one split swings wildly — the neural net scores R² ≈ 0.41 on the notebook's fixed split but only ≈ 0.06 averaged over many cross-validated shuffles.
- Feature quality beats model capacity. The net uses 115 features for ~97 training rows (57 are constant zeros after coercion). Replacing them with 5 features from the gacha data — rarity, pull popularity, banner count, release version, and the share of owners at ≥C1 — lifts cross-validated R² from 0.06 → 0.52 (MAE 11.8 → 8.6 points) using ExtraTrees. Part Four of the notebook shows the comparison.
R² ≈ 0.5 is likely the ceiling from character-intrinsic data: real usage also depends on team compositions, weapons and the rotating abyss enemies, none of which are in this dataset.
characterAbyssUsage.csvhas 13k rows, but they are the same 126 characters repeated at ~106 levels each, with an identicalaverageon every row. Train on it and the target leaks across folds — usecharacterStatsAbyssUsage.csv(one row per character) instead.
data/genshin_reviews.csvis anonymized: the reviewer name, profile-image URL and review id from the original Google Play scrape are dropped.[HSYLC]_D3_Visualization.ipynbstill reads from a local checkout of the KQM data repo, which this project does not ship; those cells won't run as-is.