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:
committed 2026-10-10 01:50:08 +02:00
1 parent 22de4a8645
commit 7f340b4c08
6 files changed
+226 -88

No files matched your search

+1 -81
View File
@@ -41,6 +41,7 @@
const http = require('http');
const XLSX = require('xlsx');
const { transformExcel } = require('./transform-excel');
const PDFDocument = require('pdfkit');
const SUPABASE_URL = (process.env.SUPABASE_URL || 'http://supabase_kong_Convivo:8000').replace(/\/$/, '');
@@ -288,87 +289,6 @@ function transform(data) {
return { payload: { speakers, sessions }, skippedSpeakers };
}
// Excel serial date (days since 1899-12-30) -> { date, start_time, end_time }.
// Sessionize exports "Scheduled At" as an Excel serial and "Scheduled Duration"
// in minutes. The epoch is 1899-12-30 (the Excel 1900 system, incl. its
// spurious 1900 leap day, which is irrelevant for modern dates).
function excelSerialToTime(serial, durationMin) {
const ms = Math.round((serial - 25569) * 86400 * 1000);
const d = new Date(ms);
const pad = (n) => String(n).padStart(2, '0');
const date = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
const start = `${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}`;
const endMs = ms + (durationMin || 0) * 60 * 1000;
const e = new Date(endMs);
const end = `${pad(e.getUTCHours())}:${pad(e.getUTCMinutes())}:${pad(e.getUTCSeconds())}`;
return { date, start_time: start, end_time: end };
}
// Transform the Sessionize "Sessions and speakers (advanced)" .xlsx into the
// sync_sessionize_excel payload. Two sheets:
// "Accepted sessions" -> sessions (Speaker Ids -> emails via the speakers sheet)
// "Accepted speakers" -> speakers (matched by email)
function transformExcel(buffer) {
const wb = XLSX.read(buffer, { type: 'buffer' });
const sheetName = (n) => wb.SheetNames.find((s) => s.toLowerCase().includes(n)) || null;
const toRows = (name) => {
const sn = sheetName(name);
if (!sn) return [];
return XLSX.utils.sheet_to_json(wb.Sheets[sn], { defval: '' });
};
const speakerRows = toRows('speaker');
const sessionRows = toRows('session');
// Speaker Id -> { email, full_name, linkedin_url }.
const speakerById = new Map();
const speakers = [];
for (const r of speakerRows) {
const id = String(r['Speaker Id'] ?? '').trim();
const email = String(r['Email'] ?? '').trim();
const first = String(r['FirstName'] ?? '').trim();
const last = String(r['LastName'] ?? '').trim();
const full = [first, last].filter(Boolean).join(' ').trim();
if (!id || !email || !full) continue;
const linkedin = String(r['LinkedIn'] ?? '').trim() || null;
speakerById.set(id, { email, full_name: full, linkedin_url: linkedin });
speakers.push({ email, full_name: full, external_id: id, linkedin_url: linkedin });
}
const sessions = [];
for (const r of sessionRows) {
const id = String(r['Session Id'] ?? '').trim();
const title = String(r['Title'] ?? '').trim();
const schedAt = Number(r['Scheduled At']);
const dur = Number(r['Scheduled Duration']);
if (!id || !title || !schedAt) continue;
const { date, start_time, end_time } = excelSerialToTime(schedAt, dur);
const speakerIds = String(r['Speaker Ids'] ?? '')
.split(',')
.map((s) => s.trim())
.filter(Boolean);
const speakerEmails = speakerIds.map((sid) => speakerById.get(sid)?.email).filter(Boolean);
sessions.push({
external_id: id,
title,
description: String(r['Description'] ?? '').trim() || null,
room: String(r['Room'] ?? '').trim() || null,
date,
start_time,
end_time,
is_service_session: /service|break|lunch|closing|plenum/i.test(String(r['Session Format'] ?? '')),
// Level + area (free-text classification for agenda filtering).
// The Sessionize "Sessions and speakers (advanced)" .xlsx may include
// "Level" and "Area"/"Topic" columns; we read them if present.
level: String(r['Level'] ?? '').trim() || null,
area: String(r['Area'] ?? r['Topic'] ?? '').trim() || null,
speakers: speakerEmails,
});
}
return { payload: { speakers, sessions } };
}
async function runSync(eventId) {
if (running) throw new Error('a sync is already running');
running = true;
+86
View File
@@ -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 };