diff options
author | 2020-10-13 21:24:08 +0530 | |
---|---|---|
committer | 2020-10-27 13:15:37 +0530 | |
commit | fadaccdb8396a178134ef95982e96ed8a5cddc26 (patch) | |
tree | d81b7d33dbc373d0656f969e24783aba2aaeae33 /components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java | |
parent | 9170fe0e3aad7a336b0f0d08e63b9de127a9f9de (diff) |
Fix Issues
- Fix certificate issue for authenticated topic
- Fix consumer thread issue
Issue-ID: DCAEGEN2-2485
Signed-off-by: dhebeha <dhebeha.mj71@wipro.com>
Change-Id: I91fe9b1b86579da7142955ac7adaa25ac4bc22e9
Diffstat (limited to 'components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java')
-rw-r--r-- | components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java index a003e9c0..52670d53 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java @@ -50,19 +50,22 @@ public class AverageCalculator { * Find average of samples */ public List<MeasurementObject> findAverageOfSamples(List<List<MeasurementObject>> samples) { + log.debug("find average for samples {}", samples); int numOfSamples = samples.size(); List<MeasurementObject> result = new ArrayList<>(); - samples.forEach(sample -> - sample.forEach(cellMeasObj -> { - int index = result.indexOf(cellMeasObj); - if(index != -1) { - result.set(index, findSum(result.get(index), cellMeasObj)); + if(!samples.isEmpty()) { + for(List<MeasurementObject> sample : samples) { + for(MeasurementObject cellMeasObj : sample) { + int index = MeasurementObject.findIndex(cellMeasObj.getMeasurementObjectId(), result); + if(index != -1) { + result.set(index, findSum(result.get(index), cellMeasObj)); + } + else { + result.add(cellMeasObj); + } + } } - else { - result.add(cellMeasObj); - } - }) - ); + } return findAvg(result, numOfSamples); } @@ -81,13 +84,15 @@ public class AverageCalculator { * Calculate the average */ public List<MeasurementObject> findAvg(List<MeasurementObject> result, int numOfSamples) { - result.forEach(cellMeasObj -> - pmNames.forEach(pmName -> { - int value = (cellMeasObj.getPmData().get(pmName))/numOfSamples; - cellMeasObj.getPmData().put(pmName, value); - }) - ); - log.debug("Average of measurement data samples {}",result); + if(!result.isEmpty()) { + result.forEach(cellMeasObj -> + pmNames.forEach(pmName -> { + int value = (cellMeasObj.getPmData().get(pmName))/numOfSamples; + cellMeasObj.getPmData().put(pmName, value); + }) + ); + log.debug("Average of measurement data samples {}",result); + } return result; } } |