Archived
2

small fixes

This commit is contained in:
VLE2FE 2020-08-20 10:42:55 +02:00
parent e8529c2b23
commit 092c547fff
3 changed files with 296 additions and 117 deletions

View File

@ -9,27 +9,204 @@ const _ = require('lodash');
const stages = { const stages = {
materials: true, materials: true,
samples: false, samples: true,
dpt: false dpt: true,
dptFromList: false // ignores dpts not on the dptList
} }
const dptList = [
'Eh01_Eh3001_01_csv.DPT',
'Eh01_Eh3001_02_csv.DPT',
'Eh01_Eh3001_03_csv.DPT',
'Eh01_Eh3002_01_csv.DPT',
'Eh01_Eh3002_02_csv.DPT',
'Eh01_Eh3002_03_csv.DPT',
'Eh01_Eh3003_01_csv.DPT',
'Eh01_Eh3003_02_csv.DPT',
'Eh01_Eh3003_03_csv.DPT',
'Eh01_Eh3004_01_csv.DPT',
'Eh01_Eh3004_02_csv.DPT',
'Eh01_Eh3004_03_csv.DPT',
'Eh01_Eh3005_01_csv.DPT',
'Eh01_Eh3005_02_csv.DPT',
'Eh01_Eh3005_03_csv.DPT',
'Eh01_Eh3005_04_csv.DPT',
'Eh01_Eh3005_05_csv.DPT',
'Eh01_Eh3005_06_csv.DPT',
'Eh01_Eh3005_07_csv.DPT',
'Eh01_Eh3005_08_csv.DPT',
'Eh01_Eh3005_09_csv.DPT',
'Eh01_Eh3006_01_csv.DPT',
'Eh01_Eh3006_02_csv.DPT',
'Eh01_Eh3006_03_csv.DPT',
'Eh01_Eh3007_01_csv.DPT',
'Eh01_Eh3007_02_csv.DPT',
'Eh01_Eh3007_03_csv.DPT',
'Eh01_Eh3008_01_csv.DPT',
'Eh01_Eh3008_02_csv.DPT',
'Eh01_Eh3008_03_csv.DPT',
'Eh01_Eh3009_01_csv.DPT',
'Eh01_Eh3009_02_csv.DPT',
'Eh01_Eh3009_03_csv.DPT',
'Eh01_Eh3010_01_csv.DPT',
'Eh01_Eh3010_02_csv.DPT',
'Eh01_Eh3010_03_csv.DPT',
'Eh01_Eh3011_01_csv.DPT',
'Eh01_Eh3011_02_csv.DPT',
'Eh01_Eh3011_03_csv.DPT',
'Eh01_Eh3012_01_csv.DPT',
'Eh01_Eh3012_02_csv.DPT',
'Eh01_Eh3012_03_csv.DPT',
'Eh01_Eh3013_01_csv.DPT',
'Eh01_Eh3013_02_csv.DPT',
'Eh01_Eh3013_03_csv.DPT',
'Eh01_Eh3013_04_csv.DPT',
'Eh01_Eh3013_05_csv.DPT',
'Eh01_Eh3013_06_csv.DPT',
'Eh01_Eh3013_07_csv.DPT',
'Eh01_Eh3013_08_csv.DPT',
'Eh01_Eh3013_09_csv.DPT',
'Eh01_Eh3014_01_csv.DPT',
'Eh01_Eh3014_02_csv.DPT',
'Eh01_Eh3014_03_csv.DPT',
'Eh01_Eh3015_01_csv.DPT',
'Eh01_Eh3015_02_csv.DPT',
'Eh01_Eh3015_03_csv.DPT',
'Eh01_Eh3016_01_csv.DPT',
'Eh01_Eh3016_02_csv.DPT',
'Eh01_Eh3016_03_csv.DPT',
'Eh01_Eh3017_01_csv.DPT',
'Eh01_Eh3017_02_csv.DPT',
'Eh01_Eh3017_03_csv.DPT',
'Eh01_Eh3018_01_csv.DPT',
'Eh01_Eh3018_02_csv.DPT',
'Eh01_Eh3018_03_csv.DPT',
'Eh01_Eh3019_01_csv.DPT',
'Eh01_Eh3019_02_csv.DPT',
'Eh01_Eh3019_03_csv.DPT',
'Eh01_Eh3020_01_csv.DPT',
'Eh01_Eh3020_02_csv.DPT',
'Eh01_Eh3020_03_csv.DPT',
'Eh01_Eh3021_01_csv.DPT',
'Eh01_Eh3021_02_csv.DPT',
'Eh01_Eh3021_03_csv.DPT',
'Eh01_Eh3022_01_csv.DPT',
'Eh01_Eh3022_02_csv.DPT',
'Eh01_Eh3022_03_csv.DPT',
'Eh01_Eh4001_01_csv.DPT',
'Eh01_Eh4001_02_csv.DPT',
'Eh01_Eh4001_03_csv.DPT',
'Eh01_Eh4001_04_csv.DPT',
'Eh01_Eh4001_05_csv.DPT',
'Eh01_Eh4001_06_csv.DPT',
'Eh01_Eh4001_07_csv.DPT',
'Eh01_Eh4001_08_csv.DPT',
'Eh01_Eh4001_09_csv.DPT',
'Eh01_Eh4002_01_csv.DPT',
'Eh01_Eh4002_02_csv.DPT',
'Eh01_Eh4002_03_csv.DPT',
'Eh01_Eh4003_01_csv.DPT',
'Eh01_Eh4003_02_csv.DPT',
'Eh01_Eh4003_03_csv.DPT',
'Eh01_Eh4003_04_csv.DPT',
'Eh01_Eh4003_05_csv.DPT',
'Eh01_Eh4003_06_csv.DPT',
'Eh01_Eh4003_07_csv.DPT',
'Eh01_Eh4003_08_csv.DPT',
'Eh01_Eh4003_09_csv.DPT',
'Eh01_Eh4004_01_csv.DPT',
'Eh01_Eh4004_02_csv.DPT',
'Eh01_Eh4004_03_csv.DPT',
'Eh01_Eh4004_04_csv.DPT',
'Eh01_Eh4004_05_csv.DPT',
'Eh01_Eh4004_06_csv.DPT',
'Eh01_Eh4004_07_csv.DPT',
'Eh01_Eh4004_08_csv.DPT',
'Eh01_Eh4004_09_csv.DPT',
'Eh01_Eh4005_01_csv.DPT',
'Eh01_Eh4005_02_csv.DPT',
'Eh01_Eh4005_03_csv.DPT',
'Eh01_Eh4005_04_csv.DPT',
'Eh01_Eh4005_05_csv.DPT',
'Eh01_Eh4005_06_csv.DPT',
'Eh01_Eh4005_07_csv.DPT',
'Eh01_Eh4005_08_csv.DPT',
'Eh01_Eh4005_09_csv.DPT',
'Eh01_Eh4006_01_csv.DPT',
'Eh01_Eh4006_02_csv.DPT',
'Eh01_Eh4006_03_csv.DPT',
'Eh01_Eh4006_04_csv.DPT',
'Eh01_Eh4006_05_csv.DPT',
'Eh01_Eh4006_06_csv.DPT',
'Eh01_Eh4006_07_csv.DPT',
'Eh01_Eh4006_08_csv.DPT',
'Eh01_Eh4006_09_csv.DPT',
'Eh01_Eh4007_01_csv.DPT',
'Eh01_Eh4007_02_csv.DPT',
'Eh01_Eh4007_03_csv.DPT',
'Eh01_Eh4007_04_csv.DPT',
'Eh01_Eh4007_05_csv.DPT',
'Eh01_Eh4007_06_csv.DPT',
'Eh01_Eh4007_07_csv.DPT',
'Eh01_Eh4007_08_csv.DPT',
'Eh01_Eh4007_09_csv.DPT',
'Eh01_Eh4008_01_csv.DPT',
'Eh01_Eh4008_02_csv.DPT',
'Eh01_Eh4008_03_csv.DPT',
'Eh01_Eh4008_04_csv.DPT',
'Eh01_Eh4008_05_csv.DPT',
'Eh01_Eh4008_06_csv.DPT',
'Eh01_Eh4008_07_csv.DPT',
'Eh01_Eh4008_08_csv.DPT',
'Eh01_Eh4008_09_csv.DPT',
'Eh01_Eh4009_01_csv.DPT',
'Eh01_Eh4009_02_csv.DPT',
'Eh01_Eh4009_03_csv.DPT',
'Eh01_Eh4009_04_csv.DPT',
'Eh01_Eh4009_05_csv.DPT',
'Eh01_Eh4009_06_csv.DPT',
'Eh01_Eh4009_07_csv.DPT',
'Eh01_Eh4009_08_csv.DPT',
'Eh01_Eh4009_09_csv.DPT',
'Eh01_Eh4010_01_csv.DPT',
'Eh01_Eh4010_02_csv.DPT',
'Eh01_Eh4010_03_csv.DPT',
'Eh01_Eh4010_04_csv.DPT',
'Eh01_Eh4010_05_csv.DPT',
'Eh01_Eh4010_06_csv.DPT',
'Eh01_Eh4010_07_csv.DPT',
'Eh01_Eh4010_08_csv.DPT',
'Eh01_Eh4010_09_csv.DPT',
'Eh01_Eh4011_01_csv.DPT',
'Eh01_Eh4011_02_csv.DPT',
'Eh01_Eh4011_03_csv.DPT',
'Eh01_Eh4011_04_csv.DPT',
'Eh01_Eh4011_05_csv.DPT',
'Eh01_Eh4011_06_csv.DPT',
'Eh01_Eh4011_07_csv.DPT',
'Eh01_Eh4011_08_csv.DPT',
'Eh01_Eh4011_09_csv.DPT'
];
const docs = [ const docs = [
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv", "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPPD_DPPD-frei.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_B.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_WaP.csv", // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_B.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_WaP.csv",
]; ];
const errors = []; const errors = [];
const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\nmDocs'; // NormMaster Documents const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\nmDocs'; // NormMaster Documents
const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT'; // Spectrum files // const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT'; // Spectrum files
const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT_DPPD'; // Spectrum files
const host = 'http://localhost:3000'; const host = 'http://localhost:3000';
// const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; // const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
const requiredProperties = ['samplenumber','materialnumber','materialname','supplier','reinforcementmaterial','material','granulate/part','color','charge/batch','comments']; const requiredProperties = ['samplenumber','materialnumber','materialname','supplier','reinforcementmaterial','material','granulate/part','color','charge/batch','comments'];
@ -81,7 +258,7 @@ async function main() {
for (let i in docs) { for (let i in docs) {
await importCsv(docs[i]); await importCsv(docs[i]);
await allMaterials(); await allMaterials();
// await saveMaterials(); await saveMaterials();
} }
fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor)); fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor));
fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog)); fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog));
@ -140,6 +317,7 @@ async function importCsv(doc) {
'charge/batchgranulate/part': 'charge/batch', 'charge/batchgranulate/part': 'charge/batch',
'charge': 'charge/batch', 'charge': 'charge/batch',
'anmerkung': 'comments', 'anmerkung': 'comments',
'vz': 'vz(ml/g)',
'vz[ml/g]': 'vz(ml/g)', 'vz[ml/g]': 'vz(ml/g)',
'vz[cm³/g]': 'vz(ml/g)', 'vz[cm³/g]': 'vz(ml/g)',
'abbau(%)': 'degradation(%)', 'abbau(%)': 'degradation(%)',
@ -247,116 +425,118 @@ async function allDpts() {
res.data.forEach(sample => { res.data.forEach(sample => {
sampleIds[sample.number] = sample._id; sampleIds[sample.number] = sample._id;
}); });
const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+[_.]\d+)(_JDX)?[.]{1,2}(DPT|csv|CSV|JDX)/; const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+[_.]\d+)(_JDX|_csv)?[.]{1,2}(DPT|csv|CSV|JDX)/;
const dpts = fs.readdirSync(dptFiles); const dpts = fs.readdirSync(dptFiles);
for (let i in dpts) { for (let i in dpts) {
let regexInput; if (!stages.dptFromList || dptList.indexOf(dpts[i]) >= 0) { // if list option active, only use from filter
const bjRes = /^(Bj[FT]?)\s?([a-z0-9_]*)_JDX.DPT/.exec(dpts[i]); let regexInput;
if (bjRes) { // correct Bj numbers with space const bjRes = /^(Bj[FT]?)\s?([a-z0-9_]*)_JDX.DPT/.exec(dpts[i]);
regexInput = `Bj01_${bjRes[1]}${bjRes[2]}_0.DPT`; if (bjRes) { // correct Bj numbers with space
} regexInput = `Bj01_${bjRes[1]}${bjRes[2]}_0.DPT`;
else { // remove _JDX from name
regexInput = dpts[i].replace(/_JDX.*\./, '.');
}
const regexRes = dptRegex.exec(regexInput);
if (regexRes && !sampleIds[regexRes[2]]) { // when sample number includes an additional _x instead of having _x_x for spectrum description
regexRes[2] = `${regexRes[2]}_${regexRes[3].split('_')[0]}`;
}
let baseSample = null;
if (regexRes) {
baseSample = regexRes[2].split('_')[0];
if (baseSample === 'Wa11') { // as Wa11 samples use all the same material
baseSample = 'Wa11_B0_1';
} }
} else { // remove _JDX from name
if (regexRes && !sampleIds[regexRes[2]] && sampleIds[baseSample]) { // when number_abx does not exist but number regexInput = dpts[i].replace(/_JDX.*\./, '.');
dptSampleAddLog.push(`Trying to find ${baseSample}`); }
dptSampleAddLog.push(host + '/sample/' + sampleIds[baseSample]); const regexRes = dptRegex.exec(regexInput);
res = await axios({ // get base sample if (regexRes && !sampleIds[regexRes[2]]) { // when sample number includes an additional _x instead of having _x_x for spectrum description
method: 'get', regexRes[2] = `${regexRes[2]}_${regexRes[3].split('_')[0]}`;
url: host + '/sample/' + stripSpaces(sampleIds[baseSample]), }
auth: { let baseSample = null;
username: 'admin', if (regexRes) {
password: 'Abc123!#' baseSample = regexRes[2].split('_')[0];
if (baseSample === 'Wa11') { // as Wa11 samples use all the same material
baseSample = 'Wa11_B0_1';
} }
}).catch(err => { }
if (err.response) { if (regexRes && !sampleIds[regexRes[2]] && sampleIds[baseSample]) { // when number_abx does not exist but number
console.error(err.response.data); dptSampleAddLog.push(`Trying to find ${baseSample}`);
errors.push(`DPT Could not fetch sample ${baseSample}: ${JSON.stringify(err.response.data)}`); dptSampleAddLog.push(host + '/sample/' + sampleIds[baseSample]);
} res = await axios({ // get base sample
}); method: 'get',
if (res) { url: host + '/sample/' + stripSpaces(sampleIds[baseSample]),
const data = _.merge(_.pick(res.data, ['color', 'type', 'batch']),
{number: regexRes[2], condition: {}, notes: {}, material_id: res.data.material._id});
res = await axios({
method: 'post',
url: host + '/sample/new',
auth: { auth: {
username: res.data.user, username: 'admin',
password: res.data.user === 'admin' ? 'Abc123!#' : '2020DeFinMachen!' password: 'Abc123!#'
}, }
data
}).catch(err => { }).catch(err => {
if (err.response) { if (err.response) {
console.error(err.response.data); console.error(err.response.data);
errors.push(`DPT Could not save sample ${data}: ${err.response.data}`); errors.push(`DPT Could not fetch sample ${baseSample}: ${JSON.stringify(err.response.data)}`);
} }
}); });
if (res.data) { if (res) {
dptSampleAddLog.push(`${regexRes[2]} from ${baseSample}`) const data = _.merge(_.pick(res.data, ['color', 'type', 'batch']),
sampleIds[regexRes[2]] = res.data._id; {number: regexRes[2], condition: {}, notes: {}, material_id: res.data.material._id});
res = await axios({
method: 'post',
url: host + '/sample/new',
auth: {
username: res.data.user,
password: res.data.user === 'admin' ? 'Abc123!#' : '2020DeFinMachen!'
},
data
}).catch(err => {
if (err.response) {
console.error(err.response.data);
errors.push(`DPT Could not save sample ${data}: ${err.response.data}`);
}
});
if (res.data) {
dptSampleAddLog.push(`${regexRes[2]} from ${baseSample}`)
sampleIds[regexRes[2]] = res.data._id;
}
} }
} }
} if (regexRes && sampleIds[regexRes[2]]) { // found matching sample
if (regexRes && sampleIds[regexRes[2]]) { // found matching sample console.log(`${i}/${dpts.length} ${dpts[i]} -> ${regexRes[2]}`);
console.log(`${i}/${dpts.length} ${dpts[i]} -> ${regexRes[2]}`); dptLog.push(`${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[2]],
sample_id: sampleIds[regexRes[2]], values: {},
values: {}, measurement_template
measurement_template };
}; data.values.device = regexRes[1];
data.values.device = regexRes[1]; data.values.filename = dpts[i];
data.values.filename = dpts[i]; data.values.dpt = f.split('\r\n').map(e => e.split(',').map(e => parseFloat(e)));
data.values.dpt = f.split('\r\n').map(e => e.split(',').map(e => parseFloat(e))); let rescale = false;
let rescale = false; for (let i in data.values.dpt) {
for (let i in data.values.dpt) { if (data.values.dpt[i][1] > 10) {
if (data.values.dpt[i][1] > 10) { rescale = true;
rescale = true; break;
break; }
} }
} if (rescale) {
if (rescale) { data.values.dpt = data.values.dpt.map(e => [e[0], e[1] / 100]);
data.values.dpt = data.values.dpt.map(e => [e[0], e[1] / 100]);
}
await axios({
method: 'post',
url: host + '/measurement/new',
auth: {
username: 'admin',
password: 'Abc123!#'
},
data
}).catch(err => {
console.log(dpts[i]);
if (err.response) {
console.error(err.response.data);
errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${err.response.data}`);
} }
else { await axios({
console.error(err); method: 'post',
errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${JSON.stringify(err)}`); url: host + '/measurement/new',
} auth: {
}); username: 'admin',
} password: 'Abc123!#'
else { },
console.log(`Could not find sample for ${dpts[i]}`); data
if (regexRes) { }).catch(err => {
errors.push(`Could not find sample for ${dpts[i]}; [DEBUG] ${regexRes[2]}, ${!sampleIds[regexRes[2]]}, ${sampleIds[baseSample]}`); console.log(dpts[i]);
if (err.response) {
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 {
errors.push(`Could not find sample for ${dpts[i]} (did not match RegEx)`); console.log(`Could not find sample for ${dpts[i]}`);
if (regexRes) {
errors.push(`Could not find sample for ${dpts[i]}; [DEBUG] ${regexRes[2]}, ${!sampleIds[regexRes[2]]}, ${sampleIds[baseSample]}`);
}
else {
errors.push(`Could not find sample for ${dpts[i]} (did not match RegEx)`);
}
} }
} }
} }
@ -399,6 +579,7 @@ async function allMcVn() {
for (let index in data) { for (let index in data) {
console.info(`MC/VN ${index}/${data.length}`); console.info(`MC/VN ${index}/${data.length}`);
let sample = data[index]; let sample = data[index];
console.log(sample);
sample['samplenumber'] = sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, ''); sample['samplenumber'] = sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, '');
let credentials = ['admin', 'Abc123!#']; let credentials = ['admin', 'Abc123!#'];
if (sampleDevices[sample['samplenumber']]) { if (sampleDevices[sample['samplenumber']]) {
@ -671,10 +852,6 @@ async function allMaterials() {
// process all samples // process all samples
for (let index in data) { for (let index in data) {
let sample = data[index]; let sample = data[index];
// TODO: remove next if, only for duplicate m names
if (duplicateMNames.indexOf(sample['materialname']) >= 0) {
duplicateMNamesLog.push(sample);
}
if (sample['supplier'] === '') { // empty supplier fields if (sample['supplier'] === '') { // empty supplier fields
sample['supplier'] = 'unknown'; sample['supplier'] = 'unknown';
} }
@ -700,7 +877,7 @@ async function allMaterials() {
} }
} }
else { // new material else { // new material
// console.info(`MATERIAL LOAD ${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']),

View File

@ -4,7 +4,7 @@ import db from '../db';
const ModelSchema = new mongoose.Schema({ const ModelSchema = new mongoose.Schema({
group: {type: String, index: {unique: true}}, group: {type: String, index: {unique: true}},
models: [new mongoose.Schema({ models: [new mongoose.Schema({
name: {type: String, index: {unique: true}}, name: String,
url: String, url: String,
label: String label: String
} ,{ _id : false })] } ,{ _id : false })]

View File

@ -262,7 +262,9 @@ router.get('/samples', async (req, res, next) => {
// count total number of items before $skip and $limit, only works when from-id is not specified and spectra are not // count total number of items before $skip and $limit, only works when from-id is not specified and spectra are not
// included // included
if (!filters.fields.find(e => e.indexOf(globals.spectrum.spectrum + '.') >= 0) && !filters['from-id']) { if (!filters.fields.find(e =>
e.indexOf(globals.spectrum.spectrum + '.' + globals.spectrum.dpt) >= 0) && !filters['from-id']
) {
queryPtr.push({$facet: {count: [{$count: 'count'}], samples: []}}); queryPtr.push({$facet: {count: [{$count: 'count'}], samples: []}});
queryPtr = queryPtr[queryPtr.length - 1].$facet.samples; // add rest of aggregation pipeline into $facet queryPtr = queryPtr[queryPtr.length - 1].$facet.samples; // add rest of aggregation pipeline into $facet
} }