forked from burmanm/gorilla-tsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76dff33
commit 909e6b0
Showing
9 changed files
with
609 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/gr/aueb/compression/gorilla/DecompressorPmcMr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/gr/aueb/compression/gorilla/DecompressorSwingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/main/java/gr/aueb/compression/gorilla/LinearFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.