Skip to content

Commit

Permalink
Merge pull request #253 from Vizzuality/develop
Browse files Browse the repository at this point in the history
production release
  • Loading branch information
andresgnlez authored Apr 11, 2024
2 parents 96a13c5 + 3de7d71 commit 1271bd0
Show file tree
Hide file tree
Showing 136 changed files with 7,847 additions and 3,923 deletions.
13 changes: 13 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
. "$(dirname -- "$0")/_/husky.sh"

SCRIPT_DIR="$(pwd)"
CMS_ENV_FILE="$SCRIPT_DIR/cms/.env"
echo $CMS_ENV_FILE
if [[ -f "$CMS_ENV_FILE" ]] ; then
echo "Importing CMS config.."
cd ./cms && yarn config-sync import -y
else
echo "CMS env file does not exist, can't import config"
echo "DEBUG: looking for env file in $CMS_ENV_FILE"
fi
30 changes: 30 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
. "$(dirname -- "$0")/_/husky.sh"

# If frontend yarn.lock has changed, run yarn to install dependencies
CLIENT_CHANGED=`git diff HEAD@{1} --stat -- ./frontend/yarn.lock | wc -l`
if [ "$CLIENT_CHANGED" -gt 0 ];
then
echo "frontend/yarn.lock has changed!"
cd ./frontend && yarn
fi

# If CMS yarn.lock has changed, run yarn to install dependencies
CMS_CHANGED=`git diff HEAD@{1} --stat -- ./cms/yarn.lock | wc -l`
if [ "$CMS_CHANGED" -gt 0 ];
then
echo "cms/yarn.lock has changed!"
cd ./cms && yarn
fi

# If CMS env file exists and there are changes to the config sync files, import them into the DB
CMS_CONFIG_CHANGED=`git diff HEAD@{1} --stat -- ./cms/config/sync/ | wc -l`
SCRIPT_DIR="$(pwd)"
CMS_ENV_FILE="$SCRIPT_DIR/../cms/.env"
if [ ! -f "$CMS_ENV_FILE" ] ; then
echo "CMS env file does not exist, can't import config."
echo "DEBUG: looking for env file in $CMS_ENV_FILE"
elif [ -f "$CMS_ENV_FILE" && "$CMS_CONFIG_CHANGED" -gt 0 ]; then
echo "Importing CMS config..."
cd ./cms && yarn config-sync import -y
fi
10 changes: 9 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@

cd ./frontend && yarn types && yarn lint --fix && yarn check-types && git add src/types/generated/

