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 = {
materials: true,
samples: false,
dpt: false
samples: true,
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 = [
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_B.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_WaP.csv",
"C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPPD_DPPD-frei.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv",
// "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.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 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 = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
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) {
await importCsv(docs[i]);
await allMaterials();
// await saveMaterials();
await saveMaterials();
}
fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor));
fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog));
@ -140,6 +317,7 @@ async function importCsv(doc) {
'charge/batchgranulate/part': 'charge/batch',
'charge': 'charge/batch',
'anmerkung': 'comments',
'vz': 'vz(ml/g)',
'vz[ml/g]': 'vz(ml/g)',
'vz[cm³/g]': 'vz(ml/g)',
'abbau(%)': 'degradation(%)',
@ -247,9 +425,10 @@ async function allDpts() {
res.data.forEach(sample => {
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);
for (let i in dpts) {
if (!stages.dptFromList || dptList.indexOf(dpts[i]) >= 0) { // if list option active, only use from filter
let regexInput;
const bjRes = /^(Bj[FT]?)\s?([a-z0-9_]*)_JDX.DPT/.exec(dpts[i]);
if (bjRes) { // correct Bj numbers with space
@ -360,6 +539,7 @@ async function allDpts() {
}
}
}
}
}
async function allMcVn() {
@ -399,6 +579,7 @@ async function allMcVn() {
for (let index in data) {
console.info(`MC/VN ${index}/${data.length}`);
let sample = data[index];
console.log(sample);
sample['samplenumber'] = sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, '');
let credentials = ['admin', 'Abc123!#'];
if (sampleDevices[sample['samplenumber']]) {
@ -671,10 +852,6 @@ async function allMaterials() {
// process all samples
for (let index in data) {
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
sample['supplier'] = 'unknown';
}
@ -700,7 +877,7 @@ async function allMaterials() {
}
}
else { // new material
// console.info(`MATERIAL LOAD ${index}/${data.length} ${sample['materialname']}`);
console.info(`MATERIAL LOAD ${index}/${data.length} ${sample['materialname']}`);
materials[sample['materialname']] = {
name: trim(sample['materialname']),
supplier: trim(sample['supplier']),

View File

@ -4,7 +4,7 @@ import db from '../db';
const ModelSchema = new mongoose.Schema({
group: {type: String, index: {unique: true}},
models: [new mongoose.Schema({
name: {type: String, index: {unique: true}},
name: String,
url: String,
label: String
} ,{ _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
// 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 = queryPtr[queryPtr.length - 1].$facet.samples; // add rest of aggregation pipeline into $facet
}