Skip to content

Commit a76bee7

Browse files
committed
refactor: rename Analyzer to ComponentProcessor, move to analysis module
1 parent 789ff26 commit a76bee7

File tree

9 files changed

+32
-38
lines changed

9 files changed

+32
-38
lines changed

measure/src/main/java/net/laprun/sustainability/power/measure/DescriptiveStatisticsAnalyzer.java renamed to analysis/src/main/java/net/laprun/sustainability/power/analysis/DescriptiveStatisticsComponentProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package net.laprun.sustainability.power.measure;
1+
package net.laprun.sustainability.power.analysis;
22

33
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
44

55
@SuppressWarnings("unused")
6-
public class DescriptiveStatisticsAnalyzer implements Analyzer {
6+
public class DescriptiveStatisticsComponentProcessor implements ComponentProcessor {
77
private final DescriptiveStatistics statistics;
88

9-
public DescriptiveStatisticsAnalyzer() {
9+
public DescriptiveStatisticsComponentProcessor() {
1010
statistics = new DescriptiveStatistics();
1111
}
1212

measure/src/main/java/net/laprun/sustainability/power/measure/HdrHistogramAnalyzer.java renamed to analysis/src/main/java/net/laprun/sustainability/power/analysis/HdrHistogramComponentProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package net.laprun.sustainability.power.measure;
1+
package net.laprun.sustainability.power.analysis;
22

33
import org.HdrHistogram.IntCountsHistogram;
44

55
@SuppressWarnings("unused")
6-
public class HdrHistogramAnalyzer implements Analyzer {
6+
public class HdrHistogramComponentProcessor implements ComponentProcessor {
77
private static final int HIGHEST_TRACKABLE_VALUE = 1_000_000;
88
private static final int NUMBER_OF_SIGNIFICANT_VALUE_DIGITS = 4;
99
private static final int CONVERSION_FACTOR = 1000;
1010
private final IntCountsHistogram histogram;
1111

12-
public HdrHistogramAnalyzer() {
12+
public HdrHistogramComponentProcessor() {
1313
histogram = new IntCountsHistogram(HIGHEST_TRACKABLE_VALUE, NUMBER_OF_SIGNIFICANT_VALUE_DIGITS);
1414
}
1515

measure/pom.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@
1919
<version>${project.version}</version>
2020
</dependency>
2121
<dependency>
22-
<groupId>org.apache.commons</groupId>
23-
<artifactId>commons-math3</artifactId>
24-
<version>3.6.1</version>
25-
</dependency>
26-
<dependency>
27-
<groupId>org.hdrhistogram</groupId>
28-
<artifactId>HdrHistogram</artifactId>
29-
<version>2.2.2</version>
22+
<groupId>org.assertj</groupId>
23+
<artifactId>assertj-core</artifactId>
24+
<version>3.26.3</version>
25+
<scope>test</scope>
3026
</dependency>
3127
</dependencies>
3228

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package net.laprun.sustainability.power.analysis;
2+
3+
public interface Analyzers {
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.laprun.sustainability.power.analysis;
2+
3+
public interface ComponentProcessor {
4+
default void recordComponentValue(double value, long timestamp) {
5+
}
6+
}

measure/src/main/java/net/laprun/sustainability/power/measure/Analyzer.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

measure/src/main/java/net/laprun/sustainability/power/measure/OngoingPowerMeasure.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Optional;
77

88
import net.laprun.sustainability.power.SensorMetadata;
9+
import net.laprun.sustainability.power.analysis.ComponentProcessor;
910

1011
public class OngoingPowerMeasure implements PowerMeasure {
1112
private static final int DEFAULT_SIZE = 32;
@@ -21,9 +22,9 @@ public class OngoingPowerMeasure implements PowerMeasure {
2122
private int samples;
2223
private final double[][] measures;
2324
private long[] timestamps;
24-
private final Analyzer[] analyzers;
25+
private final ComponentProcessor[] analyzers;
2526

26-
public OngoingPowerMeasure(SensorMetadata sensorMetadata, Analyzer... analyzers) {
27+
public OngoingPowerMeasure(SensorMetadata sensorMetadata, ComponentProcessor... analyzers) {
2728
this.sensorMetadata = sensorMetadata;
2829
startedAt = System.currentTimeMillis();
2930

@@ -37,7 +38,7 @@ public OngoingPowerMeasure(SensorMetadata sensorMetadata, Analyzer... analyzers)
3738
// we don't need to record the total component as a non-zero component since it's almost never zero and we compute the std dev separately
3839
nonZeroComponents = new BitSet(numComponents);
3940
totalComponents = sensorMetadata.totalComponents();
40-
this.analyzers = Objects.requireNonNullElseGet(analyzers, () -> new Analyzer[0]);
41+
this.analyzers = Objects.requireNonNullElseGet(analyzers, () -> new ComponentProcessor[0]);
4142
}
4243

4344
@Override
@@ -135,7 +136,7 @@ public Optional<double[]> getMeasuresFor(int component) {
135136
}
136137

137138
@Override
138-
public Analyzer[] analyzers() {
139+
public ComponentProcessor[] analyzers() {
139140
return analyzers;
140141
}
141142
}

measure/src/main/java/net/laprun/sustainability/power/measure/PowerMeasure.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Optional;
55

66
import net.laprun.sustainability.power.SensorMetadata;
7+
import net.laprun.sustainability.power.analysis.ComponentProcessor;
78

89
public interface PowerMeasure {
910
private static double sumOfComponents(double[] recorded) {
@@ -61,15 +62,5 @@ default double average() {
6162

6263
Optional<double[]> getMeasuresFor(int component);
6364

64-
Analyzer[] analyzers();
65-
66-
/**
67-
* Records the standard deviations for the aggregated energy comsumption value (as returned by {@link #total()}) and
68-
* per component
69-
*
70-
* @param aggregate
71-
* @param perComponent
72-
*/
73-
record StdDev(double aggregate, double[] perComponent) {
74-
}
65+
ComponentProcessor[] analyzers();
7566
}

measure/src/main/java/net/laprun/sustainability/power/measure/StoppedPowerMeasure.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Optional;
55

66
import net.laprun.sustainability.power.SensorMetadata;
7+
import net.laprun.sustainability.power.analysis.ComponentProcessor;
78

89
@SuppressWarnings("unused")
910
public class StoppedPowerMeasure implements PowerMeasure {
@@ -15,7 +16,7 @@ public class StoppedPowerMeasure implements PowerMeasure {
1516
private final double max;
1617
private final double[] averages;
1718
private final double[][] measures;
18-
private final Analyzer[] analyzers;
19+
private final ComponentProcessor[] processors;
1920

2021
public StoppedPowerMeasure(PowerMeasure powerMeasure) {
2122
this.sensorMetadata = powerMeasure.metadata();
@@ -30,7 +31,7 @@ public StoppedPowerMeasure(PowerMeasure powerMeasure) {
3031
for (int i = 0; i < cardinality; i++) {
3132
measures[i] = powerMeasure.getMeasuresFor(i).orElse(null);
3233
}
33-
analyzers = powerMeasure.analyzers();
34+
processors = powerMeasure.analyzers();
3435
}
3536

3637
@Override
@@ -74,7 +75,7 @@ public Optional<double[]> getMeasuresFor(int component) {
7475
}
7576

7677
@Override
77-
public Analyzer[] analyzers() {
78-
return analyzers;
78+
public ComponentProcessor[] analyzers() {
79+
return processors;
7980
}
8081
}

0 commit comments

Comments
 (0)