вычисление общей конверсии

This commit is contained in:
Tamara 2024-04-11 01:29:02 +03:00
parent af4c68304a
commit f0f5b1fe96
5 changed files with 24 additions and 20 deletions

@ -113,6 +113,7 @@ export default function Analytics() {
} }
}; };
console.log(general);
const now = moment(); const now = moment();
return ( return (
<LocalizationProvider dateAdapter={AdapterMoment}> <LocalizationProvider dateAdapter={AdapterMoment}>

@ -270,7 +270,8 @@ export const Answers: FC<AnswersProps> = ({ data }) => {
color: theme.palette.brightPurple.main, color: theme.palette.brightPurple.main,
}, },
}} }}
>Заголовок вопроса. >
Заголовок вопроса.
{currentAnswer?.[0].split("(")[0].trim() {currentAnswer?.[0].split("(")[0].trim()
? ` ${currentAnswer?.[0]}` ? ` ${currentAnswer?.[0]}`
: "Без заголовка"} : "Без заголовка"}

@ -11,6 +11,7 @@ type GeneralItemsProps = {
color: string; color: string;
numberType: "sum" | "percent" | "time"; numberType: "sum" | "percent" | "time";
calculateTime?: boolean; calculateTime?: boolean;
conversionValue?: number;
}; };
type GeneralProps = { type GeneralProps = {
@ -39,6 +40,7 @@ const GeneralItem = ({
color, color,
numberType, numberType,
calculateTime = false, calculateTime = false,
conversionValue,
}: GeneralItemsProps) => { }: GeneralItemsProps) => {
const theme = useTheme(); const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(700)); const isMobile = useMediaQuery(theme.breakpoints.down(700));
@ -46,13 +48,14 @@ const GeneralItem = ({
const numberValue = const numberValue =
numberType === "sum" numberType === "sum"
? Object.values(general).reduce((total, item) => total + item, 0) ? Object.values(general).reduce((total, item) => total + item, 0)
: 0; : title === "Конверсия"
Object.entries(general).reduce( ? conversionValue
(total, [key, value]) => total + (value / Number(key)) * 100, : 0;
0,
) / Object.keys(general).length || Number(0);
if (Object.keys(general).length === 0) { if (
Object.keys(general).length === 0 ||
Object.values(general).every((x) => x === 0)
) {
return ( return (
<Typography textAlign="center">{`${title} - нет данных`}</Typography> <Typography textAlign="center">{`${title} - нет данных`}</Typography>
); );
@ -76,7 +79,7 @@ const GeneralItem = ({
> >
<Typography sx={{ margin: "20px 20px 0" }}>{title}</Typography> <Typography sx={{ margin: "20px 20px 0" }}>{title}</Typography>
<Typography sx={{ margin: "10px 20px 0", fontWeight: "bold" }}> <Typography sx={{ margin: "10px 20px 0", fontWeight: "bold" }}>
{numberType === "percent" ? `${numberValue.toFixed()}%` : numberValue} {numberType === "percent" ? `${numberValue.toFixed(2)}%` : numberValue}
</Typography> </Typography>
<LineChart <LineChart
xAxis={[ xAxis={[
@ -117,7 +120,13 @@ export const General: FC<GeneralProps> = ({ data }) => {
</Typography> </Typography>
); );
} }
const conversionValue =
(Object.values(data.Result).reduce((total, item) => total + item, 0) /
Object.values(data.Open).reduce((total, item) => total + item, 0)) *
100;
console.log(conversionValue);
// console.log(data.Result)
return ( return (
<Box sx={{ marginTop: "45px" }}> <Box sx={{ marginTop: "45px" }}>
<Typography <Typography
@ -145,26 +154,19 @@ export const General: FC<GeneralProps> = ({ data }) => {
<GeneralItem <GeneralItem
title="Открыли квиз" title="Открыли квиз"
numberType="sum" numberType="sum"
general={ general={data.Open}
Object.entries(data.Open)
.filter(([, v]) => v > 0)
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) || { 0: 0 }
}
color={COLORS[0]} color={COLORS[0]}
/> />
<GeneralItem <GeneralItem
title="Получено заявок" title="Получено заявок"
numberType="sum" numberType="sum"
general={ general={data.Result}
Object.entries(data.Result)
.filter(([, v]) => v > 0)
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) || { 0: 0 }
}
color={COLORS[1]} color={COLORS[1]}
/> />
<GeneralItem <GeneralItem
title="Конверсия" title="Конверсия"
numberType="percent" numberType="percent"
conversionValue={conversionValue}
general={ general={
Object.entries(data.Conversion) Object.entries(data.Conversion)
.filter(([, v]) => v > 0) .filter(([, v]) => v > 0)

@ -66,7 +66,7 @@ export default function PageOptions({ disableInput, question }: Props) {
placeholder={"Можно добавить текст"} placeholder={"Можно добавить текст"}
value={question.content.text} value={question.content.text}
onChange={({ target }) => setText(target.value)} onChange={({ target }) => setText(target.value)}
maxLength={50} maxLength={700}
/> />
</Box> </Box>

@ -108,7 +108,7 @@ export default function MyQuizzesFull({
( (
(quiz.passed_count / quiz.session_count) * (quiz.passed_count / quiz.session_count) *
100 100
).toFixed(1), ).toFixed(2),
) )
: 0 : 0
} }