fix: import localized topics and flattened Sessionize speakers
Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
22de4a8645
commit
7f340b4c08
6 files changed
+226
-88
No files matched your search
@@ -0,0 +1,86 @@
|
||||
const XLSX = require('xlsx');
|
||||
|
||||
function excelSerialToTime(serial, durationMin) {
|
||||
const ms = Math.round((serial - 25569) * 86400 * 1000);
|
||||
const date = new Date(ms);
|
||||
const end = new Date(ms + (durationMin || 0) * 60 * 1000);
|
||||
return {
|
||||
date: date.toISOString().slice(0, 10),
|
||||
start_time: date.toISOString().slice(11, 19),
|
||||
end_time: end.toISOString().slice(11, 19),
|
||||
};
|
||||
}
|
||||
|
||||
function firstNonempty(row, headers) {
|
||||
for (const header of headers) {
|
||||
const value = String(row[header.toLowerCase()] ?? '').trim();
|
||||
if (value) return value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function transformExcel(buffer) {
|
||||
const workbook = XLSX.read(buffer, { type: 'buffer' });
|
||||
const toRows = (kind, otherKind) => {
|
||||
const sheetName = workbook.SheetNames.find((name) =>
|
||||
name.toLowerCase().includes(kind) && !name.toLowerCase().includes(otherKind))
|
||||
|| workbook.SheetNames.find((name) => name.toLowerCase().includes(kind));
|
||||
if (!sheetName) return [];
|
||||
return XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], { defval: '' }).map((row) =>
|
||||
Object.fromEntries(Object.entries(row).map(([header, value]) => [header.trim().toLowerCase(), value])));
|
||||
};
|
||||
|
||||
const speakerById = new Map();
|
||||
const speakersByEmail = new Map();
|
||||
for (const row of toRows('speaker', 'session')) {
|
||||
const id = firstNonempty(row, ['Speaker Id']);
|
||||
const email = firstNonempty(row, ['Email']);
|
||||
const fullName = [firstNonempty(row, ['FirstName']), firstNonempty(row, ['LastName'])]
|
||||
.filter(Boolean).join(' ');
|
||||
if (!id || !email || !fullName) continue;
|
||||
speakerById.set(id, email);
|
||||
if (!speakersByEmail.has(email)) {
|
||||
speakersByEmail.set(email, {
|
||||
email,
|
||||
full_name: fullName,
|
||||
external_id: id,
|
||||
linkedin_url: firstNonempty(row, ['LinkedIn']) || null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const sessionsById = new Map();
|
||||
for (const row of toRows('session', 'speaker')) {
|
||||
const id = firstNonempty(row, ['Session Id']);
|
||||
const title = firstNonempty(row, ['Title']);
|
||||
const scheduledAt = Number(row['scheduled at']);
|
||||
const duration = Number(row['scheduled duration']);
|
||||
if (!id || !title || !scheduledAt) continue;
|
||||
const area = firstNonempty(row, ['Themenfeld / Area of Topic', 'Area', 'Topic']) || null;
|
||||
if (!sessionsById.has(id)) {
|
||||
sessionsById.set(id, {
|
||||
external_id: id,
|
||||
title,
|
||||
description: firstNonempty(row, ['Description']) || null,
|
||||
room: firstNonempty(row, ['Room']) || null,
|
||||
...excelSerialToTime(scheduledAt, duration),
|
||||
is_service_session: /service|break|lunch|closing|plenum/i.test(firstNonempty(row, ['Session Format'])),
|
||||
level: firstNonempty(row, ['Level']) || null,
|
||||
area,
|
||||
speakers: [],
|
||||
});
|
||||
}
|
||||
const session = sessionsById.get(id);
|
||||
if (!session.area && area) session.area = area;
|
||||
const speakerIds = firstNonempty(row, ['Speaker Ids', 'Speaker Id'])
|
||||
.split(',').map((speakerId) => speakerId.trim()).filter(Boolean);
|
||||
for (const speakerId of speakerIds) {
|
||||
const email = speakerById.get(speakerId);
|
||||
if (email && !session.speakers.includes(email)) session.speakers.push(email);
|
||||
}
|
||||
}
|
||||
|
||||
return { payload: { speakers: [...speakersByEmail.values()], sessions: [...sessionsById.values()] } };
|
||||
}
|
||||
|
||||
module.exports = { transformExcel };
|
||||
Reference in new issue
Block a user