From e20a251cb2ec9a9ae499bd67efa44ab084ae11d5 Mon Sep 17 00:00:00 2001 From: Nighty3098 <154594695+Nighty3098@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:39:46 +0700 Subject: [PATCH] Fixed a bug where incorrect percentages were displayed in the user profile when there were no projects or tasks in the user profile --- src/CodeKeeper/CodeKeeper_ru_RU.ts | 190 ++++++++++++---------- src/CodeKeeper/accountFunc/functional.cpp | 102 ++++++++++-- 2 files changed, 193 insertions(+), 99 deletions(-) diff --git a/src/CodeKeeper/CodeKeeper_ru_RU.ts b/src/CodeKeeper/CodeKeeper_ru_RU.ts index 4b2d8123..2045742e 100644 --- a/src/CodeKeeper/CodeKeeper_ru_RU.ts +++ b/src/CodeKeeper/CodeKeeper_ru_RU.ts @@ -4,14 +4,14 @@ AccountWindow - + Public repos: Публичные репозитории: - + Following: @@ -20,7 +20,7 @@ Following: Подписки: - + Followers: @@ -29,7 +29,7 @@ Followers: Подписчики: - + Stars: @@ -38,20 +38,30 @@ Stars: Звёзды: - + Completed Выполнено - + Started Начато - + Not Started Не начато + + + None + Отсутствуют + + + + Other + Другие + Not started projects: Не начато: @@ -69,22 +79,22 @@ Stars: Закончено: - + Not started Не начато - + In Dev В разработке - + On Review На ревью - + Finished Закончено @@ -101,7 +111,7 @@ Tasks Задачи - + Projects @@ -114,7 +124,7 @@ Projects Проекты - + Languages @@ -123,13 +133,14 @@ Languages Языки - - + + + Loading... Загрузка... - + Open Git Открыть GIT @@ -137,26 +148,26 @@ Languages MainWindow - + - + Notes Заметки - + - - + + Tasks Задачи - + - - - + + + Projects Проекты @@ -466,62 +477,62 @@ Languages Введите новое название: - + Repo Репозиторий - + Created at Создан - + Open issues Открытые проблемы - + Forks Форки - + Lang Языки - + Stars Звёзды - + Repo size Размер - + License Лицензия - + Last commit Последняя выгрузка - + Downloads Скачивания - + Release Релиз - + Release at Дата релиза @@ -538,7 +549,7 @@ Languages - + Save Сохранить @@ -570,12 +581,13 @@ Languages Проблемы - + + Edit task Изменить - + Cancel Отмена @@ -585,98 +597,98 @@ Languages - + ~ CodeKeeper ~ - + Settings Настройки - + Sync Синхронизация - + Account Аккаунт - + Just start typing - + Note Заметка - + Incomplete Незавершенные - + Inprocess В процессе - + Complete Выполнено - + Task... Задача... - + Not started Не начато - + Started Начато - + For review На ревью - + Finished Закончено - + Homepage Домашняя страница - + Doc Документация - + Home Домашняя страница - - + + Welcome, Добро пожаловать, - + ! You have @@ -685,12 +697,12 @@ You have У тебя - + uncompleted tasks out of невыполненных задач из - + ! You have completed all of your tasks for the day. Good job! @@ -937,22 +949,22 @@ You have completed all of your tasks for the day. Good job! Кастомная тема - + Dark Темная - + Light Светлая - + English Английский - + Russian Русский @@ -969,113 +981,113 @@ You have completed all of your tasks for the day. Good job! Испанский - + Language: Язык - + Storage settings Параметры хранилища - - + + Directory Директория - + Projects content Проект - + Created time Дата создания - + Last release time Дата релиза - + Last commit time Дата последней выгрузки - + Total pull requests Количество prs - + License Лицензия - + Release Релиз - + Issues Проблемы - + Downloads Скачивания - + Commits Commits - + Langs Языки - + Stars Звёзды - + Forks Форки - + Repo size Размер репозитория - + About О приложении - + Sync Синхронизация - + Storage Хранилище - + Appereance Оформление - + Projects Проекты diff --git a/src/CodeKeeper/accountFunc/functional.cpp b/src/CodeKeeper/accountFunc/functional.cpp index a72e9a21..aae8bb7a 100644 --- a/src/CodeKeeper/accountFunc/functional.cpp +++ b/src/CodeKeeper/accountFunc/functional.cpp @@ -325,9 +325,39 @@ void AccountWindow::setTasksProgress() double percentage = static_cast(completeTasksCount) / static_cast(totalTasks) * 100.0; - double complete_percentage = static_cast(completeTasksCount) / static_cast(totalTasks) * 100.0; - double started_percentage = static_cast(inprocessTasksCount) / static_cast(totalTasks) * 100.0; - double ns_percentage = static_cast(incompleteTasksCount) / static_cast(totalTasks) * 100.0; + double complete_percentage, started_percentage, ns_percentage; + + if (completeTasksCount <= 0) + { + complete_percentage = 0.0; + } + else + { + complete_percentage = static_cast(completeTasksCount) / static_cast(totalTasks) * 100.0; + } + + if (inprocessTasksCount <= 0) + { + started_percentage = 0.0; + } + else + { + started_percentage = static_cast(inprocessTasksCount) / static_cast(totalTasks) * 100.0; + } + + if (incompleteTasksCount <= 0) + { + ns_percentage = 0.0; + } + else + { + ns_percentage = static_cast(incompleteTasksCount) / static_cast(totalTasks) * 100.0; + } + + if (totalTasks <= 0) + { + tasksStatsProgress->hide(); + } qDebug() << completeTasksCount << "/" << totalTasks; @@ -363,13 +393,50 @@ void AccountWindow::setProjectsStats() int finishlineProjectsCount = mainWindow->finishedProjects->count(); int finishedProjectsCount = mainWindow->finishlineProjects->count(); + float ns_p, s_p, fl_p, f_p; + int totalProjects = notStartedProjectsCount + startedProjectsCount + finishlineProjectsCount + finishedProjectsCount; - float ns_p = static_cast(notStartedProjectsCount) / static_cast(totalProjects) * 100.0; - float s_p = static_cast(startedProjectsCount) / static_cast(totalProjects) * 100.0; - float fl_p = static_cast(finishlineProjectsCount) / static_cast(totalProjects) * 100.0; - float f_p = static_cast(finishedProjectsCount) / static_cast(totalProjects) * 100.0; + if (notStartedProjectsCount <= 0) + { + ns_p = 0.0; + } + else + { + ns_p = static_cast(notStartedProjectsCount) / static_cast(totalProjects) * 100.0; + } + if (startedProjectsCount <= 0) + { + s_p = 0.0; + } + else + { + s_p = static_cast(startedProjectsCount) / static_cast(totalProjects) * 100.0; + } + if (finishlineProjectsCount <= 0) + { + fl_p = 0.0; + } + else + { + fl_p = static_cast(finishlineProjectsCount) / static_cast(totalProjects) * 100.0; + } + if (finishedProjectsCount <= 0) + { + f_p = 0.0; + } + else + { + f_p = static_cast(finishedProjectsCount) / static_cast(totalProjects) * 100.0; + } + + if (totalProjects == 0) + { + projectsChart->hide(); + } + + qDebug() << "Projects: " << ns_p << " " << s_p << " " << fl_p << " " << f_p << " " << totalProjects; projectsChart->setMaximumValue(100); @@ -387,8 +454,14 @@ void AccountWindow::setProjectsStats() void AccountWindow::setLangsStats(const QString langsData) { QStringList langsColors; - langsColors << "#c75d5e" << "#e09132" << "#b1e032" << "#78b3ba" - << "#5dc7c3" << "#c75da9" << "#c7c25d" << "#875dc7"; + langsColors << "#c75d5e" + << "#e09132" + << "#b1e032" + << "#78b3ba" + << "#5dc7c3" + << "#c75da9" + << "#c7c25d" + << "#875dc7"; QStringList result = langsData.split(' '); int count = result.size() / 2; @@ -408,7 +481,16 @@ void AccountWindow::setLangsStats(const QString langsData) } langsChart->addValue(other, QColor("#333333")); - langsValuesDisplay->addValue("Other", other, "#333333", selectedFont); langsTitle->setText(tr("\n\nLanguages")); + + if (count <= 0) + { + langsChart->hide(); + langsValuesDisplay->addValue(tr("None"), other, "#333333", selectedFont); + } + else + { + langsValuesDisplay->addValue(tr("Other"), other, "#333333", selectedFont); + } }