diff --git a/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilterBigDecimal.java b/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilterBigDecimal.java deleted file mode 100644 index ea19236..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/DecompressorSwingFilterBigDecimal.java +++ /dev/null @@ -1,50 +0,0 @@ -package gr.aueb.delorean.chimp; - -import java.math.BigDecimal; -import java.util.List; - -public class DecompressorSwingFilterBigDecimal { - - private List swingSegments; - private BigDecimal storedVal = new BigDecimal(0); - private boolean endOfStream = false; - private int currentElement = 0; - private int currentTimestampOffset = 0; - - public DecompressorSwingFilterBigDecimal(List 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; - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/gr/aueb/delorean/chimp/LossyCompressor32.java b/src/main/java/gr/aueb/delorean/chimp/LossyCompressor32.java deleted file mode 100644 index 603fcef..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/LossyCompressor32.java +++ /dev/null @@ -1,187 +0,0 @@ -package gr.aueb.delorean.chimp; - -import fi.iki.yak.ts.compression.gorilla.BitOutput; - -/** - * Implements the time series compression as described in the Facebook's Gorilla Paper. Value compression - * is for floating points only. - * - * @author Michael Burman - */ -public class LossyCompressor32 { - - private int storedLeadingZeros = Integer.MAX_VALUE; - private int storedTrailingZeros = 0; - private int storedVal = 0; - private boolean first = true; - private int size; - private int cases[]; - private float trailingDiff; - private float leadingDiff; - - private BitOutput out; - private int logOfError; - - public LossyCompressor32(BitOutput output, int logOfError) { - this.out = output; - this.size = 0; - this.logOfError = logOfError; - int cases[] = {0, 0, 0}; - this.cases = cases; - this.trailingDiff = 0; - this.leadingDiff = 0; - } - - /** - * Adds a new long value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(int value) { - if(first) { - writeFirst(value); - } else { - compressValue(value); - } - } - - /** - * Adds a new double value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(float value) { - if(first) { - writeFirst(Float.floatToRawIntBits(value)); - } else { - compressValue(Float.floatToRawIntBits(value)); - } - } - - private void writeFirst(int value) { - first = false; - storedVal = value; - out.writeBits(storedVal, 32); - size += 32; - } - - /** - * Closes the block and writes the remaining stuff to the BitOutput. - */ - public void close() { - addValue(Float.NaN); - out.skipBit(); - out.flush(); - } - - 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; - - if (space > 0) { - value = value >> space << space; - value = value | (storedVal & (2^space - 1)); - } - - int xor = storedVal ^ value; - - if(xor == 0) { - // Write 0 - cases[0] += 1; - out.skipBit(); - size += 1; - } else { - int leadingZeros = Integer.numberOfLeadingZeros(xor); - int trailingZeros = Integer.numberOfTrailingZeros(xor); - - // Check overflow of leading? Can't be 32! - if(leadingZeros >= 16) { - leadingZeros = 15; - } - - // Store bit '1' - out.writeBit(); - size += 1; - - if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { - cases[1] += 1; - this.trailingDiff += trailingZeros - storedTrailingZeros; - this.leadingDiff += leadingZeros - storedLeadingZeros; - writeExistingLeading(xor); - } else { - cases[2] += 2; - writeNewLeading(xor, leadingZeros, trailingZeros); - } - } - - storedVal = value; - } - - /** - * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) - * store the meaningful XORed value - * - * @param xor XOR between previous value and current - */ - private void writeExistingLeading(int xor) { - out.skipBit(); - int significantBits = 32 - storedLeadingZeros - storedTrailingZeros; - out.writeBits(xor >>> storedTrailingZeros, significantBits); - size += 1 + significantBits; - } - - /** - * store the length of the number of leading zeros in the next 5 bits - * store length of the meaningful XORed value in the next 6 bits, - * store the meaningful bits of the XORed value - * (type b) - * - * @param xor XOR between previous value and current - * @param leadingZeros New leading zeros - * @param trailingZeros New trailing zeros - */ - private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) { - out.writeBit(); - out.writeBits(leadingZeros, 4); // Number of leading zeros in the next 4 bits - - int significantBits = 32 - leadingZeros - trailingZeros; - if (significantBits == 32) { - out.writeBits(0, 5); // Length of meaningful bits in the next 5 bits - } else { - out.writeBits(significantBits, 5); // Length of meaningful bits in the next 5 bits - } - out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR - - storedLeadingZeros = leadingZeros; - storedTrailingZeros = trailingZeros; - size += 1 + 4 + 5 + significantBits; - } - - public int getSize() { - return size; - } - - public float getLeadingDiff() { - return leadingDiff; - } - - public float getTrailingDiff() { - return trailingDiff; - } - - public int[] getCases() { - return cases; - } -} diff --git a/src/main/java/gr/aueb/delorean/chimp/NewDecompressor32.java b/src/main/java/gr/aueb/delorean/chimp/NewDecompressor32.java deleted file mode 100644 index c14ac9f..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/NewDecompressor32.java +++ /dev/null @@ -1,82 +0,0 @@ -package gr.aueb.delorean.chimp; - -import fi.iki.yak.ts.compression.gorilla.BitInput; - -/** - * Decompresses a compressed stream created by the Compressor. Returns pairs of timestamp and floating point value. - * - * @author Michael Burman - */ -public class NewDecompressor32 { - - private int storedLeadingZeros = Integer.MAX_VALUE; - private int storedTrailingZeros = 0; - private int storedVal = 0; - private boolean first = true; - private boolean endOfStream = false; - - private BitInput in; - - private final static int NAN_INT = 0x7fc00000; - - - public NewDecompressor32(BitInput input) { - in = input; - } - - /** - * Returns the next pair in the time series, if available. - * - * @return Pair if there's next value, null if series is done. - */ - public Value readValue() { - next(); - if(endOfStream) { - return null; - } - return new Value(storedVal); - } - - private void next() { - if (first) { - first = false; - storedVal = (int) in.getLong(32); - if (storedVal == NAN_INT) { - endOfStream = true; - return; - } - - } else { - nextValue(); - } - } - - private void nextValue() { - // Read value - if (in.readBit()) { - // else -> same value as before - if (in.readBit()) { - // New leading and trailing zeros - storedLeadingZeros = (int) in.getLong(4); -// storedLeadingZeros = (int) in.getLong(3) * 2; - - byte significantBits = (byte) in.getLong(5); - if(significantBits == 0) { - significantBits = 32; - } - storedTrailingZeros = 32 - significantBits - storedLeadingZeros; - } - int value = (int) in.getLong(32 - storedLeadingZeros - storedTrailingZeros); - value <<= storedTrailingZeros; - value = storedVal ^ value; - if (value == NAN_INT) { - endOfStream = true; - return; - } else { - storedVal = value; - } - - } - } - -} \ No newline at end of file diff --git a/src/main/java/gr/aueb/delorean/chimp/NewLossyCompressor32.java b/src/main/java/gr/aueb/delorean/chimp/NewLossyCompressor32.java deleted file mode 100644 index 889562e..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/NewLossyCompressor32.java +++ /dev/null @@ -1,190 +0,0 @@ -package gr.aueb.delorean.chimp; - -import fi.iki.yak.ts.compression.gorilla.BitOutput; - -/** - * Implements the time series compression as described in the Facebook's Gorilla Paper. Value compression - * is for floating points only. - * - * @author Michael Burman - */ -public class NewLossyCompressor32 { - - private int storedLeadingZeros = Integer.MAX_VALUE; - private int storedTrailingZeros = 0; - private int storedVal = 0; - private boolean first = true; - private int size; - private int cases[]; - private float trailingDiff; - private float leadingDiff; - - private BitOutput out; - private int logOfError; - - public NewLossyCompressor32(BitOutput output, int logOfError) { - this.out = output; - this.size = 0; - this.logOfError = logOfError; - int cases[] = {0, 0, 0}; - this.cases = cases; - this.trailingDiff = 0; - this.leadingDiff = 0; - } - - /** - * Adds a new long value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(int value) { - if(first) { - writeFirst(value); - } else { - compressValue(value); - } - } - - /** - * Adds a new double value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(float value) { - if(first) { - writeFirst(Float.floatToRawIntBits(value)); - } else { - compressValue(Float.floatToRawIntBits(value)); - } - } - - private void writeFirst(int value) { - first = false; - storedVal = value; - out.writeBits(storedVal, 32); - size += 32; - } - - /** - * Closes the block and writes the remaining stuff to the BitOutput. - */ - public void close() { - addValue(Float.NaN); - out.skipBit(); - out.flush(); - } - - 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; - - if (space > 0) { - value = value >> space << space; - value = value | (storedVal & (2^space - 1)); - } - - int xor = storedVal ^ value; - - if(xor == 0) { - // Write 0 - cases[0] += 1; - out.skipBit(); - size += 1; - } else { - int leadingZeros = Integer.numberOfLeadingZeros(xor); - int trailingZeros = Integer.numberOfTrailingZeros(xor); - - // Check overflow of leading? Can't be 32! - if(leadingZeros >= 16) { - leadingZeros = 15; - } -// leadingZeros = leadingZeros % 2 == 0 ? leadingZeros : (leadingZeros - 1); - - // Store bit '1' - out.writeBit(); - size += 1; - - if((leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) - && leadingZeros + trailingZeros < storedLeadingZeros + storedTrailingZeros + 10) { - cases[1] += 1; - this.trailingDiff += trailingZeros - storedTrailingZeros; - this.leadingDiff += leadingZeros - storedLeadingZeros; - writeExistingLeading(xor); - } else { - cases[2] += 2; - writeNewLeading(xor, leadingZeros, trailingZeros); - } - } - - storedVal = value; - } - - /** - * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) - * store the meaningful XORed value - * - * @param xor XOR between previous value and current - */ - private void writeExistingLeading(int xor) { - out.skipBit(); - int significantBits = 32 - storedLeadingZeros - storedTrailingZeros; - out.writeBits(xor >>> storedTrailingZeros, significantBits); - size += 1 + significantBits; - } - - /** - * store the length of the number of leading zeros in the next 5 bits - * store length of the meaningful XORed value in the next 6 bits, - * store the meaningful bits of the XORed value - * (type b) - * - * @param xor XOR between previous value and current - * @param leadingZeros New leading zeros - * @param trailingZeros New trailing zeros - */ - private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) { - out.writeBit(); - out.writeBits(leadingZeros, 4); // Number of leading zeros in the next 4 bits -// out.writeBits(leadingZeros / 2, 3); // Number of leading zeros in the next 4 bits - - int significantBits = 32 - leadingZeros - trailingZeros; - if (significantBits == 32) { - out.writeBits(0, 5); // Length of meaningful bits in the next 5 bits - } else { - out.writeBits(significantBits, 5); // Length of meaningful bits in the next 5 bits - } - out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR - - storedLeadingZeros = leadingZeros; - storedTrailingZeros = trailingZeros; - size += 1 + 4 + 5 + significantBits; - } - - public int getSize() { - return size; - } - - public float getLeadingDiff() { - return leadingDiff; - } - - public float getTrailingDiff() { - return trailingDiff; - } - - public int[] getCases() { - return cases; - } -} diff --git a/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingDecompressor32.java b/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingDecompressor32.java deleted file mode 100644 index 5c2c576..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingDecompressor32.java +++ /dev/null @@ -1,92 +0,0 @@ -package gr.aueb.delorean.chimp; - -import fi.iki.yak.ts.compression.gorilla.BitInput; - -/** - * Decompresses a compressed stream created by the Compressor. Returns pairs of timestamp and floating point value. - * - * @author Michael Burman - */ -public class RunLengthEncodingDecompressor32 { - - private int storedLeadingZeros = Integer.MAX_VALUE; - private int storedTrailingZeros = 0; - private int storedVal = 0; - private boolean first = true; - private boolean endOfStream = false; - private int runSize = 0; - - private BitInput in; - - private final static int NAN_INT = 0x7fc00000; - - - public RunLengthEncodingDecompressor32(BitInput input) { - in = input; - } - - /** - * Returns the next pair in the time series, if available. - * - * @return Pair if there's next value, null if series is done. - */ - public Value readValue() { - next(); - if(endOfStream) { - return null; - } - return new Value(storedVal); - } - - private void next() { - if (first) { - first = false; - storedVal = (int) in.getLong(32); - if (storedVal == NAN_INT) { - endOfStream = true; - return; - } - - } else { - nextValue(); - } - } - - private void nextValue() { - if (runSize > 0) { - runSize--; - return; - } - // Read value - if (in.readBit()) { - // else -> same value as before - if (in.readBit()) { - // New leading and trailing zeros - storedLeadingZeros = (int) in.getLong(4); -// storedLeadingZeros = (int) in.getLong(3) * 2; - - byte significantBits = (byte) in.getLong(5); - if(significantBits == 0) { - significantBits = 32; - } - storedTrailingZeros = 32 - significantBits - storedLeadingZeros; - } - int value = (int) in.getLong(32 - storedLeadingZeros - storedTrailingZeros); - value <<= storedTrailingZeros; - value = storedVal ^ value; - if (value == NAN_INT) { - endOfStream = true; - return; - } else { - storedVal = value; - } - - } else { - if (in.readBit()) { - runSize = (int) in.getLong(32); - runSize--; - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingLossyCompressor32.java b/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingLossyCompressor32.java deleted file mode 100644 index b6534a7..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/RunLengthEncodingLossyCompressor32.java +++ /dev/null @@ -1,219 +0,0 @@ -package gr.aueb.delorean.chimp; - -import fi.iki.yak.ts.compression.gorilla.BitOutput; - -/** - * Implements the time series compression as described in the Facebook's Gorilla Paper. Value compression - * is for floating points only. - * - * @author Michael Burman - */ -public class RunLengthEncodingLossyCompressor32 { - - private int storedLeadingZeros = Integer.MAX_VALUE; - private int storedTrailingZeros = 0; - private int storedVal = 0; - private boolean first = true; - private int size; - private int cases[]; - private float trailingDiff; - private float leadingDiff; - private int runSize; - - private BitOutput out; - private int logOfError; - - public RunLengthEncodingLossyCompressor32(BitOutput output, int logOfError) { - this.out = output; - this.size = 0; - this.logOfError = logOfError; - int cases[] = {0, 0, 0}; - this.cases = cases; - this.trailingDiff = 0; - this.leadingDiff = 0; - this.runSize = 0; - } - - /** - * Adds a new long value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(int value) { - if(first) { - writeFirst(value); - } else { - compressValue(value); - } - } - - /** - * Adds a new double value to the series. Note, values must be inserted in order. - * - * @param timestamp Timestamp which is inside the allowed time block (default 24 hours with millisecond precision) - * @param value next floating point value in the series - */ - public void addValue(float value) { - if(first) { - writeFirst(Float.floatToRawIntBits(value)); - } else { - compressValue(Float.floatToRawIntBits(value)); - } - } - - private void writeFirst(int value) { - first = false; - storedVal = value; - out.writeBits(storedVal, 32); - size += 32; - } - - /** - * Closes the block and writes the remaining stuff to the BitOutput. - */ - public void close() { - if (runSize > 1600) { - out.skipBit(); - out.writeBit(); - out.writeBits(runSize, 4); - runSize = 0; - } else if (runSize > 0) { - for (int i = 0; i < runSize; i++) { - out.skipBit(); - out.skipBit(); - } - runSize = 0; - } - addValue(Float.NaN); - out.skipBit(); - out.flush(); - } - - 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(); - runSize++; - return; - } - - if (runSize > 16) { - out.skipBit(); - out.writeBit(); - out.writeBits(runSize, 32); - size += 34; - runSize = 0; - } else if (runSize > 0) { - for (int i = 0; i < runSize; i++) { - out.skipBit(); - out.skipBit(); - size += 2; - } - runSize = 0; - } - - // TODO Fix already compiled into a big method - int integerDigits = (value << 1 >>> 24) - 127; - int space = 23 + this.logOfError - integerDigits; - - if (space > 0) { - value = value >> space << space; - value = value | (storedVal & (2^space - 1)); - } - - int xor = storedVal ^ value; - - if(xor == 0) { - // Write 0 - cases[0] += 1; - out.skipBit(); - size += 1; - } else { - int leadingZeros = Integer.numberOfLeadingZeros(xor); - int trailingZeros = Integer.numberOfTrailingZeros(xor); - - // Check overflow of leading? Can't be 32! - if(leadingZeros >= 16) { - leadingZeros = 15; - } -// leadingZeros = leadingZeros % 2 == 0 ? leadingZeros : (leadingZeros - 1); - - // Store bit '1' - out.writeBit(); - size += 1; - - if((leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) - && leadingZeros + trailingZeros < storedLeadingZeros + storedTrailingZeros + 10) { - cases[1] += 1; - this.trailingDiff += trailingZeros - storedTrailingZeros; - this.leadingDiff += leadingZeros - storedLeadingZeros; - writeExistingLeading(xor); - } else { - cases[2] += 2; - writeNewLeading(xor, leadingZeros, trailingZeros); - } - } - - storedVal = value; - } - - /** - * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) - * store the meaningful XORed value - * - * @param xor XOR between previous value and current - */ - private void writeExistingLeading(int xor) { - out.skipBit(); - int significantBits = 32 - storedLeadingZeros - storedTrailingZeros; - out.writeBits(xor >>> storedTrailingZeros, significantBits); - size += 1 + significantBits; - } - - /** - * store the length of the number of leading zeros in the next 5 bits - * store length of the meaningful XORed value in the next 6 bits, - * store the meaningful bits of the XORed value - * (type b) - * - * @param xor XOR between previous value and current - * @param leadingZeros New leading zeros - * @param trailingZeros New trailing zeros - */ - private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) { - out.writeBit(); - out.writeBits(leadingZeros, 4); // Number of leading zeros in the next 4 bits -// out.writeBits(leadingZeros / 2, 3); // Number of leading zeros in the next 4 bits - - int significantBits = 32 - leadingZeros - trailingZeros; - if (significantBits == 32) { - out.writeBits(0, 5); // Length of meaningful bits in the next 5 bits - } else { - out.writeBits(significantBits, 5); // Length of meaningful bits in the next 5 bits - } - out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR - - storedLeadingZeros = leadingZeros; - storedTrailingZeros = trailingZeros; - size += 1 + 4 + 5 + significantBits; - } - - public int getSize() { - return size; - } - - public float getLeadingDiff() { - return leadingDiff; - } - - public float getTrailingDiff() { - return trailingDiff; - } - - public int[] getCases() { - return cases; - } -} diff --git a/src/main/java/gr/aueb/delorean/chimp/SwingFilterBigDecimal.java b/src/main/java/gr/aueb/delorean/chimp/SwingFilterBigDecimal.java deleted file mode 100644 index e81dfbe..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/SwingFilterBigDecimal.java +++ /dev/null @@ -1,75 +0,0 @@ -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 filter(Collection points, BigDecimal epsilon) { - - List swingSegments = new ArrayList<>(); - - PointBigDecimal first = null; - LinearFunctionBigDecimal uiOld = null; - LinearFunctionBigDecimal liOld = null; - - Iterator 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; - } - } - } - } -} diff --git a/src/main/java/gr/aueb/delorean/chimp/SwingSegmentBigDecimal.java b/src/main/java/gr/aueb/delorean/chimp/SwingSegmentBigDecimal.java deleted file mode 100644 index ab17127..0000000 --- a/src/main/java/gr/aueb/delorean/chimp/SwingSegmentBigDecimal.java +++ /dev/null @@ -1,40 +0,0 @@ -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()); - } - -} \ No newline at end of file