Archived
2

fixed sample requests for the restructured material

This commit is contained in:
VLE2FE
2020-07-17 10:41:19 +02:00
parent 78d35c520e
commit cd81cbf4bd
11 changed files with 115 additions and 28 deletions

View File

@ -5,6 +5,7 @@ const {Builder} = require('selenium-webdriver'); // selenium and the chrome d
const chrome = require('selenium-webdriver/chrome');
const pdfReader = require('pdfreader');
const iconv = require('iconv-lite');
const _ = require('lodash');
const metaDoc = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\metadata.csv'; // metadata files
const kfDoc = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\kf.csv';
@ -15,6 +16,7 @@ const host = 'http://localhost:3000';
// const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
let data = []; // metadata contents
let materials = {};
const numberToColor = {};
let samples = [];
let normMaster = {};
let sampleDevices = {};
@ -30,7 +32,7 @@ let sampleDevices = {};
main();
async function main() {
if (0) { // materials
if (1) { // materials
await getNormMaster();
await importCsv(metaDoc);
await allMaterials();
@ -42,7 +44,7 @@ async function main() {
await allMaterials();
await saveMaterials();
}
if (0) { // samples
if (1) { // samples
sampleDeviceMap();
if (1) {
console.log('-------- META ----------');
@ -244,6 +246,7 @@ async function allSamples() {
});
const dbMaterials = {}
res.data.forEach(m => {
m.numbers = m.numbers.map(e => ({number: e, color: numberToColor[e]}));
dbMaterials[m.name] = m;
})
res = await axios({
@ -274,8 +277,6 @@ async function allSamples() {
if (!material) { // could not find material, skipping sample
continue;
}
console.log(sample['Material name']);
console.log(material._id);
samples.push({
number: sample['Sample number'],
type: sample['Granulate/Part'],
@ -290,14 +291,20 @@ async function allSamples() {
samples[si].color = material.numbers.find(e => e.number === sample['Material number']).color;
}
else if (sample['Color'] && sample['Color'] !== '') {
let number = material.numbers.find(e => e.color.indexOf(trim(sample['Color'])) >= 0);
console.log(material);
let number = material.numbers.find(e => e.color && e.color.indexOf(trim(sample['Color'])) >= 0);
if (!number && /black/.test(sample['Color'])) { // special case bk for black
number = material.numbers.find(e => e.color.toLowerCase().indexOf('bk') >= 0);
if (!number) { // try German word
number = material.numbers.find(e => e.color.toLowerCase().indexOf('schwarz') >= 0);
}
}
samples[si].color = number.color;
if (number) {
samples[si].color = number.color;
}
else {
samples[si].color = '';
}
}
else if (sampleColors[sample['Sample number'].split('_')[0]]) { // derive color from main sample for kf/vz
samples[si].color = sampleColors[sample['Sample number'].split('_')[0]];
@ -373,23 +380,33 @@ async function allMaterials() {
supplier: trim(sample['Supplier']),
group: trim(sample['Material'])
};
materials[sample['Material name']].properties = {material_template: '5f0efe6fce7fd20ce4e99013'};
let tmp = /M(\d+)/.exec(sample['Reinforcing material']);
materials[sample['Material name']].mineral = tmp ? tmp[1] : 0;
materials[sample['Material name']].properties.mineral = tmp ? tmp[1] : 0;
tmp = /GF(\d+)/.exec(sample['Reinforcing material']);
materials[sample['Material name']].glass_fiber = tmp ? tmp[1] : 0;
materials[sample['Material name']].properties.glass_fiber = tmp ? tmp[1] : 0;
tmp = /CF(\d+)/.exec(sample['Reinforcing material']);
materials[sample['Material name']].carbon_fiber = tmp ? tmp[1] : 0;
materials[sample['Material name']].properties.carbon_fiber = tmp ? tmp[1] : 0;
materials[sample['Material name']].numbers = await numbersFetch(sample);
console.log(materials[sample['Material name']]);
}
}
}
Object.keys(materials).forEach(mKey => {
materials[mKey].numbers.forEach(number => {
if (number.number && number.color) {
numberToColor[number.number] = number.color;
}
})
});
}
async function saveMaterials() {
const mKeys = Object.keys(materials)
for (let i in mKeys) {
console.info(`${i}/${mKeys.length}`);
const material = _.cloneDeep(materials[mKeys[i]]);
material.numbers = material.numbers.map(e => e.number).filter(e => e !== '').map(e => e.replace(/ /g, ''));
await axios({
method: 'post',
url: host + '/material/new',
@ -397,10 +414,10 @@ async function saveMaterials() {
username: 'admin',
password: 'Abc123!#'
},
data: materials[mKeys[i]]
data: material
}).catch(err => {
if (err.response.data.status && err.response.data.status !== 'Material name already taken') {
console.info(materials[mKeys[i]]);
console.info(material);
console.error(err.response.data);
}
});