fix: import localized topics and flattened Sessionize speakers

This commit is contained in:
Lago committed 2026-10-10 01:50:08 +02:00
1 parent 5c93d4a0cb
commit 648daa0794
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;