diff --git a/lib/www/server/api/middleware/event/get/html.js b/lib/www/server/api/middleware/event/get/html.js index 539a648..57f65da 100644 --- a/lib/www/server/api/middleware/event/get/html.js +++ b/lib/www/server/api/middleware/event/get/html.js @@ -10,7 +10,7 @@ const html = async function (req, res, next) { const query = req.query; query.sequence = req.params.sequence; const {events, sequences} = await prepare(req.params.project, query); - const seis = transform(events, sequences, {projectId: req.params.project}); + const seis = transform(events, sequences, {projectId: req.params.project, missingAsEvent: true}); const template = (await configuration.get(req.params.project, "sse/templates/0/template")) || defaultTemplatePath; // console.log("TEMPLATE", template); diff --git a/lib/www/server/api/middleware/event/get/pdf.js b/lib/www/server/api/middleware/event/get/pdf.js index 4fc6eee..95b98ce 100644 --- a/lib/www/server/api/middleware/event/get/pdf.js +++ b/lib/www/server/api/middleware/event/get/pdf.js @@ -19,7 +19,7 @@ const pdf = async function (req, res, next) { const query = req.query; query.sequence = req.params.sequence; const {events, sequences} = await prepare(req.params.project, query); - const seis = transform(events, sequences, {projectId: req.params.project}); + const seis = transform(events, sequences, {projectId: req.params.project, missingAsEvent: true}); const template = (await configuration.get(req.params.project, "sse/templates/0/template")) || defaultTemplatePath; const html = await render(seis, template); diff --git a/lib/www/server/lib/sse/prepare.js b/lib/www/server/lib/sse/prepare.js index 10000e2..aad3f2d 100644 --- a/lib/www/server/lib/sse/prepare.js +++ b/lib/www/server/lib/sse/prepare.js @@ -2,7 +2,8 @@ const { event, sequence, info } = require('../db'); async function prepare (project, query) { const events = await event.list(project, query); - const sequences = await sequence.list(project, query); + // Get missing shots by default + const sequences = await sequence.list(project, Object.assign({missing:true}, query)); const equipment = await info.get(null, "equipment"); for (const sequence of sequences) { const maxTstamp = sequence.ts1_final || sequence.ts1 || +Infinity; diff --git a/lib/www/server/lib/sse/transform.js b/lib/www/server/lib/sse/transform.js index 733a6b0..4f25457 100644 --- a/lib/www/server/lib/sse/transform.js +++ b/lib/www/server/lib/sse/transform.js @@ -6,6 +6,7 @@ function transform (events, sequences, opts = {}) { const exportQC = opts.exportQC !== false; const exportGeneral = opts.exportGeneral !== false; const exportMissing = opts.exportMissing !== false; + const missingAsEvent = opts.missingAsEvent; const output = { DglProjectId: opts.projectId, @@ -283,6 +284,35 @@ function transform (events, sequences, opts = {}) { // endpoint; these are not returned by default. if ("missing_final" in sequence) { SequenceObject.MissingShots = sequence.missing_final.map(s => s.point).sort(); + + // Add (pseudo-)events for missing shots + if (missingAsEvent) { + + // Create the ‘dummy’ missing shot events + const pseudoevents = SequenceObject.MissingShots.map( point => { + return { + ShotPointId: point, + EntryType: "Missing shot" + } + }); + + const isAscending = SequenceObject.Entries[0].ShotPointId <= SequenceObject.Entries[SequenceObject.Entries.length-1].ShotPointId; + + pseudoevents.forEach( pseudoevent => { + for (const index in SequenceObject.Entries) { + const ShotPointId = SequenceObject.Entries[index].ShotPointId; + const slotFound = isAscending + ? ShotPointId > pseudoevent.ShotPointId + : ShotPointId < pseudoevent.ShotPointId; + + if (slotFound) { + SequenceObject.Entries.splice(index, 0, pseudoevent); + break; + } + } + }); + + } } } }