Skip to content
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
15 changes: 7 additions & 8 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ catalog:
coordo add foreignkey inv_bio.year bio_pop.year --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
coordo add file data/all4trees/enquete/20260422_EnqueteMenage_DonneesExternes.xlsx --package catalog/enquete

coordo add foreignkey enquete_menage.proj enq_samp.proj --package catalog/enquete
coordo add foreignkey enquete_menage.typ enq_pop.typ --package catalog/enquete
coordo add foreignkey enquete_menage.loc2 enq_gps.loc2 --package catalog/enquete
coordo add foreignkey enquete_menage.fw_cod enq_fw.fw_cod --package catalog/enquete
coordo add foreignkey enquete_menage.coal_unit enq_coal.coal_unit --package catalog/enquete
coordo add kobotoolbox data/all4trees/enquete/20260709_EnqueteMenage_DonneesK.xlsx --form data/all4trees/enquete/20260519_EnqueteMenage_QuestionnaireK.xlsx --package catalog/enquete
coordo add file data/all4trees/enquete/20260713_EnqueteMenage_DonneesExternes.xlsx --package catalog/enquete

coordo add foreignkey enquete_menage.proj hh_samp.proj --package catalog/enquete
coordo add foreignkey enquete_menage.loc2 hh_gps.loc2 --package catalog/enquete
coordo add foreignkey enquete_menage.fw_cod hh_fw.fw_cod --package catalog/enquete
coordo add foreignkey enquete_menage.coal_unit hh_coal.coal_unit --package catalog/enquete

