Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | 160x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 8x 8x 8x 17009x 45x 45x 45x 45x 103x 103x 58x 58x 58x 58x 45x 45x 45x 45x 45x 6853x 6853x 45x 45x 276x 276x 158x 158x 118x 118x 118x 118x 118x 118x 118x 118x 118x 15707x 15707x 15707x 15707x 15707x 1493x 1493x 14214x 618x 618x 13596x 1442x 1236x 1442x 1442x 12154x 12154x 118x 618x 118x 1493x 118x 372x 93x 372x 38704x 9676x 9676x 372x 3936x 984x 372x 25x 209x 20886x 209x 125x 84x 2478x 25x 25x 294x 294x 294x 294x 25x 105x 294x 118x 118x 118x 118x 48x 48x 73x 118x 2x 314x 118x 63x 184x 184x 184x 157x 184x 184x 618x 618x 618x 618x 618x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 115x | import { Component, EventEmitter, OnInit, OnChanges, Input, Output, inject } from '@angular/core';
import { TwinpadApiService } from '../../services/twinpad-api.service';
import { Signal, SignalsPreset, SignalGroup } from '../../models/signals';
import { MultiSelectModule } from 'primeng/multiselect';
import { FormsModule } from '@angular/forms';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Device } from '../../models/devices';
import { first } from 'rxjs';
import { deepCopy, areEqual, isId, formatPostProcessingSignal, arrayContains } from '../../utils/utils';
import { ButtonModule } from 'primeng/button';
import { PopoverModule } from 'primeng/popover';
import { SelectModule } from 'primeng/select';
import { InputTextModule } from 'primeng/inputtext';
import { FloatLabelModule } from 'primeng/floatlabel';
import { MessageModule } from 'primeng/message';
import { MessageService } from 'primeng/api';
@Component({
selector: 'app-multi-select-signals',
imports: [MultiSelectModule, FormsModule, ButtonModule, PopoverModule, InputTextModule, FloatLabelModule, SelectModule, MessageModule],
templateUrl: './multi-select-signals.component.html',
styleUrl: './multi-select-signals.component.scss'
})
export class MultiSelectSignalsComponent implements OnInit, OnChanges {
private twinpadApiService = inject(TwinpadApiService);
private router = inject(Router);
private route = inject(ActivatedRoute);
private messageService = inject(MessageService);
@Input() selectionLimit: number | null = null;
@Input() isLive: boolean = true;
@Input() graphId: string = "";
@Input() postProcessingMode: boolean = false;
@Output() selectionChanged = new EventEmitter<string[]>();
@Output() finishedLoadingSignals = new EventEmitter<boolean>();
totalSignals: number = 0;
isFiltering: boolean = false;
signalIds: string[] = [];
signalsById: Map<string, Signal>;
signalIdsToDisplay: SignalGroup[] = [];
signalIdsToPlot: string[] = [];
loadedFromUrl: boolean = false;
querySignalId: string = "signal_id";
signalsPresets: SignalsPreset[] = [];
selectedSignalsPreset: SignalsPreset | undefined;
isSignalsPresetNew: boolean = true;
isPresetNameValid: boolean = false;
_newSignalsPresetName: string = "";
set newSignalsPresetName(value: string) {
this._newSignalsPresetName = value;
this.isSignalsPresetNew = this.signalsPresets.find(signalsPreset => signalsPreset.name === value) === undefined;
this.isPresetNameValid = value.length > 3;
}
get newSignalsPresetName() : string {
return this._newSignalsPresetName;
}
ngOnInit(): void {
this.signalIds = [];
this.signalsById = new Map();
this.querySignalId = `signal_id${this.graphId}`;
this.route.queryParams.subscribe(params => {
const signalIds = params[this.querySignalId];
if (signalIds) {
Eif (signalIds instanceof Array) {
this.signalIdsToPlot = signalIds;
}
else {
this.signalIdsToPlot = [signalIds];
}
Iif (!this.signalIds || this.signalIds.length == 0) {
this.signalIds = deepCopy(this.signalIdsToPlot);
}
this.loadedFromUrl = true;
}
else {
this.signalIdsToPlot = [];
}
});
this.loadSignalIds(this.loadedFromUrl);
this.loadSignalsPresets();
}
loadSignalIds(loadedFromUrl: boolean) {
this.twinpadApiService.getSignalsIds().subscribe({
next: signalIds => {
for (const signalId of signalIds) {
// This is done to not disturb the signals' order when they've been added from url query
Iif (loadedFromUrl) {
const index: number = this.signalIds.indexOf(signalId);
if (index > -1) {
this.signalIds.splice(index, 1);
}
}
this.signalIds.push(signalId);
}
this.filterSignalIds();
this.finishedLoadingSignals.emit(true);
}
});
}
filterSignalIds() {
this.twinpadApiService.devicesBehaviorSubject$.pipe(first()).subscribe({
next: devices => {
if (devices.length === 0) {
setTimeout(() => this.filterSignalIds(), 50);
return;
}
this.twinpadApiService.getConfigNames().subscribe({
next: configNames => {
const signalsGroup: SignalGroup[] = [];
const signalIds = deepCopy(this.signalIds);
// First we're going to segregate every type of signals for easier processing
const postProcessingSignals: string[] = [];
const systemSignals: string[] = [];
const v1ConfigSignals: string[] = [];
const v2ConfigSignals: string[] = [];
const deviceStatusSignals: string[] = [];
for (const signalId of signalIds) {
// First verify that every signal_id is valid and skip the invalid ones
const splitSignal = signalId.split(".");
Iif (splitSignal.length < 2) {
continue;
}
const firstSegment = splitSignal[0];
const secondSegment = splitSignal[1];
// Post processing signals are separated since they have a complex naming scheme
if (firstSegment === "post_processing") {
postProcessingSignals.push(signalId);
continue;
}
// Filter out the data storage's queue size and bandwidths
if (firstSegment.includes("storage")) {
systemSignals.push(signalId);
continue;
}
// Due to previous lax naming policies, it is possible that v1 config devices don't have an ID as their device_id
// Since only v2 configs should have the config_id in second position, if it's not the case, it's from a v1 config
if (!isId(secondSegment)) {
// Mode, load and status signals only refer to the device ID, they can be added to the device's signals
if (arrayContains(["_MODE", "_LOAD", "_STATUS"], secondSegment)) {
deviceStatusSignals.push(signalId);
}
v1ConfigSignals.push(signalId);
continue;
}
// We still check the signal's ticker to ensure it is not an ID for v2 configs
Eif (splitSignal.length > 2 && !isId(splitSignal[2])) {
v2ConfigSignals.push(signalId);
}
}
const systemGroup: SignalGroup = {
deviceName: "System",
signals: systemSignals.map(signalId => {return {signalId: signalId, ticker: this.formatSystemSignal(signalId)};})
};
const postProcessingGroup: SignalGroup = {
deviceName: "Post-processing",
signals: postProcessingSignals.map(signalId => {return {signalId: signalId, ticker: formatPostProcessingSignal(signalId)[0]};})
};
if (this.isLive) {
// In live mode, only display signals from up devices which should all be using a v2 config
const upDevices: Device[] = devices.filter(device => device.status === "up");
for (const device of upDevices) {
const signals = v2ConfigSignals.filter(signalId =>
signalId.indexOf(device.device_id) === 0 &&
signalId.indexOf(device.config_id) === 13
).map(signalId => {
const splitSignalId = signalId.split(".");
return {
signalId: signalId,
ticker: splitSignalId[2]
};
});
// Add device status signals (mode, load, status)
signals.push(...deviceStatusSignals.filter(signalId =>
signalId.indexOf(device.device_id) === 0
).map(signalId => {
return {
signalId: signalId,
ticker: signalId.split(".")[1],
};
}));
signalsGroup.push({
deviceName: `${device.name} (#${device.device_id.slice(8)})`,
signals: signals,
});
}
}
else {
// When not live, it should still be possible to plot signals from v1 configs
// The received configs are v2 since they are the only ones saved in this table, which allows us to put every v2 signal here
for (const config of configNames) {
const configsSignal = v2ConfigSignals.filter(signalId =>
signalId.indexOf(config.target_device_id) === 0 &&
signalId.indexOf(config.config_id) === 13
);
if (configsSignal.length === 0) {
continue;
}
signalsGroup.push({
deviceName: `${config.device_name} (${config.config_name})`,
signals: configsSignal.map(signalId => {
return {
signalId: signalId,
ticker: signalId.split(".")[2]
};
})
});
}
// Since devices could have kept the same device_id but now run a v2 config, only use the device_id to name it
// Here, we split the v1 signal_ids by device_id
const signalIdsByDevice: Map<string, string[]> = new Map;
for (const signalId of v1ConfigSignals) {
const deviceId = signalId.split(".")[0];
const devicesSignalId = signalIdsByDevice.get(deviceId) ?? [];
devicesSignalId.push(signalId);
signalIdsByDevice.set(deviceId, devicesSignalId);
}
// Once the signal_ids are grouped, add them to the list under their respective device
for (const [deviceId, signalIds] of signalIdsByDevice.entries()) {
signalsGroup.push({
deviceName: `Old device (#${deviceId})`,
signals: signalIds.map(signalId => {
return {
signalId: signalId,
ticker: signalId.split(".")[1]
};
})
});
}
}
signalsGroup.push(postProcessingGroup);
signalsGroup.push(systemGroup);
this.signalIdsToDisplay = signalsGroup;
this.cleanSelectedSignals();
}
});
}
});
}
loadSignalsPresets() {
this.twinpadApiService.getUserSignalsPresets().subscribe({
next: signalsPresets => {
this.signalsPresets = signalsPresets;
}
});
}
ngOnChanges() {
this.filterSignalIds();
}
cleanSelectedSignals() {
const newSelection = this.signalIdsToPlot.filter(signalId =>
this.signalIdsToDisplay.filter(signalGroup =>
signalGroup.signals.filter(signalDisplay => signalDisplay.signalId === signalId).length !== -1
)
);
Iif (!areEqual(this.signalIdsToPlot, newSelection)) {
this.onChangeSelection(newSelection);
}
}
onChangeSelection(newSelection: string[]){
this.route.queryParams.subscribe(queryParams => {
const params: Params = {};
const signal_id_string = this.querySignalId;
for (const [key, value] of Object.entries(queryParams)) {
Iif (key !== signal_id_string) {
params[key] = value;
}
}
params[signal_id_string] = newSelection;
this.router.navigate([], {
queryParams: params
});
});
}
formatSystemSignal(signalId: string): string {
const cleanId = signalId.replaceAll("_", " ");
const splitSignalId = cleanId.split(".");
const service_name = splitSignalId[0];
const cleanTicker = (splitSignalId[splitSignalId.length - 1] ?? "unknown ticker").toLowerCase();
return `${service_name}'s ${cleanTicker}`;
}
saveSignalsPreset() {
if (this.isSignalsPresetNew) {
this.createSignalsPreset();
}
else {
let existingSignalsPreset = this.signalsPresets.find(signalsPreset => signalsPreset.name === this._newSignalsPresetName);
Iif (existingSignalsPreset === undefined) {
this.createSignalsPreset();
return;
}
existingSignalsPreset.signal_ids = this.signalIdsToPlot;
this.twinpadApiService.updateSignalsPreset(existingSignalsPreset).subscribe({
next: updatedSignalsPreset => {
existingSignalsPreset = updatedSignalsPreset;
this.messageService.add({ severity: 'success', summary: 'Preset edit successful', detail: `Preset ${this._newSignalsPresetName} has been edited` });
this.loadSignalsPresets();
},
error: err => {
this.messageService.add({ severity: 'error', summary: 'Preset edit failed', detail: err.error.detail });
}
});
}
}
createSignalsPreset() {
this.twinpadApiService.createSignalsPreset(this._newSignalsPresetName, this.signalIdsToPlot).subscribe({
next: newSignalsPresetId => {
this.isSignalsPresetNew = false;
const newSignalsPreset = new SignalsPreset();
newSignalsPreset.id = newSignalsPresetId;
newSignalsPreset.name = this._newSignalsPresetName;
newSignalsPreset.signal_ids = this.signalIdsToPlot;
this.signalsPresets.push(newSignalsPreset);
this.messageService.add({ severity: 'success', summary: 'Preset creation successful', detail: `Preset ${this._newSignalsPresetName} has been created` });
this.loadSignalsPresets();
},
error: err => {
this.messageService.add({ severity: 'error', summary: 'Preset creation failed', detail: err.error.detail });
}
});
}
loadSignalsPreset() {
this.onChangeSelection(this.selectedSignalsPreset?.signal_ids ?? []);
}
deletePreset() {
Iif (this.selectedSignalsPreset === undefined) {
return;
}
this.twinpadApiService.deleteSignalsPreset(this.selectedSignalsPreset.id).subscribe({
next: wasDeleted => {
Iif (this.selectedSignalsPreset === undefined) {
return;
}
Eif (wasDeleted) {
this.messageService.add({ severity: 'success', summary: 'Preset deletion successful', detail: `Preset ${this.selectedSignalsPreset.name} has been deleted` });
this.selectedSignalsPreset = undefined;
}
else {
this.messageService.add({ severity: 'error', summary: 'Preset deletion failed', detail: `Preset ${this.selectedSignalsPreset.name} failed to be deleted` });
}
this.loadSignalsPresets();
},
error: err => {
this.messageService.add({ severity: 'error', summary: 'Preset deletion failed', detail: err.error.detail });
}
});
}
}
|