Skip to content

Commit 179892c

Browse files
Merge pull request #340 from mapswipe/dev
All configuration is now stored in environment vars.
2 parents 16b90d5 + 02b66f9 commit 179892c

34 files changed

+4756
-330
lines changed

.travis

Lines changed: 0 additions & 19 deletions
This file was deleted.

.travis.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This is a special configuration file to run tests on Travis-CI via
2+
# GitHub notifications when changes are committed.
3+
#
4+
# For technical details, see http://travis-ci.org/
5+
#
6+
branches:
7+
except:
8+
- docs
9+
10+
dist: bionic
11+
addons:
12+
apt:
13+
sources:
14+
- ppa:ubuntugis/ppa
15+
update: true
16+
packages:
17+
- gdal-bin
18+
- python-gdal
19+
- python3-gdal
20+
- libgdal-dev
21+
22+
language: python
23+
python:
24+
- "3.6"
25+
virtualenv:
26+
system_site_packages: true
27+
28+
services:
29+
- docker
30+
31+
before_install:
32+
- pip install --upgrade pip setuptools
33+
- pip install flake8 black
34+
35+
install:
36+
- pip install mapswipe_workers/
37+
- mkdir --parents ~/.config/mapswipe_workers
38+
- mkdir --parents ~/.local/share/mapswipe_workers
39+
- echo "$SERVICE_ACCOUNT_KEY" > ~/.config/mapswipe_workers/serviceAccountKey.json
40+
- docker build --tag mapswipe_postgres --file postgres/Dockerfile-dev postgres/
41+
42+
before_script:
43+
- docker run --detach --publish 5432:5432 --name mapswipe_postgres -e POSTGRES_DB="$POSTGRES_DB" -e POSTGRES_USER="$POSTGRES_USER" -e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" mapswipe_postgres
44+
- docker-compose up --build --detach firebase_deploy
45+
46+
script:
47+
# - TODO: Run black and flake8
48+
- python -m unittest -v tests.integration_tests.test_gdal
49+
# TODO: Use line below once tests have been implemented
50+
#- python -m unittest discover -v -s mapswipe_workers/tests/integration_tests/ -p 'test_*.py'
51+
52+
# before_deploy:
53+
# # SSH setup to deploy to server after build.
54+
# - apk add openssh-client
55+
# - mkdir -p ~/.ssh
56+
# - chmod 700 ~/.ssh
57+
# - eval "$(ssh-agent -s)"
58+
# - export KEY_FILE=~/.ssh/api_server_ssh_key
59+
# - echo "$DEPLOYMENT_SERVER_PRIVATE_KEY" | tr -d '\r' > $KEY_FILE
60+
# - chmod 600 $KEY_FILE
61+
# - ssh-add $KEY_FILE > /dev/null
62+
# - ssh-keyscan -H "$DEPLOYMENT_SERVER_IP" >> ~/.ssh/known_hosts
63+
# - chmod 644 ~/.ssh/known_hosts
64+
# - ssh -i $KEY_FILE -o StrictHostKeyChecking=no "mapswipe@$DEPLOYMENT_SERVER_IP"
65+
66+
# deploy:
67+
# provider: script
68+
# script: bash scripts/deploy.sh
69+
# on:
70+
# branch: dev
71+

