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

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();
return (
<LocalizationProvider dateAdapter={AdapterMoment}>

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

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

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

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