events_processing.ts 718 B

123456789101112131415161718192021222324252627
  1. import _ 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. }