From f57f472f6a5eb2f12c94b9b063a8c24ac98e5c2b Mon Sep 17 00:00:00 2001 From: Brad Gonzales Date: Mon, 24 Feb 2014 16:40:41 -0600 Subject: [PATCH] Issue #2386 fixed spatial overlap rule application. Amend: updates from peer review. Change-Id: Icd33c9175f210d864bd5117fc54c76362b76ac22 Former-commit-id: b6e2ce4b74bdcadf7a6bc233555585b6eb08ac98 [formerly 783afb15858f569ef05d58b7b7cfa345f8a69a79] [formerly 8b2b50baaf73bdc139b1f55a57778607b2c14c43 [formerly 807f278d542bc36331aa83b46a86a3af9dbb6675]] Former-commit-id: 8b2b50baaf73bdc139b1f55a57778607b2c14c43 Former-commit-id: 5ce1939d01f4ac144df17dd5b5326b0d97b3ac4e --- .../services/overlap/GridOverlapData.java | 56 ++++++++------- .../service/services/overlap/OverlapData.java | 70 ++++++++++--------- .../services/overlap/PointOverlapData.java | 34 ++++----- .../services/overlap/GridOverlapDataTest.java | 57 ++++++++++++++- .../overlap/PointOverlapDataTest.java | 3 +- 5 files changed, 142 insertions(+), 78 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapData.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapData.java index 47ca5b4f16..91bc718906 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapData.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapData.java @@ -40,6 +40,10 @@ import com.raytheon.uf.common.datadelivery.service.subscription.SubscriptionOver * ------------ ---------- ----------- -------------------------- * Oct 17, 2013 2292 mpduff Initial creation * Feb 13, 2014 2386 bgonzale Change pass comparisons to >= instead of only >. + * Renamed sub1 and sub2 to otherSub and sub to make + * it easier to see what is compared against, and + * changed the spatial check to check the intersection + * coverage of sub, not otherSub. * * * @@ -68,49 +72,49 @@ public class GridOverlapData /** * Constructor. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub * @param config */ - public GridOverlapData(Subscription sub1, Subscription sub2, + public GridOverlapData(Subscription sub, Subscription otherSub, SubscriptionOverlapConfig config) { - super(sub1, sub2, config); + super(sub, otherSub, config); } /** - * Calculates the percent, 0-100, of how many cycle hours from sub2 are - * satisfied by sub1. + * Calculates the percent, 0-100, of how many cycle hours from sub are + * satisfied by otherSub. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub */ public void calculateCycleDuplicationPercent( - Subscription sub1, - Subscription sub2) { + Subscription sub, + Subscription otherSub) { - GriddedTime gtime1 = sub1.getTime(); - GriddedTime gtime2 = sub2.getTime(); + GriddedTime gtimeOther = otherSub.getTime(); + GriddedTime gtime = sub.getTime(); - cycleDuplication = this.getDuplicationPercent(gtime1.getCycleTimes(), - gtime2.getCycleTimes()); + cycleDuplication = this.getDuplicationPercent( + gtimeOther.getCycleTimes(), gtime.getCycleTimes()); } /** - * Calculates the percent, 0-100, of how many forecast hours from sub2 are - * satisfied by sub1. + * Calculates the percent, 0-100, of how many forecast hours from sub are + * satisfied by otherSub. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub */ public void calculateForecastHourDuplicationPercent( - Subscription sub1, - Subscription sub2) { - GriddedTime gtime1 = sub1.getTime(); - GriddedTime gtime2 = sub2.getTime(); + Subscription sub, + Subscription otherSub) { + GriddedTime gtimeOther = otherSub.getTime(); + GriddedTime gtime = sub.getTime(); fcstHrDuplication = getDuplicationPercent( - gtime1.getSelectedTimeIndices(), - gtime2.getSelectedTimeIndices()); + gtimeOther.getSelectedTimeIndices(), + gtime.getSelectedTimeIndices()); } /** @@ -119,8 +123,8 @@ public class GridOverlapData @Override protected void determineOverlapping() { super.determineOverlapping(); - calculateCycleDuplicationPercent(sub1, sub2); - calculateForecastHourDuplicationPercent(sub1, sub2); + calculateCycleDuplicationPercent(sub, otherSub); + calculateForecastHourDuplicationPercent(sub, otherSub); GridSubscriptionOverlapConfig config = (GridSubscriptionOverlapConfig) this.config; fcstHrPass = fcstHrDuplication >= config diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/OverlapData.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/OverlapData.java index 624f08952b..c9c153122e 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/OverlapData.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/OverlapData.java @@ -47,6 +47,8 @@ import com.raytheon.uf.common.util.CollectionUtil; * ------------ ---------- ----------- -------------------------- * Oct 17, 2013 2292 mpduff Initial creation * Feb 13, 2014 2386 bgonzale Change pass comparisons to >= instead of only >. + * Renamed sub1 and sub2 to otherSub and sub to make + * it easier to see what is compared against. * * * @@ -86,54 +88,54 @@ public abstract class OverlapData { /** The subscription overlap config object */ protected SubscriptionOverlapConfig config; - /** Subscription 1 */ - protected Subscription sub1; + /** Primary Subscription */ + protected Subscription sub; - /** Subscription 2 */ - protected Subscription sub2; + /** Other Subscription to compare against */ + protected Subscription otherSub; /** * Constructor. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub * @param config */ - public OverlapData(Subscription sub1, Subscription sub2, + public OverlapData(Subscription sub, Subscription otherSub, SubscriptionOverlapConfig config) { - this.sub1 = sub1; - this.sub2 = sub2; + this.otherSub = otherSub; + this.sub = sub; this.config = config; this.matchStrategy = config.getMatchStrategy(); } /** - * Calculates the percent, 0-100, of how much spatial coverage from sub2 is - * satisfied by sub1. + * Calculates the percent, 0-100, of how much spatial coverage from sub is + * satisfied by otherSub. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub */ - protected void calculateSpatialDuplicationPercent(Subscription sub1, - Subscription sub2) { + protected void calculateSpatialDuplicationPercent(Subscription sub, + Subscription otherSub) { - final Coverage sub1Coverage = sub1.getCoverage(); - final Coverage sub2Coverage = sub2.getCoverage(); + final Coverage otherSubCoverage = otherSub.getCoverage(); + final Coverage subCoverage = sub.getCoverage(); - if (sub1Coverage != null && sub2Coverage != null) { - final ReferencedEnvelope sub1Envelope = sub1Coverage + if (otherSubCoverage != null && subCoverage != null) { + final ReferencedEnvelope otherSubEnvelope = otherSubCoverage .getRequestEnvelope(); - final ReferencedEnvelope sub2Envelope = sub2Coverage + final ReferencedEnvelope subEnvelope = subCoverage .getRequestEnvelope(); - if (sub1Envelope != null && sub2Envelope != null) { + if (otherSubEnvelope != null && subEnvelope != null) { // try { ReferencedEnvelope intersection; try { - intersection = MapUtil.reprojectAndIntersect(sub1Envelope, - sub2Envelope); + intersection = MapUtil.reprojectAndIntersect( + otherSubEnvelope, subEnvelope); final double intersectionArea = intersection.getArea(); - spatialDuplication = (int) ((intersectionArea * 100) / sub2Envelope + spatialDuplication = (int) ((intersectionArea * 100) / subEnvelope .getArea()); } catch (TransformException e) { statusHandler.handle(Priority.PROBLEM, @@ -144,24 +146,24 @@ public abstract class OverlapData { } /** - * Calculates the percent, 0-100, of how many parameters from sub2 are - * satisfied by sub1. + * Calculates the percent, 0-100, of how many parameters from sub are + * satisfied by otherSub. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub */ - protected void calculateParameterDuplicationPercent( - Subscription sub1, Subscription sub2) { - parameterDuplication = getDuplicationPercent(sub1.getParameter(), - sub2.getParameter()); + protected void calculateParameterDuplicationPercent(Subscription sub, + Subscription otherSub) { + parameterDuplication = getDuplicationPercent(otherSub.getParameter(), + sub.getParameter()); } /** * Determine the overlap values */ protected void determineOverlapping() { - calculateParameterDuplicationPercent(sub1, sub2); - calculateSpatialDuplicationPercent(sub1, sub2); + calculateParameterDuplicationPercent(sub, otherSub); + calculateSpatialDuplicationPercent(sub, otherSub); this.parameterPass = this.parameterDuplication >= config .getMaxAllowedParameterDuplication(); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapData.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapData.java index b90c01abd2..6799fb0213 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapData.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/src/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapData.java @@ -42,6 +42,8 @@ import com.raytheon.uf.common.datadelivery.service.subscription.SubscriptionOver * Feb 13, 2014 2386 bgonzale Change pass comparisons to >= instead of only >. * Change halfNumAttrs comp to a double for comparisons * against half of uneven numbers of attributes. + * Renamed sub1 and sub2 to otherSub and sub to make + * it easier to see what is compared against. * * * @@ -63,34 +65,34 @@ public class PointOverlapData extends /** * Constructor. * - * @param sub1 - * @param sub2 + * @param sub + * @param otherSub * @param config */ - public PointOverlapData(Subscription sub1, Subscription sub2, + public PointOverlapData(Subscription sub, Subscription otherSub, SubscriptionOverlapConfig config) { - super(sub1, sub2, config); + super(sub, otherSub, config); } /** * Calculates the percent, 0-100, of how similar the time is from sub2 to * sub1. * - * @param sub1 - * @param sub2 + * @param otherSub + * @param sub */ private void calculateTimeDuplicationPercent( - Subscription sub1, - Subscription sub2) { - PointTime ptime1 = sub1.getTime(); - PointTime ptime2 = sub2.getTime(); + Subscription sub, + Subscription otherSub) { + PointTime ptimeOther = otherSub.getTime(); + PointTime ptime = sub.getTime(); - List intervalList1 = new ArrayList(); - intervalList1.add(ptime1.getInterval()); - List intervalList2 = new ArrayList(); - intervalList2.add(ptime2.getInterval()); + List intervalListOther = new ArrayList(); + intervalListOther.add(ptimeOther.getInterval()); + List intervalList = new ArrayList(); + intervalList.add(ptime.getInterval()); - timeDuplication = getDuplicationPercent(intervalList1, intervalList2); + timeDuplication = getDuplicationPercent(intervalListOther, intervalList); } /** @@ -100,7 +102,7 @@ public class PointOverlapData extends protected void determineOverlapping() { super.determineOverlapping(); PointSubscriptionOverlapConfig config = (PointSubscriptionOverlapConfig) this.config; - calculateTimeDuplicationPercent(sub1, sub2); + calculateTimeDuplicationPercent(sub, otherSub); this.timeDuplicationPass = this.timeDuplication >= config .getMaxAllowedTimeDuplication(); } diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapDataTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapDataTest.java index b47f7d3a63..7853de9987 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapDataTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/GridOverlapDataTest.java @@ -29,6 +29,7 @@ import java.util.List; import org.geotools.geometry.jts.ReferencedEnvelope; import org.junit.BeforeClass; import org.junit.Test; +import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.raytheon.uf.common.datadelivery.registry.DataType; import com.raytheon.uf.common.datadelivery.registry.GriddedCoverage; @@ -55,6 +56,11 @@ import com.vividsolutions.jts.geom.Envelope; * ------------ ---------- ----------- -------------------------- * Oct 18, 2013 2292 mpduff Initial creation * Feb 13, 2014 2386 bgonzale Added test cases to match ticket 2771 test procedures. + * Fixed areaLessThan50PercentOverlap bounds. + * Added Test case to match issue of a less than + * 50% overlap for an existing, but more than 50% + * overlap for a new subscription, but still not passing + * a 50% overlap rule. * * * @@ -90,7 +96,7 @@ public class GridOverlapDataTest { matchMeParameters.add(ParameterFixture.INSTANCE.get(1)); areaMatchMe = new Envelope(0, 10, 0, 20); - areaLessThan50PercentOverlap = new Envelope(0, 25, 0, 15); + areaLessThan50PercentOverlap = new Envelope(5, 25, 0, 15); areaGreaterThan50PercentOverlap = new Envelope(0, 10, 10, 25); areaWithNoOverlap = new Envelope(0, 30, 20, 20); @@ -388,6 +394,55 @@ public class GridOverlapDataTest { assertTrue("These should overlap", overlapResult.spatialPass); } + @Test + public void testMatchAnySpatialOnlyLessThan50PercentOfExistingGreaterThan50PercentOfNew() { + int parameter = 50; + int spatial = 50; + int forecastHours = 100; + int cycles = 100; + final GridSubscriptionOverlapConfig overlap = new GridSubscriptionOverlapConfig( + parameter, forecastHours, cycles, spatial, + SubscriptionOverlapMatchStrategy.MATCH_ANY); + + List parameters2 = new ArrayList(); + parameters2.addAll(matchMeParameters); + parameters2.add(ParameterFixture.INSTANCE.get(20)); + + List parameters3 = new ArrayList(); + parameters3.add(ParameterFixture.INSTANCE.get(30)); + + CoordinateReferenceSystem crs = MapUtil.LATLON_PROJECTION; + ReferencedEnvelope matchEnv = new ReferencedEnvelope( + -353287.9146908128, 499474.38945139456, 4064387.3713984187, + 4442030.0353220245, crs); + ReferencedEnvelope otherEnvelope = new ReferencedEnvelope( + -584748.4738489623, 487298.1073337787, 4113114.739653571, + 4783132.733000439, crs); + + SiteSubscription match = getSubscription( + 1, + matchEnv, + matchMeParameters, + createGriddedTime(Arrays.asList(0, 1, 2, 3), + Arrays.asList(0, 1, 2, 3))); + SiteSubscription otherSub = getSubscription( + 1, + otherEnvelope, + parameters3, + createGriddedTime(Arrays.asList(7, 8, 9), + Arrays.asList(7, 8, 9))); + GridOverlapData overlapResult = new GridOverlapData( + match, otherSub, overlap); + + assertFalse("These should not be duplicates", + overlapResult.isDuplicate()); + assertTrue("These should overlap", overlapResult.isOverlapping()); + assertFalse("These should not overlap", overlapResult.cyclePass); + assertFalse("These should not overlap", overlapResult.fcstHrPass); + assertFalse("These should not overlap", overlapResult.parameterPass); + assertTrue("These should overlap", overlapResult.spatialPass); + } + @Test public void testMatchAnyForecastHoursOnly() { int parameter = 50; diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapDataTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapDataTest.java index c65284c9d6..07aa122f6e 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapDataTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/service/services/overlap/PointOverlapDataTest.java @@ -35,6 +35,7 @@ import com.vividsolutions.jts.geom.Envelope; * ------------ ---------- ----------- -------------------------- * Oct 18, 2013 2292 mpduff Initial creation * Feb 13, 2014 2386 bgonzale Added test cases to match ticket 2771 test procedures. + * Fixed areaLessThan50PercentOverlap bounds. * * * @@ -65,7 +66,7 @@ public class PointOverlapDataTest { @BeforeClass public static void setup() { areaMatchPoints = new Envelope(0, 10, 0, 20); - areaLessThan50PercentOverlap = new Envelope(0, 25, 0, 15); + areaLessThan50PercentOverlap = new Envelope(5, 25, 0, 15); areaGreaterThan50PercentOverlap = new Envelope(0, 10, 10, 25); areaWithNoOverlap = new Envelope(0, 30, 20, 20);