Skip to content

Commit

Permalink
Merge pull request #4898 from Vulpine05/Vulpine05-3403-Revised
Browse files Browse the repository at this point in the history
Add estimated completion date and completion before deadline columns to Tasks tab
  • Loading branch information
AenBleidd authored Aug 30, 2022
2 parents 2a261b4 + 832c64b commit c134d0f
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 31 deletions.
14 changes: 10 additions & 4 deletions clientgui/MainDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2660,10 +2660,8 @@ wxString FormatTime(double secs) {
if (secs <= 0) {
return wxT("---");
}
wxInt32 iHour = (wxInt32)(secs / (60 * 60));
wxInt32 iMin = (wxInt32)(secs / 60) % 60;
wxInt32 iSec = (wxInt32)(secs) % 60;
wxTimeSpan ts = wxTimeSpan(iHour, iMin, iSec);

wxTimeSpan ts = convert_to_timespan(secs);
return ts.Format((secs>=86400)?"%Dd %H:%M:%S":"%H:%M:%S");
}

Expand All @@ -2672,6 +2670,14 @@ wxString format_number(double x, int nprec) {

}

wxTimeSpan convert_to_timespan(double secs) {
wxInt32 iHour = (wxInt32)(secs / (60 * 60));
wxInt32 iMin = (wxInt32)(secs / 60) % 60;
wxInt32 iSec = (wxInt32)(secs) % 60;
wxTimeSpan ts = wxTimeSpan(iHour, iMin, iSec);
return (ts);
}

// the autoattach process deletes the installer filename file when done
//
bool autoattach_in_progress() {
Expand Down
1 change: 1 addition & 0 deletions clientgui/MainDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ extern void remove_eols(wxString& strMessage);
extern void https_to_http(wxString& strMessage);
extern void color_cycle(int i, int n, wxColour& color);
extern wxString FormatTime(double secs);
extern wxTimeSpan convert_to_timespan(double secs);
extern bool autoattach_in_progress();


Expand Down
145 changes: 123 additions & 22 deletions clientgui/ViewWork.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2020 University of California
// Copyright (C) 2022 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -52,17 +52,21 @@
#define COLUMN_REPORTDEADLINE 5
#define COLUMN_APPLICATION 6
#define COLUMN_NAME 7
#define COLUMN_ESTIMATEDCOMPLETION 8
#define COLUMN_DEADLINEDIFF 9


// DefaultShownColumns is an array containing the
// columnIDs of the columns to be shown by default,
// in ascending order. It may or may not include
// all columns.
// Columns ESTIMATEDCOMPLETION and DEADLINEDIFF are hidden by default.
// Not all users may want to see those columns.
//
// For now, show all columns by default
static int DefaultShownColumns[] = { COLUMN_PROJECT, COLUMN_PROGRESS, COLUMN_STATUS,
COLUMN_CPUTIME, COLUMN_TOCOMPLETION,
COLUMN_REPORTDEADLINE, COLUMN_APPLICATION,
COLUMN_NAME};
COLUMN_NAME };

// groups that contain buttons
#define GRP_TASKS 0
Expand All @@ -81,7 +85,9 @@ CWork::CWork() {
m_fCPUTime = -1.0;
m_fProgress = -1.0;
m_fTimeToCompletion = -1.0;
m_tReportDeadline = (time_t)0;
m_fDeadlineDiff = -1.0;
m_tReportDeadline = (time_t)-1;
m_tEstimatedCompletion = (time_t)-1;
}


Expand All @@ -95,6 +101,8 @@ CWork::~CWork() {
m_strProgress.Clear();
m_strTimeToCompletion.Clear();
m_strReportDeadline.Clear();
m_strEstimatedCompletion.Clear();
m_strDeadlineDiff.Clear();
}


Expand Down Expand Up @@ -181,6 +189,20 @@ static bool CompareViewWorkItems(int iRowIndex1, int iRowIndex2) {
case COLUMN_STATUS:
result = work1->m_strStatus.CmpNoCase(work2->m_strStatus);
break;
case COLUMN_ESTIMATEDCOMPLETION:
if (work1->m_tEstimatedCompletion < work2->m_tEstimatedCompletion) {
result = -1;
} else if (work1->m_tEstimatedCompletion > work2->m_tEstimatedCompletion) {
result = 1;
}
break;
case COLUMN_DEADLINEDIFF:
if (work1->m_fDeadlineDiff < work2->m_fDeadlineDiff) {
result = -1;
} else if (work1->m_fDeadlineDiff > work2->m_fDeadlineDiff) {
result = 1;
}
break;
}

