Skip to content
Merged
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
7 changes: 3 additions & 4 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ catalog:
# All 4 Trees - Inventaire forestier

coordo add kobotoolbox data/all4trees/inventaire_for/20260422_InventaireForestier_DonneesK.xlsx --form data/all4trees/inventaire_for/20260519_InventaireForestier_QuestionnaireK.xlsx --package catalog/inventaire_for
coordo add file data/all4trees/inventaire_for/20260703_InventaireForestier_DonneesExternes.xlsx --package catalog/inventaire_for
coordo add file data/all4trees/inventaire_for/20260713_InventaireForestier_DonneesExternes.xlsx --package catalog/inventaire_for

coordo add foreignkey adu.decay for_dw.decay --package catalog/inventaire_for
coordo add foreignkey inv_for.proj for_samp.proj --package catalog/inventaire_for
Expand All @@ -27,12 +27,11 @@ catalog:
coordo add foreignkey barbd_001.barbD_tax3 for_mf_tax3.tax3 --package catalog/inventaire_for

# All 4 Trees - Inventaire Biologique
coordo add kobotoolbox data/all4trees/inventaire_bio/20260422_InventaireBiologique_DonneesK.xlsx --form data/all4trees/inventaire_bio/20260519_InventaireBiologique_QuestionnaireK.xlsx --package catalog/inventaire_bio
coordo add file data/all4trees/inventaire_bio/20260422_InventaireBiologique_DonneesExternes.xlsx --package catalog/inventaire_bio
coordo add kobotoolbox data/all4trees/inventaire_bio/20260710_InventaireBiologique_DonneesK.xlsx --form data/all4trees/inventaire_bio/20260709_InventaireBiologique_QuestionnaireK.xlsx --package catalog/inventaire_bio
coordo add file data/all4trees/inventaire_bio/20260713_InventaireBiologique_DonneesExternes.xlsx --package catalog/inventaire_bio

coordo add foreignkey inv_bio.proj bio_samp.proj --package catalog/inventaire_bio
coordo add foreignkey inv_bio.year bio_pop.year --package catalog/inventaire_bio
coordo add foreignkey inv_001.tax3 bio_sp.tax3 --package catalog/inventaire_bio

