Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiche Espece] Ajustement de la structure de config + Renommage "espèce" en "taxon" #3205

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,11 @@ def general_stats(permissions):
return data


@routes.route("/species_stats/<int:cd_ref>", methods=["GET"])
@routes.route("/taxon_stats/<int:cd_ref>", methods=["GET"])
@permissions.check_cruved_scope("R", get_scope=True, module_code="SYNTHESE")
@json_resp
def species_stats(scope, cd_ref):
"""Return stats about distinct species."""
def taxon_stats(scope, cd_ref):
"""Return stats about distinct taxon"""

area_type = request.args.get("area_type")

Expand Down
74 changes: 0 additions & 74 deletions backend/geonature/core/gn_synthese/synthese_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,77 +100,3 @@
{"prop": "dataset_name", "name": "JDD", "max_width": 200},
{"prop": "observers", "name": "observateur", "max_width": 200},
]


class DefaultProfile:
ENABLED = True
## DEFAULT PROFILE INDICATORS
LIST_INDICATORS = [
{
"name": "observation(s) valide(s)",
"matIcon": "search",
"field": "count_valid_data",
"type": "number",
},
{
"name": "Première observation",
"matIcon": "schedule",
"field": "first_valid_data",
"type": "date",
},
{
"name": "Dernière observation",
"matIcon": "search",
"field": "last_valid_data",
"type": "date",
},
{
"name": "Plage d'altitude(s)",
"matIcon": "terrain",
"field": ["altitude_min", "altitude_max"],
"unit": "m",
"type": "number",
},
]


class DefaultGeographicOverview:
pass


class DefaultSpeciesSheet:
## DEFAULT SPECIES SHEET INDICATORS
LIST_INDICATORS = [
{
"name": "observation(s)",
"matIcon": "search",
"field": "observation_count",
"type": "number",
},
{
"name": "observateur(s)",
"matIcon": "people",
"field": "observer_count",
"type": "number",
},
{
"name": "commune(s)",
"matIcon": "location_on",
"field": "area_count",
"type": "number",
},
{
"name": "Plage d'altitude(s)",
"matIcon": "terrain",
"unit": "m",
"type": "number",
"field": ["altitude_min", "altitude_max"],
},
{
"name": "Plage d'observation(s)",
"matIcon": "date_range",
"type": "date",
"field": ["date_min", "date_max"],
"separator": "-",
},
]
32 changes: 6 additions & 26 deletions backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
)
from marshmallow.validate import OneOf, Regexp, Email, Length

from geonature.core.gn_synthese.synthese_config import (
DEFAULT_EXPORT_COLUMNS,
DEFAULT_LIST_COLUMN,
DefaultGeographicOverview,
DefaultProfile,
DefaultSpeciesSheet,
)
from geonature.core.gn_synthese.synthese_config import DEFAULT_EXPORT_COLUMNS, DEFAULT_LIST_COLUMN
from geonature.utils.env import GEONATURE_VERSION, BACKEND_DIR, ROOT_DIR
from geonature.utils.module import iter_modules_dist, get_module_config
from geonature.utils.utilsmails import clean_recipients
Expand Down Expand Up @@ -277,24 +271,10 @@ class ExportObservationSchema(Schema):
geojson_local_field = fields.String(load_default="geojson_local")


class SpeciesSheetProfile(Schema):
ENABLED = fields.Boolean(load_default=DefaultProfile.ENABLED)
LIST_INDICATORS = fields.List(fields.Dict, load_default=DefaultProfile.LIST_INDICATORS)


class SpeciesSheetGeographicOverview(Schema):
pass


class SpeciesSheet(Schema):
class TaxonSheet(Schema):
# --------------------------------------------------------------------
# SYNTHESE - SPECIES_SHEET
LIST_INDICATORS = fields.List(fields.Dict, load_default=DefaultSpeciesSheet.LIST_INDICATORS)

GEOGRAPHIC_OVERVIEW = fields.Dict(
load_default=SpeciesSheetGeographicOverview().load({})
) # rename
PROFILE = fields.Nested(SpeciesSheetProfile, load_default=SpeciesSheetProfile().load({}))
# SYNTHESE - TAXON_SHEET
ENABLE_PROFILE = fields.Boolean(load_default=True)


