Return events in structured sequence export format.

The events endpoint will return data in the format
agreed with Multiseis if the request has an
Accept: application/vnd.seis+json
header.

Related to #12.
This commit is contained in:
D. Berge
2020-09-26 22:55:11 +02:00
parent 78adb2bef7
commit acf58df59f
2 changed files with 157 additions and 2 deletions

View File

@@ -1,13 +1,13 @@
const json = require('./json');
const geojson = require('./geojson');
// const seis = require('./seis');
const seis = require('./seis');
module.exports = async function (req, res, next) {
try {
const handlers = {
"application/json": json,
"application/geo+json": geojson,
// "application/vnd.seis+json": seis
"application/vnd.seis+json": seis
};
const mimetype = req.accepts(Object.keys(handlers));

View File

@@ -0,0 +1,155 @@
const { event, sequence } = require('../../../../lib/db');
function transform (events, sequences) {
const output = {
Sequences: []
};
// NOTE: Events come in descending chronological
// order from the server.
for (const event of events.reverse()) {
const SequenceNumber = event.sequence;
if (SequenceNumber) {
const sequence = sequences.find(s => s.sequence = SequenceNumber);
if (!sequence) {
throw Error(`Sequence ${SequenceNumber} not found in sequence list`);
}
let SequenceObject = output.Sequences.find(s => s.SequenceNumber == SequenceNumber);
if (!SequenceObject) {
SequenceObject = {
SequenceNumber,
Entries: []
};
output.Sequences.push(SequenceObject);
}
if (event.labels.includes("FSP")) {
const entry = {
"EntryType": "Start of line recording",
"EntryTypeId": 3000,
"Comment": event.remarks.toString(),
"Heading": sequence.azimuth,
"IsReshoot": sequence.reshoot, // FIXME Add this property to sequence object
"IsUndershoot": false,
// NOTE https://gitlab.com/wgp/dougal/software/-/issues/12#note_419162674
"LineNumber": sequence.line.toString(),
"LineType": "Prime", // FIXME
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("FGSP")) {
const entry = {
"EntryType": "Start good",
"EntryTypeId": 3001,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("FCSP")) {
const entry = {
"EntryType": "Start charged",
"EntryTypeId": 3002,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("LGFFSP")) {
const entry = {
"EntryType": "Last good Full Fold",
"EntryTypeId": 3008,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("LCFFSP")) {
const entry = {
"EntryType": "Last charged Full Fold",
"EntryTypeId": 3009,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("FDSP")) {
const entry = {
"EntryType": "Midnight",
"EntryTypeId": 3003,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("LCSP")) {
const entry = {
"EntryType": "End charged",
"EntryTypeId": 3005,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("LGSP")) {
const entry = {
"EntryType": "End good",
"EntryTypeId": 3006,
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
if (event.labels.includes("LSP")) {
const entry = {
"EntryType": "End of line recording",
"EntryTypeId": 3007,
"IsNTBP": sequence.status == "ntbp",
"LineStatus": "Complete", // FIXME
"ShotPointId": event.point,
"Time": event.tstamp
}
SequenceObject.Entries.push(entry);
}
}
}
return output;
}
const seis = async function (req, res, next) {
try {
const events = await event.list(req.params.project, req.query);
const sequences = await sequence.list(req.params.project);
const response = transform(events, sequences);
res.status(200).send(response);
next();
} catch (err) {
next(err);
}
};
module.exports = seis;