Унификация расчета процентов с бэкендом
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:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "play-life-web",
|
||||
"version": "3.25.3",
|
||||
"version": "3.25.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -307,6 +307,9 @@ function AppContent() {
|
||||
// Обрабатываем ответ: приходит массив с одним объектом [{total: ..., projects: [...]}]
|
||||
let projects = []
|
||||
let total = null
|
||||
let groupProgress1 = null
|
||||
let groupProgress2 = null
|
||||
let groupProgress0 = null
|
||||
|
||||
if (Array.isArray(jsonData) && jsonData.length > 0) {
|
||||
// Если ответ - массив, проверяем первый элемент
|
||||
@@ -316,6 +319,9 @@ function AppContent() {
|
||||
if (firstItem.projects && Array.isArray(firstItem.projects)) {
|
||||
projects = firstItem.projects
|
||||
total = firstItem.total !== undefined ? firstItem.total : null
|
||||
groupProgress1 = firstItem.group_progress_1 !== undefined ? firstItem.group_progress_1 : null
|
||||
groupProgress2 = firstItem.group_progress_2 !== undefined ? firstItem.group_progress_2 : null
|
||||
groupProgress0 = firstItem.group_progress_0 !== undefined ? firstItem.group_progress_0 : null
|
||||
} else {
|
||||
// Если это просто массив проектов
|
||||
projects = jsonData
|
||||
@@ -328,11 +334,17 @@ function AppContent() {
|
||||
// Если ответ - объект напрямую
|
||||
projects = jsonData.projects || jsonData.data || []
|
||||
total = jsonData.total !== undefined ? jsonData.total : null
|
||||
groupProgress1 = jsonData.group_progress_1 !== undefined ? jsonData.group_progress_1 : null
|
||||
groupProgress2 = jsonData.group_progress_2 !== undefined ? jsonData.group_progress_2 : null
|
||||
groupProgress0 = jsonData.group_progress_0 !== undefined ? jsonData.group_progress_0 : null
|
||||
}
|
||||
|
||||
setCurrentWeekData({
|
||||
projects: Array.isArray(projects) ? projects : [],
|
||||
total: total
|
||||
total: total,
|
||||
group_progress_1: groupProgress1,
|
||||
group_progress_2: groupProgress2,
|
||||
group_progress_0: groupProgress0
|
||||
})
|
||||
} catch (err) {
|
||||
setCurrentWeekError(err.message)
|
||||
|
||||
@@ -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