Skip to content

Commit

Permalink
Merge pull request #3330 from ProjectSidewalk/develop
Browse files Browse the repository at this point in the history
v7.15.4
  • Loading branch information
misaugstad authored Jul 31, 2023
2 parents e671f2e + c44068f commit ac78f3c
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 837 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ Make sure Docker is running on your machine. You should see a Docker whale in yo

On Windows, we recommend [Windows Powershell](https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7) (built in to Win10). On Mac, use the basic terminal or, even better, [iTerm2](https://www.iterm2.com/). On Linux (or if you're using WSL2 on Windows), the default Linux Shell (such as [Bash](https://www.gnu.org/software/bash/)) is a great choice.

1. Email Mikey (michaelssaugstad@gmail.com) and ask for a database dump, a Mapbox API key, and a Google Maps API key & secret (if you are not part of our team, you'll have to [create a Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key) yourself). Rename the database dump `sidewalk-dump` and put it in the `db/` directory (other files in this dir include `init.sh` and `schema.sql`, for example).
1. Email Mikey (michaelssaugstad@gmail.com) and ask for a database dump, a Mapbox API key, and a Google Maps API key & secret (if you are not part of our team, you'll have to [create a Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key) yourself).
1. If your computer has an Apple Silicon (M1 or M2) chip, then you should modify the `platform` line in the `docker-compose.yml`, changing it to `linux/arm64`.
1. If your computer has less than 16 GB of RAM, I'd recommend modifying `-mem 12288` to `-mem 8192` or lower in the `package.json` file so that you don't fill up your computer's memory.
1. Modify the `MAPBOX_API_KEY`, `GOOGLE_MAPS_API_KEY`, and `GOOGLE_MAPS_SECRET` lines in the `docker-compose.yml` using the keys and secret you've acquired.
1. Modify the `SIDEWALK_CITY_ID` line in the `docker-compose.yml` to use the ID of the appropriate city. You can find the list of IDs for the cities starting at line 7 of `conf/cityparams.conf`.
1. Modify the `DATABASE_URL` line in the `docker-compose.yml`, replacing "sidewalk" with "sidewalk-\<city-name\>", where the `<city-name>` comes from the city ID you found in the previous step. Note that if a state abbreviation comes after, you'll remove that. So if the `city-id` is "newberg-or", your db URL will contain "sidewalk-newberg". And if your `city-id` is "cdmx" then your URL will contain "sidewalk-cdmx".
1. Rename the database dump file that you got from Mikey to "sidewalk-\<city-name\>-dump" (same name as prev step) and put it in the `db/` directory (other files in this dir include `init.sh` and `schema.sql`).
1. From the root SidewalkWebpage dir, run `make dev`. This will take time (20-30 mins or more depending on your Internet connection) as the command downloads the docker images, spins up the containers, and opens a Docker shell into the webpage container in that same terminal. The containers (running Ubuntu Stretch) will have all the necessary packages and tools so no installation is necessary. This command also initializes the database, though we still need to import the data. Successful output of this command will look like:

```
Expand All @@ -75,14 +77,14 @@ On Windows, we recommend [Windows Powershell](https://docs.microsoft.com/en-us/p
root@[container-id]:/opt#
```
1. In a separate terminal, run the commands below. In the second command, replace `<city-name>` with one of `dc`, `seattle`, `newberg`, `columbus`, `cdmx`, `spgg`, `chicago`, `amsterdam`, `la-piedad`, `oradell`, or `pittsburg` (pittsburgh is missing the 'h', but it's a typo we're stuck with), depending on which city your database dump is for.
1. In a separate terminal, run the commands below. In the second command, replace `<city-name>` with the one used above. There is one outlier: `pittsburg` (pittsburgh is missing the 'h', but it's a typo we're stuck with; the typo is only relevant for this one command).
```
docker exec -it projectsidewalk-db psql -c "CREATE ROLE saugstad SUPERUSER LOGIN ENCRYPTED PASSWORD 'sidewalk';" -U postgres -d postgres
docker exec -it projectsidewalk-db psql -c "CREATE ROLE sidewalk_<city-name> SUPERUSER LOGIN ENCRYPTED PASSWORD 'sidewalk';" -U postgres -d postgres
```
1. Run `make import-dump db=sidewalk` from the root project directory outside the Docker shell (from a new Ubuntu terminal). This may take a while depending on the size of the dump. Don't panic if this step fails :) and consult the [Docker Troubleshooting wiki](https://github.com/ProjectSidewalk/SidewalkWebpage/wiki/Docker-Troubleshooting). Check the output carefully. If it looks like there are errors, do not skip to the next step, check the wiki and ask Mikey if you don't find solutions in there.
1. Run `make import-dump db=sidewalk-<city-name>` (needs to be the same thing you put in the `DATABASE_URL`) from the root project directory outside the Docker shell (from a new Ubuntu terminal). This may take a while depending on the size of the dump. Don't panic if this step fails :) and consult the [Docker Troubleshooting wiki](https://github.com/ProjectSidewalk/SidewalkWebpage/wiki/Docker-Troubleshooting). Check the output carefully. If it looks like there are errors, do not skip to the next step, check the wiki and ask Mikey if you don't find solutions in there.
1. Run `npm start` from inside the Docker shell (the terminal where you ran `make dev`). If this is your first time running the command, *everything* will need to be compiled. So, it may take 5+ minutes initially, but will be orders of magnitude faster in the future (~10 secs).
The behavior of `npm start` is dictated by what `start` is supposed to do as defined in `package.json` file. As per the current code, running this command will run `grunt watch` & `sbt compile "~ run"` (the `~` here is triggered execution that allows for the server to run in watch mode). This should start the web server. Successful output of this command will look like:
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import models.daos.slick.DBTableDefinitions.UserTable
import models.label.TagTable.selectTagsByLabelType
import models.street.StreetEdgePriorityTable
import models.utils.Configs
import models.attribute.ConfigTable
import play.api.Play
import play.api.Play.current
import play.api.i18n.Messages
Expand Down Expand Up @@ -131,7 +132,7 @@ class ApplicationController @Inject() (implicit val env: Environment[User, Sessi
val cityName: String = Play.configuration.getString("city-params.city-name." + cityStr).get
val stateAbbreviation: String = Play.configuration.getString("city-params.state-abbreviation." + cityStr).get
val cityShortName: String = Play.configuration.getString("city-params.city-short-name." + cityStr).get
val mapathonLink: Option[String] = Play.configuration.getString("city-params.mapathon-event-link." + cityStr)
val mapathonLink: Option[String] = ConfigTable.getMapathonEventLink
// Get names and URLs for other cities so we can link to them on landing page.
val otherCityUrls: List[(String, String, String, String)] = Configs.getAllCityInfo(excludeCity = cityStr)
// Get total audited distance. If using metric system, convert from miles to kilometers.
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/AuditController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import models.audit._
import models.daos.slick.DBTableDefinitions.{DBUser, UserTable}
import models.label.LabelTable
import models.mission.{Mission, MissionSetProgress, MissionTable, MissionTypeTable}
import models.attribute.ConfigTable
import models.region._
import models.route.{Route, RouteTable, UserRoute, UserRouteTable}
import models.street.StreetEdgeRegionTable
Expand Down Expand Up @@ -132,7 +133,7 @@ class AuditController @Inject() (implicit val env: Environment[User, SessionAuth
val completedMissions: Boolean = MissionTable.countCompletedMissions(user.userId, missionType = "audit") > 0

val cityStr: String = Play.configuration.getString("city-id").get
val tutorialStreetId: Int = Play.configuration.getInt("city-params.tutorial-street-edge-id." + cityStr).get
val tutorialStreetId: Int = ConfigTable.getTutorialStreetId
val cityShortName: String = Play.configuration.getString("city-params.city-short-name." + cityStr).get
if (missionSetProgress.missionType != "audit") {
Future.successful(Redirect("/validate"))
Expand Down Expand Up @@ -190,7 +191,7 @@ class AuditController @Inject() (implicit val env: Environment[User, SessionAuth
val completedMission: Boolean = MissionTable.countCompletedMissions(user.userId, missionType = "audit") > 0

val cityStr: String = Play.configuration.getString("city-id").get
val tutorialStreetId: Int = Play.configuration.getInt("city-params.tutorial-street-edge-id." + cityStr).get
val tutorialStreetId: Int = ConfigTable.getTutorialStreetId
val cityShortName: String = Play.configuration.getString("city-params.city-short-name." + cityStr).get
if (missionSetProgress.missionType != "audit") {
Future.successful(Redirect("/validate"))
Expand Down Expand Up @@ -256,7 +257,7 @@ class AuditController @Inject() (implicit val env: Environment[User, SessionAuth
}

val cityStr: String = Play.configuration.getString("city-id").get
val tutorialStreetId: Int = Play.configuration.getInt("city-params.tutorial-street-edge-id." + cityStr).get
val tutorialStreetId: Int = ConfigTable.getTutorialStreetId
val cityShortName: String = Play.configuration.getString("city-params.city-short-name." + cityStr).get

if (missionSetProgress.missionType != "audit") {
Expand Down
67 changes: 33 additions & 34 deletions app/controllers/ConfigController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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

/**
* Holds the HTTP requests associated with getting data from the parameters in our config files.
Expand All @@ -24,14 +25,13 @@ class ConfigController @Inject() (implicit val env: Environment[User, SessionAut
*/
def getCityMapParams() = Action.async { implicit request =>
val mapboxApiKey: String = Play.configuration.getString("mapbox-api-key").get
val cityStr: String = Play.configuration.getString("city-id").get
val cityLat: Double = Play.configuration.getDouble("city-params.city-center-lat." + cityStr).get
val cityLng: Double = Play.configuration.getDouble("city-params.city-center-lng." + cityStr).get
val southwestLat: Double = Play.configuration.getDouble("city-params.southwest-boundary-lat." + cityStr).get
val southwestLng: Double = Play.configuration.getDouble("city-params.southwest-boundary-lng." + cityStr).get
val northeastLat: Double = Play.configuration.getDouble("city-params.northeast-boundary-lat." + cityStr).get
val northeastLng: Double = Play.configuration.getDouble("city-params.northeast-boundary-lng." + cityStr).get
val defaultZoom: Double = Play.configuration.getDouble("city-params.default-map-zoom." + cityStr).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
Future.successful(Ok(Json.obj(
"mapbox_api_key" -> mapboxApiKey,
"city_center" -> Json.obj("lat" -> cityLat, "lng" -> cityLng),
Expand All @@ -55,35 +55,34 @@ class ConfigController @Inject() (implicit val env: Environment[User, SessionAut
*/
def getCityAPIDemoParams() = Action.async { implicit request =>
val mapboxApiKey: String = Play.configuration.getString("mapbox-api-key").get
val cityStr: String = Play.configuration.getString("city-id").get
val southwestLat: Double = Play.configuration.getDouble("city-params.southwest-boundary-lat." + cityStr).get
val southwestLng: Double = Play.configuration.getDouble("city-params.southwest-boundary-lng." + cityStr).get
val northeastLat: Double = Play.configuration.getDouble("city-params.northeast-boundary-lat." + cityStr).get
val northeastLng: Double = Play.configuration.getDouble("city-params.northeast-boundary-lng." + cityStr).get
val southwestLat: Double = ConfigTable.getSouthwestLat
val southwestLng: Double = ConfigTable.getSouthwestLng
val northeastLat: Double = ConfigTable.getNortheastLat
val northeastLng: Double = ConfigTable.getNortheastLng

val attributeCenterLat: Double = Play.configuration.getDouble("city-params.api-demos.attribute-center-lat." + cityStr).get
val attributeCenterLng: Double = Play.configuration.getDouble("city-params.api-demos.attribute-center-lng." + cityStr).get
val attributeZoom: Double = Play.configuration.getDouble("city-params.api-demos.attribute-zoom." + cityStr).get
val attributeLat1: Double = Play.configuration.getDouble("city-params.api-demos.attribute-lat1." + cityStr).get
val attributeLng1: Double = Play.configuration.getDouble("city-params.api-demos.attribute-lng1." + cityStr).get
val attributeLat2: Double = Play.configuration.getDouble("city-params.api-demos.attribute-lat2." + cityStr).get
val attributeLng2: Double = Play.configuration.getDouble("city-params.api-demos.attribute-lng2." + cityStr).get
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 = Play.configuration.getDouble("city-params.api-demos.street-center-lat." + cityStr).get
val streetCenterLng: Double = Play.configuration.getDouble("city-params.api-demos.street-center-lng." + cityStr).get
val streetZoom: Double = Play.configuration.getDouble("city-params.api-demos.street-zoom." + cityStr).get
val streetLat1: Double = Play.configuration.getDouble("city-params.api-demos.street-lat1." + cityStr).get
val streetLng1: Double = Play.configuration.getDouble("city-params.api-demos.street-lng1." + cityStr).get
val streetLat2: Double = Play.configuration.getDouble("city-params.api-demos.street-lat2." + cityStr).get
val streetLng2: Double = Play.configuration.getDouble("city-params.api-demos.street-lng2." + cityStr).get
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 = Play.configuration.getDouble("city-params.api-demos.region-center-lat." + cityStr).get
val regionCenterLng: Double = Play.configuration.getDouble("city-params.api-demos.region-center-lng." + cityStr).get
val regionZoom: Double = Play.configuration.getDouble("city-params.api-demos.region-zoom." + cityStr).get
val regionLat1: Double = Play.configuration.getDouble("city-params.api-demos.region-lat1." + cityStr).get
val regionLng1: Double = Play.configuration.getDouble("city-params.api-demos.region-lng1." + cityStr).get
val regionLat2: Double = Play.configuration.getDouble("city-params.api-demos.region-lat2." + cityStr).get
val regionLng2: Double = Play.configuration.getDouble("city-params.api-demos.region-lng2." + cityStr).get
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

Future.successful(Ok(Json.obj(
"mapbox_api_key" -> mapboxApiKey,
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/LabelController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import controllers.headers.ProvidesHeader
import models.label._
import models.user.User
import models.attribute.ConfigTable
import play.api.libs.json._
import play.api.mvc.Action
import play.api.Play
import play.api.Play.current
import scala.collection.JavaConverters._
import scala.concurrent.Future

/**
Expand Down Expand Up @@ -74,8 +72,7 @@ class LabelController @Inject() (implicit val env: Environment[User, SessionAuth
* Gets all tags in the database in JSON.
*/
def getLabelTags() = Action.async { implicit request =>
val cityStr: String = Play.configuration.getString("city-id").get
val excludedTags: List[String] = Play.configuration.getStringList("city-params.excluded-tags." + cityStr).get.asScala.toList
val excludedTags: List[String] = ConfigTable.getExcludedTags
val tags: List[Tag] = TagTable.selectAllTags().filter( tag => !excludedTags.contains(tag.tag))
Future.successful(Ok(JsArray(tags.map { tag => Json.obj(
"tag_id" -> tag.tagId,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/helper/ShapefilesCreatorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* This class handles the creation of Shapefile archives to be used by the SidewalkAPIController.
*
*
* Code was started and modified from the Geotools feature tutorial:
* https://docs.geotools.org/stable/tutorials/feature/csv2shp.html
*
Expand Down Expand Up @@ -394,7 +394,7 @@ public Timestamp apply() {

}

/*
/*
* Creates a zip archive from the given array of shapefile filenames, and returns
* the zip archive as a java File type.
*
Expand Down
Loading

0 comments on commit ac78f3c

Please sign in to comment.