docker-compose.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ services:
5151
container_name: mapswipe_workers
5252
build:
5353
context: mapswipe_workers/
54+
environment:
55+
FIREBASE_DB: '${FIREBASE_DB}'
56+
FIREBASE_API_KEY: '{FIREBASE_API_KEY}'
57+
FIREBASE_TOKEN: '{FIREBASE_TOKEN}'
58+
GOOGLE_APPLICATION_CREDENTIALS: 'serviceAccountKey.json'
59+
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
60+
POSTGRES_USER: '${POSTGRES_USER}'
61+
POSTGRES_DB: '${POSTGRES_DB}'
62+
POSTGRES_HOST: 'postgres'
63+
POSTGRES_PORT: 5432
64+
PGDATA: '/var/lib/postgresql/mapswipe'
65+
IMAGE_BING_API_KEY: '${IMAGE_BING_API_KEY}'
66+
IMAGE_ESRI_API_KEY: '${IMAGE_ESRI_API_KEY}'
67+
IMAGE_ESRI_BETA_API_KEY: '${IMAGE_ESRI_BETA_API_KEY}'
68+
IMAGE_MAPBOX_API_KEY: '${IMAGE_MAPBOX_API_KEY}'
69+
IMAGE_MAXAR_PREMIUM_API_KEY: '${IMAGE_MAXAR_PREMIUM_API_KEY}'
70+
IMAGE_MAXAR_STANDARD_API_KEY: '${IMAGE_MAXAR_STANDARD_API_KEY}'
71+
SLACK_TOKEN: '${SLACK_TOKEN}'
72+
SLACK_CHANNEL: '${SLACK_CHANNEL}'
73+
SENTRY_DSN: '${SENTRY_DSN}'
5474
depends_on:
5575
- postgres
5676
command: mapswipe_workers --verbose run --schedule
@@ -67,8 +87,8 @@ services:
6787
context: postgres/
6888
environment:
6989
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
70-
POSTGRES_USER: 'mapswipe_workers'
71-
POSTGRES_DB: 'mapswipe'
90+
POSTGRES_USER: '${POSTGRES_USER}'
91+
POSTGRES_DB: '${POSTGRES_DB}'
7292
PGDATA: '/var/lib/postgresql/mapswipe'
7393
WALG_GS_PREFIX: '${WALG_GS_PREFIX}'
7494
GOOGLE_APPLICATION_CREDENTIALS: '/serviceAccountKey.json'
@@ -88,8 +108,8 @@ services:
88108
context: postgres/recovery/
89109
environment:
90110
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
91-
POSTGRES_USER: 'mapswipe_workers'
92-
POSTGRES_DB: 'mapswipe'
111+
POSTGRES_USER: '${POSTGRES_USER}'
112+
POSTGRES_DB: '${POSTGRES_DB}'
93113
PGDATA: '/var/lib/postgresql/mapswipe'
94114
WALG_GS_PREFIX: '${WALG_GS_PREFIX}'
95115
GOOGLE_APPLICATION_CREDENTIALS: '/serviceAccountKey.json'
@@ -104,6 +124,7 @@ services:
104124
context: firebase/
105125
environment:
106126
FIREBASE_TOKEN: '${FIREBASE_TOKEN}'
107-
command: firebase deploy --token $FIREBASE_TOKEN --only functions,database:rules
127+
FIREBASE_DB: '${FIREBASE_DB}'
128+
command: sh -c "firebase use $FIREBASE_DB && firebase deploy --token $FIREBASE_TOKEN --only functions,database:rules"
108129
volumes:
109130
- ./firebase:/firebase
32.5 KB
Loading
576 KB
Loading
7.64 KB
Loading
82.6 KB
Loading

docs/source/configuration.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Configuration Reference
22

33
Most of the configuration is stored in environment variables.
4-
At the root of the GitHub repository an example file (`example.env`) with all possible configuration variables exists. To get started copy this file to `.env` and fill in missing variables. Once done source this file to make variables accessible as environment variables: `source .env` to either be used by docker-compose during deployment setup or by MapSwipe Workers directly.
4+
At the root of the GitHub repository (in the same directory as `docker-compose.yml`) an example file (`example.env`) with all possible configuration variables exists. To get started copy this file to `.env` (no name is required) and fill in missing variables. The Docker Compose file will access those variables when needed.
5+
6+
> Note: If you want those variables to be accessible as Environment Variables in your current shell (Eg. Inside a Python virtual environment for development.) your need to parse the file and export the variables: `export $(cat .env | xargs)`
57
68
In following chapters configuration values and keys are discussed for each part of the MapSwipe Back-end.
79

@@ -13,14 +15,13 @@ All configuration values for MapSwipe Workers are stored in environment variable
1315
Required environment variables are:
1416
- FIREBASE_API_KEY
1517
- FIREBASE_DB
16-
- GOOGLE_APPLICATION_CREDENTIALS
1718
- POSTGRES_DB
1819
- POSTGRES_HOST
1920
- POSTGRES_PASSWORD
2021
- POSTGRES_PORT
2122
- POSTGRES_USER
2223

23-
Mandatory environment variables are:
24+
Optional environment variables are:
2425
- SLACK_CHANNEL
2526
- SLACK_TOKEN
2627
- SENTRY_DSN
@@ -37,31 +38,47 @@ In addition to get access to Firebase a Service Account Key is required.
3738
The path the Service Account Key is defined in:
3839
- GOOGLE_APPLICATION_CREDENTIALS
3940

