Skip to content

Commit

Permalink
reduce redundant work in revgeo
Browse files Browse the repository at this point in the history
  • Loading branch information
David Blackman committed Jan 28, 2014
1 parent 87baddd commit c94cfc8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions server/src/main/scala/ReverseGeocoderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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())
}
})
}
Expand Down

0 comments on commit c94cfc8

Please sign in to comment.