demographics section done

This commit is contained in:
2026-02-02 09:04:29 +01:00
parent 6b3fcb2f43
commit d770645d8e
6 changed files with 265 additions and 14 deletions

View File

@@ -13,8 +13,12 @@ from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE
def image_alt_text_generator(fpath):
def image_alt_text_generator(fpath, include_dataset_dirname=False) -> str:
"""convert image file path to alt text
Args:
fpath (str or Path): path to image file, must start with 'figures/'
include_dataset_dirname (bool): whether to include the dataset directory name in the alt text. Recommended to keep False, so that the images do not get tied to a specific dataset export. (Defeats the purpose of assigning alt text to be able to update images when new datasets are exported.)
"""
if not isinstance(fpath, Path):
@@ -23,7 +27,10 @@ def image_alt_text_generator(fpath):
fparts = fpath.parts
assert fparts[0] == 'figures', "Image file path must start with 'figures'"
return Path('/'.join(fparts[2:])).as_posix()
if include_dataset_dirname:
return Path('/'.join(fparts[1:])).as_posix()
else:
return Path('/'.join(fparts[2:])).as_posix()
def pptx_replace_named_image(presentation_path, target_tag, new_image_path, save_path):
"""