40-
> Notes: When deploying using `docker` or `docker-compose` `POSTGRES_HOST` should have the value `postgres` and the Service Account Key (`serviceAccountKey.json`) should be copied to `mapswipe_workers/serviceAccountKey.json` as described in detail in [Deployment](deployment.md).
41+
> Notes: When deploying using `docker` or `docker-compose` `POSTGRES_HOST` should have the value `postgres` and the Service Account Key (`serviceAccountKey.json`) should be copied to `mapswipe_workers/serviceAccountKey.json` so that during the build of the image the file can by copied by Docker.
42+
43+
44+
### Elaboration
45+
46+
**Firebase**: MapSwipe Workers use the Firebase Python SDK and the Firebase REST API. Both require the database name (`FIREBASE_DB`) and the API-Key from the Firebase instance. The Firebase Python SDK does also need a Service Account Key. The path to this file is set in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
47+
48+
**Postgres**: MapSwipe Workers writes data to a Postgres database and generate files for the API based data in Postgres.
49+
50+
**Sentry (optional)**: MapSwipe workers use sentry to capture exceptions. You can find your project’s DSN in the “Client Keys” section of your “Project Settings” in Sentry. Check [Sentry's documentation](https://docs.sentry.io/error-reporting/configuration/?platform=python) for more information.
51+
52+
**Slack (optional)**: The MapSwipe workers send messages to slack when a project has been created successfully, the project creation failed or an exception gets raised. refer to [Python slackclient's documentation](https://github.com/slackapi/python-slackclient) how to get a Slack Token.
53+
54+
**Imagery:** MapSwipe uses satellite imagery provided by Tile Map Services (TMS).
55+
If you are not familiar with the basic concept have a look at [Bing's documentation](https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system).
4156

4257

4358
## Postgres
4459

45-
Required environment variables are:
60+
Required environment variables are (Those are the same as needed by MapSwipe Workers):
4661
- POSTGRES_DB
4762
- POSTGRES_HOST
4863
- POSTGRES_PASSWORD
4964
- POSTGRES_PORT
5065
- POSTGRES_USER
5166

67+
> Notes: When deploying using `docker` or `docker-compose` `POSTGRES_HOST` should have the value `postgres`.
68+
5269

5370
### Postgres Backup
5471

55-
On details of how the back-up works please refer to [Postgres Backup](backup.md).
72+
On details of how the back-up works please refer to [Postgres Backup](backup.html).
5673

5774
Required environment variables are:
5875
- WALG_GS_PREFIX
5976

60-
To gain access to Google Cloud Storage another Service Account Key is needed. Again refer to [Postgres Backup](backup.md) on how to create this file.
77+
To gain access to Google Cloud Storage another Service Account Key is needed. Again refer to [Postgres Backup](backup.html) on how to create this file.
6178
The Service Account Key (`serviceAccountKey.json`) should be saved to `postgres/serviceAccountKey.json`
6279

6380

64-
### Manager Dashboard
81+
## Manager Dashboard
6582

6683
`manager_dashboard/manager_dashboard/js/app.js`
6784

docs/source/data.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Data
2+
Swiping is just the beginning -- MapSwipe data is created by our users and accessible to the entire community. Through the [MapSwipe website](https://mapswipe.org/data.html) you can see where we've mapped, which organizations are requesting data, and how many individuals contribute to our impact. When using MapSwipe data, all you have to do is credit the MapSwipe contributors. Here you find a more detailed description of the data available.
3+
4+
## Projects
5+
6+
Files:
7+
- [projects.csv](https://apps.mapswipe.org/api/projects/projects.csv)
8+
- [projects_geom.geojson](https://apps.mapswipe.org/api/projects/projects_geom.geojson)
9+
- [projects_centroid.geojson](https://apps.mapswipe.org/api/projects/projects_centroid.geojson)
10+
11+
Attributes:
12+
13+
| Name | Type | Description |
14+
| ---- | ---- | ----------- |
15+
| idx | integer | - |
16+
| project_id | string | The ID of the project used in Firebase. |
17+
| name | string | The name of the project as displayed in the app. For newer projects this will be a composition of project topic, project region and project number. |
18+
| project_details | string | The project description. This is displayed in the app on the project page. |
19+
| look_for | string | What should the users look for (e.g. buildings, cars, trees)? |
20+
| project_type | integer | The type of the project. 1=BuildArea, 2=Footprint, 3=ChangeDetection, 4=Completeness |
21+
| tile_server_names | string | The names of the satellite imagery providers used for this project. Some projects, e.g. Change Detection Type projects, have multiple tile server names. |
22+
| status | string | The status of the project defines if the project is visible in the app. There are the following values: active, inactive, finished, archived. Archived projects can not be set to active again. |
23+
| area_sqkm | float | The size of the project area in square kilometers. |
24+
| geom | string | The geometry of the project region as WKT geometry. |
25+
| centroid | string | The centroid of the project geometry as WKT geometry. |
26+
| progress | float | The mapping progress of the project. 1.0=completed. |
27+
| number_of_users | integer | The number of distinct users who contributed to this project. |
28+
| number_of_results | integer | The total number of results for all tasks. |
29+
| number_of_results_progress | integer | The number of results that are taken into account for the progress calculation. If a tasks has been mapped more often than required, usually 3-times, the additional results are not considered for the progress calculation. |
30+
| day | string | The date when the project information was updated the last time. |
31+
32+
33+
## Aggregated Results
34+
This gives you the unfiltered MapSwipe results. This is most suited if you want to apply some custom data processing with the MapSwipe data, e.g. select only specific tasks for machine learning. If you want to use MapSwipe data in the Tasking Manager you might look for the data explained below.
35+
36+
Files:
37+
- `aggregated_results_{project_id}.csv`, e.g. [agg\_results\_-M56eeMCZ5VeOHjJN4Bx.csv](https://apps.mapswipe.org/api/agg_results/agg_results_-M56eeMCZ5VeOHjJN4Bx.csv)
38+
- `aggregated_results_{project_id}.geojson`, e.g. [agg\_results\_-M56eeMCZ5VeOHjJN4Bx.geojson](https://apps.mapswipe.org/api/agg_results/agg_results_-M56eeMCZ5VeOHjJN4Bx.geojson)
39+
40+
| Name | Type | Description |
41+
| ---- | ---- | ----------- |
42+
| idx | integer | - |
43+
| task_id | string | The ID of the task, for BuildArea projects this is a composition of `TileZ-TileX-TileY` |
44+
| 0_count | integer | The number of users who marked this task as 0, e.g. "no building" for BuildArea Project Type. |
45+
| 1_count | integer | The number of users who marked this task as 1, e.g. "building" for BuildArea Project Type. |
46+
| 2_count | integer | The number of users who marked this task as 2, e.g. "maybe" for BuildArea Project Type. |
47+
| 3_count | integer | The number of users who marked this task as 3, e.g. "bad imagery" for BuildArea Project Type. |
48+
| total_count | integer | The total number of users who mapped this task. |
49+
| 0_share | float | 0_count divived by total_count. This gives you the share of all users who marked as 0. |
50+
| 1_share | float | 1_count divived by total_count. This gives you the share of all users who marked as 1. |
51+
| 2_share | float | 2_count divived by total_count. This gives you the share of all users who marked as 2. |
52+
| 3_share | float | 3_count divived by total_count. This gives you the share of all users who marked as 3. |
53+
| agreement | float | This is defined as [Scott's Pi](https://en.wikipedia.org/wiki/Scott%27s_Pi) and gives you an understanding of inter-rater reliability. The value is 1.0 if all users agree, e.g. all users classify as "building". If users disagree this value will be lower. |
54+
| geom | string | The geometry of this task as WKT geometry. |
55+
56+
57+
## HOT Tasking Manager Geometries
58+
This gives you filtered MapSwipe data ready to be imported to the HOT Tasking Manager. Currently, the geometries in this dataset consist of maximum 15 MapSwipe Tasks, where at least 35% of all users indicated the presence of a building by classifying as "yes" or "maybe".
59+
60+
Files:
61+
- `hot_tm_{project_id}.geojson`, e.g. [hot\_tm\_-M56eeMCZ5VeOHjJN4Bx.geojson](https://apps.mapswipe.org/api/hot_tm/hot_tm_-M56eeMCZ5VeOHjJN4Bx.geojson)
62+
63+
| Name | Type | Description |
64+
| ---- | ---- | ----------- |
65+
| group_id | integer | A ID for the geometry. It has no connection to the MapSwipe data model. |
66+
| geometry | geometry | A polygon geometry representing the selected MapSwipe tasks. In our GIS workflow we further aggregate and simplify the geometry, hence they kind of look like easter eggs. |
67+
68+
<img src="_static/img/tasking_manager_geometries_example.png" width="600px">
69+
70+

docs/source/debugging.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
## Logs - MapSwipe Workers
44

55
Where can I find logs?
6+
- `docker logs mapswipe_workers`
7+
- or
8+
- `cat mapswipe-data/mapswipe_workers.log`
69

7-
Logs are written to directly to console and also to `/var/log/mapswipe_workers.log`:
10+
Logs are written to directly to the terminal (stdout). The easiest way is therefore is to run `docker logs mapswipe_workers` to see the logs.
811

9-
- `docker exec -t mapswipe_workers cat /var/log/mapswipe_workers/mapswipe_workers.log` (if container is running)
10-
- `docker logs container_name` (also if container is not running)
12+
Logs are also writing to file inside the Docker container (`~/.local/share/mapswipe_workers/mapswipe_workers.log`). The parent directory of the file is the data directory of MapSwipe Workers. This directory is mounted (as a Docker volume) locally to disk (`mapswipe-data/`). Logs can therefore be accessed as text file as well: `cat mapswipe-data/mapswipe_workers.log`
1113

1214

1315
## Common Errors

0 commit comments

Comments
 (0)