# Seed - Survey
coordo add file data/seed/survey.zip --package catalog/seed
Expand Down
12 changes: 7 additions & 5 deletions backend/configs/all4trees_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,21 @@
"path": "../catalog/enquete",
"resource": "enquete_menage",
"layerType": "symbol",
"groupby": ["loc2"],
"groupby": ["loc2", "year"],
"cluster": {
"radius": 50,
"maxZoom": 12,
"steps": [10, 20],
"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)))",
"geom": "centroid(merge(point(hh_gps.long, hh_gps.latit)))",
"project": "first(proj)",
"loc1": "first(loc1)",
"household_nb": "count(_id)",
"population": "sum(res)",
"fuel_sources": "list_aggregate(flatten(list(ener)), 'histogram')",
"wood_fuel_cons": "sum( 12 * ( ifnull(fw_qty * enq_fw.fw_vol * fw_freq, 0) + ifnull(coal_qty * enq_coal.coal_kg * coal_freq * enq_coal.coal_fw, 0) / enq_coal.coal_dens )) / sum(res)",
"wood_fuel_cons": "sum( 12 * ( ifnull(fw_qty * hh_fw.fw_vol * fw_freq, 0) + ifnull(coal_qty * hh_coal.coal_kg * coal_freq * hh_coal.coal_fw, 0) / hh_coal.coal_dens )) / sum(res)",
"firewood_collec_time": "avg(ifnull(coll_freq, 0) * ifnull(coll_dur, 0) / 30)",
"firewood_satis": "histogram(wf_satis if int(wf_satis) > 0)",
"firewood_satis_tot": "count(1 if int(wf_satis) > 0)",
Expand All @@ -161,15 +163,15 @@
"timber_satis": "histogram(timb_satis if timb_yn = '1')",
"timber_satis_tot": "count(1 if timb_yn = '1')",
"lean_period": "avg(len(lean) if lean_yn = 1)",
"lean_months": "list_aggregate(flatten(list(lean)), 'histogram')",
"food_diversity": "list_aggregate(flatten(list(food_cons)), 'histogram')",
"food_diversity_score": "avg(list_unique(food_cons) / int(food_cons_max) * 10)",
"food_self_suff_score": "avg(ifnull(list_unique(food_self), 0) / list_unique(food_cons) * 100)",
"food_self_suff_score": "avg( ((0 if list_contains(food_self, '<NA>') else list_unique(food_self)) / list_unique(food_cons) * 100) if list_contains(food_cons, '<NA>') != 'true')",
"living_cond_perception": "histogram(cond_evol)",
"revenue_change": "avg(0 - inc_dif if inc_evol = '2' else ifnull(inc_dif, 0))",
"assets_idx_raw": "avg( ( ( int(hous_typ) + int(hous_size)) * int(hous_own) + ifnull(list_unique(ass),0) + int(lvst_yn) * ( int(lvst_s) + int(lvst_l) ) + ( int( land_own ) + int( land_titl ) + int( land_size ) if int(land_own) > 0 else 0) ) if ( ( int(hous_typ) + int(hous_size)) * int(hous_own) + list_unique(ass) + int(lvst_yn) * ( int(lvst_s) + int(lvst_l) ) + int( land_own ) + int( land_titl ) + int( land_size ) ) <= int(ass_tot_max) )",
"assets_idx": "10 / int(ass_tot_max) * avg( ( ( int(hous_typ) + int(hous_size)) * int(hous_own) + ifnull(list_unique(ass),0) + int(lvst_yn) * ( int(lvst_s) + int(lvst_l) ) + ( int( land_own ) + int( land_titl ) + int( land_size ) if int(land_own) > 0 else 0) ) if ( ( int(hous_typ) + int(hous_size)) * int(hous_own) + list_unique(ass) + int(lvst_yn) * ( int(lvst_s) + int(lvst_l) ) + int( land_own ) + int( land_titl ) + int( land_size ) ) <= int(ass_tot_max) )",
"nb_income_sources" : "avg(int(inc_no))",
"nb_additional_incomes": "'N/A'",
"benef_pract1": "count(1 if int(pract1) = 2) / count(1) * 100",
"benef_pract2": "count(1 if int(pract2) = 2) / count(1) * 100",
"benef_pract3": "count(1 if int(pract3) = 2) / count(1) * 100",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/entities/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type ExternalData = {
for_label: LabelData[];
bio_label: LabelData[];
hh_label: LabelData[];
bio_sp: BioSpeciesData[];
for_mf_tax1: any[];
for_mf_tax2: any[];
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/entities/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export const EXTERNAL_RESOURCES_BY_LAYER = new Map<string, string[]>([
["for_label", "for_mf_tax1", "for_mf_tax2", "for_mf_tax3", "for_score"],
],
[LAYERS.INVENTORY_BIO, ["bio_label", "bio_sp"]],
[LAYERS.ENQUETE, [""]],
[LAYERS.ENQUETE, ["hh_label"]],
[LAYERS.SEED_POINT, [""]],
]);

export const LABEL_DATA = new Map<string, string>([
[LAYERS.INVENTORY_FOR, "for_label"],
[LAYERS.INVENTORY_BIO, "bio_label"],
[LAYERS.ENQUETE, "hh_label"],
]);
8 changes: 8 additions & 0 deletions webapp/src/entities/socio-eco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SOCIO_LABEL_FIELDS = {
BENEFICIAL_PRACTICES: "pract",
ENERGY_SOURCES: "ener",
EVOLUTION: "evol",
FOOD_CONSOMMATION: "food_cons",
LEAN_MONTHS: "lean",
SATISFACTION: "satis",
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findLabel } from "@features/indicators/utils";
import { findLabel } from "@features/indicators/labels";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findStatus } from "@features/indicators/utils";
import { findStatus } from "@features/indicators/labels";

import type { BioSpeciesData } from "@entities/data";

Expand Down
16 changes: 12 additions & 4 deletions webapp/src/features/charts/components/bar-chart-benef-control.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PropsWithChildren } from "react";
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";

