-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
47 lines (42 loc) · 1 KB
/
parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
const config = require("./config");
const utils = require("./utils");
const csvArray = (dataArray) => {
const arr = dataArray.map((x) => {
return [`${x.variable} [${x.unit}]`, String(x.value)];
});
// const cols = arr.map((x) => x[0]);
const data = arr.map((x) => x[1]);
return data;
};
const csvString = (data, sep) => {
const arr = csvArray(data);
return arr.join(sep) + "\n";
};
const prettify = (data) => {
const timestamp = utils.timestamp(config.DATA_TIMESTAMP_FORMAT);
return [
{
variable: "timestamp",
value: timestamp,
unit: config.DATA_TIMESTAMP_FORMAT,
},
{
variable: "degree_plato",
value: data.plato,
unit: "°P",
},
{
variable: "temperature",
value: data.temperature,
unit: "°C",
},
{
variable: "specific_gravity",
value: data.specGravity,
unit: "-",
},
].filter((x) => x.value !== null);
};
module.exports.prettify = prettify;
module.exports.csvString = csvString;