Skip to content

Commit

Permalink
feat: use Duration instead of dimension-less long for duration
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Jul 7, 2024
1 parent b68454c commit 50fd4df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.laprun.sustainability.power.measure;

import java.time.Duration;
import java.util.ArrayList;

import net.laprun.sustainability.power.SensorMetadata;
Expand Down Expand Up @@ -46,8 +47,8 @@ public double total() {
return PowerMeasure.sumOfComponents(totals);
}

public long duration() {
return System.currentTimeMillis() - startedAt;
public Duration duration() {
return Duration.ofMillis(System.currentTimeMillis() - startedAt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.laprun.sustainability.power.measure;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
Expand All @@ -9,7 +10,7 @@
public interface PowerMeasure {
int numberOfSamples();

long duration();
Duration duration();

default double average() {
return total() / numberOfSamples();
Expand Down Expand Up @@ -72,7 +73,7 @@ record StdDev(double aggregate, double[] perComponent) {
}

static String asString(PowerMeasure measure) {
final var durationInSeconds = measure.duration() / 1000;
final var durationInSeconds = measure.duration().getSeconds();
final var samples = measure.numberOfSamples();
final var measuredMilliWatts = measure.total();
final var stdDevs = measure.standardDeviations();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.laprun.sustainability.power.measure;

import java.time.Duration;

public class StoppedPowerMeasure extends AbstractPowerMeasure {
private final long duration;
private final Duration duration;
private final double total;
private final double min;
private final double max;
Expand All @@ -17,7 +19,7 @@ public StoppedPowerMeasure(PowerMeasure powerMeasure) {
}

@Override
public long duration() {
public Duration duration() {
return duration;
}

Expand Down

0 comments on commit 50fd4df

Please sign in to comment.