-
Notifications
You must be signed in to change notification settings - Fork 5
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
Panagiotis Liakos
committed
Jul 29, 2022
1 parent
9f4d7e4
commit 0033db0
Showing
10 changed files
with
433 additions
and
26 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
50 changes: 50 additions & 0 deletions
50
src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilterBigDecimal.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.delorean.chimp; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
public class DecompressorSwingFilterBigDecimal { | ||
|
||
private List<SwingSegmentBigDecimal> swingSegments; | ||
private BigDecimal storedVal = new BigDecimal(0); | ||
private boolean endOfStream = false; | ||
private int currentElement = 0; | ||
private int currentTimestampOffset = 0; | ||
|
||
public DecompressorSwingFilterBigDecimal(List<SwingSegmentBigDecimal> constants) { | ||
this.swingSegments = constants; | ||
} | ||
|
||
/** | ||
* Returns the next pair in the time series, if available. | ||
* | ||
* @return Pair if there's next value, null if series is done. | ||
*/ | ||
public BigDecimal readValue() { | ||
next(); | ||
if(endOfStream) { | ||
return null; | ||
} | ||
return storedVal; | ||
} | ||
|
||
private void next() { | ||
SwingSegmentBigDecimal swingSegment = swingSegments.get(currentElement); | ||
if (swingSegment.getFinalTimestamp() >= (swingSegment.getInitialTimestamp() + currentTimestampOffset)) { | ||
storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp() + currentTimestampOffset); | ||
// System.out.println("LineDec: " + swingSegment.getLine() + "\t" + (swingSegment.getInitialTimestamp() + currentTimestampOffset) + "\t" + storedVal); | ||
currentTimestampOffset++; | ||
} else { | ||
currentElement++; | ||
if (currentElement < swingSegments.size()) { | ||
swingSegment = swingSegments.get(currentElement); | ||
storedVal = swingSegment.getLine().get(swingSegment.getInitialTimestamp()); | ||
|
||
currentTimestampOffset = 1; | ||
} else { | ||
endOfStream = true; | ||
} | ||
} | ||
} | ||
|
||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/gr/aueb/delorean/chimp/LinearFunctionBigDecimal.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,45 @@ | ||
/* 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.delorean.chimp; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.MathContext; | ||
import java.math.RoundingMode; | ||
|
||
public class LinearFunctionBigDecimal { | ||
|
||
MathContext mc = new MathContext(30, RoundingMode.HALF_UP) ; | ||
|
||
/** Constructors **/ | ||
public LinearFunctionBigDecimal(long ts, BigDecimal vs, long te, BigDecimal ve) { | ||
this.a = ve.subtract(vs).divide(new BigDecimal(te - ts), mc); | ||
this.b = vs.subtract(a.multiply(new BigDecimal(ts))); | ||
} | ||
|
||
/** Public Methods **/ | ||
public BigDecimal get(long ts) { | ||
return (this.a.multiply(new BigDecimal(ts)).add(b)); | ||
} | ||
|
||
private BigDecimal a; | ||
/** Instance Variables **/ | ||
private BigDecimal b; | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%.15fx+%f", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gr.aueb.delorean.chimp; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class PointBigDecimal { | ||
|
||
private final long timestamp; | ||
private BigDecimal value; | ||
|
||
public PointBigDecimal(long timestamp, BigDecimal value) { | ||
this.timestamp = timestamp; | ||
this.value = value; | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public BigDecimal getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(BigDecimal value) { | ||
this.value = value; | ||
} | ||
|
||
} |
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
75 changes: 75 additions & 0 deletions
75
src/main/java/gr/aueb/delorean/chimp/SwingFilterBigDecimal.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,75 @@ | ||
package gr.aueb.delorean.chimp; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.MathContext; | ||
import java.math.RoundingMode; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class SwingFilterBigDecimal { | ||
|
||
MathContext mc = new MathContext(30, RoundingMode.HALF_UP) ; | ||
|
||
public List<SwingSegmentBigDecimal> filter(Collection<PointBigDecimal> points, BigDecimal epsilon) { | ||
|
||
List<SwingSegmentBigDecimal> swingSegments = new ArrayList<>(); | ||
|
||
PointBigDecimal first = null; | ||
LinearFunctionBigDecimal uiOld = null; | ||
LinearFunctionBigDecimal liOld = null; | ||
|
||
Iterator<PointBigDecimal> iterator = points.iterator(); | ||
|
||
PointBigDecimal previous = first = iterator.next(); | ||
PointBigDecimal current = iterator.next(); | ||
uiOld = new LinearFunctionBigDecimal(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), | ||
current.getValue().add(epsilon)); | ||
liOld = new LinearFunctionBigDecimal(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), | ||
current.getValue().subtract(epsilon)); | ||
|
||
while (true) { | ||
if (!iterator.hasNext()) { | ||
if (uiOld != null && liOld != null) { | ||
// System.out.println("need to start new line"); | ||
LinearFunctionBigDecimal line = new LinearFunctionBigDecimal(first.getTimestamp(), first.getValue(), | ||
current.getTimestamp(), | ||
(uiOld.get(current.getTimestamp()).add(liOld.get(current.getTimestamp()))).divide(new BigDecimal(2), mc)); | ||
swingSegments.add(new SwingSegmentBigDecimal(first.getTimestamp(), current.getTimestamp(), line)); | ||
} else { | ||
swingSegments.add(new SwingSegmentBigDecimal(first.getTimestamp(), first.getTimestamp(), first.getValue(), first.getValue())); | ||
} | ||
return swingSegments; | ||
} | ||
previous = current; | ||
current = iterator.next(); | ||
// System.out.println("Points: " + first.getValue() + "\t" + previous.getValue() + "\t" + current.getValue() + "\t" + uiOld + "\t" + liOld); | ||
if (uiOld.get(current.getTimestamp()).compareTo(current.getValue().subtract(epsilon)) < 0 | ||
|| liOld.get(current.getTimestamp()).compareTo(current.getValue().add(epsilon)) > 0) { | ||
PointBigDecimal newPoint = new PointBigDecimal(previous.getTimestamp(), (uiOld.get(previous.getTimestamp()).add(liOld.get(previous.getTimestamp()))).divide(new BigDecimal(2), mc)); | ||
System.out.println("need to start new line: " + first.getValue() + "\t" + newPoint.getValue() + "\t" + previous.getTimestamp()); | ||
swingSegments.add(new SwingSegmentBigDecimal(first.getTimestamp(), previous.getTimestamp() - 1, first.getValue(), newPoint.getValue())); | ||
// swingSegments.add(new SwingSegment(first.getTimestamp(), previous.getTimestamp() - 1, first.getValue(), (uiOld.get(previous.getTimestamp()) + liOld.get(previous.getTimestamp())) / 2)); | ||
previous = first = newPoint; | ||
uiOld = new LinearFunctionBigDecimal(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), | ||
current.getValue().add(epsilon)); | ||
liOld = new LinearFunctionBigDecimal(previous.getTimestamp(), previous.getValue(), current.getTimestamp(), | ||
current.getValue().subtract(epsilon)); | ||
// System.out.println("New range: " + current.getValue() + "\t" + current.getTimestamp() + "\t" + uiOld + "\t" + liOld); | ||
} else { | ||
LinearFunctionBigDecimal uiNew = new LinearFunctionBigDecimal(first.getTimestamp(), first.getValue(), | ||
current.getTimestamp(), current.getValue().add(epsilon)); | ||
LinearFunctionBigDecimal liNew = new LinearFunctionBigDecimal(first.getTimestamp(), first.getValue(), | ||
current.getTimestamp(), current.getValue().subtract(epsilon)); | ||
// System.out.println("Cand: " + current.getValue() + "\t" + current.getTimestamp() + "\t" + uiNew + "\t" + liNew); | ||
if (uiOld == null || uiOld.get(current.getTimestamp()).compareTo(uiNew.get(current.getTimestamp())) > 0) { | ||
uiOld = uiNew; | ||
} | ||
if (liOld == null || liOld.get(current.getTimestamp()).compareTo(liNew.get(current.getTimestamp())) < 0) { | ||
liOld = liNew; | ||
} | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/gr/aueb/delorean/chimp/SwingSegmentBigDecimal.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,40 @@ | ||
package gr.aueb.delorean.chimp; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class SwingSegmentBigDecimal { | ||
|
||
private long initialTimestamp; | ||
private long finalTimestamp; | ||
private LinearFunctionBigDecimal line; | ||
|
||
public SwingSegmentBigDecimal(long initialTimestamp, long finalTimestamp, LinearFunctionBigDecimal line) { | ||
this.initialTimestamp = initialTimestamp; | ||
this.finalTimestamp = finalTimestamp; | ||
this.line = line; | ||
} | ||
|
||
public SwingSegmentBigDecimal(long initialTimestamp, long finalTimestamp, BigDecimal first, BigDecimal last) { | ||
this.initialTimestamp = initialTimestamp; | ||
this.finalTimestamp = finalTimestamp; | ||
this.line = new LinearFunctionBigDecimal(initialTimestamp, first, finalTimestamp + 1, last); | ||
} | ||
|
||
public long getFinalTimestamp() { | ||
return finalTimestamp; | ||
} | ||
|
||
public long getInitialTimestamp() { | ||
return initialTimestamp; | ||
} | ||
|
||
public LinearFunctionBigDecimal getLine() { | ||
return line; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%d-%d: %f", getInitialTimestamp(), getFinalTimestamp(), getLine()); | ||
} | ||
|
||
} |
Oops, something went wrong.