added data validation
This commit is contained in:
@@ -91,10 +91,10 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
|
||||
subscribeWS() {
|
||||
this.socket$.subscribe((message) => {
|
||||
// console.log(message);
|
||||
console.log(message);
|
||||
if (message instanceof Array) {
|
||||
message.forEach(element => {
|
||||
this.updateList(element.message);
|
||||
this.updateList(element);
|
||||
});
|
||||
} else {
|
||||
this.updateList(message);
|
||||
@@ -112,14 +112,43 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
// console.log(this.serverMessages);
|
||||
// console.log(obj);
|
||||
const index = this.serverMessages.findIndex((e) => e.location === obj.location);
|
||||
try {
|
||||
obj.volumeflow = Number(obj.volumeflow.toFixed(2));
|
||||
} catch {
|
||||
console.log('can transform to fixed decimal data missing or not a number');
|
||||
}
|
||||
try {
|
||||
obj.current = Number(obj.current.toFixed(2));
|
||||
} catch {
|
||||
console.log('can transform to fixed decimal data missing or not a number');
|
||||
}
|
||||
try {
|
||||
obj.intakepressure = Number(obj.intakepressure.toFixed(2));
|
||||
} catch {
|
||||
console.log('can transform to fixed decimal data missing or not a number');
|
||||
}
|
||||
try {
|
||||
obj.frequency = Number(obj.frequency.toFixed(2));
|
||||
} catch {
|
||||
console.log('can transform to fixed decimal data missing or not a number');
|
||||
}
|
||||
|
||||
if (index === -1) {
|
||||
this.serverMessages.push(obj);
|
||||
|
||||
} else {
|
||||
if (! obj.volumeflow) {
|
||||
obj.volumeflow = this.serverMessages[index].volumeflow;
|
||||
}
|
||||
if (! obj.current) {
|
||||
obj.current = this.serverMessages[index].current;
|
||||
}
|
||||
if (! obj.frequency) {
|
||||
obj.frequency = this.serverMessages[index].frequency;
|
||||
}
|
||||
if (! obj.intakepressure) {
|
||||
obj.intakepressure = this.serverMessages[index].intakepressure;
|
||||
}
|
||||
this.serverMessages[index] = obj;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +156,9 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
totalFlowRates() {
|
||||
let temp = 0;
|
||||
this.serverMessages.forEach(element => {
|
||||
if (element.volumeflow) {
|
||||
temp += element.volumeflow;
|
||||
}
|
||||
});
|
||||
return Number(temp.toFixed(2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user