events_processing.ts 761 B

123456789101112131415161718192021222324252627
  1. import { concat, every, find, groupBy, head, map, partition } from 'lodash';
  2. export function dedupAnnotations(annotations: any) {
  3. let dedup = [];
  4. // Split events by annotationId property existence
  5. const events = partition(annotations, 'id');
  6. const eventsById = groupBy(events[0], 'id');
  7. dedup = map(eventsById, (eventGroup) => {
  8. if (eventGroup.length > 1 && !every(eventGroup, isPanelAlert)) {
  9. // Get first non-panel alert
  10. return find(eventGroup, (event) => {
  11. return event.eventType !== 'panel-alert';
  12. });
  13. } else {
  14. return head(eventGroup);
  15. }
  16. });
  17. dedup = concat(dedup, events[1]);
  18. return dedup;
  19. }
  20. function isPanelAlert(event: { eventType: string }) {
  21. return event.eventType === 'panel-alert';
  22. }