Skip to content

Commit

Permalink
work on filters
Browse files Browse the repository at this point in the history
  • Loading branch information
panagiotisl committed Mar 31, 2022
1 parent 76dff33 commit 909e6b0
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down Expand Up @@ -134,17 +139,6 @@
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/gr/aueb/compression/gorilla/DecompressorPmcMr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gr.aueb.compression.gorilla;

import java.util.List;

import gr.aueb.compression.gorilla.PmcMR.Constant;

public class DecompressorPmcMr {

private List<Constant> constants;
private float storedVal = 0f;
private boolean endOfStream = false;
private int currentElement = 0;
private int currentTimestampOffset = 0;

public DecompressorPmcMr(List<Constant> constants) {
this.constants = constants;
}

/**
* Returns the next pair in the time series, if available.
*
* @return Pair if there's next value, null if series is done.
*/
public Float readValue() {
next();
if(endOfStream) {
return null;
}
return storedVal;
}

private void next() {
Constant constant = constants.get(currentElement);
if (constant.getFinalTimestamp() >= (constant.getInitialTimestamp() + currentTimestampOffset)) {
storedVal = constant.getValue();
currentTimestampOffset++;
} else {
currentElement++;
if (currentElement < constants.size()) {
constant = constants.get(currentElement);
storedVal = constant.getValue();
currentTimestampOffset = 1;
} else {
endOfStream = true;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gr.aueb.compression.gorilla;

import java.util.List;

import gr.aueb.compression.gorilla.PmcMR.Constant;
import gr.aueb.compression.gorilla.SwingFilter.SwingSegment;

public class DecompressorSwingFilter {

private List<SwingSegment> swingSegments;
private float storedVal = 0f;
private boolean endOfStream = false;
private int currentElement = 0;
private int currentTimestampOffset = 0;

public DecompressorSwingFilter(List<SwingSegment> swingSegments) {
this.swingSegments = swingSegments;
}

/**
* Returns the next pair in the time series, if available.
*
* @return Pair if there's next value, null if series is done.
*/
public Float readValue() {
next();
if(endOfStream) {
return null;
}
return storedVal;
}

private void next() {
SwingSegment swingSegment = swingSegments.get(currentElement);
if (swingSegment.getFinalTimestamp() >= (swingSegment.getInitialTimestamp() + currentTimestampOffset)) {
storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp() + currentTimestampOffset);
currentTimestampOffset++;
} else {
currentElement++;
if (currentElement < swingSegments.size()) {
swingSegment = swingSegments.get(currentElement);
storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp());
currentTimestampOffset = 1;
} else {
endOfStream = true;
}
}
}

}
32 changes: 32 additions & 0 deletions src/main/java/gr/aueb/compression/gorilla/LinearFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright 2018 The ModelarDB Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package gr.aueb.compression.gorilla;

public class LinearFunction {

/** Constructors **/
public LinearFunction(long ts, float vs, long te, float ve) {
this.a = (ve - vs) / (te - ts);
this.b = vs - a * ts;
}

/** Public Methods **/
public float get(long ts) {
return this.a * ts + this.b;
}

/** Instance Variables **/
public final float a, b;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public void close() {
}

private void compressValue(int value) {
// if values is within error wrt the previous value, use the previous value
if (Math.abs(Float.intBitsToFloat(value) - Float.intBitsToFloat(storedVal)) < Math.pow(2, this.logOfError)) {
// Write 0
cases[0] += 1;
out.skipBit();
size += 1;
return;
}

// TODO Fix already compiled into a big method
int integerDigits = (value << 1 >>> 24) - 127;
int space = 23 + this.logOfError - integerDigits;
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/gr/aueb/compression/gorilla/PmcMR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package gr.aueb.compression.gorilla;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class PmcMR {


public List<Constant> filter(Collection<Point> points, float epsilon) {

List<Constant> constants = new ArrayList<>();
Constant currentConstant = null;

float max = Float.MIN_VALUE;
float min = Float.MAX_VALUE;

for (Point point : points) {

if (point.getValue() > max) {
max = point.getValue();
}
if (point.getValue() < min) {
min = point.getValue();
}

if (max - min <= epsilon && currentConstant != null) {
currentConstant.setFinalTimestamp(point.getTimestamp());
currentConstant.setValue(max - ((max - min) / 2));
} else {
if (currentConstant != null) {
constants.add(currentConstant);
}
max = point.getValue();
min = point.getValue();
currentConstant = new Constant();
currentConstant.setInitialTimestamp(point.getTimestamp());
currentConstant.setFinalTimestamp(point.getTimestamp());
currentConstant.setValue(point.getValue());
}

}
if (currentConstant != null) {
constants.add(currentConstant);
}

return constants;
}

public class Constant {

private long initialTimestamp;
private long finalTimestamp;
private float value;

public void setFinalTimestamp(long finalTimestamp) {
this.finalTimestamp = finalTimestamp;
}

public void setInitialTimestamp(long initialTimestamp) {
this.initialTimestamp = initialTimestamp;
}

public void setValue(float value) {
this.value = value;
}

public long getFinalTimestamp() {
return finalTimestamp;
}

public long getInitialTimestamp() {
return initialTimestamp;
}

public float getValue() {
return value;
}

@Override
public String toString() {
return String.format("%d-%d: %f", getInitialTimestamp(), getFinalTimestamp(), getValue());
}

}

}
21 changes: 21 additions & 0 deletions src/main/java/gr/aueb/compression/gorilla/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gr.aueb.compression.gorilla;

public class Point {

private final long timestamp;
private final float value;

public Point(long timestamp, float value) {
this.timestamp = timestamp;
this.value = value;
}

public long getTimestamp() {
return timestamp;
}

public float getValue() {
return value;
}

}
Loading

0 comments on commit 909e6b0

Please sign in to comment.