feat: finalize ticket merging and speaker-aware imports
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
7f340b4c08
commit
fbc827c2b8
35 files changed
+1772
-348
No files matched your search
@@ -1,4 +1,5 @@
|
||||
const XLSX = require('xlsx');
|
||||
const { createHash } = require('node:crypto');
|
||||
|
||||
function excelSerialToTime(serial, durationMin) {
|
||||
const ms = Math.round((serial - 25569) * 86400 * 1000);
|
||||
@@ -21,13 +22,17 @@ function firstNonempty(row, headers) {
|
||||
|
||||
function transformExcel(buffer) {
|
||||
const workbook = XLSX.read(buffer, { type: 'buffer' });
|
||||
const readRows = (sheetName) => sheetName
|
||||
? XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], { defval: '' }).map((row) =>
|
||||
Object.fromEntries(Object.entries(row).map(([header, value]) => [header.trim().toLowerCase(), value])))
|
||||
: [];
|
||||
const toRows = (kind, otherKind) => {
|
||||
const sheetName = workbook.SheetNames.find((name) =>
|
||||
const sheetNames = workbook.SheetNames.filter((name) =>
|
||||
kind !== 'session' || !name.toLowerCase().includes('service'));
|
||||
const sheetName = 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])));
|
||||
|| sheetNames.find((name) => name.toLowerCase().includes(kind));
|
||||
return readRows(sheetName);
|
||||
};
|
||||
|
||||
const speakerById = new Map();
|
||||
@@ -50,21 +55,34 @@ function transformExcel(buffer) {
|
||||
}
|
||||
|
||||
const sessionsById = new Map();
|
||||
for (const row of toRows('session', 'speaker')) {
|
||||
const id = firstNonempty(row, ['Session Id']);
|
||||
const serviceSheet = workbook.SheetNames.find((name) => name.trim().toLowerCase() === 'service sessions');
|
||||
const sessionRows = [
|
||||
...toRows('session', 'speaker').map((row) => ({ row, serviceSheet: false })),
|
||||
...readRows(serviceSheet).map((row) => ({ row, serviceSheet: true })),
|
||||
];
|
||||
for (const entry of sessionRows) {
|
||||
const { row } = entry;
|
||||
const title = firstNonempty(row, ['Title']);
|
||||
const scheduledAt = Number(row['scheduled at']);
|
||||
const duration = Number(row['scheduled duration']);
|
||||
if (!id || !title || !scheduledAt) continue;
|
||||
if (!title || !Number.isFinite(scheduledAt) || scheduledAt <= 0) continue;
|
||||
const isServiceSession = entry.serviceSheet
|
||||
|| /service|break|lunch|closing|plenum/i.test(firstNonempty(row, ['Session Format']));
|
||||
const room = firstNonempty(row, ['Room']) || null;
|
||||
const timing = excelSerialToTime(scheduledAt, Number.isFinite(duration) ? duration : 0);
|
||||
const id = firstNonempty(row, ['Session Id']) || (isServiceSession
|
||||
? `excel-service:${createHash('sha256').update(JSON.stringify([title, room, timing.date, timing.start_time])).digest('hex')}`
|
||||
: '');
|
||||
if (!id) 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'])),
|
||||
room,
|
||||
...timing,
|
||||
is_service_session: isServiceSession,
|
||||
level: firstNonempty(row, ['Level']) || null,
|
||||
area,
|
||||
speakers: [],
|
||||
|
||||
@@ -89,4 +89,54 @@ test('service session classification and unscheduled-row filtering remain unchan
|
||||
assert.equal(payload.sessions.length, formats.length);
|
||||
assert.deepEqual(payload.sessions.map((session) => session.is_service_session), [true, true, true, true, true, false]);
|
||||
assert.ok(payload.sessions.every((session) => session.speakers.length === 0));
|
||||
});
|
||||
|
||||
test('explicit service sheet imports ID-less services alongside flattened talks without duplicates', () => {
|
||||
const service = { Title: 'Arrival & Coffee', Room: 'Main hall', 'Scheduled At': 46305.35416666667,
|
||||
'Scheduled Duration': 30 };
|
||||
const sheets = { 'Accepted sessions and speakers': [{ ...sessionRow, ...speakerRow }],
|
||||
' Service Sessions ': [service, service, { ...service, Title: 'Lunch', 'Scheduled At': 46305.5 },
|
||||
{ ...service, 'Session Id': 'service-existing', Title: 'Opening Keynote' }] };
|
||||
const first = transformSheets(sheets);
|
||||
assert.equal(first.sessions.length, 4);
|
||||
assert.equal(first.speakers.length, 1);
|
||||
assert.deepEqual(first.sessions[0].speakers, ['[email protected]']);
|
||||
assert.equal(first.sessions[0].external_id, 'session-1');
|
||||
const arrival = first.sessions[1];
|
||||
assert.match(arrival.external_id, /^excel-service:[a-f0-9]{64}$/);
|
||||
assert.equal(arrival.start_time, '08:30:00');
|
||||
assert.equal(arrival.end_time, '09:00:00');
|
||||
assert.equal(first.sessions[3].external_id, 'service-existing');
|
||||
for (const session of first.sessions.slice(1)) {
|
||||
assert.equal(session.is_service_session, true);
|
||||
assert.deepEqual(session.speakers, []);
|
||||
}
|
||||
assert.deepEqual(transformSheets(sheets), first);
|
||||
const reordered = transformSheets({ ...sheets, ' Service Sessions ': [...sheets[' Service Sessions ']].reverse() });
|
||||
assert.deepEqual(reordered.sessions.map(session => session.external_id).sort(),
|
||||
first.sessions.map(session => session.external_id).sort());
|
||||
});
|
||||
|
||||
test('ID-less format-marked services import but missing IDs on talks and missing titles never do', () => {
|
||||
const payload = transformSheets({ 'Accepted sessions': [
|
||||
{ ...sessionRow, 'Session Id': '', Title: 'Coffee break', 'Session Format': 'Coffee break' },
|
||||
{ ...sessionRow, 'Session Id': '', Title: 'Talk without ID' },
|
||||
{ ...sessionRow, Title: '', 'Session Format': '' },
|
||||
{ ...sessionRow, Title: '', 'Session Format': 'Service' },
|
||||
{ ...sessionRow, Title: 'Invalid schedule', 'Scheduled At': 'not a date' },
|
||||
] });
|
||||
assert.equal(payload.sessions.length, 1);
|
||||
assert.equal(payload.sessions[0].title, 'Coffee break');
|
||||
assert.equal(payload.sessions[0].is_service_session, true);
|
||||
});
|
||||
|
||||
test('service-only workbook uses title, room, date and start as identity, not duration or row order', () => {
|
||||
const row = { Title: 'Break', Room: 'Hall A', 'Scheduled At': 46305.5, 'Scheduled Duration': 15 };
|
||||
const first = transformSheets({ 'Service sessions': [row] });
|
||||
const edited = transformSheets({ 'Service sessions': [{ ...row, 'Scheduled Duration': 30, Description: 'Updated' }] });
|
||||
assert.equal(first.sessions[0].external_id, edited.sessions[0].external_id);
|
||||
assert.equal(edited.sessions[0].end_time, '12:30:00');
|
||||
const distinct = transformSheets({ 'Service sessions': [row, { ...row, Room: 'Hall B' },
|
||||
{ ...row, 'Scheduled At': 46305.6 }, { ...row, 'Scheduled At': 46306.5 }, { ...row, Title: 'Lunch' }] });
|
||||
assert.equal(new Set(distinct.sessions.map(session => session.external_id)).size, 5);
|
||||
});
|
||||
Reference in new issue
Block a user