Skip to content

Commit

Permalink
Merge pull request #3365 from ProjectSidewalk/develop
Browse files Browse the repository at this point in the history
v7.15.5
  • Loading branch information
misaugstad authored Aug 15, 2023
2 parents ac78f3c + 0db9fac commit b1aeb1f
Show file tree
Hide file tree
Showing 100 changed files with 3,412 additions and 974 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ node_modules
.DS_Store
tmp/**/*
.idea
.ivy2/cache/org.jetbrains.scala/
.ivy2/cache/scala_2.10/sbt_0.13/org.jetbrains.scala/
#.idea/**/*
*.iml
*.sublime-*
Expand Down Expand Up @@ -110,3 +112,7 @@ nohup.out

# docker db files
db/dump

# Python
scripts/__pycache__

1 change: 1 addition & 0 deletions app/controllers/AdminController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
writer.print(features.map(_.toString).mkString(","))
startIndex += batchSize
if (features.length < batchSize) moreWork = false
else writer.print(",")
}
writer.print("]")
writer.close()
Expand Down
17 changes: 14 additions & 3 deletions app/controllers/AuditController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class AuditController @Inject() (implicit val env: Environment[User, SessionAuth
def explore(newRegion: Boolean, retakeTutorial: Option[Boolean], routeId: Option[Int], resumeRoute: Boolean) = UserAwareAction.async { implicit request =>
val timestamp: Timestamp = new Timestamp(Instant.now.toEpochMilli)
val ipAddress: String = request.remoteAddress
val qString = request.queryString.map { case (k, v) => k.mkString -> v.mkString }

val studyGroupInput: Option[String] = qString.get("studyGroup")
val studyGroup: String = studyGroupInput.map(g => if (g == "1" || g == "2") g else "").getOrElse("")

val retakingTutorial: Boolean = retakeTutorial.isDefined && retakeTutorial.get

Expand Down Expand Up @@ -138,13 +142,20 @@ class AuditController @Inject() (implicit val env: Environment[User, SessionAuth
if (missionSetProgress.missionType != "audit") {
Future.successful(Redirect("/validate"))
} else {
Future.successful(Ok(views.html.explore("Project Sidewalk - Audit", task, mission, region.get, userRoute, missionSetProgress.numComplete, completedMissions, nextTempLabelId, Some(user), cityShortName, tutorialStreetId)))
// On the crowdstudy server, we want to assign users to a study group.
val response = Ok(views.html.explore("Project Sidewalk - Audit", task, mission, region.get, userRoute, missionSetProgress.numComplete, completedMissions, nextTempLabelId, Some(user), cityShortName, tutorialStreetId))
if (cityStr == "crowdstudy" && studyGroup.nonEmpty) Future.successful(response.withCookies(Cookie("SIDEWALK_STUDY_GROUP", studyGroup, httpOnly = false)))
else Future.successful(response)
}
// For anonymous users.
case None =>
// UTF-8 codes needed to pass a URL that contains parameters: ? is %3F, & is %26
val queryParams: String = routeId.map(rId => s"%3FrouteId=$rId").getOrElse("")
Future.successful(Redirect("/anonSignUp?url=/explore" + queryParams))
val routeParam: String = routeId.map(rId => s"%3FrouteId=$rId").getOrElse("")
val studyGroupParam: String =
if (routeParam.nonEmpty && studyGroup.nonEmpty) s"%26studyGroup=$studyGroup"
else if (studyGroup.nonEmpty) s"%3FstudyGroup=$studyGroup"
else ""
Future.successful(Redirect("/anonSignUp?url=/explore" + routeParam + studyGroupParam))
}
}

Expand Down
89 changes: 15 additions & 74 deletions app/controllers/ConfigController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import play.api.Play.current
import play.api.mvc.Action
import play.api.libs.json._
import scala.concurrent.Future
import models.attribute.ConfigTable
import models.attribute.{ConfigTable, MapParams}

/**
* Holds the HTTP requests associated with getting data from the parameters in our config files.
Expand All @@ -24,20 +24,13 @@ class ConfigController @Inject() (implicit val env: Environment[User, SessionAut
* Get the city-specific parameters used to pan/zoom maps to correct location.
*/
def getCityMapParams() = Action.async { implicit request =>
val mapboxApiKey: String = Play.configuration.getString("mapbox-api-key").get
val cityLat: Double = ConfigTable.getCityLat
val cityLng: Double = ConfigTable.getCityLng
val southwestLat: Double = ConfigTable.getSouthwestLat
val southwestLng: Double = ConfigTable.getSouthwestLng
val northeastLat: Double = ConfigTable.getNortheastLat
val northeastLng: Double = ConfigTable.getNortheastLng
val defaultZoom: Double = ConfigTable.getDefaultMapZoom
val cityMapParams: MapParams = ConfigTable.getCityMapParams
Future.successful(Ok(Json.obj(
"mapbox_api_key" -> mapboxApiKey,
"city_center" -> Json.obj("lat" -> cityLat, "lng" -> cityLng),
"southwest_boundary" -> Json.obj("lat" -> southwestLat, "lng" -> southwestLng),
"northeast_boundary" -> Json.obj("lat" -> northeastLat, "lng" -> northeastLng),
"default_zoom" -> defaultZoom
"mapbox_api_key" -> Play.configuration.getString("mapbox-api-key").get,
"city_center" -> Json.obj("lat" -> cityMapParams.centerLat, "lng" -> cityMapParams.centerLng),
"southwest_boundary" -> Json.obj("lat" -> cityMapParams.lat1, "lng" -> cityMapParams.lng1),
"northeast_boundary" -> Json.obj("lat" -> cityMapParams.lat2, "lng" -> cityMapParams.lng2),
"default_zoom" -> cityMapParams.zoom
)))
}

Expand All @@ -54,67 +47,15 @@ class ConfigController @Inject() (implicit val env: Environment[User, SessionAut
* Get all city-specific parameters needed for the API page demos.
*/
def getCityAPIDemoParams() = Action.async { implicit request =>
val mapboxApiKey: String = Play.configuration.getString("mapbox-api-key").get
val southwestLat: Double = ConfigTable.getSouthwestLat
val southwestLng: Double = ConfigTable.getSouthwestLng
val northeastLat: Double = ConfigTable.getNortheastLat
val northeastLng: Double = ConfigTable.getNortheastLng

val attributeCenterLat: Double = ConfigTable.getApiAttributeCenterLat
val attributeCenterLng: Double = ConfigTable.getApiAttributeCenterLng
val attributeZoom: Double = ConfigTable.getAttributeZoom
val attributeLat1: Double = ConfigTable.getAttributeLatOne
val attributeLng1: Double = ConfigTable.getAttributeLngOne
val attributeLat2: Double = ConfigTable.getAttributeLatTwo
val attributeLng2: Double = ConfigTable.getAttributeLngTwo

val streetCenterLat: Double = ConfigTable.getStreetCenterLat
val streetCenterLng: Double = ConfigTable.getStreetCenterLng
val streetZoom: Double = ConfigTable.getStreetZoom
val streetLat1: Double = ConfigTable.getStreetLatOne
val streetLng1: Double = ConfigTable.getStreetLngOne
val streetLat2: Double = ConfigTable.getStreetLatTwo
val streetLng2: Double = ConfigTable.getStreetLngTwo

val regionCenterLat: Double = ConfigTable.getRegionCenterLat
val regionCenterLng: Double = ConfigTable.getRegionCenterLng
val regionZoom: Double = ConfigTable.getRegionZoom
val regionLat1: Double = ConfigTable.getRegionLatOne
val regionLng1: Double = ConfigTable.getRegionLngOne
val regionLat2: Double = ConfigTable.getRegionLatTwo
val regionLng2: Double = ConfigTable.getRegionLngTwo

val cityMapParams: MapParams = ConfigTable.getCityMapParams
val (apiAttribute, apiStreet, apiRegion): (MapParams, MapParams, MapParams) = ConfigTable.getApiFields
Future.successful(Ok(Json.obj(
"mapbox_api_key" -> mapboxApiKey,
"southwest_boundary" -> Json.obj("lat" -> southwestLat, "lng" -> southwestLng),
"northeast_boundary" -> Json.obj("lat" -> northeastLat, "lng" -> northeastLng),
"attribute" -> Json.obj(
"center_lat" -> attributeCenterLat,
"center_lng" -> attributeCenterLng,
"zoom" -> attributeZoom,
"lat1" -> attributeLat1,
"lng1" -> attributeLng1,
"lat2" -> attributeLat2,
"lng2" -> attributeLng2
),
"street" -> Json.obj(
"center_lat" -> streetCenterLat,
"center_lng" -> streetCenterLng,
"zoom" -> streetZoom,
"lat1" -> streetLat1,
"lng1" -> streetLng1,
"lat2" -> streetLat2,
"lng2" -> streetLng2
),
"region" -> Json.obj(
"center_lat" -> regionCenterLat,
"center_lng" -> regionCenterLng,
"zoom" -> regionZoom,
"lat1" -> regionLat1,
"lng1" -> regionLng1,
"lat2" -> regionLat2,
"lng2" -> regionLng2
)
"mapbox_api_key" -> Play.configuration.getString("mapbox-api-key").get,
"southwest_boundary" -> Json.obj("lat" -> cityMapParams.lat1, "lng" -> cityMapParams.lng1),
"northeast_boundary" -> Json.obj("lat" -> cityMapParams.lat2, "lng" -> cityMapParams.lng2),
"attribute" -> apiAttribute.toJSON,
"street" -> apiStreet.toJSON,
"region" -> apiRegion.toJSON
)))
}
}
2 changes: 2 additions & 0 deletions app/controllers/ProjectSidewalkAPIController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
writer.print(features.map(_.toString).mkString(","))
startIndex += batchSize
if (features.length < batchSize) moreWork = false
else writer.print(",")
}
writer.print("]}")
writer.close()
Expand Down Expand Up @@ -235,6 +236,7 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
writer.print(features.map(_.toString).mkString(","))
startIndex += batchSize
if (features.length < batchSize) moreWork = false
else writer.print(",")
}
writer.print("]}")
writer.close()
Expand Down
2 changes: 1 addition & 1 deletion app/formats/json/TaskSubmissionFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object TaskSubmissionFormats {
(JsPath \ "completed").read[Boolean] and
(JsPath \ "audit_task_id").readNullable[Int] and
(JsPath \ "skipped").read[Boolean]
)(AuditMissionProgress.apply _)
)(AuditMissionProgress.apply _)

implicit val auditTaskSubmissionReads: Reads[AuditTaskSubmission] = (
(JsPath \ "mission").read[AuditMissionProgress] and
Expand Down
171 changes: 38 additions & 133 deletions app/models/attribute/ConfigTable.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package models.attribute

import models.daos.slick.DBTableDefinitions.{DBUser, UserTable}
import models.utils.MyPostgresDriver.simple._
import play.api.Play.current
import scala.slick.lifted.ForeignKeyQuery

case class ConfigApi(apiAttributeCenterLat: Double, apiAttributeCenterLng: Double,
apiAttributeZoom: Double, apiAttributeLatOne: Double, apiAttributeLngOne: Double, apiAttributeLatTwo: Double,
apiAttributeLngTwo: Double, apiStreetCenterLat: Double, apiStreetCenterLng: Double, apiStreetZoom: Double,
apiStreetLatOne: Double, apiStreetLngOne: Double, apiStreetLatTwo: Double, apiStreetLngTwo: Double,
apiRegionCenterLat: Double, apiRegionCenterLng: Double, apiRegionZoom: Double, apiRegionLatOne: Double,
apiRegionLngOne: Double, apiRegionLatTwo: Double, apiRegionLngTwo: Double)
import play.api.libs.json._

case class MapParams(centerLat: Double, centerLng: Double, zoom: Double, lat1: Double, lng1: Double, lat2: Double, lng2: Double) {
def toJSON: JsObject = {
Json.obj(
"center_lat" -> centerLat,
"center_lng" -> centerLng,
"zoom" -> zoom,
"lat1" -> lat1,
"lng1" -> lng1,
"lat2" -> lat2,
"lng2" -> lng2
)
}
}

case class Config(openStatus: String, mapathonEventLink: Option[String], cityCenterLat: Double, cityCenterLng: Double, southwestBoundaryLat: Double,
southwestBoundaryLng: Double, northeastBoundaryLat: Double, northeastBoundaryLng: Double, defaultMapZoom: Double,
tutorialStreetEdgeID: Int, offsetHours: Int, excludedTags: String, configApi: ConfigApi)
case class Config(openStatus: String, mapathonEventLink: Option[String], cityMapParams: MapParams,
tutorialStreetEdgeID: Int, offsetHours: Int, excludedTags: String, apiAttribute: MapParams,
apiStreet: MapParams, apiRegion: MapParams)

class ConfigTable(tag: slick.lifted.Tag) extends Table[Config](tag, Some("sidewalk"), "config") {
def openStatus: Column[String] = column[String]("open_status", O.NotNull)
Expand Down Expand Up @@ -51,16 +57,19 @@ class ConfigTable(tag: slick.lifted.Tag) extends Table[Config](tag, Some("sidewa
def apiRegionLatTwo: Column[Double] = column[Double]("api_region_lat2", O.NotNull)
def apiRegionLngTwo: Column[Double] = column[Double]("api_region_lng2", O.NotNull)

def * = (openStatus, mapathonEventLink, cityCenterLat, cityCenterLng, southwestBoundaryLat, southwestBoundaryLng, northeastBoundaryLat, northeastBoundaryLng, defaultMapZoom, tutorialStreetEdgeID, offsetHours, excludedTags, (
apiAttributeCenterLat, apiAttributeCenterLng, apiAttributeZoom, apiAttributeLatOne, apiAttributeLngOne, apiAttributeLatTwo, apiAttributeLngTwo, apiStreetCenterLat, apiStreetCenterLng, apiStreetZoom, apiStreetLatOne, apiStreetLngOne, apiStreetLatTwo, apiStreetLngTwo, apiRegionCenterLat, apiRegionCenterLng, apiRegionZoom, apiRegionLatOne, apiRegionLngOne, apiRegionLatTwo, apiRegionLngTwo
)
).shaped <> ( {
case (openStatus, mapathonEventLink, cityCenterLat, cityCenterLng, southwestBoundaryLat, southwestBoundaryLng, northeastBoundaryLat, northeastBoundaryLng, defaultMapZoom, tutorialStreetEdgeID, offsetHours, excludedTag, configApi) =>
Config(openStatus, mapathonEventLink, cityCenterLat, cityCenterLng, southwestBoundaryLat, southwestBoundaryLng, northeastBoundaryLat, northeastBoundaryLng, defaultMapZoom, tutorialStreetEdgeID, offsetHours, excludedTag, ConfigApi.tupled.apply(configApi))
def * = (openStatus, mapathonEventLink,
(cityCenterLat, cityCenterLng, defaultMapZoom, southwestBoundaryLat, southwestBoundaryLng, northeastBoundaryLat, northeastBoundaryLng),
tutorialStreetEdgeID, offsetHours, excludedTags,
(apiAttributeCenterLat, apiAttributeCenterLng, apiAttributeZoom, apiAttributeLatOne, apiAttributeLngOne, apiAttributeLatTwo, apiAttributeLngTwo),
(apiStreetCenterLat, apiStreetCenterLng, apiStreetZoom, apiStreetLatOne, apiStreetLngOne, apiStreetLatTwo, apiStreetLngTwo),
(apiRegionCenterLat, apiRegionCenterLng, apiRegionZoom, apiRegionLatOne, apiRegionLngOne, apiRegionLatTwo, apiRegionLngTwo)
).shaped <> ( {
case (openStatus, mapathonEventLink, cityMapParams, tutorialStreetEdgeID, offsetHours, excludedTag, apiAttribute, apiStreet, apiRegion) =>
Config(openStatus, mapathonEventLink, MapParams.tupled.apply(cityMapParams), tutorialStreetEdgeID, offsetHours, excludedTag, MapParams.tupled.apply(apiAttribute), MapParams.tupled.apply(apiStreet), MapParams.tupled.apply(apiRegion))
}, {
c: Config =>
def f(i: ConfigApi) = ConfigApi.unapply(i).get
Some((c.openStatus, c.mapathonEventLink, c.cityCenterLng, c.cityCenterLng, c.southwestBoundaryLat, c.southwestBoundaryLng, c.northeastBoundaryLat, c.northeastBoundaryLng, c.defaultMapZoom, c.tutorialStreetEdgeID, c.offsetHours, c.excludedTags, f(c.configApi)))
def f1(i: MapParams) = MapParams.unapply(i).get
Some((c.openStatus, c.mapathonEventLink, f1(c.cityMapParams), c.tutorialStreetEdgeID, c.offsetHours, c.excludedTags, f1(c.apiAttribute), f1(c.apiStreet), f1(c.apiRegion)))
}
)
}
Expand All @@ -72,6 +81,15 @@ object ConfigTable {
val db = play.api.db.slick.DB
val config = TableQuery[ConfigTable]

def getCityMapParams: MapParams = db.withSession { implicit session =>
config.run.head.cityMapParams
}

def getApiFields: (MapParams, MapParams, MapParams) = db.withSession { implicit session =>
val c = TableQuery[ConfigTable].run.head
(c.apiAttribute, c.apiStreet, c.apiRegion)
}

def getTutorialStreetId: Int = db.withSession { implicit session =>
config.map(_.tutorialStreetEdgeID).list.head
}
Expand All @@ -91,117 +109,4 @@ object ConfigTable {
def getExcludedTags: List[String] = db.withSession { implicit session =>
config.map(_.excludedTags).list.head.drop(2).dropRight(2).split("\" \"").toList
}

def getCityLat: Double = db.withSession { implicit session =>
config.map(_.cityCenterLat).list.head
}

def getCityLng: Double = db.withSession { implicit session =>
config.map(_.cityCenterLng).list.head
}

def getSouthwestLat: Double = db.withSession { implicit session =>
config.map(_.southwestBoundaryLat).list.head
}

def getSouthwestLng: Double = db.withSession { implicit session =>
config.map(_.southwestBoundaryLng).list.head
}

def getNortheastLat: Double = db.withSession { implicit session =>
config.map(_.northeastBoundaryLat).list.head
}

def getNortheastLng: Double = db.withSession { implicit session =>
config.map(_.northeastBoundaryLng).list.head
}

def getDefaultMapZoom: Double = db.withSession { implicit session =>
config.map(_.defaultMapZoom).list.head
}

def getApiAttributeCenterLat: Double = db.withSession { implicit session =>
config.map(_.apiAttributeCenterLat).list.head
}

def getApiAttributeCenterLng: Double = db.withSession { implicit session =>
config.map(_.apiAttributeCenterLng).list.head
}

def getAttributeZoom: Double = db.withSession { implicit session =>
config.map(_.apiAttributeZoom).list.head
}

def getAttributeLatOne: Double = db.withSession { implicit session =>
config.map(_.apiAttributeLatOne).list.head
}

def getAttributeLngOne: Double = db.withSession { implicit session =>
config.map(_.apiAttributeLngOne).list.head
}

def getAttributeLatTwo: Double = db.withSession { implicit session =>
config.map(_.apiAttributeLatTwo).list.head
}

def getAttributeLngTwo: Double = db.withSession { implicit session =>
config.map(_.apiAttributeLngTwo).list.head
}

def getStreetCenterLat: Double = db.withSession { implicit session =>
config.map(_.apiStreetCenterLat).list.head
}

def getStreetCenterLng: Double = db.withSession { implicit session =>
config.map(_.apiStreetCenterLng).list.head
}

def getStreetZoom: Double = db.withSession { implicit session =>
config.map(_.apiStreetZoom).list.head
}

def getStreetLatOne: Double = db.withSession { implicit session =>
config.map(_.apiStreetLatOne).list.head
}

def getStreetLngOne: Double = db.withSession { implicit session =>
config.map(_.apiStreetLngOne).list.head
}

def getStreetLatTwo: Double = db.withSession { implicit session =>
config.map(_.apiStreetLatTwo).list.head
}

def getStreetLngTwo: Double = db.withSession { implicit session =>
config.map(_.apiStreetLngTwo).list.head
}

def getRegionCenterLat: Double = db.withSession { implicit session =>
config.map(_.apiRegionCenterLat).list.head
}

def getRegionCenterLng: Double = db.withSession { implicit session =>
config.map(_.apiRegionCenterLng).list.head
}

def getRegionZoom: Double = db.withSession { implicit session =>
config.map(_.apiRegionZoom).list.head
}

def getRegionLatOne: Double = db.withSession { implicit session =>
config.map(_.apiRegionLatOne).list.head
}

def getRegionLngOne: Double = db.withSession { implicit session =>
config.map(_.apiRegionLngOne).list.head
}

def getRegionLatTwo: Double = db.withSession { implicit session =>
config.map(_.apiRegionLatTwo).list.head
}

def getRegionLngTwo: Double = db.withSession { implicit session =>
config.map(_.apiRegionLngTwo).list.head
}

}
Loading

0 comments on commit b1aeb1f

Please sign in to comment.