transitlos.map.ranking_tab¶
Ranking tab of the US / Spain stats panel (nation-wide maps whose stats come from per-state stats_chunks/).
build_ranking_table(chunk_dir) streams every <state>.json.gz once and writes ranking.json: for each geometry level that the chunks
carry (state / county / place), the population-weighted mean and median level_of_service of every unit, for each weight column that exists
(population, jobs-like count columns). Levels whose geometry is not in the chunks (metropolitan areas, tracts, electoral districts,
school districts ...) are listed in the tab as "not available" rather than faked.
RANKING_JS is the tab: level picker, weight column, mean / median, restricted to the scope chosen in the scope bar.
build_ranking_table(chunk_dir)
¶
ranking.json: score and weights of every state, county and place from the stats chunks (and
ranking_top.json).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_dir
|
str
|
Stats chunk folder (with |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path of |
write_ranking_top(chunk_dir, levels=None)
¶
ranking_top.json: the state / county / place rows with only what the top bar's score needs, so the page does not download the
whole ranking table (tens of MB) at start; ranking.json is fetched when the stats panel is opened.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_dir
|
str
|
Stats chunk folder. |
required |
levels
|
Optional[dict]
|
Ranking levels; |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path of |
write_rank_cells(cells, state_key, units, out_dir)
¶
cells (column h3, population and the map's numeric columns) + per level in units ({level: GeoDataFrame GEOID/geometry,
or a callable on the joined ids}) the unit id of each cell centre -> <out_dir>/rank_cells/<state_key>.parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
Cells with |
required | |
state_key
|
str
|
State key. |
required |
units
|
dict
|
|
required |
out_dir
|
str
|
Stats chunk folder. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path of the parquet. |
build_rank_columns(chunk_dir)
¶
ranking_cols/columns.json + ranking_cols/<level>/<i>.json (see the block comment). Returns the number of files written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_dir
|
str
|
Stats chunk folder. |
required |
ranking_script(chunk_dir, rel_dir, country, rebuild=False)
¶
The ranking tab of a nation-wide map, (re)building its tables when they are missing or older than the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_dir
|
str
|
Stats chunk folder. |
required |
rel_dir
|
str
|
Path of that folder relative to the page. |
required |
country
|
str
|
Country code of the map. |
required |
rebuild
|
bool
|
Rebuild every table. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|