Compare commits
No commits in common. "4ad5eba7e071b9c60928adaf4494f35958265840" and "873f00b21bea3902da1193bf2517ec682ea0156a" have entirely different histories.
4ad5eba7e0
...
873f00b21b
@ -37,16 +37,13 @@ class PacketInfluxPointFactory extends Transform{
|
||||
_transform(packet, encoding, next){
|
||||
// Create measurements
|
||||
MEASUREMENT_MAP.forEach((objKey, measurement) => {
|
||||
if(packet[objKey] == null) return;
|
||||
if(!Object.keys(packet).includes(objKey)) return;
|
||||
|
||||
let point = new Point(measurement); // Create point
|
||||
|
||||
// Set tags
|
||||
TAG_LIST.filter(tag => Object.keys(packet).includes(tag)) // Filter tags available on object
|
||||
.filter(tag => packet[tag] != null) // Filter tags not falsy on object
|
||||
.forEach(tag => {
|
||||
tagObjectRecursively(point, tag, packet[tag]);
|
||||
});
|
||||
TAG_LIST.filter(tag => Object.keys(packet).includes(tag))
|
||||
.forEach(tag => point.tag(tag, packet[tag]));
|
||||
|
||||
point.setField('value', packet[objKey]); // Set field
|
||||
|
||||
@ -57,15 +54,6 @@ class PacketInfluxPointFactory extends Transform{
|
||||
}
|
||||
}
|
||||
|
||||
function tagObjectRecursively(point, tag, field, suffix = ""){
|
||||
if(typeof(field) == "object"){
|
||||
// TODO: Convert boolean-arrays like "packet.flags" to key: value
|
||||
Object.entries(field).map(([key, value]) => {
|
||||
tagObjectRecursively(point, tag, value, `_${key}${suffix}`);
|
||||
});
|
||||
}
|
||||
else point.tag(tag+suffix, field);
|
||||
}
|
||||
|
||||
/** Mapping for type -> field-method */
|
||||
const POINT_FIELD_TYPE = new Map([
|
||||
|
Loading…
x
Reference in New Issue
Block a user