@Test public void testCreateEnvelopesDefault14Bands() throws Exception { Mockito.when(params.getConfiguration()).thenReturn(Default14BandEnvelopeJobConfiguration.getConfiguration()); List<Waveform> waveforms = new ArrayList<>(); waveforms = generateWaveforms(); Result<List<Waveform>> stacks = envelopeCreationService.createEnvelopes(1l, waveforms, null, false); assertTrue(stacks.isSuccess()); assertTrue(stacks.getResultPayload().isPresent()); long eventCount = waveforms.stream().map(w -> w.getEvent().getEventId()).distinct().count(); long bandCount = params.getConfiguration().getFrequencyBandConfiguration().size(); long channelCount = waveforms.stream().map(w -> w.getStream().getChannelName()).distinct().count(); assertEquals(bandCount * eventCount * channelCount, stacks.getResultPayload().get().stream().distinct().count()); }
@Override public Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks) { if (waveforms == null || waveforms.isEmpty()) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No waveforms provided; unable to compute envelopes.")), Collections.emptyList()); } if (envConf == null) { envConf = params.getConfiguration(); } if (envConf == null) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No configuration specified but is required for this endpoint; unable to compute envelopes.")), Collections.emptyList()); } Set<Waveform> distinctWaveforms = new HashSet<>(waveforms); List<Waveform> results = generateEnvelopesForBands(distinctWaveforms.stream().filter(Objects::nonNull).collect(Collectors.toList()), envConf); if (shouldReturnStacks) { results = results.stream() .filter(w -> w.getEvent() != null && w.getLowFrequency() != null && w.getStream() != null && w.getStream().getStation() != null) .collect(Collectors.groupingBy(w -> w.getEvent().getEventId() + w.getLowFrequency() + w.getStream().getStation().hashCode())) .values() .stream() .map(waves -> { return stacker.stackEnvelopes(waves); }) .collect(Collectors.toList()); } return new Result<>(true, results); }
EnvelopeCreationServiceImpl implements EnvelopeCreationService { @Override public Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks) { if (waveforms == null || waveforms.isEmpty()) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No waveforms provided; unable to compute envelopes.")), Collections.emptyList()); } if (envConf == null) { envConf = params.getConfiguration(); } if (envConf == null) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No configuration specified but is required for this endpoint; unable to compute envelopes.")), Collections.emptyList()); } Set<Waveform> distinctWaveforms = new HashSet<>(waveforms); List<Waveform> results = generateEnvelopesForBands(distinctWaveforms.stream().filter(Objects::nonNull).collect(Collectors.toList()), envConf); if (shouldReturnStacks) { results = results.stream() .filter(w -> w.getEvent() != null && w.getLowFrequency() != null && w.getStream() != null && w.getStream().getStation() != null) .collect(Collectors.groupingBy(w -> w.getEvent().getEventId() + w.getLowFrequency() + w.getStream().getStation().hashCode())) .values() .stream() .map(waves -> { return stacker.stackEnvelopes(waves); }) .collect(Collectors.toList()); } return new Result<>(true, results); } }
EnvelopeCreationServiceImpl implements EnvelopeCreationService { @Override public Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks) { if (waveforms == null || waveforms.isEmpty()) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No waveforms provided; unable to compute envelopes.")), Collections.emptyList()); } if (envConf == null) { envConf = params.getConfiguration(); } if (envConf == null) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No configuration specified but is required for this endpoint; unable to compute envelopes.")), Collections.emptyList()); } Set<Waveform> distinctWaveforms = new HashSet<>(waveforms); List<Waveform> results = generateEnvelopesForBands(distinctWaveforms.stream().filter(Objects::nonNull).collect(Collectors.toList()), envConf); if (shouldReturnStacks) { results = results.stream() .filter(w -> w.getEvent() != null && w.getLowFrequency() != null && w.getStream() != null && w.getStream().getStation() != null) .collect(Collectors.groupingBy(w -> w.getEvent().getEventId() + w.getLowFrequency() + w.getStream().getStation().hashCode())) .values() .stream() .map(waves -> { return stacker.stackEnvelopes(waves); }) .collect(Collectors.toList()); } return new Result<>(true, results); } @Autowired  EnvelopeCreationServiceImpl(WaveformToTimeSeriesConverter converter, EnvelopeParamsService params, WaveformStacker stacker); }
EnvelopeCreationServiceImpl implements EnvelopeCreationService { @Override public Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks) { if (waveforms == null || waveforms.isEmpty()) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No waveforms provided; unable to compute envelopes.")), Collections.emptyList()); } if (envConf == null) { envConf = params.getConfiguration(); } if (envConf == null) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No configuration specified but is required for this endpoint; unable to compute envelopes.")), Collections.emptyList()); } Set<Waveform> distinctWaveforms = new HashSet<>(waveforms); List<Waveform> results = generateEnvelopesForBands(distinctWaveforms.stream().filter(Objects::nonNull).collect(Collectors.toList()), envConf); if (shouldReturnStacks) { results = results.stream() .filter(w -> w.getEvent() != null && w.getLowFrequency() != null && w.getStream() != null && w.getStream().getStation() != null) .collect(Collectors.groupingBy(w -> w.getEvent().getEventId() + w.getLowFrequency() + w.getStream().getStation().hashCode())) .values() .stream() .map(waves -> { return stacker.stackEnvelopes(waves); }) .collect(Collectors.toList()); } return new Result<>(true, results); } @Autowired  EnvelopeCreationServiceImpl(WaveformToTimeSeriesConverter converter, EnvelopeParamsService params, WaveformStacker stacker); @Override Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks); }
EnvelopeCreationServiceImpl implements EnvelopeCreationService { @Override public Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks) { if (waveforms == null || waveforms.isEmpty()) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No waveforms provided; unable to compute envelopes.")), Collections.emptyList()); } if (envConf == null) { envConf = params.getConfiguration(); } if (envConf == null) { return new Result<>(false, Collections.singletonList(new LightweightIllegalStateException("No configuration specified but is required for this endpoint; unable to compute envelopes.")), Collections.emptyList()); } Set<Waveform> distinctWaveforms = new HashSet<>(waveforms); List<Waveform> results = generateEnvelopesForBands(distinctWaveforms.stream().filter(Objects::nonNull).collect(Collectors.toList()), envConf); if (shouldReturnStacks) { results = results.stream() .filter(w -> w.getEvent() != null && w.getLowFrequency() != null && w.getStream() != null && w.getStream().getStation() != null) .collect(Collectors.groupingBy(w -> w.getEvent().getEventId() + w.getLowFrequency() + w.getStream().getStation().hashCode())) .values() .stream() .map(waves -> { return stacker.stackEnvelopes(waves); }) .collect(Collectors.toList()); } return new Result<>(true, results); } @Autowired  EnvelopeCreationServiceImpl(WaveformToTimeSeriesConverter converter, EnvelopeParamsService params, WaveformStacker stacker); @Override Result<List<Waveform>> createEnvelopes(Long sessionId, Collection<Waveform> waveforms, EnvelopeJobConfiguration envConf, boolean shouldReturnStacks);  }