Skip to content

Commit

Permalink
feat: adjust species-sheet config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Sep 27, 2024
1 parent 30e42d9 commit 98cc3df
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 188 deletions.
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": "-",
},
]
24 changes: 2 additions & 22 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):
# --------------------------------------------------------------------
# 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({}))
ENABLE_PROFILE = fields.Boolean(load_default=True)


class Synthese(Schema):
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.SPECIES_SHEET]
# Options dédiées à la fiche espèce
#Permet d'activer ou non la section "Profile" de la fiche espèce
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
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

0 comments on commit 98cc3df

Please sign in to comment.