Унификация расчета процентов с бэкендом
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m8s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m8s
This commit is contained in:
@@ -356,46 +356,27 @@ function CurrentWeek({ onProjectClick, data, loading, error, onRetry, allProject
|
||||
})
|
||||
}
|
||||
|
||||
// Вычисляем процент выполнения для каждой группы
|
||||
const calculateGroupProgress = (projects) => {
|
||||
if (projects.length === 0) return 0
|
||||
|
||||
let totalProgress = 0
|
||||
let validProjects = 0
|
||||
|
||||
projects.forEach(project => {
|
||||
const safeTotal = Number.isFinite(project.total_score) ? project.total_score : 0
|
||||
const safeMinGoal = Number.isFinite(project.min_goal_score) ? project.min_goal_score : 0
|
||||
|
||||
if (safeMinGoal > 0) {
|
||||
const projectProgress = Math.min((safeTotal / safeMinGoal) * 100, 100)
|
||||
totalProgress += projectProgress
|
||||
validProjects++
|
||||
}
|
||||
})
|
||||
|
||||
return validProjects > 0 ? totalProgress / validProjects : 0
|
||||
}
|
||||
|
||||
const mainProgress = calculateGroupProgress(priorityGroups.main)
|
||||
const importantProgress = calculateGroupProgress(priorityGroups.important)
|
||||
const othersProgress = calculateGroupProgress(priorityGroups.others)
|
||||
|
||||
// Пересчитываем общий прогресс как среднее от групповых процентов
|
||||
const recalculatedOverallProgress = (() => {
|
||||
const groups = []
|
||||
if (priorityGroups.main.length > 0) groups.push(mainProgress)
|
||||
if (priorityGroups.important.length > 0) groups.push(importantProgress)
|
||||
if (priorityGroups.others.length > 0) groups.push(othersProgress)
|
||||
|
||||
if (groups.length === 0) return null
|
||||
|
||||
const average = groups.reduce((sum, progress) => sum + progress, 0) / groups.length
|
||||
return Math.max(0, average) // Убираем ограничение на 100% для текста
|
||||
// Получаем проценты групп из API данных
|
||||
const mainProgress = (() => {
|
||||
const rawValue = data?.group_progress_1
|
||||
const parsedValue = rawValue === undefined || rawValue === null ? null : parseFloat(rawValue)
|
||||
return Number.isFinite(parsedValue) && parsedValue >= 0 ? parsedValue : 0
|
||||
})()
|
||||
|
||||
// Используем пересчитанный общий прогресс вместо API данных
|
||||
const displayOverallProgress = recalculatedOverallProgress !== null ? recalculatedOverallProgress : (hasProgressData ? overallProgress : null)
|
||||
const importantProgress = (() => {
|
||||
const rawValue = data?.group_progress_2
|
||||
const parsedValue = rawValue === undefined || rawValue === null ? null : parseFloat(rawValue)
|
||||
return Number.isFinite(parsedValue) && parsedValue >= 0 ? parsedValue : 0
|
||||
})()
|
||||
|
||||
const othersProgress = (() => {
|
||||
const rawValue = data?.group_progress_0
|
||||
const parsedValue = rawValue === undefined || rawValue === null ? null : parseFloat(rawValue)
|
||||
return Number.isFinite(parsedValue) && parsedValue >= 0 ? parsedValue : 0
|
||||
})()
|
||||
|
||||
// Используем общий прогресс из API данных
|
||||
const displayOverallProgress = overallProgress
|
||||
|
||||
return (
|
||||
<div className="relative pt-8">
|
||||
|
||||
Reference in New Issue
Block a user