class Synthese(Schema):
Expand Down Expand Up @@ -452,8 +432,8 @@ class Synthese(Schema):
BLUR_SENSITIVE_OBSERVATIONS = fields.Boolean(load_default=True)

# --------------------------------------------------------------------
# SYNTHESE - SPECIES_SHEET
SPECIES_SHEET = fields.Nested(SpeciesSheet, load_default=SpeciesSheet().load({}))
# SYNTHESE - TAXON_SHEET
TAXON_SHEET = fields.Nested(TaxonSheet, load_default=TaxonSheet().load({}))

@pre_load
def warn_deprecated(self, data, **kwargs):
Expand Down
13 changes: 9 additions & 4 deletions config/default_config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
# Vues d'export personnalisées
EXPORT_OBSERVATIONS_CUSTOM_VIEWS = [
{
label = "format personnalisé",
label = "format personnalisé",
view_name = "schema_name.view_name"
}
}
]
# Noms des colonnes obligatoires de la vue ``gn_synthese.v_metadata_for_export``
EXPORT_METADATA_ID_DATASET_COL = "jdd_id"
Expand Down Expand Up @@ -441,6 +441,11 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
# Seulement les données de présence
cd_nomenclature_observation_status = ['Pr']

[SYNTHESE.TAXON_SHEET]
# Options dédiées à la fiche taxon
# Permet d'activer ou non la section "Profile"
ENABLE_PROFILE = True

# Gestion des demandes d'inscription
[ACCOUNT_MANAGEMENT]
# Activer l'affichage du lien vers le formulaire d'inscription
Expand Down Expand Up @@ -601,12 +606,12 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
[[AUTHENTICATION.PROVIDERS]]
module="pypnusershub.auth.providers.default.DefaultConfiguration"
id_provider="local_provider"

[[AUTHENTICATION.PROVIDERS]]
module="pypnusershub.auth.providers.openid_provider.OpenIDConnectProvider"
id_provider = "google"
logo = "<i class='fa fa-google' aria-hidden='true'></i>"
label = "Google"
ISSUER = "https://accounts.google.com/"
CLIENT_ID = "ID" # API key
CLIENT_SECRET = "SECRET" # API Secret
CLIENT_SECRET = "SECRET" # API Secret
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class SyntheseDataService {
return this._api.get<any>(`${this.config.API_ENDPOINT}/synthese/general_stats`);
}

