Recreate mappings every time

This saves the user a little hassle and is very fast.
This commit is contained in:
Nate Bowman
2026-10-04 02:23:53 -04:00
parent 03ab8d72bc
commit 24f315c107
7 changed files with 28 additions and 65 deletions

View File

@@ -1,5 +1,5 @@
from flashcards.decks import create_deck
from flashcards.maps import read_data_to_dicts
from flashcards.maps import create_maps, read_data_to_dict
@@ -7,8 +7,9 @@ from flashcards.maps import read_data_to_dicts
deck_name = 'Unit Costs'
deck_fname = 'unit-costs'
# specify the namelist used to create the deck
namelist = 'base-units'
# specify the namelist to be used to create the deck
# give the relative path of the file from config.namelists_dir
namelist = 'base-units.txt'
# key into json file specifying which data you want
# uncomment either 'units_buildings' or 'techs'
@@ -17,12 +18,15 @@ data_json_key = 'units_buildings'
# --- create list of notes ---
# read in data and maps between names and numbers
data, nums, names = read_data_to_dicts(namelist, data_json_key)
# read in data
data = read_data_to_dict(data_json_key)
# create maps between names and numbers based on namelist
names, _ = create_maps(namelist, data_json_key)
# create cards based on data and maps
notes = []
for num, name in nums.items():
for num, name in names.items():
cost = data[num]['cost']
back = '\n'.join([f'{res}: {val}' for res, val in cost.items()
if val != 0])

View File

@@ -1,5 +1,5 @@
from flashcards.decks import create_deck
from flashcards.maps import read_data_to_dicts
from flashcards.maps import create_maps, read_data_to_dict
@@ -7,8 +7,9 @@ from flashcards.maps import read_data_to_dicts
deck_name = 'Research Costs'
deck_fname = 'research-costs'
# specify the namelist used to create the deck
namelist = 'research'
# specify the namelist to be used to create the deck
# give the relative path of the file from config.namelists_dir
namelist = 'research.txt'
# key into json file specifying which data you want
# uncomment either 'units_buildings' or 'techs'
@@ -17,12 +18,15 @@ data_json_key = 'techs'
# --- create list of notes ---
# read in data and maps between names and numbers
data, nums, names = read_data_to_dicts(namelist, data_json_key)
# read in data
data = read_data_to_dict(data_json_key)
# create maps between names and numbers based on namelist
names, _ = create_maps(namelist, data_json_key)
# create cards based on data and maps
notes = []
for num, name in nums.items():
for num, name in names.items():
cost = data[num]['cost']
back = '\n'.join([f'{res}: {val}' for res, val in cost.items()
if val != 0])