// Always return FALSE for equality (result == 0)
Expand Down Expand Up @@ -265,6 +287,8 @@ CViewWork::CViewWork(wxNotebook* pNotebook) :
m_aStdColNameOrder->Insert(_("Deadline"), COLUMN_REPORTDEADLINE);
m_aStdColNameOrder->Insert(_("Application"), COLUMN_APPLICATION);
m_aStdColNameOrder->Insert(_("Name"), COLUMN_NAME);
m_aStdColNameOrder->Insert(_("Estimated Completion"), COLUMN_ESTIMATEDCOMPLETION);
m_aStdColNameOrder->Insert(_("Completion Before Deadline"), COLUMN_DEADLINEDIFF);

// m_iStdColWidthOrder is an array of the width for each column.
// Entries must be in order of ascending Column ID. We initialize
Expand All @@ -281,6 +305,8 @@ CViewWork::CViewWork(wxNotebook* pNotebook) :
m_iStdColWidthOrder.Insert(150, COLUMN_REPORTDEADLINE);
m_iStdColWidthOrder.Insert(95, COLUMN_APPLICATION);
m_iStdColWidthOrder.Insert(285, COLUMN_NAME);
m_iStdColWidthOrder.Insert(150, COLUMN_ESTIMATEDCOMPLETION);
m_iStdColWidthOrder.Insert(150, COLUMN_DEADLINEDIFF);

wxASSERT(m_iStdColWidthOrder.size() == m_aStdColNameOrder->size());

Expand Down Expand Up @@ -331,6 +357,14 @@ void CViewWork::AppendColumn(int columnID){
m_pListPane->AppendColumn((*m_aStdColNameOrder)[COLUMN_NAME],
wxLIST_FORMAT_LEFT, m_iStdColWidthOrder[COLUMN_NAME]);
break;
case COLUMN_ESTIMATEDCOMPLETION:
m_pListPane->AppendColumn((*m_aStdColNameOrder)[COLUMN_ESTIMATEDCOMPLETION],
wxLIST_FORMAT_LEFT, m_iStdColWidthOrder[COLUMN_ESTIMATEDCOMPLETION]);
break;
case COLUMN_DEADLINEDIFF:
m_pListPane->AppendColumn((*m_aStdColNameOrder)[COLUMN_DEADLINEDIFF],
wxLIST_FORMAT_LEFT, m_iStdColWidthOrder[COLUMN_DEADLINEDIFF]);
break;
}
}

Expand Down Expand Up @@ -752,9 +786,15 @@ wxString CViewWork::OnListGetItemText(long item, long column) const {
case COLUMN_STATUS:
strBuffer = work->m_strStatus;
break;
case COLUMN_ESTIMATEDCOMPLETION:
strBuffer = work->m_strEstimatedCompletion;
break;
case COLUMN_DEADLINEDIFF:
strBuffer = work->m_strDeadlineDiff;
break;
}
}

return strBuffer;
}

