improved mail service
This commit is contained in:
@ -47,7 +47,7 @@ let sampleDevices = {};
|
||||
const sampleReferences = []; // references to other samples in format {sample, referencedSample, relation}
|
||||
let commentsLog = [];
|
||||
let customFieldsLog = [];
|
||||
const vzValues = {}; // vz values from comments
|
||||
const vnValues = {}; // vn values from comments
|
||||
const dptLog = [];
|
||||
const dptSampleAddLog = []; // log samples created during dpt insertion
|
||||
const typeLog = [];
|
||||
@ -73,7 +73,7 @@ async function main() {
|
||||
await importCsv(docs[i]);
|
||||
await allSamples();
|
||||
await saveSamples();
|
||||
await allKfVz();
|
||||
await allMcVn();
|
||||
}
|
||||
// write logs
|
||||
fs.writeFileSync('./data_import/comments.txt', commentsLog.join('\r\n'));
|
||||
@ -332,7 +332,7 @@ async function allDpts() {
|
||||
}
|
||||
}
|
||||
|
||||
async function allKfVz() {
|
||||
async function allMcVn() {
|
||||
let res = await axios({
|
||||
method: 'get',
|
||||
url: host + '/template/measurements',
|
||||
@ -341,8 +341,8 @@ async function allKfVz() {
|
||||
password: 'Abc123!#'
|
||||
}
|
||||
});
|
||||
const kf_template = res.data.filter(e => e.name === 'kf').sort((a, b) => b.version - a.version)[0]._id;
|
||||
const vz_template = res.data.filter(e => e.name === 'vz').sort((a, b) => b.version - a.version)[0]._id;
|
||||
const mc_template = res.data.filter(e => e.name === 'moisture content').sort((a, b) => b.version - a.version)[0]._id;
|
||||
const vn_template = res.data.filter(e => e.name === 'vn').sort((a, b) => b.version - a.version)[0]._id;
|
||||
const rmc_template = res.data.filter(e => e.name === 'reinforcement material content').sort((a, b) => b.version - a.version)[0]._id;
|
||||
res = await axios({
|
||||
method: 'get',
|
||||
@ -357,15 +357,15 @@ async function allKfVz() {
|
||||
sampleIds[sample.number] = sample._id;
|
||||
});
|
||||
for (let index in data) {
|
||||
console.info(`KF/VZ ${index}/${data.length}`);
|
||||
console.info(`MC/VN ${index}/${data.length}`);
|
||||
let sample = data[index];
|
||||
sample['samplenumber'] = sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, '');
|
||||
let credentials = ['admin', 'Abc123!#'];
|
||||
if (sampleDevices[sample['samplenumber']]) {
|
||||
credentials = [sampleDevices[sample['samplenumber']], '2020DeFinMachen!']
|
||||
}
|
||||
if (!sample['vz(ml/g)'] && vzValues[sample['samplenumber']]) { // fill in VZ values from comments
|
||||
sample['vz(ml/g)'] = vzValues[sample['samplenumber']];
|
||||
if (!sample['vz(ml/g)'] && vnValues[sample['samplenumber']]) { // fill in VN values from comments
|
||||
sample['vz(ml/g)'] = vnValues[sample['samplenumber']];
|
||||
}
|
||||
if (sample['kfingew%']) {
|
||||
await axios({
|
||||
@ -377,7 +377,7 @@ async function allKfVz() {
|
||||
},
|
||||
data: {
|
||||
sample_id: sampleIds[sample['samplenumber']],
|
||||
measurement_template: kf_template,
|
||||
measurement_template: mc_template,
|
||||
values: {
|
||||
'weight %': sample['kfingew%'],
|
||||
'standard deviation': sample['stabwn']
|
||||
@ -386,7 +386,7 @@ async function allKfVz() {
|
||||
}).catch(err => {
|
||||
console.log(sample['samplenumber']);
|
||||
console.error(err.response.data);
|
||||
errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
errors.push(`MC/VN upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
});
|
||||
}
|
||||
if (sample['vz(ml/g)']) {
|
||||
@ -399,15 +399,15 @@ async function allKfVz() {
|
||||
},
|
||||
data: {
|
||||
sample_id: sampleIds[sample['samplenumber']],
|
||||
measurement_template: vz_template,
|
||||
measurement_template: vn_template,
|
||||
values: {
|
||||
vz: sample['vz(ml/g)']
|
||||
vn: sample['vz(ml/g)']
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(sample['samplenumber']);
|
||||
console.error(err.response.data);
|
||||
errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
errors.push(`MC/VN upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
});
|
||||
}
|
||||
if (sample['reinforcingmaterialcontent']) {
|
||||
@ -428,7 +428,7 @@ async function allKfVz() {
|
||||
}).catch(err => {
|
||||
console.log(sample['samplenumber']);
|
||||
console.error(err.response.data);
|
||||
errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
errors.push(`MC/VN upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -514,7 +514,7 @@ async function allSamples() {
|
||||
samples[si].color = number.color;
|
||||
}
|
||||
}
|
||||
else if (sampleColors[sample['samplenumber'].split('_')[0]]) { // derive color from main sample for kf/vz
|
||||
else if (sampleColors[sample['samplenumber'].split('_')[0]]) { // derive color from main sample for mc/vn
|
||||
samples[si].color = sampleColors[sample['samplenumber'].split('_')[0]];
|
||||
}
|
||||
if (!samples[si].color) {
|
||||
@ -913,9 +913,9 @@ function customFields (comment, sampleNumber) {
|
||||
{docKey: 'zu', dbKey: 'belongs to', regex: /zu (\S*\d+)/, category: 'reference'},
|
||||
{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+)/, category: 'reference'},
|
||||
{docKey: 'VZ =', dbKey: 'vz', regex: /VZ = (\d+) cm³\/g/, category: 'vz'},
|
||||
{docKey: 'VZ =', dbKey: 'vn', regex: /VZ = (\d+) cm³\/g/, category: 'vn'},
|
||||
{docKey: 'VWZ', dbKey: 'vwz', regex: /(\d+ min) VWZ \//, category: 'customField'},
|
||||
{docKey: 'VZ:', dbKey: 'vz', regex: /VZ: ([0-9.,]+) mL\/g[;]?/, category: 'vz'}
|
||||
{docKey: 'VZ:', dbKey: 'vn', regex: /VZ: ([0-9.,]+) mL\/g[;]?/, category: 'vn'}
|
||||
];
|
||||
const res = {}; // returned result
|
||||
const usedParts = []; // all substrings used for custom fields, subtract at the end, as some parts are used multiple times
|
||||
@ -928,8 +928,8 @@ function customFields (comment, sampleNumber) {
|
||||
if (cField.category === 'reference') {
|
||||
sampleReferences.push({sample: sampleNumber, referencedSample: regexRes[1], relation: cField.dbKey});
|
||||
}
|
||||
else if (cField.category === 'vz') {
|
||||
vzValues[sampleNumber] = regexRes[1];
|
||||
else if (cField.category === 'vn') {
|
||||
vnValues[sampleNumber] = regexRes[1];
|
||||
}
|
||||
else {
|
||||
res[cField.dbKey] = regexRes.filter((e, i) => i > 0).join(' ');
|
||||
|
Reference in New Issue
Block a user