Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lat/Lng inputs to all v2 API requests made optional. #3407

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions app/controllers/ProjectSidewalkAPIController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import formats.json.APIFormats
import java.sql.Timestamp
import java.time.Instant
import javax.inject.Inject
import models.attribute.{GlobalAttributeForAPI, GlobalAttributeTable, GlobalAttributeWithLabelForAPI}
import models.attribute.{GlobalAttributeForAPI, GlobalAttributeTable, GlobalAttributeWithLabelForAPI, ConfigTable, MapParams}
import org.locationtech.jts.geom.{Coordinate => JTSCoordinate}
import math._
import models.region._
Expand Down Expand Up @@ -125,13 +125,15 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
* @param filetype
* @return
*/
def getAccessAttributesWithLabelsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, severity: Option[String], filetype: Option[String]) = UserAwareAction.async { implicit request =>
def getAccessAttributesWithLabelsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double],
severity: Option[String], filetype: Option[String]) = UserAwareAction.async { implicit request =>
apiLogging(request.remoteAddress, request.identity, request.toString)

val minLat:Float = min(lat1, lat2).toFloat
val maxLat:Float = max(lat1, lat2).toFloat
val minLng:Float = min(lng1, lng2).toFloat
val maxLng:Float = max(lng1, lng2).toFloat
val cityMapParams: MapParams = ConfigTable.getCityMapParams
val minLat: Double = min(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val maxLat: Double = max(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val minLng: Double = min(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))
val maxLng: Double = max(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))

// In CSV format.
if (filetype.isDefined && filetype.get == "csv") {
Expand Down Expand Up @@ -198,14 +200,16 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
* @param filetype
* @return
*/
def getAccessAttributesV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, severity: Option[String],
filetype: Option[String]) = UserAwareAction.async { implicit request =>
def getAccessAttributesV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double],
severity: Option[String], filetype: Option[String]) = UserAwareAction.async { implicit request =>
apiLogging(request.remoteAddress, request.identity, request.toString)

val minLat:Float = min(lat1, lat2).toFloat
val maxLat:Float = max(lat1, lat2).toFloat
val minLng:Float = min(lng1, lng2).toFloat
val maxLng:Float = max(lng1, lng2).toFloat
val cityMapParams: MapParams = ConfigTable.getCityMapParams
val minLat:Double = min(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val maxLat:Double = max(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val minLng:Double = min(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))
val maxLng:Double = max(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))

// In CSV format.
if (filetype.isDefined && filetype.get == "csv") {
val accessAttributesfile = new java.io.File("access_attributes.csv")
Expand Down Expand Up @@ -308,9 +312,17 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
* @param filetype
* @return
*/
def getAccessScoreNeighborhoodsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, filetype: Option[String]) = UserAwareAction.async { implicit request =>
def getAccessScoreNeighborhoodsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double],
filetype: Option[String]) = UserAwareAction.async { implicit request =>
apiLogging(request.remoteAddress, request.identity, request.toString)
val coordinates = Array(min(lat1, lat2), max(lat1, lat2), min(lng1, lng2), max(lng1, lng2))

val cityMapParams: MapParams = ConfigTable.getCityMapParams
val minLat: Double = min(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val maxLat: Double = max(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val minLng: Double = min(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))
val maxLng: Double = max(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))
val coordinates = Array(minLat, maxLat, minLng, maxLng)

// In CSV format.
if (filetype.isDefined && filetype.get == "csv") {
val file: java.io.File = getAccessScoreNeighborhoodsCSV(version = 2, coordinates)
Expand Down Expand Up @@ -395,7 +407,7 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
val clusteredLabelLocations: List[LabelLocation] = clusterLabelLocations(labelLocations)
clusteredLabelLocations.map(l => AttributeForAccessScore(l.lat, l.lng, l.labelType, new Timestamp(0), new Timestamp(0), 1, 1))
case 2 =>
val globalAttributes: List[GlobalAttributeForAPI] = GlobalAttributeTable.getGlobalAttributesInBoundingBox(coordinates(0).toFloat, coordinates(2).toFloat, coordinates(1).toFloat, coordinates(3).toFloat, None)
val globalAttributes: List[GlobalAttributeForAPI] = GlobalAttributeTable.getGlobalAttributesInBoundingBox(coordinates(0), coordinates(2), coordinates(1), coordinates(3), None)
globalAttributes.map(l => AttributeForAccessScore(l.lat, l.lng, l.labelType, l.avgImageCaptureDate, l.avgLabelDate, l.imageCount, l.labelCount))
}
labelsForScore
Expand Down Expand Up @@ -545,9 +557,16 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
* @param lng2 Second longitude value for the bounding box
* @return The access score for the given neighborhood
*/
def getAccessScoreStreetsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, filetype: Option[String]) = UserAwareAction.async { implicit request =>
def getAccessScoreStreetsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double], filetype: Option[String]) = UserAwareAction.async { implicit request =>
apiLogging(request.remoteAddress, request.identity, request.toString)
val streetAccessScores: List[AccessScoreStreet] = getAccessScoreStreetsGeneric(lat1, lng1, lat2, lng2, version = 2)

val cityMapParams: MapParams = ConfigTable.getCityMapParams
val minLat: Double = min(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val maxLat: Double = max(lat1.getOrElse(cityMapParams.lat1), lat2.getOrElse(cityMapParams.lat2))
val minLng: Double = min(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))
val maxLng: Double = max(lng1.getOrElse(cityMapParams.lng1), lng2.getOrElse(cityMapParams.lng2))

val streetAccessScores: List[AccessScoreStreet] = getAccessScoreStreetsGeneric(minLat, maxLat, minLng, maxLng, version = 2)
// In CSV format.
if (filetype.isDefined && filetype.get == "csv") {
val file = new java.io.File("access_score_streets.csv")
Expand Down
4 changes: 2 additions & 2 deletions app/models/attribute/GlobalAttributeTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ object GlobalAttributeTable {
/**
* Gets global attributes within a bounding box for the public API.
*/
def getGlobalAttributesInBoundingBox(minLat: Float, minLng: Float, maxLat: Float, maxLng: Float, severity: Option[String], startIndex: Option[Int] = None, n: Option[Int] = None): List[GlobalAttributeForAPI] = db.withSession { implicit session =>
def getGlobalAttributesInBoundingBox(minLat: Double, minLng: Double, maxLat: Double, maxLng: Double, severity: Option[String], startIndex: Option[Int] = None, n: Option[Int] = None): List[GlobalAttributeForAPI] = db.withSession { implicit session =>
// Sum the validations counts, average date, and the number of the labels that make up each global attribute.
val validationCounts =
"""SELECT global_attribute.global_attribute_id AS global_attribute_id,
Expand Down Expand Up @@ -297,7 +297,7 @@ object GlobalAttributeTable {
/**
* Gets global attributes within a bounding box with the labels that make up those attributes for the public API.
*/
def getGlobalAttributesWithLabelsInBoundingBox(minLat: Float, minLng: Float, maxLat: Float, maxLng: Float, severity: Option[String], startIndex: Option[Int] = None, n: Option[Int] = None): List[GlobalAttributeWithLabelForAPI] = db.withSession { implicit session =>
def getGlobalAttributesWithLabelsInBoundingBox(minLat: Double, minLng: Double, maxLat: Double, maxLng: Double, severity: Option[String], startIndex: Option[Int] = None, n: Option[Int] = None): List[GlobalAttributeWithLabelForAPI] = db.withSession { implicit session =>
val attributesWithLabels = Q.queryNA[GlobalAttributeWithLabelForAPI](
s"""SELECT global_attribute.global_attribute_id,
| label_type.label_type,
Expand Down
8 changes: 4 additions & 4 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ POST /userapi/logWebpageActivity @controllers.UserCo
PUT /userapi/setUserOrg/:orgId @controllers.UserProfileController.setUserOrg(orgId: Int)

# Access Feature and Access Score APIs
GET /v2/access/attributes @controllers.ProjectSidewalkAPIController.getAccessAttributesV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, severity: Option[String], filetype: Option[String])
GET /v2/access/attributesWithLabels @controllers.ProjectSidewalkAPIController.getAccessAttributesWithLabelsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, severity: Option[String], filetype: Option[String])
GET /v2/access/score/streets @controllers.ProjectSidewalkAPIController.getAccessScoreStreetsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, filetype: Option[String])
GET /v2/access/score/neighborhoods @controllers.ProjectSidewalkAPIController.getAccessScoreNeighborhoodsV2(lat1: Double, lng1: Double, lat2: Double, lng2: Double, filetype: Option[String])
GET /v2/access/attributes @controllers.ProjectSidewalkAPIController.getAccessAttributesV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double], severity: Option[String], filetype: Option[String])
GET /v2/access/attributesWithLabels @controllers.ProjectSidewalkAPIController.getAccessAttributesWithLabelsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double], severity: Option[String], filetype: Option[String])
GET /v2/access/score/streets @controllers.ProjectSidewalkAPIController.getAccessScoreStreetsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double], filetype: Option[String])
GET /v2/access/score/neighborhoods @controllers.ProjectSidewalkAPIController.getAccessScoreNeighborhoodsV2(lat1: Option[Double], lng1: Option[Double], lat2: Option[Double], lng2: Option[Double], filetype: Option[String])
GET /v2/userStats @controllers.ProjectSidewalkAPIController.getUsersAPIStats(filetype: Option[String])
GET /v2/overallStats @controllers.ProjectSidewalkAPIController.getOverallSidewalkStats(filterLowQuality: Boolean ?= false, filetype: Option[String])
GET /v1/access/features @controllers.ProjectSidewalkAPIController.getAccessAttributesV1(lat1: Double, lng1: Double, lat2: Double, lng2: Double)
Expand Down