cd .. && cd ./cms && yarn cs export -y
SCRIPT_DIR="$(pwd)"
CMS_ENV_FILE="$SCRIPT_DIR/../cms/.env"
if [ -f "$CMS_ENV_FILE" ] ; then
echo "Exporting CMS config.."
cd .. && cd ./cms && yarn config-sync export -y && git add config/sync/*
else
echo "CMS env file does not exist, can't export config"
echo "DEBUG: looking for env file in $CMS_ENV_FILE"
fi
2 changes: 1 addition & 1 deletion cloud_functions/analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ install docker and docker-compose
In order to run the analysis locally using docker you will need to:

1.- set the environment variables.
2.- run `docker-compose up --build`
2.- run `docker compose up --build`

Note: the first time you run this, you will need to run as well, once the db service is up, the `skytruth-db-init service` in order to populate the db with the data.
7 changes: 6 additions & 1 deletion cloud_functions/analysis/src/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def serialize_response(data: dict) -> dict:
"""Converts the data from the database
into a Dict {locations_area:{"code":<location_iso>, "protected_area": <area>, "area":<location_marine_area>}, "total_area":<total_area>} response
"""
if not data or len(data) == 0:
raise ValueError(
"No data found, this is likely due to a geometry that does not intersect with a Marine area."
)

result = {"total_area": data[0][5]}
sub_result = {}
total_protected_area = 0
Expand Down Expand Up @@ -50,7 +55,7 @@ def get_locations_stats(db: sqlalchemy.engine.base.Engine, geojson: JSON) -> dic
with user_data as (select ST_GeomFromGeoJSON(:geometry) as geom),
user_data_stats as (select *, round((st_area(st_transform(geom,'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) user_area_km2 from user_data)
select area_km2, iso_sov1, iso_sov2, iso_sov3,
round((st_area(st_transform(st_makevalid(st_intersection(the_geom, user_data_stats.geom)),'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) portion_area_km2,
round((st_area(st_transform(st_makevalid(st_intersection(ST_Subdivide(the_geom, 20000), user_data_stats.geom)),'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) portion_area_km2,
user_data_stats.user_area_km2
from data.eez_minus_mpa emm, user_data_stats
where st_intersects(the_geom, user_data_stats.geom)
Expand Down
2 changes: 1 addition & 1 deletion cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ yarn build
### Usage with Docker (recommended)
To run with docker:

docker-compose up --build
docker compose up --build

Open the app at http://localhost:1337

Expand Down
5 changes: 1 addition & 4 deletions cms/config/sync/admin-role.strapi-author.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand Down Expand Up @@ -394,7 +393,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand All @@ -413,7 +411,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand Down Expand Up @@ -1263,4 +1260,4 @@
]
}
]
}
}
5 changes: 1 addition & 4 deletions cms/config/sync/admin-role.strapi-editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand Down Expand Up @@ -342,7 +341,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand All @@ -359,7 +357,6 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"geography",
"data_tool_ecosystems"
]
Expand Down Expand Up @@ -1099,4 +1096,4 @@
"conditions": []
}
]
}
}
100 changes: 78 additions & 22 deletions cms/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"data_tool_resource_types",
"geography",
"data_tool_ecosystems"
]
Expand Down Expand Up @@ -342,7 +342,7 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"data_tool_resource_types",
"geography",
"data_tool_ecosystems"
]
Expand All @@ -359,13 +359,63 @@
"description",
"site",
"languages",
"data_tool_resource_type",
"data_tool_resource_types",
"geography",
"data_tool_ecosystems"
]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.create",
"actionParameters": {},
"subject": "api::dataset.dataset",
"properties": {
"fields": [
"name",
"layers"
]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.delete",
"actionParameters": {},
"subject": "api::dataset.dataset",
"properties": {},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.publish",
"actionParameters": {},
"subject": "api::dataset.dataset",
"properties": {},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.read",
"actionParameters": {},
"subject": "api::dataset.dataset",
"properties": {
"fields": [
"name",
"layers"
]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.update",
"actionParameters": {},
"subject": "api::dataset.dataset",
"properties": {
"fields": [
"name",
"layers"
]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.create",
"actionParameters": {},
Expand Down Expand Up @@ -573,7 +623,8 @@
"metadata.source",
"metadata.resolution",
"metadata.content_date",
"metadata.license"
"metadata.license",
"dataset"
]
},
"conditions": []
Expand Down Expand Up @@ -609,7 +660,8 @@
"metadata.source",
"metadata.resolution",
"metadata.content_date",
"metadata.license"
"metadata.license",
"dataset"
]
},
"conditions": []
Expand All @@ -631,7 +683,8 @@
"metadata.source",
"metadata.resolution",
"metadata.content_date",
"metadata.license"
"metadata.license",
"dataset"
]
},
"conditions": []
Expand Down Expand Up @@ -713,7 +766,8 @@
"fishing_protection_level",
"mpaa_protection_level",
"location",
"area"
"area",
"mpaa_establishment_stage"
]
},
"conditions": []
Expand All @@ -735,7 +789,8 @@
"fishing_protection_level",
"mpaa_protection_level",
"location",
"area"
"area",
"mpaa_establishment_stage"
]
},
"conditions": []
Expand All @@ -750,7 +805,8 @@
"fishing_protection_level",
"mpaa_protection_level",
"location",
"area"
"area",
"mpaa_establishment_stage"
]
},
"conditions": []
Expand All @@ -761,13 +817,12 @@
"subject": "api::mpa.mpa",
"properties": {
"fields": [
"wdpaid",
"name",
"area",
"year",
"mpaa_establishment_stage",
"protection_status",
"mpa_protection_coverage_stats"
"mpa_protection_coverage_stats",
"wdpaid"
]
},
"conditions": []
Expand All @@ -785,13 +840,12 @@
"subject": "api::mpa.mpa",
"properties": {
"fields": [
"wdpaid",
"name",
"area",
"year",
"mpaa_establishment_stage",
"protection_status",
"mpa_protection_coverage_stats"
"mpa_protection_coverage_stats",
"wdpaid"
]
},
"conditions": []
Expand All @@ -802,13 +856,12 @@
"subject": "api::mpa.mpa",
"properties": {
"fields": [
"wdpaid",
"name",
"area",
"year",
"mpaa_establishment_stage",
"protection_status",
"mpa_protection_coverage_stats"
"mpa_protection_coverage_stats",
"wdpaid"
]
},
"conditions": []
Expand Down Expand Up @@ -873,7 +926,8 @@
"fields": [
"slug",
"name",
"info"
"info",
"mpa_protection_coverage_stats"
]
},
"conditions": []
Expand All @@ -893,7 +947,8 @@
"fields": [
"slug",
"name",
"info"
"info",
"mpa_protection_coverage_stats"
]
},
"conditions": []
Expand All @@ -906,7 +961,8 @@
"fields": [
"slug",
"name",
"info"
"info",
"mpa_protection_coverage_stats"
]
},
"conditions": []
Expand Down Expand Up @@ -1652,4 +1708,4 @@
"conditions": []
}
]
}
}
Loading

0 comments on commit 1271bd0

Please sign in to comment.