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: add special compensators for Projects Script #73

Merged
merged 2 commits into from
Aug 12, 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
30 changes: 25 additions & 5 deletions src/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ const PROJECTS = [
"id": 21084,
"metadata_fields": [ "Item", "Notes", "folder", "image1", "image2", "#Hazard", "Oversize", "group_id", "Condition", "internal_id", "part_number", "Photographer", "#Other Number", "picture_agency", "Sensitive_Image", "Problematic_Language", "Notes on Problematic Language" ]
}, {
/*
"name": "Scarlets & Blues (Performance Test Only)", // Feel free to delete once Community Catalog goes live
"id": 12268,
"metadata_fields": [ "Date", "Page", "image", "Catalogue" ]
}, {
"name": "How Did We Get Here?",
*/
"name": "How Did We Get Here?",
"id": 20816,
"metadata_fields": [
"image1", "image2", "internal_id", "group_id", "part_number", "folder", "#Hazard", "condition", "item", "picture_agency", "photographer", "oversize", "sensitive_image", "sensitive_image_note", "problematic_language", "probelmatic_language_notes", "#Other Number", "notes"
Expand All @@ -50,7 +52,10 @@ const PROJECTS = [
"id": 23052,
"metadata_fields": [
"file name", "object_number", "object_name", "creator", "creator.role", "production.date", "association.person", "credit line"
]
],
"special_compensators": {
"metadata_field_name_ignore_case": true
}
}
]
/*
Expand Down Expand Up @@ -163,7 +168,7 @@ Output:
*/
async function writeProjectData(project, subjects = []) {
try {
const csvRows = formatSubjectsForCsv(subjects, project.metadata_fields)
const csvRows = formatSubjectsForCsv(subjects, project.metadata_fields, project.special_compensators)
const data = unparse(csvRows)
.replaceAll(',FALSE', ',0')
.replaceAll(',TRUE', ',1')
Expand Down Expand Up @@ -193,7 +198,7 @@ Output:
(array of objects) array of subjects, in simple key-value pairs corresponding
to the project's required CSV format.
*/
function formatSubjectsForCsv(subjects = [], metadata_fields = []) {
function formatSubjectsForCsv(subjects = [], metadata_fields = [], special_compensators = {}) {
return subjects.map(subject => {
const row = {}

Expand All @@ -203,7 +208,22 @@ function formatSubjectsForCsv(subjects = [], metadata_fields = []) {
// Add metadata-specific fields
// TODO: handle metadata fields with special characters, e.g. # and !
metadata_fields.forEach(field => {
row[field] = subject.metadata[field] || ''
// Enabled for projects where there's an inconsistent CapItaLisatiOn oF
// MeTaDaTa fIeld NaMes between Subjects.
// e.g subject 1 has subject.metadata.file_name,
// while subject 2 has subject.metadata.File_Name
if (special_compensators?.metadata_field_name_ignore_case) {
let value = ''
Object.entries(subject.metadata).forEach(([key, val]) => {
if (key.toLowerCase?.() === field?.toLowerCase?.()) {
value = val
}
})
row[field] = value

} else { // Default
row[field] = subject.metadata[field] || ''
}
})

return row
Expand Down