Expand Down Expand Up @@ -870,7 +910,7 @@ void CViewWork::UpdateSelection() {
// Step through all selected items
row = m_pListPane->GetNextItem(row, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (row < 0) break; // Should never happen

result = pDoc->result(m_iSortedIndexes[row]);
if (!result) continue;
if (i == 0) {
Expand Down Expand Up @@ -919,7 +959,7 @@ void CViewWork::UpdateSelection() {
enableShowGraphics = false;
}
}

// Disable Show VM console if the selected task hasn't registered a remote
// desktop connection
//
Expand All @@ -941,7 +981,7 @@ void CViewWork::UpdateSelection() {
enableShowGraphics = false;
}
}

// Disable Abort button if any selected task already aborted
if (
result->active_task_state == PROCESS_ABORT_PENDING ||
Expand All @@ -959,7 +999,7 @@ void CViewWork::UpdateSelection() {
all_same_project = false;
}
}

if (n == 1) {
enableProperties = true;
}
Expand Down Expand Up @@ -1002,7 +1042,7 @@ void CViewWork::UpdateSelection() {
bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) {
wxString strDocumentText = wxEmptyString;
wxString strDocumentText2 = wxEmptyString;
double x = 0.0;
double x = 0.0;
time_t tDocumentTime = (time_t)0;
CWork* work;

Expand All @@ -1011,9 +1051,9 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) {
if (GetWorkCacheAtIndex(work, m_iSortedIndexes[iRowIndex])) {
return false;
}

if (iColumnIndex < 0) return false;

switch (m_iColumnIndexToColumnID[iColumnIndex]) {
case COLUMN_PROJECT:
GetDocProjectName(m_iSortedIndexes[iRowIndex], strDocumentText);
Expand Down Expand Up @@ -1066,7 +1106,39 @@ bool CViewWork::SynchronizeCacheItem(wxInt32 iRowIndex, wxInt32 iColumnIndex) {
GetDocReportDeadline(m_iSortedIndexes[iRowIndex], tDocumentTime);
if (tDocumentTime != work->m_tReportDeadline) {
work->m_tReportDeadline = tDocumentTime;
FormatReportDeadline(tDocumentTime, work->m_strReportDeadline);
FormatDateTime(tDocumentTime, work->m_strReportDeadline);
return true;
}
break;
case COLUMN_ESTIMATEDCOMPLETION:
GetDocEstCompletionDate(m_iSortedIndexes[iRowIndex], tDocumentTime);
if (tDocumentTime != work->m_tEstimatedCompletion) {
work->m_tEstimatedCompletion = tDocumentTime;
if (work->m_tEstimatedCompletion == 0) {
work->m_strEstimatedCompletion = _("---");
}
else {
FormatDateTime(tDocumentTime, work->m_strEstimatedCompletion);
}
return true;
}
break;
case COLUMN_DEADLINEDIFF:
GetDocEstDeadlineDiff(m_iSortedIndexes[iRowIndex], x);
if (x != work->m_fDeadlineDiff) {
work->m_fDeadlineDiff = x;
if (x < 0) {
// A negative difference means the task will not meet the
// deadline. Because FormatTime does not recognize negative
// numbers, the adjustment will be made here.
//
x *= -1;
work->m_strDeadlineDiff = _("-");
work->m_strDeadlineDiff += FormatTime(x);
}
else {
work->m_strDeadlineDiff = FormatTime(x);
}
return true;
}
break;
Expand Down Expand Up @@ -1185,6 +1257,7 @@ void CViewWork::GetDocCPUTime(wxInt32 item, double& fBuffer) const {
}
}


void CViewWork::GetDocProgress(wxInt32 item, double& fBuffer) const {
RESULT* result = wxGetApp().GetDocument()->result(item);

Expand Down Expand Up @@ -1219,37 +1292,65 @@ void CViewWork::GetDocTimeToCompletion(wxInt32 item, double& fBuffer) const {
}
}

void CViewWork::GetDocReportDeadline(wxInt32 item, time_t& time) const {

void CViewWork::GetDocReportDeadline(wxInt32 item, time_t& tBuffer) const {
RESULT* result = wxGetApp().GetDocument()->result(item);

if (result) {
time = (time_t)result->report_deadline;
tBuffer = (time_t)result->report_deadline;
} else {
time = (time_t)0;
tBuffer = (time_t)0;
}
}


wxInt32 CViewWork::FormatReportDeadline(time_t deadline, wxString& strBuffer) const {
// Calculates the estimated date and time a task will be completed.
// This is only calculated for active tasks. If a task is not active,
// time pt will remain at zero. The intent is for the command calling this
// function to use that value to display '---', not the epoch time.
//
void CViewWork::GetDocEstCompletionDate(wxInt32 item, time_t& tBuffer) const {
RESULT* result = wxGetApp().GetDocument()->result(item);
tBuffer = 0;
if (result->active_task_state == 1) {
time_t ttime = time(0);
tBuffer = ttime;
tBuffer += (time_t)result->estimated_cpu_time_remaining;
}
}


void CViewWork::GetDocEstDeadlineDiff(wxInt32 item, double& fBuffer) const {
RESULT* result = wxGetApp().GetDocument()->result(item);
fBuffer = 0;
if (result->active_task_state == 1) {
time_t tdeadline, testcompletion;
GetDocEstCompletionDate(item, testcompletion);
GetDocReportDeadline(item, tdeadline);
fBuffer = (double)(tdeadline - testcompletion);
}

}


wxInt32 CViewWork::FormatDateTime(time_t datetime, wxString& strBuffer) const {
#ifdef __WXMAC__
// Work around a wxCocoa bug(?) in wxDateTime::Format()
char buf[80];
struct tm * timeinfo = localtime(&deadline);
struct tm * timeinfo = localtime(&datetime);
strftime(buf, sizeof(buf), "%c", timeinfo);
strBuffer = buf;
#else
wxDateTime dtTemp;

dtTemp.Set(deadline);
dtTemp.Set(datetime);
strBuffer = dtTemp.Format();
#endif

return 0;
}




wxInt32 CViewWork::FormatStatus(wxInt32 item, wxString& strBuffer) const {
CWork* work;

Expand Down Expand Up @@ -1319,7 +1420,7 @@ int CViewWork::GetWorkCacheAtIndex(CWork*& workPtr, int index) {
workPtr = NULL;
return -1;
}

return 0;
}

Loading

0 comments on commit c134d0f

Please sign in to comment.