parent
00f21ffcd9
commit
e7d2a20d18
@ -0,0 +1,38 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { useFactors } from "../stores/useFactors";
|
||||||
|
import { useModel } from "../stores/useModel";
|
||||||
|
|
||||||
|
const getWeightedValueExpression = (factor, weight) => {
|
||||||
|
return ["*", ["to-number", ["get", factor]], weight];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useRateExpression = () => {
|
||||||
|
const { factors } = useFactors();
|
||||||
|
const { model } = useModel();
|
||||||
|
|
||||||
|
const result = useMemo(() => {
|
||||||
|
if (model === "ml") {
|
||||||
|
return ["get", "model"];
|
||||||
|
}
|
||||||
|
|
||||||
|
const weightSum = Object.entries(factors).reduce(
|
||||||
|
(acc, [_factor, weight]) => {
|
||||||
|
acc += weight;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
const weightedValuesSum = Object.entries(factors).reduce(
|
||||||
|
(acc, [factor, weight]) => {
|
||||||
|
acc.push(getWeightedValueExpression(factor, weight));
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
["+"]
|
||||||
|
);
|
||||||
|
|
||||||
|
return ["/", weightedValuesSum, weightSum];
|
||||||
|
}, [factors, model]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
import create from "zustand";
|
||||||
|
import { immer } from "zustand/middleware/immer";
|
||||||
|
|
||||||
|
const store = (set) => ({
|
||||||
|
model: "statistic",
|
||||||
|
setModel: (value) =>
|
||||||
|
set((state) => {
|
||||||
|
state.model = value;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useModel = create(immer(store));
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
import create from "zustand";
|
||||||
|
import { immer } from "zustand/middleware/immer";
|
||||||
|
|
||||||
|
const store = (set) => ({
|
||||||
|
geometry: null,
|
||||||
|
setRegionGeometry: (value) =>
|
||||||
|
set((state) => {
|
||||||
|
state.geometry = value;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useRegionGeometry = create(immer(store));
|
||||||
Loading…
Reference in new issue