Skip to content
Snippets Groups Projects
Commit e41fdda9 authored by Oleksandr Husak's avatar Oleksandr Husak
Browse files

merge times by notificationType

parent 77e6b3a9
Branches
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
} from 'ng-apexcharts'; } from 'ng-apexcharts';
import { MarkerColorMap } from 'src/environments/environment'; import { MarkerColorMap } from 'src/environments/environment';
import {Object, PositionUpdate} from 'src/app/model/base-model'; import {NotificationType, Object, PositionUpdate} from 'src/app/model/base-model';
export type ChartOptions = { export type ChartOptions = {
series: ApexAxisChartSeries; series: ApexAxisChartSeries;
...@@ -40,69 +40,9 @@ export class ChartTimelineComponent implements OnInit { ...@@ -40,69 +40,9 @@ export class ChartTimelineComponent implements OnInit {
private subsPosition: Subscription; private subsPosition: Subscription;
public chartOptions: Partial<ChartOptions> | any; public chartOptions: Partial<ChartOptions> | any;
// public series: ApexAxisChartSeries;
public seriesData: ApexAxisChartSeries;
constructor(private _mqttService: MqttService) { constructor(private _mqttService: MqttService) {
this.seriesData = [
{
name: "Bob",
data: [
{
x: "Design",
y: [
new Date("2021-09-14T09:41:20+00:00").getTime(),
new Date("2021-09-14T09:51:20+00:00").getTime()
]
},
{
x: "Code",
y: [
new Date("2021-09-14T09:52:20+00:00").getTime(),
new Date("2021-09-14T09:54:20+00:00").getTime()
]
},
{
x: "Test",
y: [
new Date("2021-09-14T10:21:20+00:00").getTime(),
new Date("2021-09-14T10:31:20+00:00").getTime()
]
}
]
},
{
name: "Joe",
data: [
{
x: "Design",
y: [
new Date("2021-09-14T09:11:20+00:00").getTime(),
new Date("2021-09-14T09:21:20+00:00").getTime()
]
},
{
x: "Code",
y: [
new Date("2021-09-14T09:11:20+00:00").getTime(),
new Date("2021-09-14T09:41:20+00:00").getTime()
]
},
{
x: "Test",
y: [
new Date("2021-09-14T11:31:20+00:00").getTime(),
new Date("2021-09-14T11:41:20+00:00").getTime()
]
}
]
}
],
this.chartOptions = { this.chartOptions = {
series: [], series: [],
chart: { chart: {
...@@ -143,6 +83,7 @@ export class ChartTimelineComponent implements OnInit { ...@@ -143,6 +83,7 @@ export class ChartTimelineComponent implements OnInit {
} }
addNewSeries(obj: Object) { addNewSeries(obj: Object) {
// --- Get index of the agent in series
let name = obj.id let name = obj.id
let idx = this.chartOptions.series.findIndex((s: { name: string; }) => s.name === name) let idx = this.chartOptions.series.findIndex((s: { name: string; }) => s.name === name)
if (idx == -1) { if (idx == -1) {
...@@ -156,22 +97,38 @@ export class ChartTimelineComponent implements OnInit { ...@@ -156,22 +97,38 @@ export class ChartTimelineComponent implements OnInit {
this.chartOptions.series[idx]["color"] = markerConf?.circle this.chartOptions.series[idx]["color"] = markerConf?.circle
} }
// --- Colect new data // --- Add new data
let dataPatch: any[] = obj.zoneDescriptors.map(zone => { obj.zoneDescriptors.forEach(zone => {
return { // [1] lastPosUpdate is `EntryNotification`
if (!this.chartOptions.series[idx]["data"].length || zone.notificationType?.toString() == "EntryNotification") {
let patch = {
"x": zone.zoneId, "x": zone.zoneId,
"y": [ "y": [
new Date(obj.lastPosUpdate).getTime(), new Date(obj.lastPosUpdate).getTime(),
new Date(obj.lastPosUpdate).getTime() + 360000 new Date(obj.lastPosUpdate).getTime() + 1000
], ],
"fillColor": markerConf?.circle, "fillColor": markerConf?.circle,
"strokeColor": markerConf?.circle "strokeColor": markerConf?.circle
} }
}); this.chartOptions.series[idx]["data"].push(patch)
// --- Add it } else {
this.chartOptions.series[idx]["data"] = dataPatch.concat(this.chartOptions.series[idx]["data"]) // [2] lastPosUpdate is `undefined` + [3] lastPosUpdate is `ExitNotification`
let oldData = this.chartOptions.series[idx]["data"].pop();
let patch = {
"x": zone.zoneId,
"y": [
oldData['y'][0],
new Date(obj.lastPosUpdate).getTime()
],
"fillColor": markerConf?.circle,
"strokeColor": markerConf?.circle
}
this.chartOptions.series[idx]["data"].push(patch)
}
});
// --- Update chart
this.chartOptions.series = this.chartOptions.series.map((s: any) => Object.assign({}, s)); this.chartOptions.series = this.chartOptions.series.map((s: any) => Object.assign({}, s));
} }
......
...@@ -45,21 +45,22 @@ interface Orientation { ...@@ -45,21 +45,22 @@ interface Orientation {
w: number w: number
} }
enum NotificationType { export enum NotificationType {
EntryNotification, "EntryNotification",
Unknown "ExitNotification",
"Unknown"
} }
enum ObjectType { enum ObjectType {
HUMAN, "HUMAN",
BOX, "BOX",
ROBOT "ROBOT"
} }
enum SensorType { enum SensorType {
UWB, "UWB",
Bluetooth, "Bluetooth",
WiFi "WiFi"
} }
......
...@@ -23,9 +23,9 @@ export const environment = { ...@@ -23,9 +23,9 @@ export const environment = {
}; };
export const MQTTconfig: IMqttServiceOptions = { export const MQTTconfig: IMqttServiceOptions = {
hostname: 'broker.hivemq.com', hostname: 'broker.emqx.io',
port: 8000, port: 8084,
protocol: 'ws', protocol: 'wss',
path: '/mqtt' path: '/mqtt'
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment