added stringin filter mode
This commit is contained in:
parent
1a784ade85
commit
a8465ff128
@ -92,7 +92,12 @@ SampleDetail:
|
|||||||
sample_references:
|
sample_references:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
properties:
|
||||||
|
sample_id:
|
||||||
$ref: 'api.yaml#/components/schemas/Id'
|
$ref: 'api.yaml#/components/schemas/Id'
|
||||||
|
relation:
|
||||||
|
type: string
|
||||||
|
example: part to this sample
|
||||||
measurements:
|
measurements:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
@ -8,10 +8,9 @@ const iconv = require('iconv-lite');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const stages = {
|
const stages = {
|
||||||
materials: false,
|
materials: true,
|
||||||
samples: true,
|
samples: true,
|
||||||
measurements: false,
|
dpt: true
|
||||||
dpt: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const docs = [
|
const docs = [
|
||||||
@ -46,17 +45,12 @@ let samples = [];
|
|||||||
let normMaster = {};
|
let normMaster = {};
|
||||||
let sampleDevices = {};
|
let sampleDevices = {};
|
||||||
const sampleReferences = []; // references to other samples in format {sample, referencedSample, relation}
|
const sampleReferences = []; // references to other samples in format {sample, referencedSample, relation}
|
||||||
let comments = [];
|
let commentsLog = [];
|
||||||
|
let customFieldsLog = [];
|
||||||
|
const vzValues = {}; // vz values from comments
|
||||||
|
const dptLog = [];
|
||||||
|
|
||||||
// TODO: conditions
|
// TODO: conditions
|
||||||
// TODO: comment and reference handling
|
|
||||||
|
|
||||||
// TODO: measurement device to spectrum
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: check last color errors (filter out already taken) use location and device for user, upload to BIC
|
|
||||||
|
|
||||||
// TODO: samples, conditions
|
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
@ -77,32 +71,19 @@ async function main() {
|
|||||||
await importCsv(docs[i]);
|
await importCsv(docs[i]);
|
||||||
await allSamples();
|
await allSamples();
|
||||||
await saveSamples();
|
await saveSamples();
|
||||||
console.log(samples);
|
await allKfVz();
|
||||||
} // TODO: get sample by number, implement smple references
|
}
|
||||||
fs.writeFileSync('./data_import/comments.txt', comments.join('\r\n'));
|
// write logs
|
||||||
// if (1) { // TODO: KfVz
|
fs.writeFileSync('./data_import/comments.txt', commentsLog.join('\r\n'));
|
||||||
// console.log('-------- META ----------');
|
fs.writeFileSync('./data_import/customFields.txt', customFieldsLog.join('\r\n'));
|
||||||
// await importCsv(metaDoc);
|
fs.writeFileSync('./data_import/sampleReferences.txt', sampleReferences.map(e => JSON.stringify(e)).join('\r\n'));
|
||||||
// await allSamples();
|
fs.writeFileSync('./data_import/sampleReferences.json', JSON.stringify(sampleReferences));
|
||||||
// await saveSamples();
|
|
||||||
// }
|
await sampleReferencesSave();
|
||||||
// if (1) {
|
|
||||||
// console.log('-------- KF ----------');
|
|
||||||
// await importCsv(kfDoc);
|
|
||||||
// await allSamples();
|
|
||||||
// await saveSamples();
|
|
||||||
// await allKfVz();
|
|
||||||
// }
|
|
||||||
// if (1) {
|
|
||||||
// console.log('-------- VZ ----------');
|
|
||||||
// await importCsv(vzDoc);
|
|
||||||
// await allSamples();
|
|
||||||
// await saveSamples();
|
|
||||||
// await allKfVz();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
if (stages.dpt) { // DPT
|
if (stages.dpt) { // DPT
|
||||||
await allDpts();
|
await allDpts();
|
||||||
|
fs.writeFileSync('./data_import/sdptLog.txt', dptLog.join('\r\n'));
|
||||||
}
|
}
|
||||||
if (0) { // pdf test
|
if (0) { // pdf test
|
||||||
console.log(await readPdf('N28_BN05-OX023_2019-07-16.pdf'));
|
console.log(await readPdf('N28_BN05-OX023_2019-07-16.pdf'));
|
||||||
@ -226,18 +207,20 @@ async function allDpts() {
|
|||||||
res.data.forEach(sample => {
|
res.data.forEach(sample => {
|
||||||
sampleIds[sample.number] = sample._id;
|
sampleIds[sample.number] = sample._id;
|
||||||
});
|
});
|
||||||
const dptRegex = /.*?_(.*?)_(\d+|\d+_\d+).DPT/;
|
const dptRegex = /(.*?)_(.*?)_(\d+|\d+_\d+).DPT/;
|
||||||
const dpts = fs.readdirSync(dptFiles);
|
const dpts = fs.readdirSync(dptFiles);
|
||||||
for (let i in dpts) {
|
for (let i in dpts) {
|
||||||
const regexRes = dptRegex.exec(dpts[i])
|
const regexRes = dptRegex.exec(dpts[i])
|
||||||
if (regexRes && sampleIds[regexRes[1]]) { // found matching sample
|
if (regexRes && sampleIds[regexRes[2]]) { // found matching sample
|
||||||
console.log(dpts[i]);
|
console.log(`${dpts[i]} -> ${regexRes[2]}`);
|
||||||
|
dptLog.push(`${dpts[i]}, ${regexRes[2]}`);
|
||||||
const f = fs.readFileSync(dptFiles + '\\' + dpts[i], 'utf-8');
|
const f = fs.readFileSync(dptFiles + '\\' + dpts[i], 'utf-8');
|
||||||
const data = {
|
const data = {
|
||||||
sample_id: sampleIds[regexRes[1]],
|
sample_id: sampleIds[regexRes[2]],
|
||||||
values: {},
|
values: {},
|
||||||
measurement_template
|
measurement_template
|
||||||
};
|
};
|
||||||
|
data.values.device = regexRes[1];
|
||||||
data.values.dpt = f.split('\r\n').map(e => e.split(','));
|
data.values.dpt = f.split('\r\n').map(e => e.split(','));
|
||||||
let rescale = false;
|
let rescale = false;
|
||||||
for (let i in data.values.dpt) {
|
for (let i in data.values.dpt) {
|
||||||
@ -259,16 +242,23 @@ async function allDpts() {
|
|||||||
data
|
data
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(dpts[i]);
|
console.log(dpts[i]);
|
||||||
|
if (err.response) {
|
||||||
console.error(err.response.data);
|
console.error(err.response.data);
|
||||||
|
errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${err.response.data}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(err);
|
||||||
|
errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${JSON.stringify(err)}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(`Could not find sample for ${dpts[i]} !!!!!!`);
|
console.log(`Could not find sample for ${dpts[i]}`);
|
||||||
|
errors.push(`Could not find sample for ${dpts[i]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: VZ from comments
|
|
||||||
async function allKfVz() {
|
async function allKfVz() {
|
||||||
let res = await axios({
|
let res = await axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@ -293,14 +283,16 @@ async function allKfVz() {
|
|||||||
sampleIds[sample.number] = sample._id;
|
sampleIds[sample.number] = sample._id;
|
||||||
});
|
});
|
||||||
for (let index in data) {
|
for (let index in data) {
|
||||||
console.info(`${index}/${data.length}`);
|
console.info(`KF/VZ ${index}/${data.length}`);
|
||||||
let sample = data[index];
|
let sample = data[index];
|
||||||
if (sample['Sample number'] !== '') {
|
|
||||||
let credentials = ['admin', 'Abc123!#'];
|
let credentials = ['admin', 'Abc123!#'];
|
||||||
if (sampleDevices[sample['Sample number']]) {
|
if (sampleDevices[sample['samplenumber']]) {
|
||||||
credentials = [sampleDevices[sample['Sample number']], '2020DeFinMachen!']
|
credentials = [sampleDevices[sample['samplenumber']], '2020DeFinMachen!']
|
||||||
}
|
}
|
||||||
if (sample['KF in Gew%']) {
|
if (!sample['vz(ml/g)'] && vzValues[sample['samplenumber']]) { // fill in VZ values from comments
|
||||||
|
sample['vz(ml/g)'] = vzValues[sample['samplenumber']];
|
||||||
|
}
|
||||||
|
if (sample['kfingew%']) {
|
||||||
await axios({
|
await axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: host + '/measurement/new',
|
url: host + '/measurement/new',
|
||||||
@ -309,16 +301,17 @@ async function allKfVz() {
|
|||||||
password: credentials[1]
|
password: credentials[1]
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
sample_id: sampleIds[sample['Sample number']],
|
sample_id: sampleIds[sample['samplenumber']],
|
||||||
measurement_template: kf_template,
|
measurement_template: kf_template,
|
||||||
values: {
|
values: {
|
||||||
'weight %': sample['KF in Gew%'],
|
'weight %': sample['kfingew%'],
|
||||||
'standard deviation': sample['Stabwn']
|
'standard deviation': sample['stabwn']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(sample['Sample number']);
|
console.log(sample['samplenumber']);
|
||||||
console.error(err.response.data);
|
console.error(err.response.data);
|
||||||
|
errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (sample['VZ (ml/g)']) {
|
if (sample['VZ (ml/g)']) {
|
||||||
@ -330,19 +323,19 @@ async function allKfVz() {
|
|||||||
password: credentials[1]
|
password: credentials[1]
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
sample_id: sampleIds[sample['Sample number']],
|
sample_id: sampleIds[sample['samplenumber']],
|
||||||
measurement_template: vz_template,
|
measurement_template: vz_template,
|
||||||
values: {
|
values: {
|
||||||
vz: sample['VZ (ml/g)']
|
vz: sample['vz(ml/g)']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(sample['Sample number']);
|
console.log(sample['samplenumber']);
|
||||||
console.error(err.response.data);
|
console.error(err.response.data);
|
||||||
|
errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function allSamples() {
|
async function allSamples() {
|
||||||
@ -375,7 +368,7 @@ async function allSamples() {
|
|||||||
|
|
||||||
|
|
||||||
for (let index in data) {
|
for (let index in data) {
|
||||||
console.info(`${index}/${data.length}`);
|
console.info(`SAMPLE LOAD ${index}/${data.length}`);
|
||||||
let sample = data[index];
|
let sample = data[index];
|
||||||
if (sample['granulate/Part'] === '') { // empty supplier fields
|
if (sample['granulate/Part'] === '') { // empty supplier fields
|
||||||
sample['granulate/Part'] = 'unknown';
|
sample['granulate/Part'] = 'unknown';
|
||||||
@ -400,11 +393,15 @@ async function allSamples() {
|
|||||||
const si = samples.length - 1; // sample index
|
const si = samples.length - 1; // sample index
|
||||||
if (samples[si].notes.custom_fields.hasOwnProperty('xRest')) { // reroute xRest property to comment
|
if (samples[si].notes.custom_fields.hasOwnProperty('xRest')) { // reroute xRest property to comment
|
||||||
samples[si].notes.comment = samples[si].notes.custom_fields.xRest;
|
samples[si].notes.comment = samples[si].notes.custom_fields.xRest;
|
||||||
|
commentsLog.push(sample['samplenumber'] + ' ' + samples[si].notes.comment);
|
||||||
delete samples[si].notes.custom_fields.xRest;
|
delete samples[si].notes.custom_fields.xRest;
|
||||||
}
|
}
|
||||||
if (Object.keys(samples[si].notes.custom_fields). length === 0) {
|
if (Object.keys(samples[si].notes.custom_fields).length === 0) { // delete empty custom fields
|
||||||
delete samples[si].notes.custom_fields;
|
delete samples[si].notes.custom_fields;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
customFieldsLog.push(sample['samplenumber'] + ' ' + JSON.stringify(samples[si].notes.custom_fields));
|
||||||
|
}
|
||||||
if (sample['materialnumber'] !== '' && material.numbers.find(e => e.number === sample['materialnumber'])) {
|
if (sample['materialnumber'] !== '' && material.numbers.find(e => e.number === sample['materialnumber'])) {
|
||||||
samples[si].color = material.numbers.find(e => e.number === sample['materialnumber']).color;
|
samples[si].color = material.numbers.find(e => e.number === sample['materialnumber']).color;
|
||||||
}
|
}
|
||||||
@ -432,7 +429,7 @@ async function allSamples() {
|
|||||||
|
|
||||||
async function saveSamples() {
|
async function saveSamples() {
|
||||||
for (let i in samples) {
|
for (let i in samples) {
|
||||||
console.info(`${i}/${samples.length}`);
|
console.info(`SAMPLE SAVE ${i}/${samples.length}`);
|
||||||
let credentials = ['admin', 'Abc123!#'];
|
let credentials = ['admin', 'Abc123!#'];
|
||||||
if (sampleDevices[samples[i].number]) {
|
if (sampleDevices[samples[i].number]) {
|
||||||
console.log(sampleDevices[samples[i].number]);
|
console.log(sampleDevices[samples[i].number]);
|
||||||
@ -450,13 +447,65 @@ async function saveSamples() {
|
|||||||
if (err.response.data.status && err.response.data.status !== 'Sample number already taken') {
|
if (err.response.data.status && err.response.data.status !== 'Sample number already taken') {
|
||||||
console.log(samples[i]);
|
console.log(samples[i]);
|
||||||
console.error(err.response.data);
|
console.error(err.response.data);
|
||||||
errors.push(`Upload for ${JSON.stringify(samples[i])} failed: ${JSON.stringify(err.response.data)}`)
|
errors.push(`Upload for ${JSON.stringify(samples[i])} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.info('saved all samples');
|
console.info('saved all samples');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sampleReferencesSave() {
|
||||||
|
for (let i in sampleReferences) {
|
||||||
|
console.info(`SAMPLE REFERENCES ${i}/${sampleReferences.length}`);
|
||||||
|
let refRes = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: host + '/sample/number/' + sampleReferences[i].referencedSample,
|
||||||
|
auth: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'Abc123!#'
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(sampleReferences[i].referencedSample);
|
||||||
|
console.error(err.response.data);
|
||||||
|
errors.push(`Getting reference id for ${JSON.stringify(sampleReferences[i])} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
|
});
|
||||||
|
if (!refRes) continue;
|
||||||
|
let sampleRes = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: host + '/sample/number/' + sampleReferences[i].sample,
|
||||||
|
auth: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'Abc123!#'
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(sampleReferences[i].sample);
|
||||||
|
console.error(err.response.data);
|
||||||
|
errors.push(`Getting sample id for ${JSON.stringify(sampleReferences[i])} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
|
});
|
||||||
|
if (!sampleRes) continue;
|
||||||
|
sampleRes.data.notes.sample_references.push({sample_id: refRes.data._id, relation: sampleReferences[i].relation})
|
||||||
|
await axios({
|
||||||
|
method: 'put',
|
||||||
|
url: host + '/sample/' + sampleRes.data._id,
|
||||||
|
auth: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'Abc123!#'
|
||||||
|
},
|
||||||
|
data: {notes: {sample_references: sampleRes.data.notes.sample_references}}
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(sampleRes.data.notes.sample_references);
|
||||||
|
if (err.response.data) {
|
||||||
|
console.error(err.response.data);
|
||||||
|
errors.push(`Saving references for ${JSON.stringify(sampleRes.data)} failed: ${JSON.stringify(err.response.data)}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(err.response);
|
||||||
|
errors.push(`Saving references for ${JSON.stringify(sampleRes.data)} failed: ${JSON.stringify(err.response)}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function allMaterials() {
|
async function allMaterials() {
|
||||||
// materials = {};
|
// materials = {};
|
||||||
let res = await axios({
|
let res = await axios({
|
||||||
@ -497,7 +546,7 @@ async function allMaterials() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // new material
|
else { // new material
|
||||||
console.info(`${index}/${data.length} ${sample['materialname']}`);
|
console.info(`MATERIAL LOAD ${index}/${data.length} ${sample['materialname']}`);
|
||||||
materials[sample['materialname']] = {
|
materials[sample['materialname']] = {
|
||||||
name: trim(sample['materialname']),
|
name: trim(sample['materialname']),
|
||||||
supplier: trim(sample['supplier']),
|
supplier: trim(sample['supplier']),
|
||||||
@ -529,7 +578,7 @@ async function allMaterials() {
|
|||||||
async function saveMaterials() {
|
async function saveMaterials() {
|
||||||
const mKeys = Object.keys(materials)
|
const mKeys = Object.keys(materials)
|
||||||
for (let i in mKeys) {
|
for (let i in mKeys) {
|
||||||
console.info(`${i}/${mKeys.length}`);
|
console.info(`MATERIAL SAVE ${i}/${mKeys.length}`);
|
||||||
const material = _.cloneDeep(materials[mKeys[i]]);
|
const material = _.cloneDeep(materials[mKeys[i]]);
|
||||||
material.numbers = material.numbers.map(e => e.number).filter(e => e !== '').map(e => e.replace(/ /g, ''));
|
material.numbers = material.numbers.map(e => e.number).filter(e => e !== '').map(e => e.replace(/ /g, ''));
|
||||||
await axios({
|
await axios({
|
||||||
@ -716,60 +765,62 @@ function sampleDeviceMap() {
|
|||||||
|
|
||||||
function customFields (comment, sampleNumber) {
|
function customFields (comment, sampleNumber) {
|
||||||
const customFields = [
|
const customFields = [
|
||||||
{docKey: 'Versuchsreihe', dbKey: 'test series', regex: /Versuchsreihe (\d+),/, reference: false},
|
{docKey: 'Versuchsreihe', dbKey: 'test series', regex: /Versuchsreihe (\d+),/, category: 'customField'},
|
||||||
{docKey: 'Stillstand', dbKey: 'idle', regex: /(\d+ min)/, reference: false},
|
{docKey: 'Stillstand', dbKey: 'idle', regex: /Stillstand (\d+ min):/, category: 'customField'},
|
||||||
{docKey: 'Serienzyklus', dbKey: 'cycle', regex: /(\d+.) Serienzyklus (\(.*?\))/, reference: false},
|
{docKey: 'Serienzyklus', dbKey: 'cycle', regex: /(\d+.) Serienzyklus (\(.*?\))/, category: 'customField'},
|
||||||
{docKey: 'Berstdruck', dbKey: 'bursting pressure', regex: /Berstdruck: (.*?bar);/, reference: false},
|
{docKey: 'Berstdruck', dbKey: 'bursting pressure', regex: /Berstdruck: (.*?bar);/, category: 'customField'},
|
||||||
{docKey: 'gemessen am', dbKey: 'measured at', regex: /gemessen am (.*20\d\d)/, reference: false},
|
{docKey: 'gemessen am', dbKey: 'measured at', regex: /gemessen am (.*20\d\d)/, category: 'customField'},
|
||||||
{docKey: 'used for', dbKey: 'used for', regex: /used for (.*)/, reference: false},
|
{docKey: 'used for', dbKey: 'used for', regex: /used for (.*)/, category: 'customField'},
|
||||||
{docKey: 'Stabilized', dbKey: 'stabilized', regex: null, reference: false},
|
{docKey: 'Stabilized', dbKey: 'stabilized', regex: /Stabilized, (.*)/, category: 'customField'},
|
||||||
{docKey: 'parts from field', dbKey: 'parts from field', regex: null, reference: false},
|
{docKey: 'parts from field', dbKey: 'parts from field', regex: null, category: 'customField'},
|
||||||
{docKey: 'side', dbKey: 'side', regex: /(\S*?) side/, reference: false},
|
{docKey: 'side', dbKey: 'side', regex: /(\S*?) side/, category: 'customField'},
|
||||||
{docKey: 'Creep test', dbKey: 'creep test', regex: null, reference: false},
|
{docKey: 'Creep test', dbKey: 'creep test', regex: null, category: 'customField'},
|
||||||
{docKey: 'Variante', dbKey: 'variant', regex: /(.*)/, reference: false},
|
{docKey: 'Variante', dbKey: 'variant', regex: /(.*)/, category: 'customField'},
|
||||||
{docKey: 'Parameter', dbKey: 'parameter', regex: /Parameter (\d)/, reference: false},
|
{docKey: 'Parameter', dbKey: 'parameter', regex: /Parameter (\d)/, category: 'customField'},
|
||||||
{docKey: 'days without cooling', dbKey: 'days without cooling', regex: /(\d+) days without cooling/, reference: false},
|
{docKey: 'days without cooling', dbKey: 'days without cooling', regex: /(\d+) days without cooling/, category: 'customField'},
|
||||||
{docKey: 'Zyklus', dbKey: 'cycle', regex: /Zyklus (\d+ s)/, reference: false},
|
{docKey: 'Zyklus', dbKey: 'cycle', regex: /Zyklus (\d+ s)/, category: 'customField'},
|
||||||
{docKey: 'fast cure', dbKey: 'fast cure', regex: null, reference: false},
|
{docKey: 'fast cure', dbKey: 'fast cure', regex: null, category: 'customField'},
|
||||||
{docKey: 'Stoff gesperrt', dbKey: 'material blocked', regex: null, reference: false},
|
{docKey: 'Stoff gesperrt', dbKey: 'material blocked', regex: null, category: 'customField'},
|
||||||
{docKey: 'anwendungsbeschränkt', dbKey: 'limited application', regex: null, reference: false},
|
{docKey: 'anwendungsbeschränkt', dbKey: 'limited application', regex: null, category: 'customField'},
|
||||||
{docKey: 'für Neuanwendungen gesperrt', dbKey: 'blocked for new applications', regex: null, reference: false},
|
{docKey: 'für Neuanwendungen gesperrt', dbKey: 'blocked for new applications', regex: null, category: 'customField'},
|
||||||
{docKey: 'V', dbKey: 'test', regex: /V(\d+-\d+);/, reference: false},
|
{docKey: 'V', dbKey: 'test', regex: /V(\d+-\d+);/, category: 'customField'},
|
||||||
{docKey: 'Twz', dbKey: 'twz', regex: /Twz \(°C\): (\d+);/, reference: false},
|
{docKey: 'Twz', dbKey: 'twz', regex: /Twz \(°C\): (\d+);/, category: 'customField'},
|
||||||
{docKey: 'Pnach', dbKey: 'pressure after', regex: /Pnach \(bar\): (\d+);/, reference: false},
|
{docKey: 'Pnach', dbKey: 'pressure after', regex: /Pnach \(bar\): (\d+);/, category: 'customField'},
|
||||||
{docKey: 'Vein', dbKey: 'volume in', regex: /Vein \(ccm\/s\): (\d+)/, reference: false},
|
{docKey: 'Vein', dbKey: 'volume in', regex: /Vein \(ccm\/s\): (\d+)/, category: 'customField'},
|
||||||
{docKey: 'low emission', dbKey: 'low emission', regex: /low emission (.*?);/, reference: false},
|
{docKey: 'low emission', dbKey: 'low emission', regex: /low emission (\S+)[;]?/, category: 'customField'},
|
||||||
{docKey: 'aus', dbKey: 'from', regex: /aus (.*)/, reference: false},
|
{docKey: 'aus', dbKey: 'from', regex: /aus (.*)/, category: 'customField'},
|
||||||
{docKey: 'Erprobung', dbKey: 'trial', regex: /Erprobung (.*?);/, reference: false},
|
{docKey: 'Erprobung', dbKey: 'trial', regex: /Erprobung (.*?);/, category: 'customField'},
|
||||||
{docKey: 'Auftragsnummer', dbKey: 'job number', regex: /Auftragsnummer: (.*?);/, reference: false},
|
{docKey: 'Auftragsnummer', dbKey: 'job number', regex: /Auftragsnummer: (\S+)[;]?/, category: 'customField'},
|
||||||
{docKey: 'Wärmealterung', dbKey: 'heat aging', regex: /Wärmealterung: (.*)/, reference: false},
|
{docKey: 'Wärmealterung', dbKey: 'heat aging', regex: /Wärmealterung: (.*)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'outer wall', regex: /Steg.*?A: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'outer wall', regex: /Steg.*?A: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'inner wall', regex: /Steg.*?I: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'inner wall', regex: /Steg.*?I: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'support wall', regex: /Steg.*?S: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'support wall', regex: /Steg.*?S: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'outer wall degraded', regex: /Degradation:.*?A: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'outer wall degraded', regex: /Degradation:.*?A: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'inner wall degraded', regex: /Degradation:.*?I: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'inner wall degraded', regex: /Degradation:.*?I: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'support wall degraded', regex: /Degradation:.*?S: (\d+)/, reference: false},
|
{docKey: 'A: Wandung außen / I: Wandung innen / S: Wandung Steg', dbKey: 'support wall degraded', regex: /Degradation:.*?S: (\d+)/, category: 'customField'},
|
||||||
{docKey: 'Reines Polymer', dbKey: 'pure polymer', regex: null, reference: false},
|
{docKey: 'Reines Polymer', dbKey: 'pure polymer', regex: null, category: 'customField'},
|
||||||
{docKey: 'Rücksendung erforderlich', dbKey: 'return needed', regex: /(.*?,) Rücksendung erforderlich, (.*)/, reference: false},
|
{docKey: 'Rücksendung erforderlich', dbKey: 'return needed', regex: /(.*?,) Rücksendung erforderlich, (.*)/, category: 'customField'},
|
||||||
{docKey: 'Prio', dbKey: 'priority', regex: /Prio (\d+)/, reference: false},
|
{docKey: 'Prio', dbKey: 'priority', regex: /Prio (\d+)/, category: 'customField'},
|
||||||
{docKey: 'beanstandet', dbKey: 'faulty', regex: null, reference: false},
|
{docKey: 'beanstandet', dbKey: 'faulty', regex: null, category: 'customField'},
|
||||||
{docKey: 'aged', dbKey: 'aged', regex: /aged: (.*)/, reference: false},
|
{docKey: 'aged', dbKey: 'aged', regex: /aged: (.*)/, category: 'customField'},
|
||||||
{docKey: 'DOPPELT!!', dbKey: 'double', regex: null, reference: false},
|
{docKey: 'DOPPELT!!', dbKey: 'double', regex: null, category: 'customField'},
|
||||||
{docKey: 'Bauteil', dbKey: 'construction part', regex: /Bauteil (\S+)/, reference: false},
|
{docKey: 'Bauteil', dbKey: 'construction part', regex: /Bauteil (\S+)/, category: 'customField'},
|
||||||
{docKey: 'T =', dbKey: 'temperature', regex: /T = (\S+)/, reference: false},
|
{docKey: 'T =', dbKey: 'temperature', regex: /T = (\S+)/, category: 'customField'},
|
||||||
{docKey: 'nicht vorgealtert', dbKey: 'not preaged', regex: /nicht vorgealtert (.*)/, reference: false},
|
{docKey: 'nicht vorgealtert', dbKey: 'not preaged', regex: /nicht vorgealtert (.*)/, category: 'customField'},
|
||||||
{docKey: 'TS119', dbKey: 'TS119', regex: /TS119 (W\S+);/, reference: false},
|
{docKey: 'TS119', dbKey: 'TS119', regex: /TS119 (W\S+);/, category: 'customField'},
|
||||||
{docKey: 'GF vom Datenblatt', dbKey: 'glass fibre from data sheet', regex: null, reference: false},
|
{docKey: 'GF vom Datenblatt', dbKey: 'glass fibre from data sheet', regex: null, category: 'customField'},
|
||||||
{docKey: 'nach Datensatz', dbKey: 'according to dataset', regex: null, reference: false},
|
{docKey: 'nach Datensatz', dbKey: 'according to dataset', regex: null, category: 'customField'},
|
||||||
{docKey: 'Dosiergeschw', dbKey: 'metering speed', regex: /Dosiergeschw.*? (.*?min)/, reference: false},
|
{docKey: 'Dosiergeschw', dbKey: 'metering speed', regex: /Dosiergeschw.*? (.*?min)/, category: 'customField'},
|
||||||
{docKey: 'Einspritzgeschw', dbKey: 'injection speed', regex: /Einspritzgeschw.*? (.*\/s)/, reference: false},
|
{docKey: 'Einspritzgeschw', dbKey: 'injection speed', regex: /Einspritzgeschw.*? (.*\/s)/, category: 'customField'},
|
||||||
{docKey: 'Heizbänder', dbKey: 'heating lines', regex: /Heizbänder (.*)/, reference: false},
|
{docKey: 'Heizbänder', dbKey: 'heating lines', regex: /Heizbänder (.*)/, category: 'customField'},
|
||||||
{docKey: 'Verweilzeit', dbKey: 'dwell time', regex: /Verweilzeit (.*?min)/, reference: false},
|
{docKey: 'Verweilzeit', dbKey: 'dwell time', regex: /Verweilzeit (.*?min)/, category: 'customField'},
|
||||||
{docKey: 'Probe', dbKey: 'belongs to', regex: /Probe (\S*\d+)/, reference: true},
|
{docKey: 'Probe', dbKey: 'belongs to', regex: /Probe (\S*\d+)/, category: 'reference'},
|
||||||
{docKey: 'zu', dbKey: 'belongs to', regex: /zu (\S*\d+)/, reference: true},
|
{docKey: 'zu', dbKey: 'belongs to', regex: /zu (\S*\d+)/, category: 'reference'},
|
||||||
{docKey: 'granulate zu', dbKey: 'granulate to', regex: /granulate zu.* (\S*\d+)/, reference: true},
|
{docKey: 'granulate zu', dbKey: 'granulate to', regex: /granulate zu.* (\S*\d+)/, category: 'reference'},
|
||||||
{docKey: 'construction part', dbKey: 'construction part', regex: /(?<!granulate)construction part.* (\S*\d+)/, reference: true},
|
{docKey: 'construction part', dbKey: 'construction part', regex: /(?<!granulate)construction part.* (\S*\d+)/, category: 'reference'},
|
||||||
|
{docKey: 'VZ =', dbKey: 'vz', regex: /VZ = (\d+) cm³\/g/, category: 'vz'},
|
||||||
|
{docKey: 'VWZ', dbKey: 'vwz', regex: /(\d+ min) VWZ \//, category: 'customField'},
|
||||||
|
{docKey: 'VZ:', dbKey: 'vz', regex: /VZ: ([0-9.,]+) mL\/g[;]?/, category: 'vz'}
|
||||||
];
|
];
|
||||||
const res = {}; // returned result
|
const res = {}; // returned result
|
||||||
const usedParts = []; // all substrings used for custom fields, subtract at the end, as some parts are used multiple times
|
const usedParts = []; // all substrings used for custom fields, subtract at the end, as some parts are used multiple times
|
||||||
@ -779,9 +830,12 @@ function customFields (comment, sampleNumber) {
|
|||||||
const regexRes = cField.regex.exec(comment);
|
const regexRes = cField.regex.exec(comment);
|
||||||
if (regexRes) {
|
if (regexRes) {
|
||||||
usedParts.push(regexRes[0]);
|
usedParts.push(regexRes[0]);
|
||||||
if (cField.reference) {
|
if (cField.category === 'reference') {
|
||||||
sampleReferences.push({sample: sampleNumber, referencedSample: regexRes[1], relation: cField.dbKey});
|
sampleReferences.push({sample: sampleNumber, referencedSample: regexRes[1], relation: cField.dbKey});
|
||||||
}
|
}
|
||||||
|
else if (cField.category === 'vz') {
|
||||||
|
vzValues[sampleNumber] = regexRes[1];
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
res[cField.dbKey] = regexRes.filter((e, i) => i > 0).join(' ');
|
res[cField.dbKey] = regexRes.filter((e, i) => i > 0).join(' ');
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ describe('/sample', () => {
|
|||||||
url: '/samples?status=all&fields[]=number&fields[]=batch&filters[]=%7B%22mode%22%3A%22xx%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
url: '/samples?status=all&fields[]=number&fields[]=batch&filters[]=%7B%22mode%22%3A%22xx%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
res: {status: 'Invalid body format', details: '"filters[0].mode" must be one of [eq, ne, lt, lte, gt, gte, in, nin]'}
|
res: {status: 'Invalid body format', details: '"filters[0].mode" must be one of [eq, ne, lt, lte, gt, gte, in, nin, stringin]'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('rejects an filter field not existing', done => {
|
it('rejects an filter field not existing', done => {
|
||||||
|
@ -758,6 +758,9 @@ function filterQueries (filters) {
|
|||||||
if (e.mode === 'or') { // allow or queries (needed for $ne added)
|
if (e.mode === 'or') { // allow or queries (needed for $ne added)
|
||||||
return {['$' + e.mode]: e.values};
|
return {['$' + e.mode]: e.values};
|
||||||
}
|
}
|
||||||
|
else if (e.mode === 'stringin') {
|
||||||
|
return {[e.field]: {['$in']: [new RegExp(e.values[0])]}};
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return {[e.field]: {['$' + e.mode]: (e.mode.indexOf('in') >= 0 ? e.values : e.values[0])}}; // add filter criteria as {field: {$mode: value}}, only use first value when mode is not in/nin
|
return {[e.field]: {['$' + e.mode]: (e.mode.indexOf('in') >= 0 ? e.values : e.values[0])}}; // add filter criteria as {field: {$mode: value}}, only use first value when mode is not in/nin
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ export default class SampleValidate {
|
|||||||
csv: Joi.boolean().default(false),
|
csv: Joi.boolean().default(false),
|
||||||
fields: Joi.array().items(Joi.string().pattern(new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm'))).default(['_id','number','type','batch','material_id','color','condition','note_id','user_id','added']).messages({'string.pattern.base': 'Invalid field name'}),
|
fields: Joi.array().items(Joi.string().pattern(new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm'))).default(['_id','number','type','batch','material_id','color','condition','note_id','user_id','added']).messages({'string.pattern.base': 'Invalid field name'}),
|
||||||
filters: Joi.array().items(Joi.object({
|
filters: Joi.array().items(Joi.object({
|
||||||
mode: Joi.string().valid('eq', 'ne', 'lt', 'lte', 'gt', 'gte', 'in', 'nin'),
|
mode: Joi.string().valid('eq', 'ne', 'lt', 'lte', 'gt', 'gte', 'in', 'nin', 'stringin'),
|
||||||
field: Joi.string().pattern(new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm')).messages({'string.pattern.base': 'Invalid filter field name'}),
|
field: Joi.string().pattern(new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm')).messages({'string.pattern.base': 'Invalid filter field name'}),
|
||||||
values: Joi.array().items(Joi.alternatives().try(Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object())).min(1)
|
values: Joi.array().items(Joi.alternatives().try(Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object())).min(1)
|
||||||
})).default([])
|
})).default([])
|
||||||
|
Reference in New Issue
Block a user