getSyntheseSpeciesSheetStat(cd_ref: number, areaType: string = 'COM') {
return this._api.get<any>(`${this.config.API_ENDPOINT}/synthese/species_stats/${cd_ref}`, {
getSyntheseTaxonSheetStat(cd_ref: number, areaType: string = 'COM') {
return this._api.get<any>(`${this.config.API_ENDPOINT}/synthese/taxon_stats/${cd_ref}`, {
params: new HttpParams().append('area_type', areaType),
});
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/app/syntheseModule/synthese.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { TaxonSheetComponent } from './taxon-sheet/taxon-sheet.component';
import {
RouteService,
ALL_TAXON_SHEET_ADVANCED_INFOS_ROUTES,
ROUTE_MANDATORY,
} from './taxon-sheet/taxon-sheet.route.service';

const routes: Routes = [
Expand All @@ -32,7 +31,7 @@ const routes: Routes = [
children: [
{
path: '',
redirectTo: ROUTE_MANDATORY.path,
redirectTo: ALL_TAXON_SHEET_ADVANCED_INFOS_ROUTES[0].path,
pathMatch: 'prefix',
},
...ALL_TAXON_SHEET_ADVANCED_INFOS_ROUTES.map((tab) => {
Expand Down
35 changes: 18 additions & 17 deletions frontend/src/app/syntheseModule/taxon-sheet/indicator/indicator.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
type IndicatorRawType = 'number' | 'string' | 'date';
export interface IndicatorRaw {
export interface Indicator {
name: string;
matIcon: string;
field: string | Array<string>;
unit?: string;
type: IndicatorRawType;
value: string | null;
}

export interface Indicator {
type IndicatorRawType = 'number' | 'string' | 'date';
export interface IndicatorDescription {
name: string;
matIcon: string;
value: string | null;
field: string | Array<string>;
unit?: string;
separator?: string;
type: IndicatorRawType;
}

type Stats = Record<string, string>;

const DEFAULT_VALUE = '-';
const DEFAULT_SEPARATOR = '-';

function getValue(field: string, indicatorConfig: IndicatorRaw, stats?: Stats) {
function getValue(field: string, indicatorConfig: IndicatorDescription, stats?: Stats) {
if (stats && stats[field]) {
let valueAsString = '';
switch (indicatorConfig.type) {
Expand All @@ -37,24 +38,24 @@ function getValue(field: string, indicatorConfig: IndicatorRaw, stats?: Stats) {
return DEFAULT_VALUE;
}

export function computeIndicatorFromConfig(
indicatorConfig: IndicatorRaw,
export function computeIndicatorFromDecsription(
indicatorDescription: IndicatorDescription,
stats?: Stats
): Indicator {
let value = DEFAULT_VALUE;
if (stats) {
if (Array.isArray(indicatorConfig.field)) {
const separator = indicatorConfig['separator'] ?? DEFAULT_SEPARATOR;
value = indicatorConfig.field
.map((field) => getValue(field, indicatorConfig, stats))
if (Array.isArray(indicatorDescription.field)) {
const separator = indicatorDescription.separator ?? DEFAULT_SEPARATOR;
value = indicatorDescription.field
.map((field) => getValue(field, indicatorDescription, stats))
.join(' ' + separator + ' ');
} else {
value = getValue(indicatorConfig.field, indicatorConfig, stats);
value = getValue(indicatorDescription.field, indicatorDescription, stats);
}
}
return {
name: indicatorConfig.name,
matIcon: indicatorConfig.matIcon,
name: indicatorDescription.name,
matIcon: indicatorDescription.matIcon,
value: value,
};
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
import { Component, OnInit } from '@angular/core';
import { GN2CommonModule } from '@geonature_common/GN2Common.module';
import { CommonModule } from '@angular/common';
import { ConfigService } from '@geonature/services/config.service';
import { DataFormService, Profile } from '@geonature_common/form/data-form.service';
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component';
import { CommonService } from '@geonature_common/service/common.service';
import { computeIndicatorFromConfig, Indicator, IndicatorRaw } from '../indicator/indicator';
import {
computeIndicatorFromDecsription,
Indicator,
IndicatorDescription,
} from '../indicator/indicator';
import { IndicatorComponent } from '../indicator/indicator.component';
import { TaxonSheetService } from '../taxon-sheet.service';

const INDICATORS: Array<IndicatorDescription> = [
{
name: 'observation(s) valide(s)',
matIcon: 'search',
field: 'count_valid_data',
type: 'number',
},
{
name: 'Première observation',
matIcon: 'schedule',
field: 'first_valid_data',
type: 'date',
},
{
name: 'Dernière observation',
matIcon: 'search',
field: 'last_valid_data',
type: 'date',
},
{
name: "Plage d'altitude(s)",
matIcon: 'terrain',
field: ['altitude_min', 'altitude_max'],
unit: 'm',
type: 'number',
},
];

@Component({
standalone: true,
selector: 'tab-profile',
Expand All @@ -21,7 +52,6 @@ export class TabProfileComponent implements OnInit {
_profile: Profile | null;

constructor(
private _config: ConfigService,
private _ds: DataFormService,
private _commonService: CommonService,
private _tss: TaxonSheetService
Expand Down Expand Up @@ -54,19 +84,8 @@ export class TabProfileComponent implements OnInit {

set profile(profile: Profile | null) {
this._profile = profile;

if (
this._config &&
this._config['SYNTHESE'] &&
this._config['SYNTHESE']['SPECIES_SHEET'] &&
this._config['SYNTHESE']['SPECIES_SHEET']['PROFILE']
) {
this.indicators = this._config['SYNTHESE']['SPECIES_SHEET']['PROFILE']['LIST_INDICATORS'].map(
(indicatorConfig: IndicatorRaw) =>
computeIndicatorFromConfig(indicatorConfig, profile?.properties)
);
} else {
this.indicators = [];
}
this.indicators = INDICATORS.map((indicatorRaw: IndicatorDescription) =>
computeIndicatorFromDecsription(indicatorRaw, profile?.properties)
);
}
}
Loading
Loading