├── src
├── config
│ ├── .gitkeep
│ └── config.example.js
├── cron
│ ├── .gitignore
│ ├── package.json
│ ├── assign-new-trees-to-clusters.sh
│ ├── update-clusters-for-deactivated-trees.sh
│ └── assign-new-trees-to-clusters.js
├── server.test.js
├── server.js
├── models
│ ├── sqls
│ │ ├── SQLCase1Timeline.test.js
│ │ ├── SQLTree.test.js
│ │ ├── SQLCase4.js
│ │ ├── SQLCase1Timeline.js
│ │ ├── SQLCase1V2.js
│ │ ├── SQLCase2Timeline.js
│ │ ├── SQLZoomTargetCase1V2.js
│ │ ├── SQLCase3Timeline.js
│ │ ├── SQLZoomTargetCase1.js
│ │ ├── SQLTree.js
│ │ ├── SQLCase1.js
│ │ ├── SQLCase3.js
│ │ └── SQLCase2.js
│ ├── Tree.test.js
│ ├── Tree.js
│ ├── Map.js
│ └── Map.spec.js
├── app.spec.js
├── HttpError.js
├── __tests__
│ ├── temp.test.js
│ └── integration.test.js
├── api
│ ├── entity.js
│ ├── entity.test.js
│ ├── nearest.js
│ └── nearest.test.js
├── routeUtils.js
└── app.js
├── .env.example
├── .gitignore
├── deployment
├── base
│ ├── namespace.yaml
│ ├── kustomization.yaml
│ ├── treetracker-webmap-api-mapping.yml
│ ├── treetracker-webmap-api-service.yml
│ └── treetracker-webmap-api-deployment.yml
└── overlays
│ ├── test
│ ├── kustomization.yaml
│ └── treetracker-webmap-api-mapping.yml
│ ├── development
│ ├── kustomization.yaml
│ └── treetracker-webmap-api-mapping.yml
│ └── production
│ ├── kustomization.yaml
│ └── treetracker-webmap-api-mapping.yml
├── Dockerfile
├── .eslintrc.json
├── .releaserc
├── package.json
├── .github
└── workflows
│ ├── treetracker-webmap-server-deploy-test.yml
│ ├── treetracker-webmap-server-deploy-prod.yml
│ ├── treetracker-webmap-server-deploy-dev.yml
│ ├── treetracker-server-unstable-build.yaml
│ └── treetracker-api-build-deploy-dev.yml
├── README.md
├── CHANGELOG.md
└── LICENSE
/src/config/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | DATABASE_URL=postgresql://username:password@host:port/treetracker_dev?ssl=no-verify
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | config/config.js
3 | src/config/config.js
4 |
5 | *.swp
6 | .DS_Store
7 |
--------------------------------------------------------------------------------
/deployment/base/namespace.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: webmap
5 |
--------------------------------------------------------------------------------
/src/config/config.example.js:
--------------------------------------------------------------------------------
1 | exports.connectionString = "postgres://user:password@host/treetrackerdb";
2 |
3 |
--------------------------------------------------------------------------------
/src/cron/.gitignore:
--------------------------------------------------------------------------------
1 | error-file.txt
2 | log-file.txt
3 | package-lock.json
4 | assign-clusters-log-file.txt
5 |
6 |
--------------------------------------------------------------------------------
/src/server.test.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | describe("Server", () => {
4 |
5 | it("API:entity", async () => {
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/deployment/overlays/test/kustomization.yaml:
--------------------------------------------------------------------------------
1 | bases:
2 | - ../../base
3 | patchesStrategicMerge:
4 | - treetracker-webmap-api-mapping.yml
5 |
--------------------------------------------------------------------------------
/deployment/overlays/development/kustomization.yaml:
--------------------------------------------------------------------------------
1 | bases:
2 | - ../../base
3 | patchesStrategicMerge:
4 | - treetracker-webmap-api-mapping.yml
5 |
--------------------------------------------------------------------------------
/deployment/overlays/production/kustomization.yaml:
--------------------------------------------------------------------------------
1 | bases:
2 | - ../../base
3 | patchesStrategicMerge:
4 | - treetracker-webmap-api-mapping.yml
5 |
--------------------------------------------------------------------------------
/deployment/base/kustomization.yaml:
--------------------------------------------------------------------------------
1 | resources:
2 | - treetracker-webmap-api-deployment.yml
3 | - treetracker-webmap-api-mapping.yml
4 | - treetracker-webmap-api-service.yml
5 | - namespace.yaml
6 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:12.19.0-alpine
2 |
3 | WORKDIR /usr/app/server
4 | COPY package.json ./
5 | COPY package-lock.json ./
6 | RUN npm ci --silent
7 | COPY . ./
8 | CMD [ "node", "src/server.js" ]
9 |
--------------------------------------------------------------------------------
/src/server.js:
--------------------------------------------------------------------------------
1 | require('dotenv').config()
2 | const app = require("./app");
3 | var port = process.env.NODE_PORT || 3000;
4 |
5 | app.listen(port, () => {
6 | console.log('listening on port ' + port);
7 | });
8 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "commonjs": true,
4 | "es2021": true,
5 | "node": true
6 | },
7 | "parserOptions": {
8 | "ecmaVersion": 12
9 | },
10 | "rules": {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/deployment/overlays/development/treetracker-webmap-api-mapping.yml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: getambassador.io/v2
3 | kind: Mapping
4 | metadata:
5 | name: webmap-be-api
6 | namespace: webmap
7 | spec:
8 | cors:
9 | origins:
10 | - '*'
11 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase1Timeline.test.js:
--------------------------------------------------------------------------------
1 | const SQLCase1Timeline = require("./SQLCase1Timeline");
2 |
3 | describe("checkTimeline", () => {
4 | it("checkTimeline", () => {
5 | SQLCase1Timeline.checkTimeline("2015-01-21_2016-12-31");
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/deployment/base/treetracker-webmap-api-mapping.yml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: getambassador.io/v2
3 | kind: Mapping
4 | metadata:
5 | name: webmap-be-api
6 | namespace: webmap
7 | spec:
8 | prefix: /webmap/
9 | service: treetracker-webmap-api-ambassador-svc
10 | rewrite: /
11 | timeout_ms: 0
12 | cors:
13 | methods: GET, OPTIONS
14 | headers:
15 | - Content-Type
16 | - Authorization
17 |
--------------------------------------------------------------------------------
/src/cron/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cron",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "assign-new-trees-to-clusters.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "pg": "^8.0.3",
13 | "request": "^2.88.0",
14 | "request-promise-native": "^1.0.7"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/deployment/overlays/test/treetracker-webmap-api-mapping.yml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: getambassador.io/v2
3 | kind: Mapping
4 | metadata:
5 | name: webmap-be-api
6 | namespace: webmap
7 | spec:
8 | cors:
9 | origins:
10 | - '*'
11 | - https://test.treetracker.org
12 | - https://test-app.forestmatic.com
13 | - https://forestmatic.com
14 | - https://app.forestmatic.com
15 | - https://staging-app.forestmatic.com
16 |
--------------------------------------------------------------------------------
/deployment/base/treetracker-webmap-api-service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: treetracker-webmap-api-ambassador-svc
5 | annotations:
6 | labels:
7 | app: treetracker-webmap-api
8 | name: treetracker-webmap-api-ambassador-svc
9 | namespace: webmap
10 | spec:
11 | ports:
12 | - name: treetracker-webmap-api
13 | port: 80
14 | protocol: TCP
15 | targetPort: 3000
16 | selector:
17 | app: treetracker-webmap-api
--------------------------------------------------------------------------------
/.releaserc:
--------------------------------------------------------------------------------
1 | {
2 | "branches": ["master"],
3 | "plugins": [
4 | "@semantic-release/commit-analyzer",
5 | "@semantic-release/release-notes-generator",
6 | "@semantic-release/changelog",
7 | "@semantic-release/npm",
8 | ["@semantic-release/git", {
9 | "assets": ["docs", "package.json", "CHANGELOG.md"],
10 | "message": "chore(release): ${nextRelease.version} [skip ci]"
11 | }],
12 | "@semantic-release/github"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/deployment/overlays/production/treetracker-webmap-api-mapping.yml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: getambassador.io/v2
3 | kind: Mapping
4 | metadata:
5 | name: webmap-be-api
6 | namespace: webmap
7 | spec:
8 | cors:
9 | origins:
10 | - '*'
11 | - https://wallet.treetracker.org
12 | - https://freetown.treetracker.org
13 | - https://map.treetracker.org
14 | - https://forestmatic.com
15 | - https://app.forestmatic.com
16 | - https://staging-app.forestmatic.com
17 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLTree.test.js:
--------------------------------------------------------------------------------
1 | const SQLTree = require("./SQLTree");
2 |
3 | describe("SQLTree", () => {
4 |
5 | it("", async () => {
6 | const sql = new SQLTree();
7 | sql.setTreeId(1);
8 | const query = await sql.getQuery();
9 | expect(query).toMatchObject({
10 | text: expect.stringMatching(/select.*trees.*token_uuid.*wallet.*inner join planter.*left join tree_species.*left join token.*left join entity.*id =/is),
11 | values: [1],
12 | });
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/cron/assign-new-trees-to-clusters.sh:
--------------------------------------------------------------------------------
1 | PID_FILE=/var/run/assign-clusters.pid
2 | LOG_FILE=/var/log/treetracker-cron-assign-clusters
3 |
4 | if [ -e $PID_FILE ]; then
5 | echo "script is already running"
6 | exit
7 | fi
8 |
9 | # Ensure PID file is removed on program exit.
10 | trap "rm -f -- '$PID_FILE'" EXIT
11 |
12 | # Create a file with current PID to indicate that process is running.
13 | echo $$ > "$PID_FILE"
14 |
15 | /usr/bin/node /root/treetracker-map-api/cron/assign-new-trees-to-clusters.js >>$LOG_FILE 2>>$LOG_FILE
16 |
--------------------------------------------------------------------------------
/src/cron/update-clusters-for-deactivated-trees.sh:
--------------------------------------------------------------------------------
1 | PID_FILE=/var/run/update-clusters-for-deactivated-trees.pid
2 | LOG_FILE=/var/log/treetracker-cron-update-clusters-for-deactivated-trees
3 |
4 | if [ -e $PID_FILE ]; then
5 | echo "script is already running"
6 | exit
7 | fi
8 |
9 | # Ensure PID file is removed on program exit.
10 | trap "rm -f -- '$PID_FILE'" EXIT
11 |
12 | # Create a file with current PID to indicate that process is running.
13 | echo $$ > "$PID_FILE"
14 |
15 | /usr/bin/node /root/treetracker-map-api/cron/update-clusters-for-deactivated-trees.js >>$LOG_FILE 2>$LOG_FILE
16 |
--------------------------------------------------------------------------------
/src/app.spec.js:
--------------------------------------------------------------------------------
1 | const request = require("supertest");
2 | jest.mock("./models/Map");
3 | const app = require("./app");
4 | const Map = require("./models/Map");
5 |
6 | describe("App", () => {
7 |
8 | beforeAll(() => {
9 | })
10 |
11 | it("app", async () => {
12 | const res = await request(app)
13 | .get("/trees?clusterRadius=8&zoom_level=2");
14 | expect(res.statusCode).toBe(200);
15 | expect(Map).toHaveBeenCalledTimes(1);
16 | const mapInstance = Map.mock.instances[0];
17 | expect(mapInstance.init).toHaveBeenCalledWith({
18 | clusterRadius: "8",
19 | zoom_level: "2",
20 | });
21 | });
22 |
23 |
24 |
25 | });
26 |
--------------------------------------------------------------------------------
/src/HttpError.js:
--------------------------------------------------------------------------------
1 | /*
2 | * To define a extended error for API, can pass through the error message, http
3 | * code, to bring some convenient for the internal class to throw out the error
4 | * and the outside of the layer can catch the error and convert to a http
5 | * response to client
6 | */
7 |
8 | class HttpError extends Error {
9 | constructor(code, message, toRollback){
10 | super(message);
11 | this.code = code;
12 | //set rollback flag, so the transaction of db would rollback when catch this error
13 | //set default to true
14 | this._toRollback = toRollback || true;
15 | }
16 |
17 | shouldRollback(){
18 | return this._toRollback;
19 | }
20 | }
21 |
22 | module.exports = HttpError;
23 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase4.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case4, search DB via clusters table
3 | */
4 |
5 | class SQLCase4{
6 |
7 | constructor(){
8 | }
9 |
10 | setBounds(bounds){
11 | this.bounds = bounds;
12 | }
13 |
14 | getBoundingBoxQuery(){
15 | let result = "";
16 | if (this.bounds) {
17 | result += 'AND location && ST_MakeEnvelope(' + this.bounds + ', 4326) ';
18 | }
19 | return result;
20 | }
21 |
22 | getQuery(){
23 | const query = {
24 | text: `
25 | /* case4 */
26 | SELECT 'cluster' as type,
27 | St_asgeojson(location) centroid, count
28 | FROM clusters
29 | WHERE zoom_level = 14
30 | ${this.getBoundingBoxQuery()}
31 | `,
32 | values: [],
33 | }
34 | return query;
35 | }
36 | }
37 |
38 | module.exports = SQLCase4;
39 |
--------------------------------------------------------------------------------
/src/__tests__/temp.test.js:
--------------------------------------------------------------------------------
1 | const request = require("supertest");
2 | const app = require("../app");
3 |
4 | describe("/trees", () => {
5 | const url = "/trees?clusterRadius=8&zoom_level=2&timeline=2015-01-01_2015-12-31";
6 | it(url, async () => {
7 | const res = await request(app)
8 | .get(url);
9 | expect(res.statusCode).toBe(200);
10 | });
11 | });
12 |
13 | describe("case2", () => {
14 | const url = "/trees?clusterRadius=0.02&zoom_level=12&bounds=36.80545735559693,-3.083181971041851,36.4437325020813,-3.411419640340873&timeline=2015-02-12_2016-01-15";
15 | it(url, async () => {
16 | const res = await request(app)
17 | .get(url);
18 | expect(res.statusCode).toBe(200);
19 | });
20 | });
21 |
22 | describe.only("case3", () => {
23 | const url = "/trees?clusterRadius=0.003&zoom_level=16&bounds=36.63570794474349,-3.2540084447912094,36.61310014139876,-3.2745229731158965&timeline=2015-02-12_2016-01-15";
24 | it(url, async () => {
25 | const res = await request(app)
26 | .get(url);
27 | expect(res.statusCode).toBe(200);
28 | });
29 | });
30 |
31 |
--------------------------------------------------------------------------------
/deployment/base/treetracker-webmap-api-deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: "apps/v1"
2 | kind: "Deployment"
3 | metadata:
4 | name: "treetracker-webmap-api"
5 | namespace: "webmap"
6 | labels:
7 | app: "treetracker-webmap-api"
8 | spec:
9 | replicas: 2
10 | selector:
11 | matchLabels:
12 | app: "treetracker-webmap-api"
13 | template:
14 | metadata:
15 | labels:
16 | app: "treetracker-webmap-api"
17 | spec:
18 | affinity:
19 | nodeAffinity:
20 | requiredDuringSchedulingIgnoredDuringExecution:
21 | nodeSelectorTerms:
22 | - matchExpressions:
23 | - key: doks.digitalocean.com/node-pool
24 | operator: In
25 | values:
26 | - microservices-node-pool
27 | containers:
28 | - name: "treetracker-webmap-api"
29 | image: "greenstand/treetracker-web-map-api:TAG"
30 | env:
31 | - name: DATABASE_URL
32 | valueFrom:
33 | secretKeyRef:
34 | name: dbconnection
35 | key: database
36 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase1Timeline.js:
--------------------------------------------------------------------------------
1 | const SQLCase1 = require("./SQLCase1");
2 |
3 | class SQLCase1Timeline extends SQLCase1{
4 |
5 | constructor(){
6 | super();
7 | this.timeline = undefined;
8 | }
9 |
10 | static checkTimeline(timeline){
11 | if(!timeline.match(/\d{4}-\d{2}-\d{2}_\d{4}-\d{2}-\d{2}/)){
12 | throw Error("Wrong timeline:" + timeline);
13 | }
14 | }
15 |
16 | addTimeline(timeline){
17 | SQLCase1Timeline.checkTimeline(timeline);
18 | this.timeline = timeline;
19 | }
20 |
21 | getJoin(){
22 | let result = "";
23 | //disable parent getJoin, so, just do my job
24 | // result += super.getJoin();
25 | if(this.timeline){
26 | result += "JOIN trees ON tree_region.tree_id = trees.id";
27 | }
28 | return result;
29 | }
30 |
31 | getFilter(){
32 | let result = "";
33 | if(this.timeline){
34 | const [_, begin,end] = this.timeline.match(/(.*)_(.*)/);
35 | result += `
36 | AND trees.time_created > '${begin}' AND trees.time_created < '${end}'
37 | `;
38 | }
39 | return result;
40 | }
41 | }
42 |
43 | module.exports = SQLCase1Timeline;
44 |
--------------------------------------------------------------------------------
/src/api/entity.js:
--------------------------------------------------------------------------------
1 | /*
2 | * The entity business, (entity table)
3 | */
4 | const express = require("express");
5 | const router = express.Router();
6 | const {Pool, Client} = require("pg");
7 |
8 | const pool = new Pool({ connectionString: process.env.DATABASE_URL });
9 |
10 | router.get("/:id", async function(req, res, next){
11 | console.log("id:", req.params.id);
12 | const query = {
13 | text: "select * from entity where id = $1",
14 | values: [req.params.id],
15 | }
16 | const result = await pool.query(query);
17 | res.status(200).send((result && result.rows && result.rows.length > 0 && result.rows[0]) || null);
18 | });
19 |
20 | router.get("/", async function(req, res, next){
21 | let where = "";
22 | let values = [];
23 | if(req.query.wallet){
24 | where = " where wallet = $1";
25 | values.push(req.query.wallet);
26 | }
27 | if(req.query.map_name){
28 | where = " where map_name = $1";
29 | values.push(req.query.map_name);
30 | }
31 | const query = {
32 | text: "select * from entity" + where,
33 | values,
34 | }
35 | const result = await pool.query(query);
36 | res.status(200).send(result.rows);
37 | });
38 |
39 | module.exports = router;
40 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase1V2.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case1, search DB via active_tree_region table,
3 | * V2, use join to filter organization trees
4 | */
5 | const SQLCase1 = require("./SQLCase1");
6 |
7 | class SQLCase1V2 extends SQLCase1{
8 |
9 | constructor(){
10 | super();
11 | }
12 |
13 | getJoin(){
14 | let result = "";
15 | if(this.isFilteringByUserId){
16 | result += "JOIN trees ON tree_region.tree_id = trees.id";
17 | }
18 | if(this.mapName){
19 | result += `
20 | INNER JOIN
21 | ( select trees.id as org_tree_id from trees
22 | where trees.planter_id in (
23 | SELECT id FROM planter
24 | JOIN (
25 | SELECT entity_id FROM getEntityRelationshipChildren(
26 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
27 | )
28 | ) org ON planter.organization_id = org.entity_id
29 | ) OR
30 | trees.planting_organization_id = (
31 | select id from entity where map_name = '${this.mapName}'
32 | )
33 | ) tree_ids
34 | ON tree_region.tree_id = tree_ids.org_tree_id`;
35 | }
36 | return result;
37 | }
38 |
39 | addMapNameFilter(mapName){
40 | this.mapName = mapName;
41 | }
42 |
43 | }
44 |
45 | module.exports = SQLCase1V2;
46 |
--------------------------------------------------------------------------------
/src/routeUtils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Some utils for router/express
3 | */
4 | const log = require("loglevel");
5 | const HttpError = require("./HttpError");
6 |
7 | /*
8 | * This is from the library https://github.com/Abazhenov/express-async-handler
9 | * Made some customization for our project. With this, we can throw Error from
10 | * the handler function or internal function call stack, and parse the error,
11 | * send to the client with appropriate response (http error code & json body)
12 | *
13 | * USAGE: wrap the express handler with this function:
14 | *
15 | * router.get("/xxx", handlerWrap(async (res, rep, next) => {
16 | * ...
17 | * }));
18 | *
19 | * Then, add the errorHandler below to the express global error handler.
20 | *
21 | */
22 | exports.handlerWrapper = fn =>
23 | function wrap(...args) {
24 | const fnReturn = fn(...args)
25 | const next = args[args.length-1]
26 | return Promise.resolve(fnReturn).catch(e => {
27 | next(e);
28 | })
29 | }
30 |
31 | exports.errorHandler = (err, req, res, next) => {
32 | log.warn("catch error:", err);
33 | if(err instanceof HttpError){
34 | res.status(err.code).send({
35 | code: err.code,
36 | message: err.message,
37 | });
38 | }else{
39 | res.status(500).send({
40 | code: 500,
41 | message: `Unknown error (${err.message})`,
42 | });
43 | }
44 | };
45 |
46 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase2Timeline.js:
--------------------------------------------------------------------------------
1 | const SQLCase2 = require("./SQLCase2");
2 |
3 | class SQLCase2Timeline extends SQLCase2{
4 |
5 |
6 | addTimeline(timeline){
7 | this.timeline = timeline;
8 | }
9 |
10 | getFilter(){
11 | let result = "";
12 | if(this.timeline){
13 | const [_, begin,end] = this.timeline.match(/(.*)_(.*)/);
14 | result += `
15 | AND trees.time_created > '${begin}' AND trees.time_created < '${end}'
16 | `;
17 | }
18 | return result;
19 | }
20 |
21 | setBounds(bounds){
22 | this.bounds = bounds;
23 | }
24 |
25 | getBoundingBoxQuery(){
26 | let result = "";
27 | if (this.bounds) {
28 | result += 'AND trees.estimated_geometric_location && ST_MakeEnvelope(' + this.bounds + ', 4326) ';
29 | }
30 | return result;
31 | }
32 |
33 | getJoin(){
34 | let result = "";
35 | return result;
36 | }
37 |
38 | getQuery(){
39 | let sql = `
40 | /* sql case2 */
41 | SELECT /* DISTINCT ON(trees.id) */
42 | 'point' AS type,
43 | trees.id, trees.lat, trees.lon
44 | FROM trees
45 | ${this.getJoin()}
46 | WHERE active = true
47 | ${this.getBoundingBoxQuery()}
48 | ${this.getFilter()}
49 | `
50 | ;
51 | console.log(sql);
52 |
53 | const query = {
54 | text: sql,
55 | values: [],
56 | };
57 | return query;
58 | }
59 | }
60 |
61 |
62 | module.exports = SQLCase2Timeline;
63 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "treetracker-web",
3 | "version": "1.17.0",
4 | "private": true,
5 | "description": "treetracker web map",
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/Greenstand/treetracker-web-map.git"
9 | },
10 | "author": "",
11 | "bugs": {
12 | "url": "https://github.com/Greenstand/treetracker-web-map/issues"
13 | },
14 | "homepage": "https://github.com/Greenstand/treetracker-web-map#readme",
15 | "scripts": {
16 | "lint": "npm run eslint",
17 | "lint:fix": "npm run eslint:fix && npm run prettier:fix",
18 | "eslint": "eslint --report-unused-disable-directives .",
19 | "eslint:fix": "npm run eslint -- --fix",
20 | "test": "jest --watchAll --runInBand",
21 | "dev": "NODE_PORT=3001 NODE_ENV=dev nodemon src/server.js",
22 | "update-db": "node src/cron/assign-new-trees-to-clusters.js"
23 | },
24 | "dependencies": {
25 | "@sentry/node": "^5.4.3",
26 | "body-parser": "^1.18.2",
27 | "chai": "^4.2.0",
28 | "dotenv": "^8.2.0",
29 | "express": "^4.16.2",
30 | "express-lru": "^1.0.0",
31 | "loglevel": "^1.7.1",
32 | "morgan": "^1.9.1",
33 | "pg": "^7.4.0"
34 | },
35 | "license": "AGPL",
36 | "devDependencies": {
37 | "jest": "^26.0.1",
38 | "nodemon": "^2.0.4",
39 | "npm": "^6.14.6",
40 | "supertest": "^4.0.2",
41 | "eslint": "^7.11.0",
42 | "eslint-config-airbnb-base": "^14.2.0",
43 | "eslint-config-prettier": "^6.13.0",
44 | "eslint-plugin-import": "^2.22.1",
45 | "eslint-plugin-prettier": "^3.2.0"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/.github/workflows/treetracker-webmap-server-deploy-test.yml:
--------------------------------------------------------------------------------
1 |
2 | name: Deploy to Test Env
3 |
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | git-tag:
9 | description: 'tag'
10 | required: true
11 |
12 | env:
13 | project-directory: ./
14 |
15 | jobs:
16 | deploy:
17 | name: Deploy, requires approval
18 | runs-on: ubuntu-latest
19 | if: |
20 | github.repository == 'Greenstand/treetracker-web-map-api'
21 | steps:
22 | - uses: actions/checkout@v2
23 | with:
24 | ref: ${{ github.event.inputs.git-tag }}
25 | - name: get-npm-version
26 | id: package-version
27 | uses: martinbeentjes/npm-get-version-action@master
28 | - name: Install kustomize
29 | run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
30 | working-directory: ${{ env.project-directory }}
31 | - name: Run kustomize
32 | run: (cd ./deployment/base && ../../kustomize edit set image greenstand/treetracker-web-map-api:${{ steps.package-version.outputs.current-version }} )
33 | working-directory: ${{ env.project-directory }}
34 | - name: Install doctl for kubernetes
35 | uses: digitalocean/action-doctl@v2
36 | with:
37 | token: ${{ secrets.DIGITALOCEAN_TOKEN }}
38 | - name: Save DigitalOcean kubeconfig
39 | run: doctl kubernetes cluster kubeconfig save ${{ secrets.TEST_CLUSTER_NAME }}
40 | - name: Update kubernetes resources
41 | run: kustomize build deployment/overlays/test | kubectl apply -n webmap --wait -f -
42 | working-directory: ${{ env.project-directory }}
43 |
--------------------------------------------------------------------------------
/.github/workflows/treetracker-webmap-server-deploy-prod.yml:
--------------------------------------------------------------------------------
1 |
2 | name: Deploy to Prod Env
3 |
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | git-tag:
9 | description: 'tag'
10 | required: true
11 |
12 | env:
13 | project-directory: ./
14 |
15 | jobs:
16 | deploy:
17 | name: Deploy, requires approval
18 | runs-on: ubuntu-latest
19 | if: |
20 | github.repository == 'Greenstand/treetracker-web-map-api'
21 | steps:
22 | - uses: actions/checkout@v2
23 | with:
24 | ref: ${{ github.event.inputs.git-tag }}
25 | - name: get-npm-version
26 | id: package-version
27 | uses: martinbeentjes/npm-get-version-action@master
28 | - name: Install kustomize
29 | run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
30 | working-directory: ${{ env.project-directory }}
31 | - name: Run kustomize
32 | run: (cd ./deployment/base && ../../kustomize edit set image greenstand/treetracker-web-map-api:${{ steps.package-version.outputs.current-version }} )
33 | working-directory: ${{ env.project-directory }}
34 | - name: Install doctl for kubernetes
35 | uses: digitalocean/action-doctl@v2
36 | with:
37 | token: ${{ secrets.DIGITALOCEAN_PRODUCTION_TOKEN }}
38 | - name: Save DigitalOcean kubeconfig
39 | run: doctl kubernetes cluster kubeconfig save ${{ secrets.PRODUCTION_CLUSTER_NAME }}
40 | - name: Update kubernetes resources
41 | run: kustomize build deployment/overlays/production | kubectl apply -n webmap --wait -f -
42 | working-directory: ${{ env.project-directory }}
43 |
--------------------------------------------------------------------------------
/.github/workflows/treetracker-webmap-server-deploy-dev.yml:
--------------------------------------------------------------------------------
1 |
2 | name: Deploy to Dev Env
3 |
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | git-tag:
9 | description: 'tag'
10 | required: true
11 |
12 | env:
13 | project-directory: ./
14 |
15 | jobs:
16 | deploy:
17 | name: Deploy
18 | runs-on: ubuntu-latest
19 | if: |
20 | github.repository == 'Greenstand/treetracker-web-map-api'
21 | steps:
22 | - uses: actions/checkout@v2
23 | with:
24 | ref: ${{ github.event.inputs.git-tag }}
25 | - name: get-npm-version
26 | id: package-version
27 | uses: martinbeentjes/npm-get-version-action@master
28 | - name: Install kustomize
29 | run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
30 | working-directory: ${{ env.project-directory }}
31 | - name: Copy kustomize.yml
32 | run: cp ./deployment/kustomize/kustomization.yaml ./deployment/kustomization.yaml
33 | working-directory: ${{ env.project-directory }}
34 | - name: Run kustomize
35 | run: (cd ./deployment/base && ../../kustomize edit set image greenstand/treetracker-web-map-api:${{ steps.package-version.outputs.current-version }} )
36 | working-directory: ${{ env.project-directory }}
37 | - name: Install doctl for kubernetes
38 | uses: digitalocean/action-doctl@v2
39 | with:
40 | token: ${{ secrets.DIGITALOCEAN_TOKEN }}
41 | - name: Save DigitalOcean kubeconfig
42 | run: doctl kubernetes cluster kubeconfig save ${{ secrets.DEV_CLUSTER_NAME }}
43 | - name: Update kubernetes resources
44 | run: kustomize build deployment/overlays/development | kubectl apply -n webmap --wait -f -
45 | working-directory: ${{ env.project-directory }}
46 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLZoomTargetCase1V2.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case6, to search cluster for next zoom target
3 | * V2, use select to get trees in organzaion rather then an explicit tree id list
4 | */
5 | const SQLZoomTargetCase1 = require("./SQLZoomTargetCase1");
6 |
7 | class SQLZoomTargetCase1V2 extends SQLZoomTargetCase1{
8 |
9 | constructor(){
10 | super();
11 | }
12 |
13 | addMapNameFilter(mapName){
14 | this.mapName = mapName;
15 | }
16 |
17 | setTreeIds(){
18 | throw new Error("dedicated");
19 | }
20 |
21 |
22 | getFilter(){
23 | let result = "";
24 | if(this.mapName){
25 | result += `
26 | AND active_tree_region.tree_id IN(
27 | select distinct * from (
28 | SELECT trees.id as id from trees
29 | INNER JOIN (
30 | SELECT id FROM planter
31 | JOIN (
32 | SELECT entity_id FROM getEntityRelationshipChildren(
33 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
34 | )
35 | ) org ON planter.organization_id = org.entity_id
36 | ) planter_ids
37 | ON trees.planter_id = planter_ids.id
38 | union all
39 | SELECT trees.id as id from trees
40 | INNER JOIN (
41 | SELECT id FROM planter
42 | JOIN (
43 | SELECT entity_id FROM getEntityRelationshipChildren(
44 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
45 | )
46 | ) org ON planter.organization_id = org.entity_id
47 | ) planter_ids
48 | ON trees.planter_id = planter_ids.id
49 | ) t1
50 | )`;
51 | }
52 | return result;
53 | }
54 |
55 | addTreesFilter(){
56 | throw new Error("dedicated");
57 | }
58 |
59 | }
60 |
61 | module.exports = SQLZoomTargetCase1V2;
62 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase3Timeline.js:
--------------------------------------------------------------------------------
1 | const SQLCase3 = require("./SQLCase3");
2 |
3 | class SQLCase3Timeline extends SQLCase3{
4 |
5 | constructor(){
6 | super();
7 | this.timeline = undefined;
8 | }
9 |
10 | static checkTimeline(timeline){
11 | if(!timeline.match(/\d{4}-\d{2}-\d{2}_\d{4}-\d{2}-\d{2}/)){
12 | throw Error("Wrong timeline:" + timeline);
13 | }
14 | }
15 |
16 | addTimeline(timeline){
17 | SQLCase3Timeline.checkTimeline(timeline);
18 | this.timeline = timeline;
19 | }
20 |
21 | /* overwrite getJoin totally */
22 | getJoin(){
23 | let result = "";
24 | //disable parent getJoin, so, just do my job
25 | //no need to join it anymore
26 | // result += super.getJoin();
27 | // if(this.timeline){
28 | // result += "JOIN trees ON tree_region.tree_id = trees.id";
29 | // }
30 | return result;
31 | }
32 |
33 | /*the getFilter */
34 | getFilter(){
35 | let result = "";
36 | if(this.timeline){
37 | const [_, begin,end] = this.timeline.match(/(.*)_(.*)/);
38 | result += `
39 | AND trees.time_created > '${begin}' AND trees.time_created < '${end}'
40 | `;
41 | }
42 | return result;
43 | }
44 |
45 | getQuery(){
46 | console.log('case 3 timline');
47 | const query = {
48 | text: `
49 | /* case3 timelinej*/
50 | SELECT 'cluster' AS type,
51 | St_asgeojson(St_centroid(clustered_locations)) centroid,
52 | St_numgeometries(clustered_locations) count
53 | FROM (
54 | SELECT Unnest(St_clusterwithin(estimated_geometric_location, $1)) clustered_locations
55 | FROM trees
56 | ${this.getJoin()}
57 | WHERE active = true
58 | ${this.getBoundingBoxQuery()}
59 | ${this.getFilter()}
60 | ${this.getJoinCriteria()}
61 | ) clusters`,
62 | values: [this.getClusterRadius()]
63 | };
64 | return query;
65 | }
66 | }
67 |
68 | module.exports = SQLCase3Timeline;
69 |
--------------------------------------------------------------------------------
/src/models/Tree.test.js:
--------------------------------------------------------------------------------
1 | const Tree = require("./Tree");
2 | const {Pool} = require("pg");
3 | const {SQLTree} = require("./sqls/SQLTree");
4 | jest.mock("pg");
5 |
6 | describe("Tree", () => {
7 | let query;
8 |
9 | beforeEach(() => {
10 | query = jest.fn().mockReturnValue(true);
11 | Pool.prototype.query = query;
12 | })
13 |
14 | it("getTree", async () => {
15 | query
16 | .mockResolvedValueOnce({
17 | rows: [{
18 | id: 1,
19 | domain_specific_data: {},
20 | }],
21 | })
22 | .mockResolvedValueOnce({
23 | rows: [{
24 | key: "key1",
25 | value: "value1",
26 | },{
27 | key: "key2",
28 | value: "value2",
29 | }],
30 | });
31 | const tree = new Tree();
32 | const treeDetail = await tree.getTreeById(1);
33 | expect(treeDetail.id).toBe(1);
34 | expect(treeDetail.domain_specific_data).toMatchObject({});
35 | expect(treeDetail.attributes).toMatchObject({
36 | key1: "value1",
37 | key2: "value2",
38 | });
39 | });
40 |
41 | it("getTreeByName", async () => {
42 | query
43 | .mockResolvedValueOnce({
44 | rows: [{
45 | id: 1,
46 | domain_specific_data: {},
47 | }],
48 | })
49 | .mockResolvedValueOnce({
50 | rows: [{
51 | key: "key1",
52 | value: "value1",
53 | },{
54 | key: "key2",
55 | value: "value2",
56 | }],
57 | });
58 | const tree = new Tree();
59 | const treeDetail = await tree.getTreeByName("a_b_c");
60 | expect(treeDetail.id).toBe(1);
61 | expect(treeDetail.domain_specific_data).toMatchObject({});
62 | expect(treeDetail.attributes).toMatchObject({
63 | key1: "value1",
64 | key2: "value2",
65 | });
66 | expect(query).toHaveBeenCalledTimes(2);
67 | expect(query.mock.calls[0][0].text).toMatch(/trees.name = 'a_b_c'/);
68 | expect(query.mock.calls[1][0]).toMatchObject({
69 | text: "select * from tree_attributes where tree_id = $1",
70 | values: [1],
71 | });
72 | });
73 |
74 | });
75 |
--------------------------------------------------------------------------------
/.github/workflows/treetracker-server-unstable-build.yaml:
--------------------------------------------------------------------------------
1 | name: Webmap Server CI/CD Unstable Branch
2 |
3 | on:
4 | push:
5 | paths:
6 | - '**'
7 | - '.github/workflows/treetracker-webmap-server*'
8 | branches:
9 | - unstable
10 |
11 | env:
12 | project-directory: ./
13 |
14 | jobs:
15 | # test:
16 | # - name: npm clean install
17 | # run: npm ci
18 | # working-directory: ${{ env.project-directory }}
19 | # - name: run ESLint
20 | # run: npm run lint
21 | #working-directory: ${{ env.project-directory }}
22 | #- name: build server project
23 | #run: npm run build
24 | #working-directory: ${{ env.project-directory }}
25 | build:
26 | name: Build Docker Image
27 | runs-on: ubuntu-latest
28 | if: |
29 | !contains(github.event.head_commit.message, 'skip-ci') &&
30 | github.event_name == 'push' &&
31 | github.repository == 'Greenstand/treetracker-web-map'
32 | steps:
33 | - uses: actions/checkout@v2
34 | - name: Use Node.js 12.x
35 | uses: actions/setup-node@v1
36 | with:
37 | node-version: '12.x'
38 | - name: npm clean install
39 | run: npm ci
40 | working-directory: ${{ env.project-directory }}
41 | - name: Set up QEMU
42 | uses: docker/setup-qemu-action@v1
43 | - name: Set up Docker Buildx
44 | uses: docker/setup-buildx-action@v1
45 | - name: Login to DockerHub
46 | uses: docker/login-action@v1
47 | with:
48 | username: ${{ secrets.DOCKERHUB_USERNAME }}
49 | password: ${{ secrets.DOCKERHUB_TOKEN }}
50 | - name: Declare some variables
51 | id: vars
52 | shell: bash
53 | run: |
54 | echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
55 | echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
56 |
57 | - name: Another step
58 | run: |
59 | echo "Branch: ${{ steps.vars.outputs.branch }}"
60 | echo "Sha: ${{ steps.vars.outputs.sha_short }}"
61 |
62 | - name: Build snapshot with git sha and push on merge
63 | id: docker_build_snapshot_merge
64 | uses: docker/build-push-action@v2
65 | with:
66 | context: ./
67 | file: Dockerfile
68 | push: true
69 | tags: greenstand/treetracker-web-map-api:${{ steps.vars.outputs.sha_short }}
70 | - shell: bash
71 | run: |
72 | echo '${{ steps.vars.outputs.sha_short }}' > image-tag
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/src/api/entity.test.js:
--------------------------------------------------------------------------------
1 | const request = require("supertest");
2 | const express = require("express");
3 | const {Pool, Client} = require("pg");
4 |
5 | jest.mock("pg");
6 | const query = jest.fn();
7 | Pool.mockImplementation(jest.fn(() => ({
8 | query,
9 | })));
10 |
11 | const entity = require("./entity");
12 |
13 | describe("entity", () => {
14 | let app;
15 |
16 | beforeEach(() => {
17 | app = express();
18 | app.use("/entities", entity);
19 | });
20 |
21 | afterAll(() => {
22 | jest.clearAllMocks();
23 | });
24 |
25 | it("/entities/1", async () => {
26 | query.mockResolvedValue({rows:[{id:1, name: "zaven"}]});
27 | const response = await request(app)
28 | .get("/entities/1")
29 | expect(new Pool().query).toBeDefined();
30 | expect(response.statusCode).toBe(200);
31 | expect(query).toHaveBeenCalledWith({
32 | text: "select * from entity where id = $1",
33 | values: ["1"],
34 | });
35 | expect(response.body).toMatchObject({
36 | id: 1,
37 | name: "zaven",
38 | });
39 | });
40 |
41 | it("/entities", async () => {
42 | query.mockResolvedValue({rows:[{id:1, name: "zaven"}]});
43 | const response = await request(app)
44 | .get("/entities")
45 | expect(response.statusCode).toBe(200);
46 | expect(query).toHaveBeenCalledWith({
47 | text: "select * from entity",
48 | values: [],
49 | });
50 | expect(response.body).toMatchObject([{
51 | id: 1,
52 | name: "zaven",
53 | }]);
54 | });
55 |
56 | it("/entities?wallet=zaven", async () => {
57 | query.mockResolvedValue({rows:[{id:1, name: "zaven"}]});
58 | const response = await request(app)
59 | .get("/entities?wallet=zaven")
60 | expect(response.statusCode).toBe(200);
61 | expect(query).toHaveBeenCalledWith({
62 | text: "select * from entity where wallet = $1",
63 | values: ["zaven"],
64 | });
65 | expect(response.body).toMatchObject([{
66 | id: 1,
67 | name: "zaven",
68 | }]);
69 | });
70 |
71 | it("/entities?map_name=freetown", async () => {
72 | query.mockResolvedValue({rows:[{id:1, name: "freetown"}]});
73 | const response = await request(app)
74 | .get("/entities?map_name=freetown")
75 | expect(response.statusCode).toBe(200);
76 | expect(query).toHaveBeenCalledWith({
77 | text: "select * from entity where map_name = $1",
78 | values: ["freetown"],
79 | });
80 | expect(response.body).toMatchObject([{
81 | id: 1,
82 | name: "freetown",
83 | }]);
84 | });
85 |
86 | });
87 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLZoomTargetCase1.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case6, to search cluster for next zoom target
3 | */
4 |
5 | class SQLZoomTargetCase1{
6 |
7 | constructor(){
8 | }
9 |
10 | setTreeIds(treeIds){
11 | this.treeIds = treeIds;
12 | }
13 |
14 |
15 | getFilter(){
16 | let result = "";
17 | if(this.treeIds && this.treeIds.length > 0){
18 | result += "AND active_tree_region.tree_id IN(" + this.treeIds.join(",") + ") ";
19 | }
20 | return result;
21 | }
22 |
23 | setZoomLevel(zoomLevel){
24 | this.zoomLevel = zoomLevel;
25 | }
26 |
27 | getZoomLevel(){
28 | if(!this.zoomLevel){
29 | throw new Error("zoom level required");
30 | }
31 | return this.zoomLevel;
32 | }
33 |
34 | setBounds(bounds){
35 | this.bounds = bounds;
36 | }
37 |
38 | getBoundingBoxQuery(){
39 | let result = "";
40 | if (this.bounds) {
41 | result += ' AND region.centroid && ST_MakeEnvelope(' + this.bounds + ', 4326) ';
42 | }
43 | return result;
44 | }
45 |
46 | addTreesFilter(treeIds){
47 | this.treeIds = treeIds;
48 | }
49 |
50 | getQuery(){
51 | const query = {
52 | text: `
53 | /* case6 zoom target */
54 | SELECT DISTINCT ON (region.id)
55 | region.id region_id,
56 | contained.region_id most_populated_subregion_id,
57 | contained.total,
58 | contained.zoom_level,
59 | ST_ASGeoJson(contained.centroid) centroid
60 | FROM
61 | (
62 | SELECT region_id, zoom_level
63 | FROM active_tree_region
64 | WHERE zoom_level = $1
65 | ${this.getFilter()}
66 | GROUP BY region_id, zoom_level
67 | ) populated_region
68 | JOIN region
69 | ON region.id = populated_region.region_id
70 | JOIN (
71 | SELECT region_id, zoom_level, count(active_tree_region.id) AS total, centroid
72 | FROM active_tree_region
73 | WHERE zoom_level = $2
74 | ${this.getFilter()}
75 | GROUP BY region_id, zoom_level, centroid
76 | ) contained
77 | ON ST_CONTAINS(region.geom, contained.centroid)
78 | WHERE true
79 | ${this.getBoundingBoxQuery()}
80 | ORDER BY region.id, total DESC`,
81 | values: [this.getZoomLevel(), this.getZoomLevel() + 2]
82 | }
83 | return query;
84 | }
85 | }
86 |
87 | module.exports = SQLZoomTargetCase1;
88 |
--------------------------------------------------------------------------------
/src/api/nearest.js:
--------------------------------------------------------------------------------
1 | /*
2 | * The entity business, (entity table)
3 | */
4 | const express = require("express");
5 | const router = express.Router();
6 | const { Pool, Client } = require("pg");
7 | const chai = require("chai");
8 |
9 | const pool = new Pool({ connectionString: process.env.DATABASE_URL });
10 |
11 | //router.get("/:id", async function (req, res, next) {
12 | // console.log("id:", req.params.id);
13 | // const query = {
14 | // text: "select * from entity where id = $1",
15 | // values: [req.params.id],
16 | // };
17 | // const result = await pool.query(query);
18 | // res
19 | // .status(200)
20 | // .send(
21 | // (result && result.rows && result.rows.length > 0 && result.rows[0]) ||
22 | // null
23 | // );
24 | //});
25 |
26 | router.get("/", async function (req, res, next) {
27 | try{
28 | let { zoom_level, lng, lat } = req.query;
29 | zoom_level = parseInt(zoom_level);
30 | lng = parseFloat(lng);
31 | lat = parseFloat(lat);
32 | console.log("lng:", lng);
33 | chai.expect(zoom_level).above(0);
34 | chai.expect(lng).not.NaN;
35 | chai.expect(lat).not.NaN;
36 | let query;
37 | if (zoom_level <= 11) {
38 | query = {
39 | text: `
40 | SELECT
41 | ST_ASGeoJson(centroid)
42 | FROM
43 | active_tree_region
44 | WHERE
45 | zoom_level = ${zoom_level}
46 | ORDER BY
47 | active_tree_region.centroid <->
48 | ST_SetSRID(ST_MakePoint(${lng}, ${lat}),4326)
49 | LIMIT 1;
50 | `,
51 | values: [],
52 | };
53 | } else if (zoom_level < 15 && zoom_level > 11) {
54 | query = {
55 | text: `
56 | SELECT
57 | ST_ASGeoJson(location)
58 | FROM
59 | clusters
60 | ORDER BY
61 | location <->
62 | ST_SetSRID(ST_MakePoint(${lng}, ${lat}),4326)
63 | LIMIT 1;
64 | `,
65 | values: [],
66 | };
67 | } else if (zoom_level >= 15) {
68 | query = {
69 | text: `
70 | SELECT
71 | ST_ASGeoJson(estimated_geometric_location)
72 | FROM
73 | trees
74 | WHERE
75 | active = true
76 | ORDER BY
77 | estimated_geometric_location <->
78 | ST_SetSRID(ST_MakePoint(${lng}, ${lat}),4326)
79 | LIMIT 1;
80 | `,
81 | values: [],
82 | };
83 | }
84 | console.log("query:", query);
85 | const result = await pool.query(query);
86 | //{"st_asgeojson":"{\"type\":\"Point\",\"coordinates\":[39.1089215842116,-5.12839483715479]}"}
87 | res.status(200).json({
88 | nearest: result.rows.length > 0 ?
89 | JSON.parse(result.rows[0].st_asgeojson)
90 | :
91 | null
92 | });
93 | }catch(e){
94 | console.error(e);
95 | res.status(500).end();
96 | }
97 | });
98 |
99 | module.exports = router;
100 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLTree.js:
--------------------------------------------------------------------------------
1 |
2 | class SQLTree {
3 |
4 | setTreeId(treeId) {
5 | this.treeId = treeId;
6 | }
7 |
8 | setTreeName(treeName) {
9 | this.treeName = treeName;
10 | }
11 |
12 | setToken(token) {
13 | this.token = token;
14 | }
15 |
16 | getQuery() {
17 | if (!this.treeId && !this.treeName && !this.token) {
18 | throw new Error("treeId or treeName or token required");
19 | }
20 |
21 | const query = {
22 | text: `
23 | SELECT
24 | trees.*,
25 | tree_species.name AS species_name,
26 | planter.first_name AS first_name, planter.last_name as last_name,
27 | planter.image_url AS user_image_url,
28 | token.id::text AS token_uuid,
29 | wallet.name as wallet
30 | FROM
31 | trees
32 | INNER JOIN planter
33 | ON planter.id = trees.planter_id
34 | LEFT JOIN tree_species ON
35 | trees.species_id = tree_species.id
36 | LEFT JOIN wallet.token token ON token.capture_id::text = trees.uuid
37 | LEFT JOIN wallet.wallet wallet ON wallet.id = token.wallet_id
38 | WHERE
39 | true
40 | ${this.getFilter()}
41 | AND trees.active = true
42 | `,
43 | values: [],
44 | };
45 | console.log("tree:", query);
46 | return query;
47 | }
48 |
49 | getFilter() {
50 | let filter = "";
51 | if (this.treeId) {
52 | filter += `AND trees.id = ${this.treeId}`;
53 | }
54 | if (this.treeName) {
55 | filter += `AND trees.name = '${this.treeName}'`;
56 | }
57 | if (this.token) {
58 | filter += `AND token.id = '${this.token}'`;
59 | }
60 | return filter;
61 | }
62 |
63 | setTreeUUID(uuid) {
64 | this.treeUUID = uuid;
65 | }
66 |
67 | getQueryUUID() {
68 | if (!this.treeUUID) {
69 | throw new Error("treeUUID required");
70 | }
71 |
72 | const query = {
73 | text: `
74 | SELECT
75 | trees.*,
76 | tree_species.name AS species_name,
77 | planter.first_name AS first_name, planter.last_name as last_name,
78 | planter.image_url AS user_image_url,
79 | token.id::text AS token_uuid,
80 | wallet.name as wallet
81 | FROM
82 | trees
83 | INNER JOIN planter
84 | ON planter.id = trees.planter_id
85 | LEFT JOIN tree_species ON
86 | trees.species_id = tree_species.id
87 | LEFT JOIN wallet.token token ON token.capture_id::text = trees.uuid
88 | LEFT JOIN wallet.wallet wallet ON wallet.id = token.wallet_id
89 | WHERE
90 | trees.uuid = $1 AND trees.active = true
91 | `,
92 | values: [this.treeUUID],
93 | };
94 | console.log("tree:", query);
95 | return query;
96 | }
97 | }
98 |
99 | module.exports = SQLTree;
100 |
--------------------------------------------------------------------------------
/src/__tests__/integration.test.js:
--------------------------------------------------------------------------------
1 | const request = require("supertest");
2 | const app = require("../app");
3 |
4 | describe.skip("Integration tests", () => {
5 |
6 | describe("/trees", () => {
7 | it("/trees?clusterRadius=8&zoom_level=2&map_name=freetown", async () => {
8 | const res = await request(app)
9 | .get("/trees?clusterRadius=8&zoom_level=2&map_name=freetown");
10 | expect(res.statusCode).toBe(200);
11 | }, 100000);
12 |
13 | it("/trees?clusterRadius=0.02&zoom_level=12&bounds=0.27413497359721345,0.09675638212298909,-0.3191267451527627,-0.07998612103164923&map_name=freetown", async () => {
14 | const res = await request(app)
15 | .get("/trees?clusterRadius=0.02&zoom_level=12&bounds=0.27413497359721345,0.09675638212298909,-0.3191267451527627,-0.07998612103164923&map_name=freetown");
16 | expect(res.statusCode).toBe(200);
17 | }, 100000);
18 |
19 | it.skip("/trees?clusterRadius=0.003&zoom_level=16&bounds=0.018839836120605472,0.005394458765216459,-0.018239021301269535,-0.0056519508298092415&map_name=freetown", async () => {
20 | const res = await request(app)
21 | .get("/trees?clusterRadius=0.003&zoom_level=16&bounds=0.018839836120605472,0.005394458765216459,-0.018239021301269535,-0.0056519508298092415&map_name=freetown");
22 | expect(res.statusCode).toBe(200);
23 | }, 90000);
24 |
25 | it("/trees?clusterRadius=0.05&zoom_level=10&userid=12", async () => {
26 | const res = await request(app)
27 | .get("/trees?clusterRadius=0.05&zoom_level=10&userid=12");
28 | expect(res.statusCode).toBe(200);
29 | }, 100000);
30 | });
31 |
32 | describe("/tree", () => {
33 | it("/tree?tree_id=198081", async () => {
34 | const res = await request(app)
35 | .get("/tree?tree_id=198081");
36 | expect(res.statusCode).toBe(200);
37 | console.log("tree detail:", res.body);
38 | expect(res.body).toMatchObject({
39 | id: 198081,
40 | domain_specific_data: {},
41 | attributes: {
42 | delta_step_count: "1",
43 | },
44 | images: {},
45 | token_uuid: expect.any(String),
46 | wallet: expect.any(String),
47 | });
48 | }, 100000);
49 | });
50 |
51 | it("/trees?clusterRadius=0.05&zoom_level=10&userid=12", async () => {
52 | const res = await request(app)
53 | .get("/trees?clusterRadius=0.05&zoom_level=10&userid=12");
54 | expect(res.statusCode).toBe(200);
55 | }, 100000);
56 |
57 |
58 | describe("wallet map", () => {
59 | it("/trees?clusterRadius=0.02&zoom_level=12&wallet=forestmatic_demo", async () => {
60 | const res = await request(app)
61 | .get("/trees?clusterRadius=0.02&zoom_level=12&wallet=forestmatic_demo");
62 | expect(res.statusCode).toBe(200);
63 | }, 100000);
64 |
65 | it("/trees?clusterRadius=0.02&zoom_level=16&wallet=forestmatic_demo", async () => {
66 | const res = await request(app)
67 | .get("/trees?clusterRadius=0.02&zoom_level=16&wallet=forestmatic_demo");
68 | expect(res.statusCode).toBe(200);
69 | }, 100000);
70 | });
71 |
72 | });
73 |
--------------------------------------------------------------------------------
/src/app.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const bodyParser = require('body-parser');
3 | const app = express();
4 | const expressLru = require('express-lru');
5 | const Sentry = require('@sentry/node');
6 | const Map = require('./models/Map');
7 | const Tree = require("./models/Tree");
8 | const helper = require("./routeUtils");
9 |
10 | Sentry.init({ dsn: null });
11 | const cache = expressLru({
12 | max: 1000,
13 | ttl: 60000 * 240,
14 | skip: function (req) {
15 | // Don't run if bounds passed in, possibly other cases as well
16 | return !!req.user || !!req.query.bounds;
17 | }
18 | });
19 | app.use(Sentry.Handlers.requestHandler());
20 | app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
21 | app.use(bodyParser.json()); // parse application/json
22 | app.set('view engine', 'html');
23 |
24 | const allowCrossDomain = (req, res, next) => {
25 | res.header('Access-Control-Allow-Origin', '*');
26 | res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
27 | res.header('Access-Control-Allow-Headers', 'Content-Type');
28 | next();
29 | }
30 |
31 | if (process.env.NODE_ENV == 'dev') {
32 | console.log('disable cors');
33 | app.use(allowCrossDomain);
34 | }
35 |
36 | //app.get(/(\/api\/web)?\/trees/, function (req, res) {
37 | app.get("/trees", cache, helper.handlerWrapper(async function (req, res) {
38 | const map = new Map();
39 | const beginTime = Date.now();
40 | await map.init(req.query);
41 | const response = {};
42 | response.data = await map.getPoints();
43 | response.zoomTargets = await map.getZoomTargets();
44 | console.log("/trees took time:%d ms", Date.now() - beginTime);
45 | res.status(200).json(response);
46 | }));
47 |
48 | app.use(Sentry.Handlers.errorHandler());
49 |
50 | //entities API
51 | const entity = require("./api/entity");
52 | //app.use(/(\/api\/web)?\/entities/, entity);
53 | app.use("/entities", entity);
54 |
55 | //nearest API
56 | const nearest = require("./api/nearest");
57 | app.use("/nearest", nearest);
58 |
59 | app.get("/tree", async function (req, res) {
60 | try {
61 | console.log('get tree')
62 | const tree = new Tree();
63 | const treeId = req.query.tree_id;
64 | const uuid = req.query.uuid;
65 | const token = req.query.token;
66 | const treeName = req.query.tree_name;
67 | let treeDetail = {};
68 | if (treeId) {
69 | treeDetail = await tree.getTreeById(treeId);
70 | } else if (uuid) {
71 | treeDetail = await tree.getTreeByUUID(uuid);
72 | } else if (treeName) {
73 | treeDetail = await tree.getTreeByName(treeName);
74 | } else if (token) {
75 | treeDetail = await tree.getTreeByToken(token);
76 | } else {
77 | console.warn("tree_id did not match any record", treeId);
78 | res.status(400).json({ message: "tree_id did not match any record" });
79 | }
80 | delete treeDetail.planter_identifier;
81 |
82 | res.status(200).json(treeDetail);
83 |
84 | } catch (error) {
85 | console.log(error)
86 | res.status(500).json({ message: "something wrong:" + error });
87 | }
88 | });
89 |
90 | /*const version = require('../package.json').version
91 | app.get('*',function (req, res) {
92 | res.status(200).send(version)
93 | });*/
94 |
95 | // Global error handler
96 | app.use(helper.errorHandler);
97 |
98 | module.exports = app;
99 |
--------------------------------------------------------------------------------
/src/api/nearest.test.js:
--------------------------------------------------------------------------------
1 | const request = require("supertest");
2 | const express = require("express");
3 | const { Pool, Client } = require("pg");
4 |
5 | jest.mock("pg");
6 | const query = jest.fn();
7 | Pool.mockImplementation(
8 | jest.fn(() => ({
9 | query,
10 | }))
11 | );
12 |
13 | const nearest = require("./nearest");
14 |
15 | const nearestResult = [{"st_asgeojson":"{\"type\":\"Point\",\"coordinates\":[39.1089215842116,-5.12839483715479]}"}];
16 |
17 | describe("nearest", () => {
18 | let app;
19 |
20 | beforeEach(() => {
21 | app = express();
22 | app.use("/nearest", nearest);
23 | });
24 |
25 | afterAll(() => {
26 | jest.clearAllMocks();
27 | });
28 |
29 | it("/nearest?zoom_level=16&lng=85.5&lat=23.4", async () => {
30 | query.mockResolvedValue({ rows: nearestResult });
31 | const response = await request(app).get(
32 | "/nearest?zoom_level=16&lng=85.5&lat=23.4"
33 | );
34 | expect(new Pool().query).toBeDefined();
35 | expect(response.statusCode).toBe(200);
36 | expect(query).toHaveBeenCalledWith({
37 | text: expect.stringMatching(/select.*trees.*active.*=.*true.*/is),
38 | values: expect.anything(),
39 | });
40 | expect(response.body).toMatchObject({
41 | nearest: expect.anything(),
42 | });
43 | });
44 |
45 | it("/nearest?zoom_level=14&lng=85.5&lat=23.4", async () => {
46 | query.mockResolvedValue({ rows: nearestResult });
47 | const response = await request(app).get(
48 | "/nearest?zoom_level=14&lng=85.5&lat=23.4"
49 | );
50 | expect(new Pool().query).toBeDefined();
51 | expect(response.statusCode).toBe(200);
52 | expect(query).toHaveBeenCalledWith({
53 | text: expect.stringMatching(/select.*clusters.*/is),
54 | values: expect.anything(),
55 | });
56 | expect(response.body).toMatchObject({
57 | nearest: expect.anything(),
58 | });
59 | });
60 |
61 | it("/nearest?zoom_level=8&lng=85.5&lat=23.4", async () => {
62 | query.mockResolvedValue({ rows: nearestResult });
63 | const response = await request(app).get(
64 | "/nearest?zoom_level=8&lng=85.5&lat=23.4"
65 | );
66 | expect(new Pool().query).toBeDefined();
67 | expect(response.statusCode).toBe(200);
68 | expect(query).toHaveBeenCalledWith({
69 | text: expect.stringMatching(/select.*active_tree_region.*/is),
70 | values: expect.anything(),
71 | });
72 | expect(response.body).toMatchObject({
73 | nearest: expect.anything(),
74 | });
75 | });
76 |
77 | // it("/entities", async () => {
78 | // query.mockResolvedValue({ rows: [{ id: 1, name: "zaven" }] });
79 | // const response = await request(app).get("/entities");
80 | // expect(response.statusCode).toBe(200);
81 | // expect(query).toHaveBeenCalledWith({
82 | // text: "select * from entity",
83 | // values: [],
84 | // });
85 | // expect(response.body).toMatchObject([
86 | // {
87 | // id: 1,
88 | // name: "zaven",
89 | // },
90 | // ]);
91 | // });
92 | //
93 | // it("/entities?wallet=zaven", async () => {
94 | // query.mockResolvedValue({ rows: [{ id: 1, name: "zaven" }] });
95 | // const response = await request(app).get("/entities?wallet=zaven");
96 | // expect(response.statusCode).toBe(200);
97 | // expect(query).toHaveBeenCalledWith({
98 | // text: "select * from entity where wallet = $1",
99 | // values: ["zaven"],
100 | // });
101 | // expect(response.body).toMatchObject([
102 | // {
103 | // id: 1,
104 | // name: "zaven",
105 | // },
106 | // ]);
107 | // });
108 | });
109 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Tree Tracker Web Map (BackEnd - API)
2 |
3 | This project is built using Node.js version 12.19.0.
4 |
5 | Project Knowledge Base: https://app.gitbook.com/@greenstand/s/impact-map/
6 |
7 | ## Requirements
8 |
9 | - Node.js 12
10 |
11 | ## News
12 |
13 | The docker image name was updated from treetracker-webmap-api to treetracker-web-map-api due to standardization in how we name docker images based of repository names. This change had introduced deployment issues. Cloud engineers please be adivsed of this change.
14 |
15 | ## Backend Development
16 |
17 | To set up your environment for BackEnd development, follow the steps below:
18 |
19 | > NOTE: We recommend all of these tasks to be executed using Visual Studio Code, openning a Terminal session.
20 |
21 |
22 | 1. Install node modules, running npm i in the root
23 | ```
24 | npm i
25 | ```
26 | 2. Set up database connection string.
27 |
28 |
29 | 1. Create a .env file at the folder server.
30 | 2. Add the following content in the .env file
31 |
32 | ```
33 | DATABASE_URL=postgresql://xxxx:xxxx@dxxxx:25060/treetracker?ssl=no-verify
34 | ```
35 |
36 | > NOTE: The default mode to run the API in the test environment is connecting with the remote database.
37 | > * Ask for the db connectiong string on the slack channel.
38 |
39 |
40 | 3. Install supervisor globally
41 |
42 | ```
43 | npm i -g supervisor
44 | ```
45 |
46 | 4. Run the Backend Development Environment
47 |
48 | Attention:
49 |
50 | - Option 1 is for **BackEnd development only**.
51 | - Option 2 is for **FrontEnd and BackEnd development**.
52 |
53 | Choose one of the options and Run the code below on the terminal:
54 |
55 | - **Option 1**:
56 |
57 | > NOTE 1: This command will run server.js with CORS restrictions lifted
58 | > NOTE 2: For environments running the FrontEnd and BackEnd, do not use this option, because API will run at port 3000 conflicting with the React project. Choose option 2.
59 |
60 |
61 | ```
62 | NODE_ENV=dev supervisor server.js
63 | ```
64 |
65 |
66 | - **Option 2**:
67 |
68 | ```
69 | cd server
70 | npm run dev
71 | ```
72 | > NOTE:
73 | > 1. In this way, the server would run on port 3001, and client would run on port 3000.
74 |
75 |
76 |
77 | > IMPORTANT NOTE: When running for the first time the API, if the endpoints are not responding, because after the queries there aren't any answer or error, it might be some incompatibility with the node version and pg module. If you are running Node.js 14, downgrade to Node.js 12.19.0.
78 | [How to Upgrade (or Downgrade) Node.js Using npm](https://www.surrealcms.com/blog/how-to-upgrade-or-downgrade-nodejs-using-npm.html)
79 |
80 |
81 |
82 |
83 |
84 | ### (Optional) Local Database
85 |
86 |
87 |
88 | * The steps below are required only for scenarios where the API needs to connect with the Postgres database locally.
89 | * The default mode to run the application is connecting with the remote database, but for some specific scenarios, as an exception, the developer might need to have the database running local.
90 | * Do not execute these steps if you are configuring the environment for the first time.
91 |
92 | 1. Install postgres
93 | 2. Install postGIS
94 | 3. Create a database named 'treetracker'
95 | 4. Import our developer seed into your database.
96 | - Ask in slack for the link to the seed.
97 | 5. Configure .env to point to your local database.
98 | 6. Run the [Backend Development Environmet](#rundev).
99 |
100 |
101 | ---
102 |
103 |
104 | ### How to test
105 |
106 | We use Jest to build tests.
107 |
108 | 1. To test server
109 | ```
110 | cd server
111 | npm test
112 | ```
113 |
114 |
--------------------------------------------------------------------------------
/src/models/Tree.js:
--------------------------------------------------------------------------------
1 | const SQLTree = require("./sqls/SQLTree");
2 | const { Pool } = require('pg');
3 | const log = require("loglevel");
4 |
5 | class Tree {
6 | constructor() {
7 | log.warn("with db:", process.env.DATABASE_URL);
8 | this.pool = new Pool({ connectionString: process.env.DATABASE_URL });
9 | }
10 |
11 | async getTreeById(treeId) {
12 | const sql = new SQLTree();
13 | sql.setTreeId(treeId);
14 | const query = await sql.getQuery();
15 | const result = await this.pool.query(query);
16 | if (result.rows.length === 0) {
17 | // throw new Error("can not find tree", treeId);
18 | return undefined;
19 | }
20 | const treeObject = result.rows[0];
21 | //attribute
22 | {
23 | const query = {
24 | text: "select * from tree_attributes where tree_id = $1",
25 | values: [treeId],
26 | };
27 | const attributes = await this.pool.query(query);
28 | const attributeJson = {};
29 | for (const r of attributes.rows) {
30 | attributeJson[r.key] = r.value;
31 | }
32 | treeObject.attributes = attributeJson;
33 | }
34 | return treeObject;
35 | }
36 |
37 | async getTreeByUUID(uuid) {
38 | const sql = new SQLTree();
39 | sql.setTreeUUID(uuid);
40 | const query = await sql.getQueryUUID();
41 | const result = await this.pool.query(query);
42 | if (result.rows.length === 0) {
43 | // throw new Error("can not find tree", treeId);
44 | return undefined;
45 | }
46 | const treeObject = result.rows[0];
47 | //attribute
48 | {
49 | const query = {
50 | text: "select * from tree_attributes where tree_id = $1",
51 | values: [treeObject.id],
52 | };
53 | console.log(query)
54 | const attributes = await this.pool.query(query);
55 | const attributeJson = {};
56 | for (const r of attributes.rows) {
57 | attributeJson[r.key] = r.value;
58 | }
59 | treeObject.attributes = attributeJson;
60 | }
61 | return treeObject;
62 | }
63 |
64 | async getTreeByName(treeName) {
65 | const sql = new SQLTree();
66 | sql.setTreeName(treeName);
67 | const query = await sql.getQuery();
68 | const result = await this.pool.query(query);
69 | if (result.rows.length === 0) {
70 | // throw new Error(`can not find tree ${treeName}`);
71 | return undefined;
72 | }
73 | const treeObject = result.rows[0];
74 | //attribute
75 | {
76 | const query = {
77 | text: "select * from tree_attributes where tree_id = $1",
78 | values: [treeObject.id],
79 | };
80 | const attributes = await this.pool.query(query);
81 | const attributeJson = {};
82 | for (const r of attributes.rows) {
83 | attributeJson[r.key] = r.value;
84 | }
85 | treeObject.attributes = attributeJson;
86 | }
87 | return treeObject;
88 | }
89 |
90 | async getTreeByToken(token) {
91 | const sql = new SQLTree();
92 | sql.setToken(token);
93 | const query = await sql.getQuery();
94 | const result = await this.pool.query(query);
95 | if (result.rows.length === 0) {
96 | // throw new Error("can not find tree", treeId);
97 | return undefined;
98 | }
99 | const treeObject = result.rows[0];
100 | //attribute
101 | {
102 | const query = {
103 | text: "select * from tree_attributes where tree_id = $1",
104 | values: [treeObject.id],
105 | };
106 | console.log(query)
107 | const attributes = await this.pool.query(query);
108 | const attributeJson = {};
109 | for (const r of attributes.rows) {
110 | attributeJson[r.key] = r.value;
111 | }
112 | treeObject.attributes = attributeJson;
113 | }
114 | return treeObject;
115 | }
116 |
117 | }
118 |
119 |
120 | module.exports = Tree;
121 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase1.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case1, search DB via active_tree_region table,
3 | */
4 |
5 | class SQLCase1{
6 |
7 | constructor(){
8 | this.isFilteringByUserId = false;
9 | this.userId = undefined;
10 | }
11 |
12 | addFilterByWallet(wallet){
13 | this.wallet = wallet;
14 | }
15 |
16 | addFilterByUserId(userId){
17 | this.isFilteringByUserId = true;
18 | this.userId = userId;
19 | }
20 |
21 | getJoin(){
22 | let result = "";
23 | if(this.isFilteringByUserId || this.wallet){
24 | result += "JOIN trees ON tree_region.tree_id = trees.id\n";
25 | }
26 | if(this.wallet){
27 | result += 'INNER JOIN wallet.token ON wallet.token.capture_id::text = trees.uuid \n';
28 | result += 'INNER JOIN wallet.wallet ON wallet.wallet.id = wallet.token.wallet_id \n';
29 | }
30 | return result;
31 | }
32 |
33 | getFilter(){
34 | let result = "";
35 | if(this.isFilteringByUserId){
36 | result += "AND planter_id = " + this.userId + " ";
37 | }
38 | if(this.treeIds && this.treeIds.length > 0){
39 | result += "AND tree_region.tree_id IN(" + this.treeIds.join(",") + ") ";
40 | }
41 | if(this.wallet) {
42 | result += "AND wallet.wallet.name = '" + this.wallet + "'"
43 | }
44 | if(this.mapName){
45 | result += `
46 | AND tree_region.tree_id IN(
47 | select distinct * from (
48 | SELECT trees.id as id from trees
49 | INNER JOIN (
50 | SELECT id FROM planter
51 | JOIN (
52 | SELECT entity_id FROM getEntityRelationshipChildren(
53 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
54 | )
55 | ) org ON planter.organization_id = org.entity_id
56 | ) planter_ids
57 | ON trees.planter_id = planter_ids.id
58 | union all
59 | SELECT trees.id as id from trees
60 | INNER JOIN (
61 | SELECT id FROM planter
62 | JOIN (
63 | SELECT entity_id FROM getEntityRelationshipChildren(
64 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
65 | )
66 | ) org ON planter.organization_id = org.entity_id
67 | ) planter_ids
68 | ON trees.planter_id = planter_ids.id
69 |
70 | UNION ALL
71 | select id from trees where planting_organization_id = (
72 | select id from entity where map_name = '${this.mapName}'
73 | )
74 | ) t1
75 | )
76 | `;
77 | }
78 | return result;
79 | }
80 |
81 | setZoomLevel(zoomLevel){
82 | this.zoomLevel = zoomLevel;
83 | }
84 |
85 | getZoomLevel(){
86 | if(!this.zoomLevel){
87 | throw new Error("zoom level required");
88 | }
89 | return this.zoomLevel;
90 | }
91 |
92 | setBounds(bounds){
93 | this.bounds = bounds;
94 | }
95 |
96 | getBoundingBoxQuery(){
97 | let result = "";
98 | if (this.bounds) {
99 | result += ' AND centroid && ST_MakeEnvelope(' + this.bounds + ', 4326) \n';
100 | }
101 | return result;
102 | }
103 |
104 | addMapNameFilter(mapName){
105 | this.mapName = mapName;
106 | }
107 |
108 | getQuery(){
109 | //TODO check the conflict case, like: can not set userid and treeIds at the same time
110 | const query = {
111 | text: `
112 | /* sql case1 */
113 | SELECT 'cluster' AS type,
114 | region_id id, ST_ASGeoJson(centroid) centroid,
115 | type_id as region_type,
116 | count(tree_region.id)
117 | FROM active_tree_region tree_region
118 | ${this.getJoin()}
119 | WHERE zoom_level = $1
120 | ${this.getFilter()}
121 | ${this.getBoundingBoxQuery()}
122 | GROUP BY region_id, centroid, type_id`,
123 | values: [this.getZoomLevel()]
124 | };
125 | return query;
126 | }
127 | }
128 |
129 | module.exports = SQLCase1;
130 |
--------------------------------------------------------------------------------
/.github/workflows/treetracker-api-build-deploy-dev.yml:
--------------------------------------------------------------------------------
1 | name: API CI/CD Pipeline
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | env:
8 | project-directory: ./
9 |
10 | jobs:
11 | test:
12 | name: Test
13 | runs-on: ubuntu-latest
14 | if: |
15 | !contains(github.event.head_commit.message, 'skip-ci')
16 | steps:
17 | - uses: actions/checkout@v2
18 | - name: Use Node.js 12.x
19 | uses: actions/setup-node@v1
20 | with:
21 | node-version: '12.x'
22 | - name: npm clean install
23 | run: npm ci
24 | working-directory: ${{ env.project-directory }}
25 | - name: run ESLint
26 | run: npm run lint
27 | working-directory: ${{ env.project-directory }}
28 | # - name: run api tests
29 | # run: npm run test
30 | # working-directory: ${{ env.project-directory }}
31 |
32 |
33 | release:
34 | name: Release
35 | needs: test
36 | runs-on: ubuntu-latest
37 | if: |
38 | !contains(github.event.head_commit.message, 'skip-ci') &&
39 | github.event_name == 'push' &&
40 | github.repository == "Greenstand/${{ github.event.repository.name }}"
41 | steps:
42 | - uses: actions/checkout@v2
43 |
44 | - name: Use Node.js 14.x
45 | uses: actions/setup-node@v1
46 | with:
47 | node-version: '14.x'
48 |
49 | - name: npm clean install
50 | run: npm ci
51 | working-directory: ${{ env.project-directory }}
52 |
53 | - run: npm i -g semantic-release @semantic-release/{git,exec,changelog}
54 |
55 | - run: semantic-release
56 | env:
57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58 |
59 | - name: get-npm-version
60 | id: package-version
61 | uses: martinbeentjes/npm-get-version-action@master
62 |
63 | - name: Set up QEMU
64 | uses: docker/setup-qemu-action@v1
65 |
66 | - name: Set up Docker Buildx
67 | uses: docker/setup-buildx-action@v1
68 |
69 | - name: Login to DockerHub
70 | uses: docker/login-action@v1
71 | with:
72 | username: ${{ secrets.DOCKERHUB_USERNAME }}
73 | password: ${{ secrets.DOCKERHUB_TOKEN }}
74 |
75 | - name: Build snapshot and push on merge
76 | id: docker_build_release
77 | uses: docker/build-push-action@v2
78 | with:
79 | context: ./
80 | file: ./Dockerfile
81 | push: true
82 | tags: greenstand/${{ github.event.repository.name }}:${{ steps.package-version.outputs.current-version }}
83 |
84 | - id: export_bumped_version
85 | run: |
86 | export BUMPED_VERSION="${{ steps.package-version.outputs.current-version }}"
87 | echo "::set-output name=bumped_version::${BUMPED_VERSION}"
88 |
89 | outputs:
90 | bumped_version: ${{ steps.export_bumped_version.outputs.bumped_version }}
91 |
92 | deploy:
93 | name: Deploy to dev env
94 | runs-on: ubuntu-latest
95 | needs: release
96 | if: |
97 | !contains(github.event.head_commit.message, 'skip-ci') &&
98 | github.event_name == 'push' &&
99 | github.repository == "Greenstand/${{ github.event.repository.name }}"
100 | steps:
101 | - uses: actions/checkout@v2
102 | - name: Install kustomize
103 | run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
104 | - name: Run kustomize
105 | run: (cd deployment/base && ../../kustomize edit set image greenstand/${{ github.event.repository.name }}:${{ needs.release.outputs.bumped_version }} )
106 | - name: Install doctl for kubernetes
107 | uses: digitalocean/action-doctl@v2
108 | with:
109 | token: ${{ secrets.DEV_DIGITALOCEAN_TOKEN }}
110 | - name: Save DigitalOcean kubeconfig
111 | run: doctl kubernetes cluster kubeconfig save ${{ secrets.DEV_CLUSTER_NAME }}
112 | - name: Update kubernetes resources
113 | run: kustomize build deployment/overlays/development | kubectl apply -n ${{ secrets.K8S_NAMESPACE }} --wait -f -
114 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase3.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Case3, to filter and count all stuff via trees table directly, it would be slow if the data set is huge
3 | */
4 |
5 | class SQLCase3{
6 |
7 | constructor(){
8 | this.isFilteringByUserId = false;
9 | this.userId = undefined;
10 | }
11 |
12 |
13 | setClusterRadius(clusterRadius){
14 | this.clusterRadius = clusterRadius;
15 | }
16 |
17 | getClusterRadius(){
18 | parseFloat(this.clusterRadius)
19 | return this.clusterRadius;
20 | }
21 |
22 | addFilterByUserid(userid){
23 | this.userid = userid;
24 | }
25 |
26 | addFilterByWallet(wallet){
27 | this.wallet = wallet;
28 | }
29 |
30 | addFilterByFlavor(flavor){
31 | this.flavor = flavor;
32 | }
33 |
34 | addFilterByToken(token){
35 | this.token = token;
36 | }
37 |
38 | addFilterByMapName(mapName){
39 | this.mapName = mapName;
40 | }
41 |
42 | getFilter(){
43 | let result = "";
44 | if(this.userid){
45 | result += 'AND trees.planter_id = ' + this.userid + ' ';
46 | }
47 | if(this.wallet) {
48 | result += "AND wallet.wallet.name = '" + this.wallet + "'"
49 | }
50 | if(this.mapName){
51 | result += `
52 | AND trees.id IN(
53 | select distinct * from (
54 | SELECT trees.id as id from trees
55 | INNER JOIN (
56 | SELECT id FROM planter
57 | JOIN (
58 | SELECT entity_id FROM getEntityRelationshipChildren(
59 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
60 | )
61 | ) org ON planter.organization_id = org.entity_id
62 | ) planter_ids
63 | ON trees.planter_id = planter_ids.id
64 | union all
65 | SELECT trees.id as id from trees
66 | INNER JOIN (
67 | SELECT id FROM planter
68 | JOIN (
69 | SELECT entity_id FROM getEntityRelationshipChildren(
70 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
71 | )
72 | ) org ON planter.organization_id = org.entity_id
73 | ) planter_ids
74 | ON trees.planter_id = planter_ids.id
75 | ) t1
76 | )
77 | `;
78 | }
79 | return result;
80 | }
81 |
82 | getJoin(){
83 | let result = "";
84 | if(this.wallet){
85 | result += 'INNER JOIN wallet.token ON wallet.token.capture_id::text = trees.uuid \n';
86 | result += 'INNER JOIN wallet.wallet ON wallet.wallet.id = wallet.token.wallet_id \n';
87 | }
88 | if(this.flavor){
89 | result += "INNER JOIN tree_attributes ON tree_attributes.tree_id = trees.id";
90 | }
91 | if(this.token){
92 | result += "INNER JOIN certificates ON trees.certificate_id = certificates.id AND certificates.token = '" + this.token + "'";
93 | }
94 | return result;
95 | }
96 |
97 | getJoinCriteria(){
98 | let result = "";
99 | if(this.flavor){
100 | result += "AND tree_attributes.key = 'app_flavor' AND tree_attributes.value = '" + this.flavor + "'";
101 | }
102 | return result;
103 | }
104 |
105 | setBounds(bounds){
106 | this.bounds = bounds;
107 | }
108 |
109 | getBoundingBoxQuery(){
110 | let result = "";
111 | if (this.bounds) {
112 | result += 'AND trees.estimated_geometric_location && ST_MakeEnvelope(' + this.bounds + ', 4326) ';
113 | }
114 | return result;
115 | }
116 |
117 | getQuery(){
118 | console.log('Calculating clusters directly');
119 | const query = {
120 | text: `
121 | /* case3 */
122 | SELECT 'cluster' AS type,
123 | St_asgeojson(St_centroid(clustered_locations)) centroid,
124 | St_numgeometries(clustered_locations) count
125 | FROM (
126 | SELECT Unnest(St_clusterwithin(estimated_geometric_location, $1)) clustered_locations
127 | FROM trees
128 | ${this.getJoin()}
129 | WHERE active = true
130 | ${this.getBoundingBoxQuery()}
131 | ${this.getFilter()}
132 | ${this.getJoinCriteria()}
133 | ) clusters`,
134 | values: [this.getClusterRadius()]
135 | };
136 | return query;
137 | }
138 | }
139 |
140 | module.exports = SQLCase3;
141 |
--------------------------------------------------------------------------------
/src/models/sqls/SQLCase2.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Search DB by trees table directly, like in the high zoom level, show trees
3 | * on the map;
4 | */
5 |
6 |
7 |
8 | class SQLCase2{
9 |
10 |
11 | addTreeFilter(treeid){
12 | this.treeid = treeid;
13 | }
14 |
15 | addTreeNameFilter(tree_name){
16 | this.tree_name = tree_name;
17 | }
18 |
19 |
20 | addUUIDFilter(uuid){
21 | this.uuid = uuid;
22 | }
23 |
24 |
25 | addTreesFilter(){
26 | throw new Error("dedicated");
27 | }
28 |
29 | addFilterByUserId(userId){
30 | this.userId = userId;
31 | }
32 |
33 | addFilterByWallet(wallet){
34 | this.wallet = wallet;
35 | }
36 |
37 | addFilterByFlavor(flavor){
38 | this.flavor = flavor;
39 | }
40 |
41 | addFilterByToken(token){
42 | this.token = token;
43 | }
44 |
45 | addFilterByMapName(mapName){
46 | this.mapName = mapName;
47 | }
48 |
49 | getFilter(){
50 | let result = "";
51 | if(this.treeid){
52 | result += 'AND trees.id = ' + this.treeid + ' \n';
53 | }
54 | if(this.tree_name){
55 | result += "AND trees.name = '" + this.tree_name + "' \n";
56 | }
57 | if(this.uuid){
58 | result += 'AND trees.uuid = ' + this.uuid + ' \n';
59 | }
60 | if(this.mapName){
61 | result += `
62 | AND trees.id IN(
63 | select distinct * from (
64 | SELECT trees.id as id from trees
65 | INNER JOIN (
66 | SELECT id FROM planter
67 | JOIN (
68 | SELECT entity_id FROM getEntityRelationshipChildren(
69 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
70 | )
71 | ) org ON planter.organization_id = org.entity_id
72 | ) planter_ids
73 | ON trees.planter_id = planter_ids.id
74 | union all
75 | SELECT trees.id as id from trees
76 | INNER JOIN (
77 | SELECT id FROM planter
78 | JOIN (
79 | SELECT entity_id FROM getEntityRelationshipChildren(
80 | (SELECT id FROM entity WHERE map_name = '${this.mapName}')
81 | )
82 | ) org ON planter.organization_id = org.entity_id
83 | ) planter_ids
84 | ON trees.planter_id = planter_ids.id
85 | ) t1
86 | )
87 | `;
88 | }
89 | if(this.userId){
90 | result += "AND trees.planter_id = " + this.userId + " \n";
91 | }
92 | if(this.wallet) {
93 | result += "AND wallet.wallet.name = '" + this.wallet + "'"
94 | }
95 | return result;
96 | }
97 |
98 | setBounds(bounds){
99 | this.bounds = bounds;
100 | }
101 |
102 | getBoundingBoxQuery(){
103 | let result = "";
104 | if (this.bounds) {
105 | result += 'AND trees.estimated_geometric_location && ST_MakeEnvelope(' + this.bounds + ', 4326) ';
106 | }
107 | return result;
108 | }
109 |
110 | getJoinCriteria(){
111 | let result = "";
112 | if(this.flavor){
113 | result += "AND tree_attributes.key = 'app_flavor' AND tree_attributes.value = '" + this.flavor + "'";
114 | }
115 | if(this.token){
116 | result += "INNER JOIN certificates ON trees.certificate_id = certificates.id AND certificates.token = '" + this.token + "'";
117 | }
118 | return result;
119 | }
120 |
121 | getJoin(){
122 | let result = "";
123 | if(this.wallet){
124 | result += 'INNER JOIN wallet.token ON wallet.token.capture_id::text = trees.uuid \n';
125 | result += 'INNER JOIN wallet.wallet ON wallet.wallet.id = wallet.token.wallet_id \n';
126 | }
127 | if(this.flavor){
128 | result += "INNER JOIN tree_attributes ON tree_attributes.tree_id = trees.id";
129 | }
130 | return result;
131 | }
132 |
133 | getQuery(){
134 | let sql = `
135 | /* sql case2 */
136 | SELECT /* DISTINCT ON(trees.id) */
137 | 'point' AS type,
138 | trees.id, trees.lat, trees.lon
139 | FROM trees
140 | ${this.getJoin()}
141 | WHERE active = true
142 | ${this.getBoundingBoxQuery()}
143 | ${this.getFilter()}
144 | ${this.getJoinCriteria()}
145 | `
146 | ;
147 | console.log(sql);
148 |
149 | const query = {
150 | text: sql,
151 | values: [],
152 | };
153 | return query;
154 | }
155 | }
156 |
157 |
158 | module.exports = SQLCase2;
159 |
--------------------------------------------------------------------------------
/src/cron/assign-new-trees-to-clusters.js:
--------------------------------------------------------------------------------
1 |
2 | const pg = require('pg');
3 | const { Pool, Client } = require('pg');
4 | const config = require('./../config/config');
5 | const pool = new Pool({
6 | connectionString: config.connectionString
7 | });
8 |
9 |
10 | (async () => {
11 |
12 | const start = Date.now();
13 |
14 | const client = await pool.connect();
15 |
16 | const select = {
17 | text: `SELECT count(trees.id)
18 | FROM trees
19 | JOIN region
20 | ON ST_Contains( region.geom, trees.estimated_geometric_location)
21 | JOIN region_zoom
22 | ON region_zoom.region_id = region.id
23 | WHERE trees.active = true
24 | AND trees.cluster_regions_assigned = false`
25 | };
26 | const rval = await client.query(select);
27 | console.log(rval.rows[0].count)
28 | /* if(rval.rows[0].count == 0){
29 | console.log("no new trees");
30 | client.release();
31 | pool.end();
32 | return;
33 | }
34 | */
35 |
36 |
37 |
38 | var done = false;
39 | while(!done){
40 |
41 | await client.query('BEGIN');
42 | const insert = {
43 | text: `INSERT INTO tree_region
44 | (tree_id, zoom_level, region_id)
45 | SELECT DISTINCT ON (trees.id, zoom_level) trees.id AS tree_id, zoom_level, region.id
46 | FROM (
47 | SELECT *
48 | FROM trees
49 | WHERE trees.active = true
50 | AND trees.cluster_regions_assigned = false
51 | LIMIT 1000
52 | ) trees
53 | JOIN region
54 | ON ST_Contains( region.geom, trees.estimated_geometric_location)
55 | JOIN region_zoom
56 | ON region_zoom.region_id = region.id
57 | ORDER BY trees.id, zoom_level, region_zoom.priority DESC
58 | `
59 | };
60 | console.log(insert);
61 | await client.query(insert);
62 |
63 | const update = {
64 | text: `UPDATE trees
65 | SET cluster_regions_assigned = true
66 | FROM tree_region
67 | WHERE tree_region.tree_id = trees.id
68 | AND cluster_regions_assigned = false`
69 | };
70 | console.log(update);
71 | const rval2 = await client.query(update);
72 | console.log(rval2);
73 |
74 | await client.query('COMMIT');
75 |
76 | const select = {
77 | text: `SELECT count(trees.id)
78 | FROM trees
79 | JOIN region
80 | ON ST_Contains( region.geom, trees.estimated_geometric_location)
81 | JOIN region_zoom
82 | ON region_zoom.region_id = region.id
83 | WHERE trees.active = true
84 | AND trees.cluster_regions_assigned = false`
85 | };
86 | const rval = await client.query(select);
87 | if(rval.rows[0].count == 0){
88 | done = true;
89 | }
90 | }
91 |
92 | await client.query('BEGIN');
93 | await client.query('COMMIT');
94 |
95 | await client.query('BEGIN');
96 | const refresh = {
97 | text: `REFRESH MATERIALIZED VIEW CONCURRENTLY active_tree_region`
98 | }
99 | await client.query(refresh);
100 |
101 | await client.query('COMMIT');
102 |
103 |
104 | await client.query('BEGIN');
105 |
106 | sql = `SELECT 'cluster' AS type,
107 | St_centroid(clustered_locations) centroid,
108 | St_numgeometries(clustered_locations) count
109 | FROM
110 | (
111 | SELECT Unnest(St_clusterwithin(estimated_geometric_location, 0.005)) clustered_locations
112 | FROM trees
113 | WHERE active = true
114 | ) clusters`;
115 | query = {
116 | text: sql,
117 | };
118 | console.log(query);
119 |
120 | const {rows} = await client.query(query);
121 | zoomLevel = 14;
122 | await client.query('DELETE FROM clusters WHERE zoom_level = ' + zoomLevel);
123 | for (let row in rows) {
124 | query = {
125 | text: 'INSERT INTO clusters (count, zoom_level, location) values ($1, $2, $3 ) RETURNING *',
126 | values: [rows[row]['count'], zoomLevel, rows[row]['centroid']]
127 | };
128 | await client.query(query);
129 | }
130 | await client.query('COMMIT');
131 | console.log('generated clusters at zoom level ' + zoomLevel);
132 |
133 | client.release();
134 | pool.end();
135 |
136 | const end = Date.now();
137 | console.log( "Start: " + start);
138 | console.log( "End: " + end);
139 | console.log( "Elapsed: " + end - start);
140 | console.log('DONE');
141 |
142 | })().catch( async function(e){
143 | console.error(e.stack);
144 | await client.query('ROLLBACK');
145 | client.release();
146 | pool.end();
147 | }
148 | );
149 |
--------------------------------------------------------------------------------
/src/models/Map.js:
--------------------------------------------------------------------------------
1 | const log = require("loglevel");
2 | const { Pool} = require('pg');
3 | const SQLCase2 = require("./sqls/SQLCase2");
4 | const SQLCase2Timeline = require("./sqls/SQLCase2Timeline");
5 | const SQLCase1 = require("./sqls/SQLCase1");
6 | const SQLCase1Timeline = require("./sqls/SQLCase1Timeline");
7 | const SQLCase3Timeline = require("./sqls/SQLCase3Timeline");
8 | const SQLCase3 = require("./sqls/SQLCase3");
9 | const SQLCase4 = require("./sqls/SQLCase4");
10 | const SQLZoomTargetCase1V2 = require("./sqls/SQLZoomTargetCase1V2");
11 |
12 |
13 | class Map{
14 | constructor(){
15 | this.pool = new Pool({ connectionString: process.env.DATABASE_URL });
16 | }
17 |
18 | async init(settings){
19 | console.debug("init map with settings:", settings);
20 | this.treeid = settings.treeid;
21 | this.tree_name = settings.tree_name;
22 | this.zoomLevel = parseInt(settings.zoom_level);
23 | this.userid = settings.userid;
24 | this.clusterRadius = settings.clusterRadius;
25 | this.mapName = settings.map_name;
26 | this.bounds = settings.bounds;
27 | this.wallet = settings.wallet;
28 | this.flavor = settings.flavor;
29 | this.token = settings.token;
30 | this.treeIds = [];
31 | this.timeline = settings.timeline;
32 | if(this.treeid){
33 | /*
34 | * Single tree map mode
35 | */
36 | this.sql = new SQLCase2();
37 | this.sql.addTreeFilter(this.treeid);
38 | }else if(this.tree_name){
39 | this.sql = new SQLCase2();
40 | this.sql.addTreeNameFilter(this.tree_name);
41 | }else if(this.capture_id){
42 | this.sql = new SQLCase2();
43 | this.sql.addUUIDFilter(this.capture_id);
44 | }else if(this.userid){
45 | /*
46 | * User map mode
47 | */
48 | //count the trees amount first
49 | const result = await this.pool.query({
50 | text: `select count(*) as count from trees where planter_id = ${this.userid}`,
51 | values:[]
52 | });
53 | const treeCount = result.rows[0].count;
54 | parseInt(treeCount);
55 | if(this.zoomLevel > 15){
56 | this.sql = new SQLCase2();
57 | this.sql.setBounds(this.bounds);
58 | this.sql.addFilterByUserId(this.userid);
59 | }else{
60 | if(treeCount > 2000){
61 | this.sql = new SQLCase1();
62 | this.sql.addFilterByUserId(this.userid);
63 | this.sql.setZoomLevel(this.zoomLevel);
64 | this.sql.setBounds(this.bounds);
65 | }else{
66 | this.sql = new SQLCase3();
67 | this.sql.setClusterRadius(this.clusterRadius);
68 | this.sql.addFilterByUserid(this.userid);
69 | this.sql.setBounds(this.bounds);
70 | }
71 | }
72 | if(this.zoomLevel <= 9){
73 | this.sqlZoomTarget = new SQLZoomTargetCase1V2();
74 | this.sqlZoomTarget.setBounds(this.bounds);
75 | this.sqlZoomTarget.setZoomLevel(this.zoomLevel);
76 | }
77 |
78 | }else if(this.wallet){
79 | /*
80 | * wallet map mode
81 | */
82 | const result = await this.pool.query({
83 | text: `
84 | SELECT count(wallet.token.id)
85 | FROM wallet."token"
86 | INNER JOIN wallet.wallet ON wallet.wallet.id = wallet.token.wallet_id
87 | WHERE wallet.wallet.name = '${this.wallet}'
88 | `,
89 | values:[]
90 | });
91 | const treeCount = result.rows[0].count;
92 | parseInt(treeCount);
93 | log.warn("count by wallet %d, get %s", this.wallet, treeCount);
94 | if(this.zoomLevel > 15){
95 | this.sql = new SQLCase2();
96 | this.sql.setBounds(this.bounds);
97 | this.sql.addFilterByWallet(this.wallet);
98 | }else{
99 | if(treeCount > 2000){
100 | this.sql = new SQLCase1();
101 | this.sql.addFilterByWallet(this.wallet);
102 | this.sql.setZoomLevel(this.zoomLevel);
103 | this.sql.setBounds(this.bounds);
104 | }else{
105 | this.sql = new SQLCase3();
106 | this.sql.setClusterRadius(this.clusterRadius);
107 | this.sql.addFilterByWallet(this.wallet);
108 | this.sql.setBounds(this.bounds);
109 | }
110 | }
111 | }else if(this.flavor){
112 | /*
113 | * flavor map mode
114 | */
115 | if(this.zoomLevel > 15){
116 | this.sql = new SQLCase2();
117 | this.sql.setBounds(this.bounds);
118 | this.sql.addFilterByFlavor(this.flavor);
119 | }else{
120 | this.sql = new SQLCase3();
121 | this.sql.setClusterRadius(this.clusterRadius);
122 | this.sql.addFilterByFlavor(this.flavor);
123 | this.sql.setBounds(this.bounds);
124 | }
125 | if(this.zoomLevel <= 9){
126 | this.sqlZoomTarget = new SQLZoomTargetCase1V2();
127 | this.sqlZoomTarget.setBounds(this.bounds);
128 | this.sqlZoomTarget.setZoomLevel(this.zoomLevel);
129 | }
130 |
131 | }else if(this.token){
132 | /*
133 | * Token map mode
134 | */
135 | if(this.zoomLevel > 15){
136 | this.sql = new SQLCase2();
137 | this.sql.setBounds(this.bounds);
138 | this.sql.addFilterByToken(this.token);
139 | }else{
140 | this.sql = new SQLCase3();
141 | this.sql.setClusterRadius(this.clusterRadius);
142 | this.sql.addFilterByToken(this.token);
143 | this.sql.setBounds(this.bounds);
144 | }
145 | if(this.zoomLevel <= 9){
146 | this.sqlZoomTarget = new SQLZoomTargetCase1V2();
147 | this.sqlZoomTarget.setBounds(this.bounds);
148 | this.sqlZoomTarget.setZoomLevel(this.zoomLevel);
149 | }
150 |
151 | }else if(this.mapName){
152 | /*
153 | * org map mode
154 | */
155 | if(this.zoomLevel > 15){
156 | this.sql = new SQLCase2();
157 | this.sql.addFilterByMapName(this.mapName);
158 | this.sql.setBounds(this.bounds);
159 | } else if ([12, 13, 14, 15].includes(this.zoomLevel) && this.mapName != 'freetown') {
160 | this.sql = new SQLCase3();
161 | this.sql.setClusterRadius(this.clusterRadius);
162 | this.sql.addFilterByMapName(this.mapName);
163 | this.sql.setBounds(this.bounds);
164 | }else{
165 | this.sql = new SQLCase1();
166 | this.sql.addMapNameFilter(this.mapName);
167 | this.sql.setBounds(this.bounds);
168 | this.sql.setZoomLevel(this.zoomLevel);
169 | }
170 | if(this.zoomLevel <= 9){
171 | this.sqlZoomTarget = new SQLZoomTargetCase1V2();
172 | this.sqlZoomTarget.setBounds(this.bounds);
173 | this.sqlZoomTarget.setZoomLevel(this.zoomLevel);
174 | this.sqlZoomTarget.addMapNameFilter(this.mapName);
175 | }
176 |
177 | }else if(this.timeline){
178 | if(this.zoomLevel > 15){
179 | this.sql = new SQLCase2Timeline();
180 | this.sql.addTimeline(this.timeline);
181 | this.sql.setBounds(this.bounds);
182 | } else if ([12, 13, 14, 15].includes(this.zoomLevel) ) {
183 | this.sql = new SQLCase3Timeline();
184 | this.sql.setClusterRadius(this.clusterRadius);
185 | this.sql.setBounds(this.bounds);
186 | this.sql.addTimeline(this.timeline);
187 | }else{
188 | this.sql = new SQLCase1Timeline();
189 | this.sql.addTimeline(this.timeline);
190 | this.sql.setBounds(this.bounds);
191 | this.sql.setZoomLevel(this.zoomLevel);
192 | }
193 | }else{
194 | /*
195 | * Normal map mode
196 | */
197 | if(this.zoomLevel > 15){
198 | this.sql = new SQLCase2();
199 | this.sql.setBounds(this.bounds);
200 | } else if ([12, 13, 14, 15].includes(this.zoomLevel)) {
201 | this.sql = new SQLCase4();
202 | this.sql.setBounds(this.bounds)
203 | }else{
204 | this.sql = new SQLCase1();
205 | this.sql.setBounds(this.bounds)
206 | this.sql.setZoomLevel(this.zoomLevel);
207 | }
208 | if(this.zoomLevel <= 9){
209 | this.sqlZoomTarget = new SQLZoomTargetCase1V2();
210 | this.sqlZoomTarget.setBounds(this.bounds);
211 | this.sqlZoomTarget.setZoomLevel(this.zoomLevel);
212 | }
213 | }
214 | return;
215 | }
216 |
217 | async getQuery(){
218 | return this.sql.getQuery();
219 | }
220 |
221 | async getZoomTargetQuery(){
222 | if(this.sqlZoomTarget){
223 | return this.sqlZoomTarget.getQuery();
224 | }else{
225 | return undefined;
226 | }
227 | }
228 |
229 | async getPoints(){
230 | const query = await this.getQuery();
231 | console.log(query);
232 | const beginTime = Date.now();
233 | const data = await this.pool.query(query);
234 | console.log("get points took time:%d ms", Date.now() - beginTime);
235 | log.warn("get point:", data.rows.length);
236 | console.log(data.rows.slice(0,2))
237 | return data.rows;
238 | }
239 |
240 | async getZoomTargets(){
241 | const zoomTargetsQuery = await this.getZoomTargetQuery();
242 | let zoomTargets;
243 | if(zoomTargetsQuery){
244 | const beginTime = Date.now();
245 | const result = await this.pool.query(zoomTargetsQuery);
246 | console.log("get zoom target took time:%d ms", Date.now() - beginTime);
247 | console.log('got zoom targets data');
248 | zoomTargets = result.rows;
249 | }
250 | return zoomTargets;
251 | }
252 |
253 | }
254 |
255 | module.exports = Map;
256 |
--------------------------------------------------------------------------------
/src/models/Map.spec.js:
--------------------------------------------------------------------------------
1 | const Map = require("./Map");
2 |
3 | const {Pool} = require("pg");
4 | jest.mock("pg");
5 |
6 | describe("Map", () => {
7 | let query;
8 |
9 | beforeEach(() => {
10 | query = jest.fn().mockReturnValue(true);
11 | Pool.prototype.query = query;
12 | })
13 |
14 | describe("Query", () => {
15 |
16 | describe("Normal cases", () => {
17 |
18 | it("{clusterRadius=8, zoom_level=2} should call SQL case1 ", async () => {
19 | const map = new Map();
20 | await map.init({
21 | clusterRadius: 8,
22 | zoom_level: 2,
23 | });
24 | let result = await map.getQuery();
25 | expect(result).toMatchObject({
26 | text: expect.stringMatching(/case1/i),
27 | values: [2],
28 | });
29 |
30 | result = await map.getZoomTargetQuery();
31 | expect(result).toMatchObject({
32 | text: expect.stringMatching(/case6/i),
33 | values: [2, 2+2],
34 | });
35 | });
36 |
37 | it("/trees?clusterRadius=0&zoom_level=17&bounds=-7.822425451587485,38.40904457076313,-7.840964880298422,38.40561440621655", async () => {
38 | const map =new Map();
39 | await map.init({
40 | clusterRadius: 0,
41 | zoom_level: 17,
42 | bounds: "37.93124715513169,-3.2148087439778705,36.74472371763169,-3.494479867143523",
43 | });
44 | let result = await map.getQuery();
45 | expect(result).toMatchObject({
46 | text: expect.stringMatching(/case2.*estimated_geometric_location && ST_MakeEnvelope/is),
47 | values: [],
48 | });
49 |
50 | result = await map.getZoomTargetQuery();
51 | expect(result).toBeUndefined();
52 | });
53 |
54 | it("/trees?clusterRadius=0.005&zoom_level=14&bounds=-13.100891610856054,8.430363406583758,-13.249207040543554,8.395721322779956", async () => {
55 | const queryCount = jest.fn()
56 | .mockResolvedValue({
57 | rows: [{count:1999}],
58 | });
59 | query.mockImplementationOnce(queryCount);
60 | const map =new Map();
61 | await map.init({
62 | clusterRadius: 0.005,
63 | zoom_level: 14,
64 | bounds: "37.93124715513169,-3.2148087439778705,36.74472371763169,-3.494479867143523",
65 | });
66 | let result = await map.getQuery();
67 | expect(result).toMatchObject({
68 | text: expect.stringMatching(/case4.*location && ST_MakeEnvelope/is),
69 | values: [],
70 | });
71 |
72 | result = await map.getZoomTargetQuery();
73 | expect(result).toBeUndefined();
74 | });
75 |
76 | });
77 |
78 | describe("User map cases", () => {
79 |
80 | it("with userid, and trees count under this user < 2000", async () => {
81 | const queryCount = jest.fn()
82 | .mockResolvedValue({
83 | rows: [{count:1999}],
84 | });
85 | query.mockImplementationOnce(queryCount);
86 | const map =new Map();
87 | await map.init({
88 | clusterRadius: 0.05,
89 | zoom_level: 9,
90 | userid:1,
91 | });
92 | let result = await map.getQuery();
93 | expect(queryCount).toBeCalledWith({
94 | text: expect.stringMatching(/count/i),
95 | values: []
96 | });
97 | expect(result).toMatchObject({
98 | //case 3
99 | text: expect.stringMatching(/case3.*AND trees.planter_id =/is),
100 | values: [0.05],
101 | });
102 |
103 | result = await map.getZoomTargetQuery();
104 | expect(result).toMatchObject({
105 | text: expect.stringMatching(/case6/i),
106 | values: [9, 9+2],
107 | });
108 | });
109 |
110 | it("with userid, and trees count under this user > 2000", async () => {
111 | const queryCount = jest.fn()
112 | .mockResolvedValue({
113 | rows: [{count:2001}],
114 | });
115 | query.mockImplementationOnce(queryCount);
116 | const map =new Map();
117 | await map.init({
118 | clusterRadius: 0.05,
119 | zoom_level: 9,
120 | userid: 12
121 | });
122 | let result = await map.getQuery();
123 | expect(queryCount).toBeCalledWith({
124 | text: expect.stringMatching(/count/i),
125 | values: []
126 | });
127 | expect(result).toMatchObject({
128 | //should call the new query with `join` to the tree,
129 | text: expect.stringMatching(/case1.*join trees on.*and planter_id =/is),
130 | values: [9],
131 | });
132 |
133 | result = await map.getZoomTargetQuery();
134 | expect(result).toMatchObject({
135 | text: expect.stringMatching(/case6/is),
136 | values: [9, 9+2],
137 | });
138 | });
139 |
140 | it("{userid:1, clusterRadius:0.095, zoom_level:9}, SQL should be case 3", async () => {
141 | const queryCount = jest.fn()
142 | .mockResolvedValue({
143 | rows: [{count:1999}],
144 | });
145 | query.mockImplementationOnce(queryCount);
146 | const map =new Map();
147 | await map.init({
148 | clusterRadius: 0.095,
149 | zoom_level: 9,
150 | userid: 1,
151 | });
152 | let result = await map.getQuery();
153 | expect(result).toMatchObject({
154 | //should call case3 with planter filter
155 | text: expect.stringMatching(/case3.*AND trees.planter_id =/is),
156 | values: expect.anything(),
157 | });
158 |
159 | result = await map.getZoomTargetQuery();
160 | expect(result).toMatchObject({
161 | text: expect.stringMatching(/case6/is),
162 | values: [9, 9 + 2],
163 | });
164 | });
165 |
166 | it("/trees?clusterRadius=0.03&zoom_level=11&bounds=37.93124715513169,-3.2148087439778705,36.74472371763169,-3.494479867143523&userid=1", async () => {
167 | const queryCount = jest.fn()
168 | .mockResolvedValue({
169 | rows: [{count:1999}],
170 | });
171 | query.mockImplementationOnce(queryCount);
172 | const map =new Map();
173 | await map.init({
174 | clusterRadius: 0.03,
175 | zoom_level: 11,
176 | bounds: "37.93124715513169,-3.2148087439778705,36.74472371763169,-3.494479867143523",
177 | userid: 1,
178 | });
179 | let result = await map.getQuery();
180 | expect(result).toMatchObject({
181 | //should call case3 with planter filter and bounds filter
182 | text: expect.stringMatching(/case3.*estimated_geometric_location && ST_MakeEnvelope.*AND trees.planter_id =/is),
183 | values: [0.03],
184 | });
185 |
186 | result = await map.getZoomTargetQuery();
187 | expect(result).toBeUndefined();
188 | });
189 |
190 | it("/trees?clusterRadius=0&zoom_level=17&bounds=37.30692471435548,-3.3515417307543633,37.288385285644544,-3.3559115991882575&userid=1", async () => {
191 | const queryCount = jest.fn()
192 | .mockResolvedValue({
193 | rows: [{count:1999}],
194 | });
195 | query.mockImplementationOnce(queryCount);
196 | const map =new Map();
197 | await map.init({
198 | clusterRadius: 0,
199 | zoom_level: 17,
200 | bounds: "37.93124715513169,-3.2148087439778705,36.74472371763169,-3.494479867143523",
201 | userid: 1,
202 | });
203 | let result = await map.getQuery();
204 | expect(result).toMatchObject({
205 | //should call case2 with planter filter and bounds filter
206 | text: expect.stringMatching(/case2.*estimated_geometric_location && ST_MakeEnvelope.*AND trees.planter_id =/is),
207 | values: [],
208 | });
209 |
210 | result = await map.getZoomTargetQuery();
211 | expect(result).toBeUndefined();
212 | });
213 | });
214 |
215 | describe("Single tree cases", () => {
216 |
217 | it("{treeid:1, clusterRadius:0.05, zoom_level:10}, SQL should be case 2", async () => {
218 | const map =new Map();
219 | await map.init({
220 | clusterRadius: 0.05,
221 | zoom_level: 10,
222 | treeid: 12
223 | });
224 | let result = await map.getQuery();
225 | expect(result).toMatchObject({
226 | //should call the new query with `join` to the tree,
227 | text: expect.stringMatching(/case2.*AND trees.id =/is),
228 | values: [],
229 | });
230 | result = await map.getZoomTargetQuery();
231 | expect(result).toBeUndefined();
232 | });
233 | });
234 |
235 | describe("Wallet map cases", () => {
236 |
237 | it("{wallet:'fortest', clusterRadius:0.05, zoom_level:10}, SQL should be case 3", async () => {
238 | const map =new Map();
239 | await map.init({
240 | clusterRadius: 0.05,
241 | zoom_level: 10,
242 | wallet: "fortest",
243 | });
244 | let result = await map.getQuery();
245 | expect(result).toMatchObject({
246 | //should call the new query with `join` to the tree,
247 | text: expect.stringMatching(/case3.*AND entity.wallet =/is),
248 | values: [0.05],
249 | });
250 |
251 | result = await map.getZoomTargetQuery();
252 | expect(result).toBeUndefined();
253 | });
254 |
255 | it("{wallet:'fortest', clusterRadius:0.003, zoom_level:17}, SQL should be case 3", async () => {
256 | const map =new Map();
257 | await map.init({
258 | clusterRadius: 0.05,
259 | zoom_level: 16,
260 | wallet: "fortest",
261 | });
262 | let result = await map.getQuery();
263 | expect(result).toMatchObject({
264 | text: expect.stringMatching(/case2.*AND entity.wallet =/is),
265 | values: [],
266 | });
267 |
268 | result = await map.getZoomTargetQuery();
269 | expect(result).toBeUndefined();
270 | });
271 | });
272 |
273 | describe("Token map cases", () => {
274 |
275 | it("{token:'fortest', clusterRadius:0.05, zoom_level:10}, SQL should be case 3", async () => {
276 | const map =new Map();
277 | await map.init({
278 | clusterRadius: 0.05,
279 | zoom_level: 10,
280 | token: "fortest",
281 | });
282 | let result = await map.getQuery();
283 | expect(result).toMatchObject({
284 | //should call the new query with `join` to the tree,
285 | text: expect.stringMatching(/case3.*INNER JOIN certificates/is),
286 | values: [0.05],
287 | });
288 |
289 | result = await map.getZoomTargetQuery();
290 | expect(result).toBeUndefined();
291 | });
292 |
293 | it("{token:'fortest', clusterRadius:0.003, zoom_level:17}, SQL should be case 3", async () => {
294 | const map =new Map();
295 | await map.init({
296 | clusterRadius: 0.05,
297 | zoom_level: 16,
298 | token: "fortest",
299 | });
300 | let result = await map.getQuery();
301 | expect(result).toMatchObject({
302 | text: expect.stringMatching(/case2.*INNER JOIN certificates/is),
303 | values: [],
304 | });
305 |
306 | result = await map.getZoomTargetQuery();
307 | expect(result).toBeUndefined();
308 | });
309 | });
310 |
311 | describe("Flavor map cases", () => {
312 |
313 | it("{flavor:'fortest', clusterRadius:0.05, zoom_level:10}, SQL should be case 3", async () => {
314 | const map =new Map();
315 | await map.init({
316 | clusterRadius: 0.05,
317 | zoom_level: 10,
318 | flavor: "fortest",
319 | });
320 | let result = await map.getQuery();
321 | expect(result).toMatchObject({
322 | //should call the new query with `join` to the tree,
323 | text: expect.stringMatching(/case3.*inner join tree_attributes.*and tree_attributes.key =/is),
324 | values: [0.05],
325 | });
326 |
327 | result = await map.getZoomTargetQuery();
328 | expect(result).toBeUndefined();
329 | });
330 |
331 | it("{flavor:'fortest', clusterRadius:0.003, zoom_level:17}, SQL should be case 3", async () => {
332 | const map =new Map();
333 | await map.init({
334 | clusterRadius: 0.05,
335 | zoom_level: 16,
336 | flavor: "fortest",
337 | });
338 | let result = await map.getQuery();
339 | expect(result).toMatchObject({
340 | text: expect.stringMatching(/case2.*inner join tree_attributes.*and tree_attributes.key =/is),
341 | values: [],
342 | });
343 |
344 | result = await map.getZoomTargetQuery();
345 | expect(result).toBeUndefined();
346 | });
347 | });
348 |
349 | describe("Org map cases", () => {
350 |
351 | it("mapName case0: /trees?clusterRadius=0.05&zoom_level=3&map_name=freetown", async () => {
352 | const queryOrg = jest.fn()
353 | .mockResolvedValue({
354 | rows: [{id:1}],
355 | });
356 | query.mockImplementationOnce(queryOrg);
357 | const map =new Map();
358 | await map.init({
359 | clusterRadius: 0.05,
360 | zoom_level: 3,
361 | map_name: "freetown",
362 | });
363 | let result = await map.getQuery();
364 | expect(result).toMatchObject({
365 | text: expect.stringMatching(/case1.*tree_region.tree_id in.*map_name =/is),
366 | values: [3],
367 | });
368 |
369 | result = await map.getZoomTargetQuery();
370 | expect(result).toMatchObject({
371 | text: expect.stringMatching(/case6.*tree_region.tree_id in.*map_name =/is),
372 | values: [3, 3+2],
373 | });
374 | });
375 |
376 | it("mapName case1: /trees?clusterRadius=0.05&zoom_level=10&map_name=freetown", async () => {
377 | const queryOrg = jest.fn()
378 | .mockResolvedValue({
379 | rows: [{id:1}],
380 | });
381 | query.mockImplementationOnce(queryOrg);
382 | const map =new Map();
383 | await map.init({
384 | clusterRadius: 0.05,
385 | zoom_level: 10,
386 | map_name: "freetown",
387 | });
388 | let result = await map.getQuery();
389 | expect(result).toMatchObject({
390 | text: expect.stringMatching(/case1.*tree_region.tree_id in.*map_name =/is),
391 | values: [10],
392 | });
393 |
394 | result = await map.getZoomTargetQuery();
395 | expect(result).toBeUndefined();
396 | });
397 |
398 | it("mapName case2: /trees?clusterRadius=0.005&zoom_level=14&bounds=-13.093788230138243,8.435735998833929,-13.242103659825743,8.401094395636814&map_name=freetown", async () => {
399 | const queryOrg = jest.fn()
400 | .mockResolvedValue({
401 | rows: [{id:1}],
402 | });
403 | query.mockImplementationOnce(queryOrg);
404 | const map =new Map();
405 | await map.init({
406 | clusterRadius: 0.005,
407 | zoom_level: 14,
408 | map_name: "freetown",
409 | bounds: "-13.093788230138243,8.435735998833929,-13.242103659825743,8.401094395636814",
410 | });
411 | let result = await map.getQuery();
412 | expect(result).toMatchObject({
413 | text: expect.stringMatching(/case1.*tree_region.tree_id in.*map_name =/is),
414 | values: [14],
415 | });
416 |
417 | result = await map.getZoomTargetQuery();
418 | expect(result).toBeUndefined();
419 | });
420 |
421 | it("mapName case3: /trees?clusterRadius=0.003&zoom_level=16&bounds=-13.149406516271055,8.422745649932644,-13.18648537369293,8.414085249049373&map_name=freetown", async () => {
422 | const queryOrg = jest.fn()
423 | .mockResolvedValue({
424 | rows: [{id:1}],
425 | });
426 | query.mockImplementationOnce(queryOrg);
427 | const map =new Map();
428 | await map.init({
429 | clusterRadius: 0.003,
430 | zoom_level: 16,
431 | map_name: "freetown",
432 | bounds: "-13.093788230138243,8.435735998833929,-13.242103659825743,8.401094395636814",
433 | });
434 | let result = await map.getQuery();
435 | expect(result).toMatchObject({
436 | text: expect.stringMatching(/case2.*location && ST_MakeEnvelope.*trees.id in.*map_name =/is),
437 | values: [],
438 | });
439 |
440 | result = await map.getZoomTargetQuery();
441 | expect(result).toBeUndefined();
442 | });
443 |
444 | });
445 |
446 | });
447 |
448 | });
449 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # [1.17.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.16.1...v1.17.0) (2022-11-09)
2 |
3 |
4 | ### Features
5 |
6 | * planting_org ([929561f](https://github.com/Greenstand/treetracker-web-map/commit/929561feb28fc4b317c5b5f2e5427ff86bbe0ac3))
7 |
8 | ## [1.16.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.16.0...v1.16.1) (2022-02-28)
9 |
10 |
11 | ### Bug Fixes
12 |
13 | * get tree by token ([dbf0319](https://github.com/Greenstand/treetracker-web-map/commit/dbf0319a36f2f0e5ed7c015f3817a76d3734d50f))
14 | * release node from 12 -> 14 ([2bcb88e](https://github.com/Greenstand/treetracker-web-map/commit/2bcb88e77c6f3bcb4897161e736bac2222fa8f1b))
15 | * remove extra line ([862a4b5](https://github.com/Greenstand/treetracker-web-map/commit/862a4b59994e5ebe7d26c13de1fad0269208f837))
16 | * remove useless code ([88c4ef0](https://github.com/Greenstand/treetracker-web-map/commit/88c4ef00471ef901f2b0488a37ef2e57007ad40c))
17 |
18 | # [1.16.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.15.1...v1.16.0) (2021-08-14)
19 |
20 |
21 | ### Features
22 |
23 | * wallet switch to case1 when big ([2c54bb2](https://github.com/Greenstand/treetracker-web-map/commit/2c54bb2a64176229fae19182ca05cccff9dd40f0))
24 |
25 | ## [1.15.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.15.0...v1.15.1) (2021-08-05)
26 |
27 |
28 | ### Bug Fixes
29 |
30 | * use delete to remove key ([94ad2d8](https://github.com/Greenstand/treetracker-web-map/commit/94ad2d8eed2d974a4955fd8feea94c22464af464))
31 |
32 | # [1.15.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.14.2...v1.15.0) (2021-08-05)
33 |
34 |
35 | ### Features
36 |
37 | * remove planter identifer from tree detail object ([af0949b](https://github.com/Greenstand/treetracker-web-map/commit/af0949bf1301f39cd252b0523ec972b948bed225))
38 |
39 | ## [1.14.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.14.1...v1.14.2) (2021-06-11)
40 |
41 |
42 | ### Bug Fixes
43 |
44 | * return undefine rather than throw error when didnt' find tree ([002008d](https://github.com/Greenstand/treetracker-web-map/commit/002008dad0fc1c2e183ce4044695de8c4dcd08dd))
45 |
46 | ## [1.14.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.14.0...v1.14.1) (2021-06-10)
47 |
48 |
49 | ### Bug Fixes
50 |
51 | * small bug on printing log ([8bb6035](https://github.com/Greenstand/treetracker-web-map/commit/8bb60358b557786f2e89482f53e04a683f3b7963))
52 |
53 | # [1.14.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.13.1...v1.14.0) (2021-06-10)
54 |
55 |
56 | ### Features
57 |
58 | * support api: /tree?tree_name=xxx ([ee16e63](https://github.com/Greenstand/treetracker-web-map/commit/ee16e63eb9fa8a2618b7fc989d0d2fa0db3f3f4b))
59 |
60 | ## [1.13.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.13.0...v1.13.1) (2021-05-22)
61 |
62 |
63 | ### Bug Fixes
64 |
65 | * remove old workflow ([839dc53](https://github.com/Greenstand/treetracker-web-map/commit/839dc5397d07bceeea05d1626a5c259ecdc118d8))
66 |
67 | # [1.13.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.12.0...v1.13.0) (2021-05-22)
68 |
69 |
70 | ### Features
71 |
72 | * add note about docker image name change ([39f979b](https://github.com/Greenstand/treetracker-web-map/commit/39f979b43ce97268ae842a15baee2a69e2702407))
73 |
74 | # [1.12.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.9...v1.12.0) (2021-05-19)
75 |
76 |
77 | ### Features
78 |
79 | * implement tree_name feature ([c1b2330](https://github.com/Greenstand/treetracker-web-map/commit/c1b2330f2a0d682589eec01d96b9eadbd918a7a1))
80 |
81 | ## [1.11.9](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.8...v1.11.9) (2021-05-04)
82 |
83 |
84 | ### Bug Fixes
85 |
86 | * workflow had extra steps in wrong order ([ff23c6c](https://github.com/Greenstand/treetracker-web-map/commit/ff23c6c2b917f017bed80f514f744253a6de8b7d))
87 |
88 | ## [1.11.8](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.7...v1.11.8) (2021-05-04)
89 |
90 |
91 | ### Bug Fixes
92 |
93 | * add eslint config ([975788b](https://github.com/Greenstand/treetracker-web-map/commit/975788b4d8857da9102c437773f632f7245c5dae))
94 | * bring package-lock.json up to date ([ea39392](https://github.com/Greenstand/treetracker-web-map/commit/ea39392a2f2f1bcf64c3883a8fac0e6da8a9f171))
95 | * skip tests ([293af67](https://github.com/Greenstand/treetracker-web-map/commit/293af67d7ec041686d86566dac380a72014d57a5))
96 |
97 | ## [1.11.7](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.6...v1.11.7) (2021-04-12)
98 |
99 |
100 | ### Bug Fixes
101 |
102 | * temporarily open CORS ([55dc487](https://github.com/Greenstand/treetracker-web-map/commit/55dc4874c6192eef40d656165a04caa6ba652eaf))
103 |
104 | ## [1.11.6](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.5...v1.11.6) (2021-04-12)
105 |
106 |
107 | ### Bug Fixes
108 |
109 | * open CORS temporarily ([6e64b2e](https://github.com/Greenstand/treetracker-web-map/commit/6e64b2e46e34004010c004297fc039e47e08a5b1))
110 |
111 | ## [1.11.5](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.4...v1.11.5) (2021-04-02)
112 |
113 |
114 | ### Bug Fixes
115 |
116 | * fix manual deployment actions ([39faa73](https://github.com/Greenstand/treetracker-web-map/commit/39faa7379c13056cfe54bc81db7fedd6ff8fc329))
117 |
118 | ## [1.11.4](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.3...v1.11.4) (2021-04-02)
119 |
120 |
121 | ### Bug Fixes
122 |
123 | * fix repository name match ([62d7458](https://github.com/Greenstand/treetracker-web-map/commit/62d745809f358a7455cae6e3c2a63b8eb630abce))
124 |
125 | ## [1.11.3](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.2...v1.11.3) (2021-04-02)
126 |
127 |
128 | ### Bug Fixes
129 |
130 | * update and clean up CORS settings ([7d15297](https://github.com/Greenstand/treetracker-web-map/commit/7d152979b4c569966ba91dc62107d5ec53756cfd))
131 |
132 | ## [1.11.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.1...v1.11.2) (2021-04-02)
133 |
134 |
135 | ### Bug Fixes
136 |
137 | * increase LRU cache time ([e052d45](https://github.com/Greenstand/treetracker-web-map/commit/e052d45e2b18a10bb48c08c2e815b6576b844eb2))
138 |
139 | ## [1.11.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.11.0...v1.11.1) (2021-03-20)
140 |
141 |
142 | ### Bug Fixes
143 |
144 | * Update README for local development ([4fdd281](https://github.com/Greenstand/treetracker-web-map/commit/4fdd281fd447dfbe755148eafa76ec9e23ca9b58))
145 | * Update README for local development ([090714a](https://github.com/Greenstand/treetracker-web-map/commit/090714a2bf777b5ab21902b3a3fb7fc4644e47fe))
146 |
147 | # [1.11.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.10.0...v1.11.0) (2021-03-20)
148 |
149 |
150 | ### Features
151 |
152 | * can show nearest tree on tree point levels ([284f5ae](https://github.com/Greenstand/treetracker-web-map/commit/284f5aec805574bbf8a191ba6150644868aa5288))
153 | * fn to scan the utf grid ([2a2bf3f](https://github.com/Greenstand/treetracker-web-map/commit/2a2bf3f7bc233a98b364ad8e0cf34f73108d33b5))
154 |
155 | # [1.10.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.9.3...v1.10.0) (2021-03-18)
156 |
157 |
158 | ### Features
159 |
160 | * close tile servver in case of wallet ([bc8ceb8](https://github.com/Greenstand/treetracker-web-map/commit/bc8ceb8cb32bfbe54ecf3f80bf8e5bd96da0b6d5))
161 | * switcher ([031847f](https://github.com/Greenstand/treetracker-web-map/commit/031847fab2fb1aa62972bdfd8426b388d30aba46))
162 |
163 | ## [1.9.3](https://github.com/Greenstand/treetracker-web-map/compare/v1.9.2...v1.9.3) (2021-03-18)
164 |
165 |
166 | ### Bug Fixes
167 |
168 | * allow tiles to show to max zoom ([83be984](https://github.com/Greenstand/treetracker-web-map/commit/83be984d22fb0aeaa8d4a380f7305cc2b167049e))
169 |
170 | ## [1.9.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.9.1...v1.9.2) (2021-03-18)
171 |
172 |
173 | ### Bug Fixes
174 |
175 | * allow tiles to show to max zoom ([3fe099f](https://github.com/Greenstand/treetracker-web-map/commit/3fe099f2da2f3ba98f9385e16386774d3ff97e4f))
176 |
177 | ## [1.9.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.9.0...v1.9.1) (2021-03-18)
178 |
179 |
180 | ### Bug Fixes
181 |
182 | * remove extra slash ([387e316](https://github.com/Greenstand/treetracker-web-map/commit/387e316303e8be869d1033e9ff1e9f82dcc72eb2))
183 |
184 | # [1.9.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.7...v1.9.0) (2021-03-18)
185 |
186 |
187 | ### Bug Fixes
188 |
189 | * add default tile server for dev ([67b68f7](https://github.com/Greenstand/treetracker-web-map/commit/67b68f78cdb057568b4dbc152adb54836da4eef6))
190 | * bug in zoom in to 'userid' map ([01c861c](https://github.com/Greenstand/treetracker-web-map/commit/01c861cff0b3eca3e8299654919c975dc104c1e3))
191 | * next tree button ([b0080a5](https://github.com/Greenstand/treetracker-web-map/commit/b0080a5e04090804f22767e3833e3f974b21887e))
192 | * shouldn't show points on zoom level 15 ([af3e7fc](https://github.com/Greenstand/treetracker-web-map/commit/af3e7fc2daca84698d2a93fc684bebb8d1ef30d6))
193 | * style problem on markers; hybrid map with google map ([bf0109b](https://github.com/Greenstand/treetracker-web-map/commit/bf0109be98eccd7ed2d8972ee30726e2f7d299bf))
194 |
195 |
196 | ### Features
197 |
198 | * add setting for tile server ([94c4c03](https://github.com/Greenstand/treetracker-web-map/commit/94c4c03d7902047492a18b75d90eb0255de8eac3))
199 | * after correcting all compilation error, map can show now ([4ebf780](https://github.com/Greenstand/treetracker-web-map/commit/4ebf780049b67f135d5a90e4e9342c92e3a1b393))
200 | * can click tile point to display panel ([24c736d](https://github.com/Greenstand/treetracker-web-map/commit/24c736d6ec711156a9bd3fd4125d1bac8509572c))
201 | * can display nearest arrow ([73893bc](https://github.com/Greenstand/treetracker-web-map/commit/73893bc170db10189dcafd657ea47d243c1f50de))
202 | * can display tree panel ([1a02190](https://github.com/Greenstand/treetracker-web-map/commit/1a021900237d52669ac167991fea0f685d30de12))
203 | * can display tree point ([23e8372](https://github.com/Greenstand/treetracker-web-map/commit/23e837273a20e9b588279ee98657187d818a8b6a))
204 | * can highlight the tree icon ([39df7dc](https://github.com/Greenstand/treetracker-web-map/commit/39df7dc6e88aa25829e9f197139407e4fc212cd1))
205 | * can show first screen correctly ([561ead6](https://github.com/Greenstand/treetracker-web-map/commit/561ead658b0f7b28086f2abbe0b08518125438aa))
206 | * can show side panel correctly ([3668d26](https://github.com/Greenstand/treetracker-web-map/commit/3668d261f48909e35656d237b44ee868d1c328ca))
207 | * can zoom in to furser zoom level ([0286879](https://github.com/Greenstand/treetracker-web-map/commit/02868795ba1ff8ae33d8b1fc78b2b0425da8ff11))
208 | * google satalite map ([5a9452a](https://github.com/Greenstand/treetracker-web-map/commit/5a9452ad5f242080ddd3ab63afe7b96434b20990))
209 | * improve marker css ([2bcbeb7](https://github.com/Greenstand/treetracker-web-map/commit/2bcbeb785939add508844712ceb000b2067b7918))
210 | * install grid leaf plugin; can display tile on the map ([cea527c](https://github.com/Greenstand/treetracker-web-map/commit/cea527ce2a1adf243ba31ffb32dab5e502ad84fa))
211 |
212 | ## [1.8.7](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.6...v1.8.7) (2021-03-13)
213 |
214 |
215 | ### Bug Fixes
216 |
217 | * keep fixing up workflow ([14de483](https://github.com/Greenstand/treetracker-web-map/commit/14de48398e9193ad047dc2be51d4c6f27b8df19a))
218 |
219 | ## [1.8.6](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.5...v1.8.6) (2021-03-13)
220 |
221 |
222 | ### Bug Fixes
223 |
224 | * must be sequence node ([e15240c](https://github.com/Greenstand/treetracker-web-map/commit/e15240c336aef4332db31d8ddc19eed07a40eb6b))
225 |
226 | ## [1.8.5](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.4...v1.8.5) (2021-03-13)
227 |
228 |
229 | ### Bug Fixes
230 |
231 | * filename extension ([fc808c1](https://github.com/Greenstand/treetracker-web-map/commit/fc808c1dd17b4d750554bd23cd7e10cacfd0864b))
232 |
233 | ## [1.8.4](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.3...v1.8.4) (2021-03-13)
234 |
235 |
236 | ### Bug Fixes
237 |
238 | * correct file name ([57a4654](https://github.com/Greenstand/treetracker-web-map/commit/57a4654c04fe284f6244a0e00b259b38a6fe5601))
239 |
240 | ## [1.8.3](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.2...v1.8.3) (2021-03-13)
241 |
242 |
243 | ### Bug Fixes
244 |
245 | * overlays not overlay ([98e6a92](https://github.com/Greenstand/treetracker-web-map/commit/98e6a9276b6526b1049db7365be13a4295e47abb))
246 |
247 | ## [1.8.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.1...v1.8.2) (2021-03-13)
248 |
249 |
250 | ### Bug Fixes
251 |
252 | * fix path ([67b2697](https://github.com/Greenstand/treetracker-web-map/commit/67b26974796d99a16172463ae46b087b0704e4e0))
253 |
254 | ## [1.8.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.8.0...v1.8.1) (2021-03-13)
255 |
256 |
257 | ### Bug Fixes
258 |
259 | * fix path to deployment yaml ([715a9b1](https://github.com/Greenstand/treetracker-web-map/commit/715a9b1042a838656735e4fe98e36515537d9118))
260 |
261 | # [1.8.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.7.0...v1.8.0) (2021-03-13)
262 |
263 |
264 | ### Features
265 |
266 | * update deployment to use overlays ([f47af84](https://github.com/Greenstand/treetracker-web-map/commit/f47af849da5ea8dab2c29e4bb899feea32302ac1))
267 |
268 | # [1.7.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.19...v1.7.0) (2021-03-10)
269 |
270 |
271 | ### Features
272 |
273 | * add the district delinations for freetown ([1c6781b](https://github.com/Greenstand/treetracker-web-map/commit/1c6781b801e2d797f2dd6a43d4ecc39d2a1ca83c))
274 |
275 | ## [1.6.19](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.18...v1.6.19) (2021-03-10)
276 |
277 |
278 | ### Bug Fixes
279 |
280 | * temporary fix to allow local development ([d5954ac](https://github.com/Greenstand/treetracker-web-map/commit/d5954acd45834f407532a06b8f79fe5bd13646d5))
281 |
282 | ## [1.6.18](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.17...v1.6.18) (2021-03-10)
283 |
284 |
285 | ### Bug Fixes
286 |
287 | * do not treat map.treetracker.org as a map name ([1ae18b9](https://github.com/Greenstand/treetracker-web-map/commit/1ae18b948e188a633be911df54381f8ea1eab269))
288 |
289 | ## [1.6.17](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.16...v1.6.17) (2021-03-10)
290 |
291 |
292 | ### Bug Fixes
293 |
294 | * update CORS for map.treetracker.org ([47bb232](https://github.com/Greenstand/treetracker-web-map/commit/47bb232c900442acd950629e06ec9a24cd4e1502))
295 |
296 | ## [1.6.16](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.15...v1.6.16) (2021-03-09)
297 |
298 |
299 | ### Bug Fixes
300 |
301 | * increase LRU TTL to 10 minutes to improve map performance ([49cc467](https://github.com/Greenstand/treetracker-web-map/commit/49cc467aaca80f000b828b803d384b398679c17b))
302 |
303 | ## [1.6.15](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.14...v1.6.15) (2021-03-05)
304 |
305 |
306 | ### Bug Fixes
307 |
308 | * include other active domains in mapping ([d9fd8e5](https://github.com/Greenstand/treetracker-web-map/commit/d9fd8e5ac7650c01881d3022a13776d2b6959670))
309 |
310 | ## [1.6.14](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.13...v1.6.14) (2021-03-05)
311 |
312 |
313 | ### Bug Fixes
314 |
315 | * some updates to support query tree by uuid ([797dfd2](https://github.com/Greenstand/treetracker-web-map/commit/797dfd2470bbc9c527c2bdc989a266158a1f1af0))
316 |
317 | ## [1.6.13](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.12...v1.6.13) (2021-03-05)
318 |
319 |
320 | ### Bug Fixes
321 |
322 | * disable request timeout ([f404d96](https://github.com/Greenstand/treetracker-web-map/commit/f404d9686ccc91077a4f6823beb0d2a9e9f9e724))
323 |
324 | ## [1.6.12](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.11...v1.6.12) (2021-03-05)
325 |
326 |
327 | ### Bug Fixes
328 |
329 | * keep fixing SQL ([5c2aac1](https://github.com/Greenstand/treetracker-web-map/commit/5c2aac1e1f101991594e49a6f846609a926b2130))
330 |
331 | ## [1.6.11](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.10...v1.6.11) (2021-03-05)
332 |
333 |
334 | ### Bug Fixes
335 |
336 | * fix sql queries ([cfb01cc](https://github.com/Greenstand/treetracker-web-map/commit/cfb01cc5784697fd2002d883fcc36089b93e1388))
337 |
338 | ## [1.6.10](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.9...v1.6.10) (2021-03-04)
339 |
340 |
341 | ### Bug Fixes
342 |
343 | * fix query ([28cb215](https://github.com/Greenstand/treetracker-web-map/commit/28cb2152be64a7d32caa975a8823a6cf92b72252))
344 | * trigger release after failed workflow ([525370b](https://github.com/Greenstand/treetracker-web-map/commit/525370b756de534dab1f2b9b8e46f2d862b6b05f))
345 |
346 | ## [1.6.10](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.9...v1.6.10) (2021-03-04)
347 |
348 |
349 | ### Bug Fixes
350 |
351 | * fix query ([28cb215](https://github.com/Greenstand/treetracker-web-map/commit/28cb2152be64a7d32caa975a8823a6cf92b72252))
352 |
353 | ## [1.6.9](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.8...v1.6.9) (2021-03-04)
354 |
355 |
356 | ### Bug Fixes
357 |
358 | * join individual tree data against wallet schema ([024a304](https://github.com/Greenstand/treetracker-web-map/commit/024a304aa6c6f2c601d0aaf1ff86b11127d633c1))
359 |
360 | ## [1.6.8](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.7...v1.6.8) (2021-03-04)
361 |
362 |
363 | ### Bug Fixes
364 |
365 | * use cast ([ce497f3](https://github.com/Greenstand/treetracker-web-map/commit/ce497f3174a85595604bfc44cf923a2721a9777e))
366 |
367 | ## [1.6.7](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.6...v1.6.7) (2021-03-04)
368 |
369 |
370 | ### Bug Fixes
371 |
372 | * compare uuid in trees table using string ([77074df](https://github.com/Greenstand/treetracker-web-map/commit/77074dfaf79492059733410dd8ab2ab94c276792))
373 |
374 | ## [1.6.6](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.5...v1.6.6) (2021-03-04)
375 |
376 |
377 | ### Bug Fixes
378 |
379 | * use uuid for capture id when matching captures in wallet for map ([902cb1b](https://github.com/Greenstand/treetracker-web-map/commit/902cb1b9fed967976d355fc62198de1d4b3db62f))
380 |
381 | ## [1.6.5](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.4...v1.6.5) (2021-03-04)
382 |
383 |
384 | ### Bug Fixes
385 |
386 | * use singular for schema name ([73d4da8](https://github.com/Greenstand/treetracker-web-map/commit/73d4da8d7c1510d480dd77d99fed4a36f2a3c6e6))
387 |
388 | ## [1.6.4](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.3...v1.6.4) (2021-03-04)
389 |
390 |
391 | ### Bug Fixes
392 |
393 | * trigger deploy ([184f3aa](https://github.com/Greenstand/treetracker-web-map/commit/184f3aa201add738772326d20244c4ee68ccfca8))
394 |
395 | ## [1.6.3](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.2...v1.6.3) (2021-03-04)
396 |
397 |
398 | ### Bug Fixes
399 |
400 | * use the manual dbconnection secret for now ([1db1d5d](https://github.com/Greenstand/treetracker-web-map/commit/1db1d5ded3b985495826bd54d226901c9fe2752b))
401 |
402 | ## [1.6.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.1...v1.6.2) (2021-03-04)
403 |
404 |
405 | ### Bug Fixes
406 |
407 | * package.json wont have correct version until split of repos ([65d47c4](https://github.com/Greenstand/treetracker-web-map/commit/65d47c4029903b07ef06e06e2a250bae1aaeded1))
408 |
409 | ## [1.6.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.6.0...v1.6.1) (2021-03-04)
410 |
411 |
412 | ### Bug Fixes
413 |
414 | * get package version from root ([876b169](https://github.com/Greenstand/treetracker-web-map/commit/876b169f44ab4d76c2649960b08fe333a87ab5d2))
415 |
416 | # [1.6.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.6...v1.6.0) (2021-03-04)
417 |
418 |
419 | ### Features
420 |
421 | * print package version ([bcbbf67](https://github.com/Greenstand/treetracker-web-map/commit/bcbbf676d9ce615748e2f9ef7d6d426bb16eba95))
422 |
423 | ## [1.5.6](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.5...v1.5.6) (2021-03-04)
424 |
425 |
426 | ### Bug Fixes
427 |
428 | * fix production deployment environment ([9d5df5d](https://github.com/Greenstand/treetracker-web-map/commit/9d5df5de0f75be485f080bfcb5c8882bd0c6d201))
429 | * perform release when actions change for server ([daf0c1e](https://github.com/Greenstand/treetracker-web-map/commit/daf0c1e5c6ea7a3f0ca8594eb1f0277ed5c4d53b))
430 |
431 | ## [1.5.5](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.4...v1.5.5) (2021-03-03)
432 |
433 |
434 | ### Bug Fixes
435 |
436 | * clean up jobs, add prod server deploy ([120d8a1](https://github.com/Greenstand/treetracker-web-map/commit/120d8a11cde753a17971490fd2fa4fc01c54ab0c))
437 |
438 | ## [1.5.4](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.3...v1.5.4) (2021-03-03)
439 |
440 |
441 | ### Bug Fixes
442 |
443 | * temporary updated mapping to allow CORS for all envs ([a569d5e](https://github.com/Greenstand/treetracker-web-map/commit/a569d5ec78fc4a3d9b802870c705baa866fa96b0))
444 |
445 | ## [1.5.3](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.2...v1.5.3) (2021-03-03)
446 |
447 |
448 | ### Bug Fixes
449 |
450 | * temporary updated mapping to allow CORS for all envs ([0c311eb](https://github.com/Greenstand/treetracker-web-map/commit/0c311eb7adb005a965516a83ab0eba842abb6c7d))
451 |
452 | ## [1.5.2](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.1...v1.5.2) (2021-03-03)
453 |
454 |
455 | ### Bug Fixes
456 |
457 | * do not skip workflows ([79e6ff8](https://github.com/Greenstand/treetracker-web-map/commit/79e6ff881d060dec036de48fa014b664c390d7b7))
458 |
459 | ## [1.5.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.5.0...v1.5.1) (2021-03-03)
460 |
461 |
462 | ### Bug Fixes
463 |
464 | * clean up releaserc ([49f64b9](https://github.com/Greenstand/treetracker-web-map/commit/49f64b9731144c6204f0f9d3275eca9db77b8bf0))
465 | * fix needs in workflow ([155e678](https://github.com/Greenstand/treetracker-web-map/commit/155e67806c2248b508221b38bf6de44b87d49100))
466 | * fix production deploy ([2edd880](https://github.com/Greenstand/treetracker-web-map/commit/2edd880ea15ada1944e807342ccebc73c871b6bf))
467 | * mark as private project ([d624924](https://github.com/Greenstand/treetracker-web-map/commit/d624924bb5a41dad13e5f4cfa150cb71391eebd3))
468 | * trigger a release ([20a5be3](https://github.com/Greenstand/treetracker-web-map/commit/20a5be34cac4070530764bc7b16a77f039743dea))
469 | * trigger release ([71cd0a9](https://github.com/Greenstand/treetracker-web-map/commit/71cd0a924c7971ea3192d8393e1e5c716374e9ee))
470 | * trigger release ([6bfda4f](https://github.com/Greenstand/treetracker-web-map/commit/6bfda4fa66eb93b15ee44455254a92c9c3f97d2c))
471 | * trigger release ([6bb906c](https://github.com/Greenstand/treetracker-web-map/commit/6bb906c407e2f66e499159581c4169c511d6e9a0))
472 |
473 | # [1.5.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.4.1...v1.5.0) (2021-03-03)
474 |
475 |
476 | ### Features
477 |
478 | * trigger a release ([268bd11](https://github.com/Greenstand/treetracker-web-map/commit/268bd114ad21bdc84470d9fcb09cdc4fd0fb2c6c))
479 |
480 | ## [1.4.1](https://github.com/Greenstand/treetracker-web-map/compare/v1.4.0...v1.4.1) (2021-02-25)
481 |
482 |
483 | ### Bug Fixes
484 |
485 | * remove unused .env ([0357b3c](https://github.com/Greenstand/treetracker-web-map/commit/0357b3c9499e2ddb4c77fa13e40350bcf091a07c))
486 | * use dotenv to load environment variables ([dd19799](https://github.com/Greenstand/treetracker-web-map/commit/dd197995d45bd1f896d1e3234d56ec21516d4868))
487 |
488 | # [1.4.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.3.0...v1.4.0) (2021-02-25)
489 |
490 |
491 | ### Bug Fixes
492 |
493 | * bug in timeline ([b4cdc9c](https://github.com/Greenstand/treetracker-web-map/commit/b4cdc9c7ae8a0cfb164be48ecbb190f70c499b4b))
494 | * ip cause crash ([28911ea](https://github.com/Greenstand/treetracker-web-map/commit/28911eaaf844ccb50392e871e4a3f1864cb2fa04))
495 |
496 |
497 | ### Features
498 |
499 | * add some infra for express: error handler ([96252bd](https://github.com/Greenstand/treetracker-web-map/commit/96252bd0cba4ef27fe5a089d1b15d858b155b41b))
500 | * api is oky for the timeline zoom = 2 ([b6ff978](https://github.com/Greenstand/treetracker-web-map/commit/b6ff978c5a5b56a8f4d90d6786ba68ffeb06d4f6))
501 | * appearnce of timeline component ([2d2db5f](https://github.com/Greenstand/treetracker-web-map/commit/2d2db5f01651724368700964b4bb07bc83149dd5))
502 | * can hide timeline in some cases ([dff0cab](https://github.com/Greenstand/treetracker-web-map/commit/dff0cab0f0d8144b69b646ca8ce2a7f18e786525))
503 | * can query timeline with date ([0dc1a47](https://github.com/Greenstand/treetracker-web-map/commit/0dc1a4753912601ce7aa738a61c2bc23b2ed99a7))
504 | * can set default timeline ([fdb279a](https://github.com/Greenstand/treetracker-web-map/commit/fdb279a9c7697140a88655204e4a43bf0b6214c4))
505 | * can show tree points with timeline ([6bde9ba](https://github.com/Greenstand/treetracker-web-map/commit/6bde9ba1b82cc3398056ef9f778adb22d4158f09))
506 | * can use basic timeline filter the zoom =2 ([b536a8a](https://github.com/Greenstand/treetracker-web-map/commit/b536a8a4b6fecaa8dfa6d282f7c374911f715f9b))
507 | * erace all timeline data when click close ([bdce282](https://github.com/Greenstand/treetracker-web-map/commit/bdce2822e13617f65fb87b09ac766f782e59ac19))
508 | * improve css ([8810eb7](https://github.com/Greenstand/treetracker-web-map/commit/8810eb7ca2f161d5857adebb3d7b7bf78b34c598))
509 | * improve the slider ([26534a0](https://github.com/Greenstand/treetracker-web-map/commit/26534a087312f79ea943ee6dffc35fcf6a92cece))
510 | * original component for timeline ([aff4be3](https://github.com/Greenstand/treetracker-web-map/commit/aff4be350b1cd23bccb77640862bd8562ca11a19))
511 | * timeline map can zoom into 12-14 level ([ba2b09a](https://github.com/Greenstand/treetracker-web-map/commit/ba2b09a3b84d9c06c0d1ef931c0f0816248cd7e5))
512 |
513 | # [1.3.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.2.0...v1.3.0) (2021-02-18)
514 |
515 |
516 | ### Features
517 |
518 | * create capture id query param to support hateoas link from wallet service ([52b3c82](https://github.com/Greenstand/treetracker-web-map/commit/52b3c82cf06e17e2876aea9c7b940023092dc5b4))
519 |
520 | # [1.2.0](https://github.com/Greenstand/treetracker-web-map/compare/v1.1.0...v1.2.0) (2021-01-28)
521 |
522 |
523 | ### Bug Fixes
524 |
525 | * syntax error ([e4d2704](https://github.com/Greenstand/treetracker-web-map/commit/e4d2704f1ca9b67f2ae3af4d2808db32174cd198))
526 | * update to our target nodejs version ([affa2c6](https://github.com/Greenstand/treetracker-web-map/commit/affa2c673624995dd94bbe98ce28da68d364e07c))
527 |
528 |
529 | ### Features
530 |
531 | * can display the spin when taking long time ([abce6de](https://github.com/Greenstand/treetracker-web-map/commit/abce6de6dbfec14d17fa462510786d9081bf0f96))
532 | * use case3 to halde org map ([72176f7](https://github.com/Greenstand/treetracker-web-map/commit/72176f70c76084a3bc299b5172a28bcae9337dc6))
533 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------