feat: add progress percentage calculation to task sections
This commit is contained in:
@@ -89,6 +89,7 @@ public class ProjectSectionDto
|
||||
|
||||
public TimeSpan FinalEstimatedHours { get; set; }
|
||||
public TimeSpan TotalTimeSpent { get; set; }
|
||||
public double ProgressPercentage { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
public bool IsInProgress { get; set; }
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ public static class ProjectMappingExtensions
|
||||
CreationDate = section.CreationDate,
|
||||
FinalEstimatedHours = section.FinalEstimatedHours,
|
||||
TotalTimeSpent = section.GetTotalTimeSpent(),
|
||||
ProgressPercentage = section.GetProgressPercentage(),
|
||||
IsCompleted = section.IsCompleted(),
|
||||
IsInProgress = section.IsInProgress(),
|
||||
Activities = section.Activities.Select(a => a.ToDto()).ToList(),
|
||||
@@ -188,6 +189,7 @@ public static class ProjectMappingExtensions
|
||||
CreationDate = section.CreationDate,
|
||||
FinalEstimatedHours = section.FinalEstimatedHours,
|
||||
TotalTimeSpent = section.GetTotalTimeSpent(),
|
||||
ProgressPercentage = section.GetProgressPercentage(),
|
||||
IsCompleted = section.IsCompleted(),
|
||||
IsInProgress = section.IsInProgress()
|
||||
// No activities or additional times for summary
|
||||
|
||||
@@ -157,6 +157,27 @@ public class TaskSection : EntityBase<Guid>
|
||||
return TimeSpan.FromTicks(_activities.Sum(a => a.GetTimeSpent().Ticks));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// محاسبه درصد پیشرفت بر اساس زمان مصرف شده به تایم برآورد شده
|
||||
/// اگر وضعیت Completed باشد، همیشه 100 درصد برمیگرداند
|
||||
/// </summary>
|
||||
public double GetProgressPercentage()
|
||||
{
|
||||
// اگر تسک کامل شده، همیشه 100 درصد
|
||||
if (Status == TaskSectionStatus.Completed)
|
||||
return 100.0;
|
||||
|
||||
// اگر تایم برآورد شده صفر است، درصد صفر است
|
||||
if (FinalEstimatedHours.TotalHours <= 0)
|
||||
return 0.0;
|
||||
|
||||
var timeSpent = GetTotalTimeSpent();
|
||||
var percentage = (timeSpent.TotalHours / FinalEstimatedHours.TotalHours) * 100.0;
|
||||
|
||||
// محدود کردن درصد به 100 (در صورتی که زمان مصرف شده بیشتر از تخمین باشد)
|
||||
return Math.Min(percentage, 100.0);
|
||||
}
|
||||
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return Status == TaskSectionStatus.Completed;
|
||||
|
||||
Reference in New Issue
Block a user