Skip to content

Commit

Permalink
wip profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Sep 20, 2021
1 parent c07ae38 commit 0e59f9c
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 178 deletions.
9 changes: 8 additions & 1 deletion backend/geonature/core/gn_profiles/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import current_app
from geoalchemy2 import Geometry
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.sql.schema import ForeignKey

from utils_flask_sqla.serializers import serializable
Expand Down Expand Up @@ -57,5 +58,11 @@ class VConsistancyData(DB.Model):
valid_distribution = DB.Column(DB.Boolean)
valid_phenology = DB.Column(DB.Boolean)
valid_altitude = DB.Column(DB.Boolean)
score = DB.Column(DB.Integer)
# score = DB.Column(DB.Integer)
valid_status = DB.Column(DB.Unicode)

def as_dict(data):
score = (data["valid_distribution"] or 0) + (
data["valid_altitude"] or 0
) + (data["valid_phenology"] or 0)
return data.update({"score":score})
40 changes: 35 additions & 5 deletions contrib/gn_module_validation/backend/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from sqlalchemy import select, func
from flask import Blueprint, request
from geojson import FeatureCollection
from sqlalchemy.sql.expression import cast
from sqlalchemy.sql.sqltypes import Integer

from utils_flask_sqla.response import json_resp
from utils_flask_sqla.serializers import SERIALIZERS
Expand Down Expand Up @@ -69,7 +71,7 @@ def get_synthese_data(info_role):
result_limit = filters.pop("limit")
else:
result_limit = blueprint.config["NB_MAX_OBS_MAP"]

result_limit = 100
# Construction de la requête select
# Les champs correspondent aux champs obligatoires
# + champs définis par l'utilisateur
Expand Down Expand Up @@ -107,24 +109,52 @@ def get_synthese_data(info_role):
serializer[column_config["column_name"]] = SERIALIZERS.get(
col.type.__class__.__name__.lower(), lambda x: x
)

# add profiles columns
columns_profile = ["valid_distribution", "valid_phenology", "valid_altitude"]
for col in columns_profile:
select_columns.append(
getattr(VConsistancyData, col)
)
serializer[col] = lambda x : x
# Construction de la requête avec SyntheseQuery
# Pour profiter des opérations CRUVED
query = (
select(select_columns)
.where(VSyntheseValidation.the_geom_4326.isnot(None))
.order_by(VSyntheseValidation.date_min.desc())
)
score = None
if "score" in filters :
score = filters.pop("score")

validation_query_class = SyntheseQuery(VSyntheseValidation, query, filters)
validation_query_class.add_join(
VConsistancyData, VConsistancyData.id_synthese,
VSyntheseValidation.id_synthese, join_type="left"
)

#filter with profile
if score:
validation_query_class.query = validation_query_class.query.where(
VConsistancyData.valid_phenology.cast(Integer)+
VConsistancyData.valid_altitude.cast(Integer) +
VConsistancyData.valid_distribution.cast(Integer)
== score
)

validation_query_class.filter_query_all_filters(info_role)
result = DB.engine.execute(validation_query_class.query.limit(result_limit))
# TODO nb_total factice
print(validation_query_class.query)
result = DB.engine.execute(validation_query_class.query.limit(100))
nb_total = 0
geojson_features = []
properties = {}
# TODO : add join on VConsistency data
for r in result:
for r in result:
properties = {k: serializer[k](r[k]) for k in serializer.keys()}
properties["score"] = (
r["valid_distribution"] or 0) + (
r["valid_phenology"] or 0) + (
r["valid_altitude"] or 0)
properties["nom_vern_or_lb_nom"] = (
r["nom_vern"] if r["nom_vern"] else r["lb_nom"]
)
Expand Down
1 change: 1 addition & 0 deletions contrib/gn_module_validation/config/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{"column_name": "nom_vern", "column_label": "nom_vern"},
{"column_name": "lb_nom", "column_label": "lb_nom"},
{"column_name": "validation_date", "column_label": "Date de validation"},
{"column_name": "score", "column_label": "Score"},
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</ng-template>
</ngx-datatable-column>

<!-- <ngx-datatable-column
<ngx-datatable-column
minWidth="10"
[maxWidth]="100"
*ngIf="appConfig.FRONTEND.DISPLAY_PROFILES"
Expand Down Expand Up @@ -225,7 +225,7 @@
</ng-template>

</ng-template>
</ngx-datatable-column> -->
</ngx-datatable-column>


<ngx-datatable-footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,18 @@ button:active {

.chip-alert {
background: red;
color: white!important;

}

.chip-warning {
background: orange;
background: rgb(255, 123, 0);
color: white!important;
}

.chip-success {
background: rgba(88, 146, 1, 0.0);
background: green;
color: white!important;
}

.mat-chip {
Expand Down
Loading

0 comments on commit 0e59f9c

Please sign in to comment.