You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by mi...@apache.org on 2020/05/16 14:55:53 UTC
[incubator-streampipes-extensions] branch feature/geodesicCalc
updated: changed round function
This is an automated email from the ASF dual-hosted git repository.
micklich pushed a commit to branch feature/geodesicCalc
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
The following commit(s) were added to refs/heads/feature/geodesicCalc by this push:
new 3d6ecf9 changed round function
3d6ecf9 is described below
commit 3d6ecf9aa81eecc475b3b85a85103abb4f1f7e58
Author: micklich <fl...@disy.net>
AuthorDate: Sat May 16 16:55:29 2020 +0200
changed round function
---
.../distancecalculator/DistanceCalculator.java | 2 +-
.../StaticDistanceCalculator.java | 2 +-
.../geo/jvm/processor/util/SpLengthCalculator.java | 38 ++++++----------------
3 files changed, 12 insertions(+), 30 deletions(-)
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
index 481a72c..4d0072b 100644
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/distancecalculator/DistanceCalculator.java
@@ -68,7 +68,7 @@ public class DistanceCalculator implements EventProcessor<DistanceCalculatorPara
length.convertUnit(unit);
}
- event.addField(DistanceCalculatorController.LENGTH_RUNTIME, length.getLengthAsString());
+ event.addField(DistanceCalculatorController.LENGTH_RUNTIME, length.getLengthValueRoundet());
event.addField(DistanceCalculatorController.UNIT_RUNTIME, length.getLengthUnit());
out.collect(event);
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
index 1ee19c4..0b5eca8 100644
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
@@ -59,7 +59,7 @@ public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCa
staticLength.convertUnit(unit);
}
- event.addField(StaticDistanceCalculatorController.LENGTH_RUNTIME, staticLength.getLengthAsString());
+ event.addField(StaticDistanceCalculatorController.LENGTH_RUNTIME, staticLength.getLengthValueRoundet());
event.addField(StaticDistanceCalculatorController.UNIT_RUNTIME, staticLength.getLengthUnit());
collector.collect(event);
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/SpLengthCalculator.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/SpLengthCalculator.java
index 61552d1..495546b 100644
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/SpLengthCalculator.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/util/SpLengthCalculator.java
@@ -19,9 +19,9 @@ public class SpLengthCalculator {
private final double EARTHRADIUS = 6378137; //meters
private final Unit<Length> M = SI.METRE;
- private final Unit<Length> KM = MetricPrefix.KILO(SI.METRE);
- private final Unit<Length> MILE = SI.METRE.multiply(1609344).divide(1000);
- private final Unit<Length> FOOT = SI.METRE.multiply(3048).divide(10000);
+ private final Unit<Length> KM = MetricPrefix.KILO(M);
+ private final Unit<Length> MILE = M.multiply(1609344).divide(1000);
+ private final Unit<Length> FOOT = M.multiply(3048).divide(10000);
public enum ValidLengthUnits {
METER(1), KM(2), MILE(3), FOOT(4);
@@ -54,8 +54,12 @@ public class SpLengthCalculator {
return decimalPosition;
}
+ public Double getLengthValueRoundet() {
+ return roundResult(length.getValue().doubleValue(), this.decimalPosition);
+ }
+
public Double getLengthValue() {
- return (length.getValue()).doubleValue();
+ return (length.getValue().doubleValue());
}
public String getLengthUnit() {
@@ -66,12 +70,6 @@ public class SpLengthCalculator {
return length.getUnit();
}
- public String getLengthAsString() {
- String result = doubleToString(getLengthValue(), getDecimalPosition());
- return result;
- }
-
-
// ========================== setter
private void setLength(Quantity<Length> length) {
@@ -137,7 +135,7 @@ public class SpLengthCalculator {
* @param decimalPositions
* @return
*/
- public static String doubleToString(Double value, int decimalPositions) {
+ protected Double roundResult(Double value, int decimalPositions) {
//handle negative values but should not be possible but if 3 decimal Position will be used
if (decimalPositions < 0) {
@@ -160,7 +158,7 @@ public class SpLengthCalculator {
}
//writes the result into a String to parse this into the stream. Cannot be parsed as a Double Otherwise scientific style comes back
- String result = df.format(value);
+ double result = Double.parseDouble(df.format(value));
return result;
}
@@ -179,20 +177,4 @@ public class SpLengthCalculator {
setLength(dist, M);
}
-
-
- public void calcGeodesicDistanceNew(double lat1, double lng1, double lat2, double lng2) {
- // using haversine formula
- double dLat = Math.toRadians(lat2-lat1);
- double dLng = Math.toRadians(lng2-lng1);
- double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
- Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
- Math.sin(dLng/2) * Math.sin(dLng/2);
- double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- float dist = (float) (EARTHRADIUS * c);
-
- setLength(dist, M);
- }
-
-
}