Skip to content

Commit

Permalink
Added ATS1 with larger step
Browse files Browse the repository at this point in the history
  • Loading branch information
MasWag committed Apr 20, 2024
1 parent 94ebb7e commit d8d5bbd
Show file tree
Hide file tree
Showing 4 changed files with 820 additions and 518 deletions.
27 changes: 13 additions & 14 deletions core/src/main/java/net/maswag/ValueWithTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.Streams;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.math3.util.Pair;

import javax.annotation.Nullable;
Expand All @@ -20,38 +19,38 @@
*/
@Getter
public class ValueWithTime<T> {
protected final List<Double> timestamp;
protected final List<Double> timestamps;
protected final List<T> values;

ValueWithTime() {
// Initialization with empty lists
this.timestamp = Collections.emptyList();
this.timestamps = Collections.emptyList();
this.values = Collections.emptyList();
}

ValueWithTime(List<Double> timestamp, List<T> values) {
if (timestamp.size() != values.size()) {
ValueWithTime(List<Double> timestamps, List<T> values) {
if (timestamps.size() != values.size()) {
throw new IllegalArgumentException("The size of timestamp and values must be the same");
}
this.timestamp = timestamp;
this.timestamps = timestamps;
this.values = values;
}

/**
* Get the number of contained values.
*/
public int size() {
return timestamp.size();
return timestamps.size();
}

/**
* Get the value at the given time.
*/
@Nullable
public T at(double time) {
assert(timestamp.size() == values.size());
for (int i = 0; i < timestamp.size(); i++) {
if (timestamp.get(i) == time) {
assert(timestamps.size() == values.size());
for (int i = 0; i < timestamps.size(); i++) {
if (timestamps.get(i) == time) {
return values.get(i);
}
}
Expand All @@ -66,8 +65,8 @@ public T at(double time) {
*/
public ValueWithTime<T> range(double from, double to) {
assert(from < to);
assert(timestamp.size() == values.size());
return Streams.zip(timestamp.stream(), values.stream(), Pair::new)
assert(timestamps.size() == values.size());
return Streams.zip(timestamps.stream(), values.stream(), Pair::new)
.filter(pair -> from < pair.getFirst() && pair.getFirst() <= to)
.collect(Collectors.collectingAndThen(Collectors.toList(), list -> {
List<Double> newTimestamp = list.stream().map(Pair::getFirst).collect(Collectors.toList());
Expand All @@ -83,8 +82,8 @@ public ValueWithTime<T> range(double from, double to) {
* @param signalStep The time step between each signal
*/
public Stream<List<T>> stream(double signalStep) {
assert(timestamp.size() == values.size());
return Streams.zip(timestamp.stream(), values.stream(), Pair::new)
assert(timestamps.size() == values.size());
return Streams.zip(timestamps.stream(), values.stream(), Pair::new)
.collect(Collectors.groupingBy(pair -> (int) ceil(pair.getFirst() / signalStep)))
.values().stream()
.map(list -> list.stream().map(Pair::getSecond).collect(Collectors.toList()));
Expand Down
Loading

0 comments on commit d8d5bbd

Please sign in to comment.