From c94cfc81fd7842a0f1f5046f0c726ea3a07171a8 Mon Sep 17 00:00:00 2001 From: David Blackman Date: Mon, 27 Jan 2014 19:51:13 -0500 Subject: [PATCH] reduce redundant work in revgeo --- server/src/main/scala/ReverseGeocoderImpl.scala | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/src/main/scala/ReverseGeocoderImpl.scala b/server/src/main/scala/ReverseGeocoderImpl.scala index 3137fdbde..551feca32 100644 --- a/server/src/main/scala/ReverseGeocoderImpl.scala +++ b/server/src/main/scala/ReverseGeocoderImpl.scala @@ -70,13 +70,12 @@ class ReverseGeocoderHelperImpl( } } - def computeCoverage( + def computeIntersectionArea( featureGeometry: Geometry, requestGeometry: Geometry ): Double = { try { - val intersection = featureGeometry.intersection(requestGeometry) - math.min(1, intersection.getArea() / requestGeometry.getArea()) + featureGeometry.intersection(requestGeometry).getArea() } catch { case e => Stats.addMetric("intersection_exception", 1) @@ -191,8 +190,6 @@ class ReverseGeocoderHelperImpl( } yield { val cellGeometries = geomIndexToCellIdMap(index).flatMap(cellid => cellGeometryMap(cellid)) - val featureIds = findMatches(otherGeom, cellGeometries) - val servingFeaturesMap: Map[StoredFeatureId, GeocodeServingFeature] = store.getByFeatureIds(featureIds.toSet.toList) @@ -206,8 +203,9 @@ class ReverseGeocoderHelperImpl( otherGeom.getNumPoints > 2) { polygonMap.get(fid).foreach(geom => { if (geom.getNumPoints > 2) { - parse.scoringFeatures.percentOfRequestCovered(computeCoverage(geom, otherGeom)) - parse.scoringFeatures.percentOfFeatureCovered(computeCoverage(otherGeom, geom)) + val overlapArea = computeIntersectionArea(geom, otherGeom) + parse.scoringFeatures.percentOfRequestCovered(overlapArea / otherGeom.getArea()) + parse.scoringFeatures.percentOfFeatureCovered(overlapArea / geom.getArea()) } }) }