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: [],
|
||||
|
||||
Reference in new issue
Block a user