Skip to content

chore: 🍱 add task that writes raw data columns to field-resource mapping csv - #139

Open
signekb wants to merge 12 commits into
mainfrom
chore/write-columns-to-mapping-csv
Open

signekb wants to merge 12 commits into
mainfrom
chore/write-columns-to-mapping-csv

Conversation

@signekb

@signekb signekb commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Description

Including the columns (new_field_name, resource_title, resource_name, comments) that we want to fill out. If the mapping csv already exists, it checks for new fields and append them (if any).

Needs a thorough review.

Checklist

  • Ran just build-raw (but didn't change the mapping csv yet)

Including the columns we want to fill out. If the mapping csv already exists, it checks for new fields and append them (if any).
Comment on lines +22 to +24
FIELD_RESOURCE_MAPPING_PATH = (
SRC / "questionnaire_data" / "metadata" / "redcap" / "mapping-field-to-resource.csv"
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly like this path, but this is the current location.

Comment thread src/questionnaire_data/data/redcap.py Outdated
df.write_csv(raw_data_path, compression="gzip")


def read_newest_raw(raw_data_paths: Path):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I need to read the newest raw data in order to split it for staging, I thought this could be reused. Although this also results in the raw data being read twice 🤔

Comment thread src/questionnaire_data/data/redcap.py Outdated
Comment on lines +52 to +65
if mapping_csv_path.exists():
mapping_csv = pl.read_csv(mapping_csv_path, separator=";")
existing_field_names = mapping_csv["field_name"].to_list()
new_fields = [
field_name
for field_name in field_names
if field_name not in existing_field_names
]
if len(new_fields) != 0:
pl.concat(
[mapping_csv, pl.DataFrame({"field_name": new_fields})],
# Fills in missing columns with None.
how="diagonal",
).write_csv(mapping_csv_path, separator=";")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is overdone, but this allows us to add any new fields if they appear without overwriting the existing when adding this as a task.

@signekb signekb moved this from To do to In review in Platform development Oct 29, 2026
@signekb signekb moved this from In review to In progress in Platform development Oct 29, 2026
@signekb signekb moved this from In progress to In review in Platform development Oct 29, 2026
Comment thread src/questionnaire_data/data/redcap.py Resolved
Comment thread src/questionnaire_data/data/redcap.py Resolved
@github-project-automation github-project-automation Bot moved this from In review to In progress in Platform development Oct 29, 2026
Comment thread src/questionnaire_data/data/redcap.py Resolved
@signekb
signekb requested a review from lwjohnst86 October 30, 2026 15:28
@signekb signekb moved this from In progress to In review in Platform development Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants