code improvements
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import {parseAsync} from 'json2csv';
|
||||
import flatten from './flatten';
|
||||
|
||||
export default function csv(input: any[], f: (err, data) => void) {
|
||||
export default function csv(input: any[], f: (err, data) => void) { // parse JSON to CSV
|
||||
parseAsync(input.map(e => flatten(e)), {includeEmptyRows: true})
|
||||
.then(csv => f(null, csv))
|
||||
.catch(err => f(err, null));
|
||||
|
@ -3,10 +3,10 @@ import globals from '../globals';
|
||||
export default function flatten (data, keepArray = false) { // flatten object: {a: {b: true}} -> {a.b: true}
|
||||
const result = {};
|
||||
function recurse (cur, prop) {
|
||||
if (Object(cur) !== cur || Object.keys(cur).length === 0) {
|
||||
if (Object(cur) !== cur || Object.keys(cur).length === 0) { // simple value
|
||||
result[prop] = cur;
|
||||
}
|
||||
else if (prop === `${globals.spectrum.spectrum}.${globals.spectrum.dpt}`) {
|
||||
else if (prop === `${globals.spectrum.spectrum}.${globals.spectrum.dpt}`) { // convert spectrum for ML
|
||||
result[prop + '.labels'] = cur.map(e => parseFloat(e[0]));
|
||||
result[prop + '.values'] = cur.map(e => parseFloat(e[1]));
|
||||
}
|
||||
@ -27,7 +27,7 @@ export default function flatten (data, keepArray = false) { // flatten object:
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else { // object
|
||||
let isEmpty = true;
|
||||
for (let p in cur) {
|
||||
isEmpty = false;
|
||||
|
@ -4,10 +4,10 @@ import axios from 'axios';
|
||||
|
||||
export default class Mail{
|
||||
|
||||
static readonly address = 'definma@bosch-iot.com';
|
||||
static uri: string;
|
||||
static auth = {username: '', password: ''};
|
||||
static mailPass: string;
|
||||
static readonly address = 'definma@bosch-iot.com'; // email address
|
||||
static uri: string; // mail API URI
|
||||
static auth = {username: '', password: ''}; // mail API credentials
|
||||
static mailPass: string; // mail API generates password
|
||||
|
||||
static init() {
|
||||
if (process.env.NODE_ENV === 'production') { // only send mails in production
|
||||
@ -51,14 +51,14 @@ export default class Mail{
|
||||
}).then(() => { // init done successfully
|
||||
console.info('Mail service established successfully');
|
||||
this.send('lukas.veit@bosch.com', 'Mail Service started', new Date().toString());
|
||||
}).catch(err => { // anywhere an error occurred
|
||||
}).catch(err => { // somewhere an error occurred
|
||||
console.error(`Mail init error: ${err.request.method} ${err.request.path}: ${err.response.status}`,
|
||||
err.response.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static send (mailAddress, subject, content, f: (x?) => void = () => {}) { // callback, executed empty or with error
|
||||
static send (mailAddress, subject, content, f: (x?) => void = () => {}) { // callback executed empty or with error
|
||||
if (process.env.NODE_ENV === 'production') { // only send mails in production
|
||||
axios({
|
||||
method: 'post',
|
||||
|
Reference in New Issue
Block a user