Skip to content

Commit

Permalink
Merge pull request #308 from lpoaura/news
Browse files Browse the repository at this point in the history
News
  • Loading branch information
lpofredc authored Apr 26, 2023
2 parents 694ee2b + f75098c commit 50fad38
Show file tree
Hide file tree
Showing 79 changed files with 1,506 additions and 847 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python
# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml ./poetry.lock* /app/

RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

COPY . /app

Expand Down
49 changes: 38 additions & 11 deletions backend/app/core/taxa/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from typing import List, Optional

from geoalchemy2 import functions as geofunc
from sqlalchemy import func
from sqlalchemy import func, cast
from sqlalchemy.orm import Session
from sqlalchemy.types import Integer

from app.core.actions.crud import BaseReadOnlyActions
from app.core.commons.models import AreaKnowledgeTaxaList
Expand All @@ -30,7 +31,9 @@ def taxa_distribution(
geom = (
LAreas.geojson_4326
if grid
else geofunc.ST_AsGeoJSON(geofunc.ST_Transform(geofunc.ST_Centroid(LAreas.geom), 4326))
else geofunc.ST_AsGeoJSON(
geofunc.ST_Transform(geofunc.ST_Centroid(LAreas.geom), 4326)
)
)
status_field = {
"breeding_old": {
Expand Down Expand Up @@ -58,12 +61,36 @@ def taxa_distribution(
"status": "Presence",
},
}
q = (

query = (
db.query(
AreaKnowledgeTaxaList.id_area.label("id"),
func.json_build_object("status", status_field[period]["status"]).label(
"properties"
),
func.json_build_object(
"status",
status_field[period]["status"],
"radius",
(
func.round(
cast(
(
geofunc.ST_DistanceSphere(
geofunc.ST_MakePoint(
geofunc.ST_XMin(LAreas.geom),
geofunc.ST_YMin(LAreas.geom),
),
geofunc.ST_MakePoint(
geofunc.ST_XMax(LAreas.geom),
geofunc.ST_YMin(LAreas.geom),
),
)
/ 2*0.9
),
Integer,
),
-2,
)
),
).label("properties"),
geom.label("geometry"),
)
.join(LAreas, LAreas.id_area == AreaKnowledgeTaxaList.id_area)
Expand All @@ -72,7 +99,7 @@ def taxa_distribution(
)

if envelope:
q = q.filter(
query = query.filter(
geofunc.ST_Intersects(
LAreas.geom,
geofunc.ST_Transform(
Expand All @@ -83,9 +110,7 @@ def taxa_distribution(
),
)
)

logger.debug(f"<taxa_distribution> q {q}")
return q.all()
return query.all()


# class TaxaAltitudeDistributionActions(BaseReadOnlyActions[MvTaxaAltitudeDistribution]):
Expand Down Expand Up @@ -124,7 +149,9 @@ def historic_atlases_distribution(
db.query(
THistoricAtlasesData.id_area.label("id"),
THistoricAtlasesData.status,
func.json_build_object("status", THistoricAtlasesData.status).label("properties"),
func.json_build_object("status", THistoricAtlasesData.status).label(
"properties"
),
LAreas.geojson_4326.label("geometry"),
)
.join(LAreas, LAreas.id_area == THistoricAtlasesData.id_area)
Expand Down
1 change: 1 addition & 0 deletions backend/app/core/taxa/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class TaxaDistributionProperties(BaseModel):
status: Optional[str]
radius: Optional[str]


class TaxaDistributionFeature(Feature):
Expand Down
Loading

0 comments on commit 50fad38

Please sign in to comment.