# All 4 Trees - Enquête ménage
coordo add kobotoolbox data/all4trees/enquete/20260422_EnqueteMenage_DonneesK.csv --form data/all4trees/enquete/20260519_EnqueteMenage_QuestionnaireK.xlsx --package catalog/enquete
Expand Down
45 changes: 40 additions & 5 deletions backend/configs/all4trees_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"resource": "inv_for",
"layerType": "symbol",
"cluster": {
"radius": 50,
"maxZoom": 12.5,
"radius": 40,
"maxZoom": 12,
"steps": [10, 20],
"colors": ["#99D6C2", "#009966", "#006B47"]
"colors": ["rgba(153,214,194,0.7)", "rgba(0,153,102,0.7)", "rgba(0,107,71,0.7)"]
},
"columns": {
"id": "_id",
Expand Down Expand Up @@ -91,6 +91,41 @@
"trigger": "click"
}
},
{
"id": "inventaire_bio",
"type": "datapackage",
"path": "../catalog/inventaire_bio",
"resource": "inv_bio",
"layerType": "symbol",
"cluster": {
"radius": 40,
"maxZoom": 12,
"steps": [10, 20],
"colors": ["rgba(249,128,56,0.7)", "rgba(199,102,44,0.7)", "rgba(149,76,33,0.7)"]
},
"columns": {
"geom": "start_point.merge().centroid()",
"id": "_id",
"conf": "conf",
"proj": "proj",
"ecos": "ecos",
"region": "loc1",
"forest": "loc2",
"start_date": "coh",
"taxon": "tax",
"type": "meth",
"samp_area": "inv_samp",
"samp_unit": "inv_unit",
"density": "int(sum(inv_001.no)) / inv_samp",
"dens_unit": "dens_unit",
"richness": "inv_001.count(no)",
"taxons_abundance_pop": "list_concat(list(inv_001.concat_ws(':', concat_ws('-',tax1, tax2, tax3), no) if inv_001.no > 0))",
"taxons_total_pop": "int(sum(inv_001.no))"
},
"popup": {
"trigger": "click"
}
},
{
"id": "enquete",
"type": "datapackage",
Expand All @@ -100,9 +135,9 @@
"groupby": ["loc2"],
"cluster": {
"radius": 50,
"maxZoom": 12.5,
"maxZoom": 12,
"steps": [10, 20],
"colors": ["#A1B5F5", "#1447E6", "#0E32A1"]
"colors": ["rgba(161,181,245,0.7)", "rgba(20,71,230,0.7)", "rgba(14,50,161,0.7)"]
},
"columns": {
"geom": "centroid(merge(point(enq_gps.long, enq_gps.latit)))",
Expand Down
3 changes: 2 additions & 1 deletion backend/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import stats
from .datapackage_manager import DatapackageManager

ALL4TREES_LAYERS = ['inventaire_for', 'enquete']
ALL4TREES_LAYERS = ['inventaire_for', 'enquete', 'inventaire_bio']

config_path = settings.BASE_DIR / "configs" / "all4trees_config.json"
map = Map.from_file(config_path)
Expand Down Expand Up @@ -108,6 +108,7 @@ def remove_foreign_key_view(request):

def get_map(user):
user_map = copy(map)
filter = ''
if user.is_authenticated:
project = user.project
if (project.lower() != ADMIN_PROJECT):
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
asgiref==3.8.1
chardet==7.4.3
coordo @ git+https://github.com/dataforgoodfr/Coordonnees.git@0.8.0#subdirectory=coordo-py
coordo @ git+https://github.com/dataforgoodfr/Coordonnees.git@0.8.1#subdirectory=coordo-py
Django>=4.2.27
djangorestframework==3.16.0
djangorestframework_simplejwt==5.5.1
Expand Down
5 changes: 4 additions & 1 deletion webapp/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"assist": {
"actions": {
"source": {
"organizeImports": {
"organizeImports": {
"level": "on",
"options": {
"groups": [
Expand All @@ -16,6 +16,7 @@
"!@pages/**",
"!@widgets/**",
"!@features/**",
"!@entities/**",
"!@shared/**",
"!@lib/**",
"!@i18n",
Expand All @@ -31,6 +32,8 @@
":BLANK_LINE:",
"@features/**",
":BLANK_LINE:",
"@entities/**",
":BLANK_LINE:",
"@shared/**",
"@lib/**",
"@i18n",
Expand Down
16 changes: 1 addition & 15 deletions webapp/src/app/providers/map-provider-all4trees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { useCategoriesFilters } from "@features/categories-filters/use-categorie
import { renderAnchor, renderLayerRow } from "@features/controls/layer-control";

import { API_URL } from "@shared/api/client";
import {
type Category,
MapContext,
} from "@shared/contexts/map-context-all4trees";
import { MapContext } from "@shared/contexts/map-context-all4trees";
import { useLocalStorage } from "@shared/hooks/use-local-storage";
import { createMap, EVENTS } from "@shared/lib/coordo";

Expand All @@ -33,7 +30,6 @@ export function MapProviderAll4Trees({ children }: MapProviderAll4TreesProps) {
const { isAuthenticated, token } = useAuth();

const mapApiRef = useRef<ReturnType<typeof createMap> | null>(null);
const [forests, setForests] = useState<Category[]>([]);
const [mapSettings, setMapSettings] = useLocalStorage<MapSettings>(
"d4g:map-settings:all4trees",
DEFAULT_MAP_SETTINGS,
Expand All @@ -54,14 +50,6 @@ export function MapProviderAll4Trees({ children }: MapProviderAll4TreesProps) {

const handleReady = () => {
setIsReady(true);
// biome-ignore lint/suspicious/noExplicitAny : <no types from the lib coordo>
const metadata: any = mapApiRef.current?.getLayerMetadata("inventaire");
const forestField = metadata?.schema?.fields?.find(
(f: { name: string }) => f.name === "for",
);
if (forestField?.categories) {
setForests(forestField.categories);
}

// On first mount, sync the map state with the local storage state of "categories-filters"
syncInitialCategoriesFilters({
Expand Down Expand Up @@ -104,12 +92,10 @@ export function MapProviderAll4Trees({ children }: MapProviderAll4TreesProps) {
<MapContext
value={{
categoriesFilters,
forests,
isReady,
mapApiRef,
mapContainerRef,
setCategoriesFilters,
setForests,
setIsReady,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/app/styles/all4trees.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
--chart-3: var(--a4t-color-citrouille);
--chart-4: var(--a4t-color-vert-de-gris);
--chart-5: #895bf5;
--chart-6: var(--a4t-color-onyx);
--chart-6: #da4238f3;

--sidebar: var(--a4t-color-alabaster);
--sidebar-foreground: var(--a4t-color-alabaster);
Expand Down
25 changes: 25 additions & 0 deletions webapp/src/entities/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type ExternalData = {
for_label: LabelData[];
bio_label: LabelData[];
bio_sp: BioSpeciesData[];
for_mf_tax1: any[];
for_mf_tax2: any[];
for_mf_tax3: any[];
// Index signature pour accepter d'autres clés dynamiques si besoin
[key: string]: any[];
};

export type LabelData = {
proj: string;
list_name: string;
name: number;
"label::fr": string;
"label::en": string;
};

export type BioSpeciesData = {
proj: string;
tax3: number;
"stat::fr": string;
"stat::en": string;
};
16 changes: 16 additions & 0 deletions webapp/src/entities/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LAYERS } from "@shared/api/layers";

export const EXTERNAL_RESOURCES_BY_LAYER = new Map<string, string[]>([
[
LAYERS.INVENTORY_FOR,
["for_label", "for_mf_tax1", "for_mf_tax2", "for_mf_tax3", "for_score"],
],
[LAYERS.INVENTORY_BIO, ["bio_label", "bio_sp"]],
[LAYERS.ENQUETE, [""]],
[LAYERS.SEED_POINT, [""]],
]);

export const LABEL_DATA = new Map<string, string>([
[LAYERS.INVENTORY_FOR, "for_label"],
[LAYERS.INVENTORY_BIO, "bio_label"],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export const useCategoriesConfig = (): {

// ----- Actions -----

const actionInventary: CategoryGroupItem = {
const actionInventory: CategoryGroupItem = {
icon: (
<TreePineIcon
className="text-inventaire"
size={ICON_SIZE}
/>
),
identifier: CATEGORY_IDENTIFIERS.ACTION_INVENTARY,
label: t("filters.categories.actions.forestInventary"),
identifier: CATEGORY_IDENTIFIERS.ACTION_INVENTORY,
label: t("filters.categories.actions.forestInventory"),
};

const actionDiversity: CategoryGroupItem = {
Expand Down Expand Up @@ -111,7 +111,7 @@ export const useCategoriesConfig = (): {
};

return {
actions: [actionInventary, actionDiversity, actionSocioEco],
actions: [actionInventory, actionDiversity, actionSocioEco],
data: [dataGround, dataSatellite, dataModel],
system: [
systemMangroveHigh,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const useCategoriesFilters = () => {
const [categoriesFilters, setCategoriesFilters] =
useLocalStorage<CategoriesFiltersState>("categories-filters", {
[CATEGORY_IDENTIFIERS.ACTION_DIVERSITY]: true,
[CATEGORY_IDENTIFIERS.ACTION_INVENTARY]: true,
[CATEGORY_IDENTIFIERS.ACTION_INVENTORY]: true,
[CATEGORY_IDENTIFIERS.ACTION_BIO]: true,
[CATEGORY_IDENTIFIERS.ACTION_SOCIO]: true,
[CATEGORY_IDENTIFIERS.DATA_GROUND]: true,
[CATEGORY_IDENTIFIERS.DATA_MODEL]: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { findLabelInExternalData } from "@features/indicators/utils";
import type { ExternalData } from "@features/popup/forest-inventory/types";
import { findLabel } from "@features/indicators/utils";

import { useTranslation } from "@shared/i18n";
import type { LabelData } from "@entities/data";

import { i18nInstance, useTranslation } from "@shared/i18n";
import type { ChartConfig } from "@shared/ui/chart";

import type { ChartComponentType } from "../components/chart-component";
Expand All @@ -10,15 +11,16 @@ import { PieChartCategorical } from "../components/pie-chart-categorical";
type PieChartProps = {
project: string;
data: Record<string, number>;
externalData: ExternalData;
metadata: LabelData[];
};

export const ChartRelativeAbundance: ChartComponentType<PieChartProps> = ({
project,
data,
externalData,
metadata,
}) => {
const { t } = useTranslation("all4trees");
const lang = i18nInstance.language;
const smallCategoriesSum = Object.values(data)
.filter((value) => value < 5)
.reduce((acc, value) => acc + value, 0);
Expand All @@ -39,13 +41,8 @@ export const ChartRelativeAbundance: ChartComponentType<PieChartProps> = ({
...chartConfig,
[element.name]: {
label:
findLabelInExternalData(
externalData,
"for_label",
project,
"ess",
Number(element.name),
) || element.name,
findLabel(metadata, project, lang, "ess", Number(element.name)) ||
element.name,
},
other: {
label: t(
Expand Down
Loading
Loading