import { useTranslation } from "@shared/i18n";
Expand All @@ -10,21 +11,24 @@ import {
import type { ChartComponentType } from "./chart-component";
import { ChartComponent } from "./chart-component";

type BarChartProps = {
type BarChartProps = PropsWithChildren<{
title: string;
chartData: Array<{ indicator: string; benef: unknown; temoin?: unknown }>;
legendLabel: string;
unit?: string;
withTemoin?: boolean;
layout?: { chartHeight: number; chartXAxisHeight: number };
};
description?: string;
}>;

export const BarCharWithBenefAndControl: ChartComponentType<BarChartProps> = ({
title,
chartData,
legendLabel,
unit = "",
withTemoin = false,
description,
children,
}) => {
const { t } = useTranslation("all4trees");
const chartConfig = {
Expand Down Expand Up @@ -56,10 +60,14 @@ export const BarCharWithBenefAndControl: ChartComponentType<BarChartProps> = ({
};

return (
<ChartComponent title={title}>
<ChartComponent
description={description}
title={title}
>
{children}
<ChartContainer
// Style: Extend the width to the container, but enforce the height for XAxis alignment
className="mx-auto h-110 max-h-110 w-full max-w-full"
className="mx-auto h-110 max-h-110 w-full max-w-full my-5"
config={chartConfig}
>
<BarChart
Expand Down
63 changes: 63 additions & 0 deletions webapp/src/features/charts/components/labeled-bar-chart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { PropsWithChildren } from "react";

import { findLabel } from "@features/indicators/labels";

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

import { i18nInstance, useTranslation } from "@shared/i18n";

import { BarCharWithBenefAndControl } from "./bar-chart-benef-control";
import type { ChartComponentType } from "./chart-component";

type Data = {
[key: string]: number;
};

type LabeledBarChartProps = PropsWithChildren<{
benef: Data;
temoin?: Data;
metadata: LabelData[];
project: string;
labelField: string;
title: string;
legendLabel: string;
description?: string;
}>;

export const LabeledBarChart: ChartComponentType<LabeledBarChartProps> = ({
benef,
temoin,
metadata,
project,
labelField,
legendLabel,
title,
description,
children,
}) => {
const { t } = useTranslation("common");
const lang = i18nInstance.language;

const chartData = Object.entries(benef).map(([key, value]) => ({
benef: value,
indicator:
findLabel(metadata, project, lang, labelField, key) ||
t("dataManagement.undefined"),
temoin: temoin?.[key as keyof typeof temoin],
}));

return (
<BarCharWithBenefAndControl
chartData={chartData}
description={description}
legendLabel={legendLabel}
title={title}
unit="%"
withTemoin={!!temoin}
>
{children}
</BarCharWithBenefAndControl>
);
};

LabeledBarChart.isChartComponent = true;
61 changes: 61 additions & 0 deletions webapp/src/features/charts/components/labeled-pie-chart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { findLabel } from "@features/indicators/labels";

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

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

import type { ChartComponentType } from "./chart-component";
import { PieChartCategorical, renderLabel } from "./pie-chart-categorical";

type LabeledPieChartProps = {
project: string;
metadata: LabelData[];
data: {
[key: string]: number;
};
title: string;
labelField: string;
colorMap: Map<string, string>;
};

export const LabeledPieChart: ChartComponentType<LabeledPieChartProps> = ({
data,
metadata,
project,
title,
colorMap,
labelField,
}) => {
const { t } = useTranslation("common");
const lang = i18nInstance.language;

const chartData = Object.entries(data).map(([key, value]) => ({
fill: colorMap.get(key) || "var(--chart-4)",
name: key,
value,
}));

const chartConfig = chartData.reduce((acc, item) => {
acc[item.name as keyof typeof acc] = {
label:
findLabel(metadata, project, lang, labelField, item.name) ||
t("dataManagement.undefined"),
};
return acc;
}, {} as ChartConfig) satisfies ChartConfig;

return (
<PieChartCategorical
chartConfig={chartConfig}
chartData={chartData}
title={title}
unit="%"
withLabel={(props) =>
renderLabel({ ...props, chartConfig, linebreak: 18 })
}
/>
);
};

LabeledPieChart.isChartComponent = true;
2 changes: 1 addition & 1 deletion webapp/src/features/charts/components/lib/taxon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findLabel } from "@features/indicators/utils";
import { findLabel } from "@features/indicators/labels";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { lineBreakLabel } from "../utils";
import type { ChartComponentType } from "./chart-component";
import { ChartComponent } from "./chart-component";

export const description = "A pie chart with a label";

export type PieChartCategoricalProps = {
title: string;
chartData: Array<{ name: string; value: number; fill: string }>;
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/features/charts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { BarCharWithBenefAndControl } from "./components/bar-chart-benef-control";
export { ChartComponent } from "./components/chart-component";
export { ChartTaxonAbundance } from "./components/chart-taxon-abundance";
export { LabeledBarChart } from "./components/labeled-bar-chart";
export { LabeledPieChart } from "./components/labeled-pie-chart";
export { PieChartCategorical } from "./components/pie-chart-categorical";
export { ChartRadarWithBenefAndControl } from "./components/radar-benef-control";

This file was deleted.

Loading
Loading