Skip to content

Commit

Permalink
Projects script: add option to exclude specific subject sets (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunanoordin authored Aug 13, 2024
1 parent 8cdb59c commit 0de2446
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ const PROJECTS = [
"metadata_fields": [
"file name", "object_number", "object_name", "creator", "creator.role", "production.date", "association.person", "credit line"
],
"special_rules" : {
"exclude_subject_sets": [ "121688" ]
// 121688 is the "betatest" subject set, and has entries duplicated on the 122511 "launch" subject set.
},
"special_compensators": {
"metadata_field_name_ignore_case": true
// e.g. some subjects use "Object_Name" instead of "object_name"
}
}
]
Expand Down Expand Up @@ -100,7 +105,10 @@ Output:
*/
async function processOneProject(project) {
try {
const subjects = await fetchAllSubjects(project.id)
let subjects = await fetchAllSubjects(project.id)
if (project.special_rules) {
subjects = refineSubjectsSelection(subjects, project.special_rules)
}
return await writeProjectData(project, subjects)

} catch (err) {
Expand Down Expand Up @@ -156,6 +164,22 @@ async function fetchSubjectsByPage(projectId = '', page = 1, pageSize = 100) {
}
}

/* Applies special rules to the subject selection.
*/
function refineSubjectsSelection(subjects = [], specialRules = {}) {
let selectedSubjects = subjects.slice()

// Filter out Subjects from specific Subject Sets.
// Useful for removing beta Subjects.
selectedSubjects = selectedSubjects.filter(subject => ( // For each Subject, remove it if...
!subject.links?.subject_sets?.some(sset => ( // ...any of its linked subject sets...
specialRules.exclude_subject_sets.includes(sset) // ...are in the list of ignored/excluded subject sets.
))))

return selectedSubjects
}


/*
Writes all fetched Subjects from one Project to a CSV file.
Expand Down

0 comments on commit 0de2446

Please sign in to comment.