Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community Catalog: filter out Subjects that belong to no Subject Sets #75

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ Output:
async function processOneProject(project) {
try {
let subjects = await fetchAllSubjects(project.id)
if (project.special_rules) {
subjects = refineSubjectsSelection(subjects, project.special_rules)
}
subjects = refineSubjectsSelection(subjects, project.special_rules)
return await writeProjectData(project, subjects)

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

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

// Filter out Subjects that don't belong to any Subject Sets
// i.e. remove deleted Subjects
selectedSubjects = selectedSubjects.filter(subject => (
subject.links?.subject_sets?.length > 0
))

// 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.
))))
if (specialRules.exclude_subject_sets) {
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
}
Expand Down