-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Migrate Python code to TypeScript Serverless (#35)
- add serverless (+deployment) - add prettier - migrate the following endpoints: - sync geozones - sync decrees - sync restrictions - retrieve area data - retrieve global statics
- Loading branch information
Showing
44 changed files
with
8,573 additions
and
1,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = LF | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{js,jsx,ts,tsx,json}] | ||
indent_style = space | ||
charset = utf-8 | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FETCH_DATA_LOCAL=true | ||
PGDATABASE=ecowater | ||
PGHOST=localhost | ||
PGPORT=5432 | ||
PGUSER=ecowater | ||
PGPASSWORD=ecowater | ||
SECURITY_GROUP_ID= | ||
SUBNET_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
.build | ||
|
||
# Serverless directories | ||
.serverless | ||
|
||
# Dotenv | ||
.env.* | ||
|
||
# Local files | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"printWidth": 120, | ||
"semi": false, | ||
"overrides": [ | ||
{ | ||
"files": "*.json.dist", | ||
"options": { "parser": "json" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,52 @@ | ||
# Sync | ||
# EcoWater's Source Code | ||
|
||
## Getting Started | ||
## Get Started | ||
|
||
```console | ||
Prerequisites: | ||
- Node & Npm | ||
- Docker & Docker Compose | ||
|
||
```bash | ||
<node-version-manager> use | ||
npm install | ||
docker compose up -d | ||
docker compose run --rm app pip install -r requirements.txt | ||
docker compose run --rm app python index.py | ||
``` | ||
|
||
## Serverless | ||
|
||
```bash | ||
serverless invoke local --function synchronize-geozones | ||
serverless invoke local --function synchronize-decrees | ||
serverless invoke local --function synchronize-restrictions -p events/restriction-query.json | ||
``` | ||
|
||
```bash | ||
serverless deploy --stage staging | ||
serverless deploy --stage prod | ||
``` | ||
|
||
## SQL Commands | ||
|
||
Get center point long lat of the first geozone: | ||
```sql | ||
SELECT gz.id, gz.name, ST_X(ST_Centroid(gz.geometry)) as longitude, ST_Y(ST_Centroid(gz.geometry)) as latitude, de.alert_level. re.user_individual | ||
FROM geozone AS gz | ||
INNER JOIN decree AS de ON de.geozone_id = gz.id | ||
INNER JOIN restriction AS re ON re.decree_id = de.id | ||
WHERE de.start_date <= NOW() AND de.end_date >= NOW() | ||
LIMIT 1; | ||
``` | ||
|
||
Find geozones by lat long: | ||
```sql | ||
SELECT gz.id, gz.external_id, gz.type, gz.name, de.alert_level | ||
FROM geozone AS gz | ||
INNER JOIN decree AS de ON de.geozone_id = gz.id | ||
WHERE ST_Contains( | ||
gz.geometry, | ||
ST_SetSRID( | ||
ST_MakePoint(4.356850234425376, 49.4610139711892), | ||
4326 | ||
) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"body": "{}", | ||
"path": "/alert-numbers", | ||
"headers": { | ||
"Accept": "application/json", | ||
"CloudFront-Forwarded-Proto": "https", | ||
"CloudFront-Is-Desktop-Viewer": "true", | ||
"CloudFront-Is-Mobile-Viewer": "false", | ||
"CloudFront-Is-SmartTV-Viewer": "false", | ||
"CloudFront-Is-Tablet-Viewer": "false", | ||
"CloudFront-Viewer-Country": "FR", | ||
"Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com", | ||
"Upgrade-Insecure-Requests": "1", | ||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", | ||
"Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)", | ||
"X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==", | ||
"X-Forwarded-For": "192.168.100.1, 192.168.1.1", | ||
"X-Forwarded-Port": "443", | ||
"X-Forwarded-Proto": "https" | ||
}, | ||
"pathParameters": {}, | ||
"multiValueHeaders": {}, | ||
"isBase64Encoded": false, | ||
"multiValueQueryStringParameters": {}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"resourceId": "us4z18", | ||
"stage": "test", | ||
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9", | ||
"identity": { | ||
"accessKey": "", | ||
"apiKeyId": "", | ||
"cognitoIdentityPoolId": "", | ||
"accountId": "", | ||
"cognitoIdentityId": "", | ||
"caller": "", | ||
"apiKey": "", | ||
"sourceIp": "192.168.100.1", | ||
"cognitoAuthenticationType": "", | ||
"cognitoAuthenticationProvider": "", | ||
"userArn": "", | ||
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", | ||
"user": "" | ||
}, | ||
"path": "", | ||
"requestTimeEpoch": 0, | ||
"resourcePath": "/restrictions", | ||
"httpMethod": "GET", | ||
"apiId": "wt6mne2s9k" | ||
}, | ||
"resource": "/alert-numbers", | ||
"httpMethod": "GET", | ||
"queryStringParameters": {}, | ||
"stageVariables": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"body": "{}", | ||
"path": "/restrictions", | ||
"headers": { | ||
"Accept": "application/json", | ||
"CloudFront-Forwarded-Proto": "https", | ||
"CloudFront-Is-Desktop-Viewer": "true", | ||
"CloudFront-Is-Mobile-Viewer": "false", | ||
"CloudFront-Is-SmartTV-Viewer": "false", | ||
"CloudFront-Is-Tablet-Viewer": "false", | ||
"CloudFront-Viewer-Country": "FR", | ||
"Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com", | ||
"Upgrade-Insecure-Requests": "1", | ||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", | ||
"Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)", | ||
"X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==", | ||
"X-Forwarded-For": "192.168.100.1, 192.168.1.1", | ||
"X-Forwarded-Port": "443", | ||
"X-Forwarded-Proto": "https" | ||
}, | ||
"pathParameters": {}, | ||
"multiValueHeaders": {}, | ||
"isBase64Encoded": false, | ||
"multiValueQueryStringParameters": {}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"resourceId": "us4z18", | ||
"stage": "test", | ||
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9", | ||
"identity": { | ||
"accessKey": "", | ||
"apiKeyId": "", | ||
"cognitoIdentityPoolId": "", | ||
"accountId": "", | ||
"cognitoIdentityId": "", | ||
"caller": "", | ||
"apiKey": "", | ||
"sourceIp": "192.168.100.1", | ||
"cognitoAuthenticationType": "", | ||
"cognitoAuthenticationProvider": "", | ||
"userArn": "", | ||
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", | ||
"user": "" | ||
}, | ||
"path": "", | ||
"requestTimeEpoch": 0, | ||
"resourcePath": "/restrictions", | ||
"httpMethod": "GET", | ||
"apiId": "wt6mne2s9k" | ||
}, | ||
"resource": "/restrictions", | ||
"httpMethod": "GET", | ||
"queryStringParameters": { | ||
"latitude": 4.3490927, | ||
"longitude": 49.4547171, | ||
"situation": "user_individual" | ||
}, | ||
"stageVariables": {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.