Skip to content

Commit

Permalink
feat: adjust config content
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Sep 27, 2024
1 parent 1e0354c commit 4d0f97f
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 206 deletions.
2 changes: 1 addition & 1 deletion backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def species_stats(scope, cd_ref):
return data


if app.config["SYNTHESE"]["SPECIES_SHEET"]["OBSERVERS"]["ENABLED"]:
if app.config["SYNTHESE"]["SPECIES_SHEET"]["ENABLE_OBSERVERS"]:

@routes.route("/species_observers/<int:cd_ref>", methods=["GET"])
@permissions.check_cruved_scope("R", get_scope=True, module_code="SYNTHESE")
Expand Down
78 changes: 0 additions & 78 deletions backend/geonature/core/gn_synthese/synthese_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,81 +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 DefaultObservers:
ENABLED = True


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": "-",
},
]
31 changes: 3 additions & 28 deletions backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +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,
DefaultObservers,
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 @@ -278,29 +271,11 @@ 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 SpeciesSheetObservers(Schema):
ENABLED = fields.Boolean(load_default=DefaultObservers.ENABLED)


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({}))
OBSERVERS = fields.Dict(load_default=SpeciesSheetObservers().load({}))
ENABLE_OBSERVERS = fields.Boolean(load_default=True)
ENABLE_PROFILE = fields.Boolean(load_default=True)


class Synthese(Schema):
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)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,55 @@ import {
RouterLinkActive,
RouterOutlet,
} from '@angular/router';
import { ConfigService } from '@geonature/services/config.service';
import { GN2CommonModule } from '@geonature_common/GN2Common.module';
import { InfosComponent } from './infos/infos.component';
import { LayoutComponent } from './layout/layout.component';
import { computeIndicatorFromConfig, Indicator, IndicatorRaw } from './indicator/indicator';
import {
computeIndicatorFromDecsription,
Indicator,
IndicatorDescription,
} from './indicator/indicator';
import { IndicatorComponent } from './indicator/indicator.component';
import { CommonModule } from '@angular/common';
import { SyntheseDataService } from '@geonature_common/form/synthese-form/synthese-data.service';
import { TaxonSheetService } from './taxon-sheet.service';
import { RouteService } from './taxon-sheet.route.service';

const INDICATORS: Array<IndicatorDescription> = [
{
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: '-',
},
];

@Component({
standalone: true,
selector: 'pnx-taxon-sheet',
Expand Down Expand Up @@ -44,7 +82,6 @@ export class TaxonSheetComponent implements OnInit {
private _route: ActivatedRoute,
private _tss: TaxonSheetService,
private _syntheseDataService: SyntheseDataService,
private _config: ConfigService,
private _routes: RouteService
) {
this.TAB_LINKS = this._routes.TAB_LINKS;
Expand All @@ -62,18 +99,9 @@ export class TaxonSheetComponent implements OnInit {
}

setIndicators(stats: any) {
if (
this._config &&
this._config['SYNTHESE'] &&
this._config['SYNTHESE']['SPECIES_SHEET'] &&
this._config['SYNTHESE']['SPECIES_SHEET']['LIST_INDICATORS']
) {
this.indicators = this._config['SYNTHESE']['SPECIES_SHEET']['LIST_INDICATORS'].map(
(indicatorConfig: IndicatorRaw) => computeIndicatorFromConfig(indicatorConfig, stats)
);
} else {
this.indicators = [];
}
this.indicators = INDICATORS.map((indicatorConfig: IndicatorDescription) =>
computeIndicatorFromDecsription(indicatorConfig, stats)
);
}

goToPath(path: string) {
Expand Down
Loading

0 comments on commit 4d0f97f

Please sign in to comment.