Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

slippage.cc

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2000 Idan Shoham <idan@m-tech.ab.ca>
00003 **  
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 ** 
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 ** 
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software 
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 #ifdef HAVE_CONFIG_H
00019 #include <config.h>
00020 #endif
00021 
00022 using namespace std;
00023 
00024 #include "project.h"
00025 #include "reporter.h"
00026 
00027 void Reporter::SlippageReport( Project *project )
00028 {
00029     TASK *t;
00030     char buf1[500], buf2[500];
00031     FILE *ftxt = NULL;
00032     FILE *ftex = NULL;
00033     FILE *fhtml = NULL;
00034 
00035     int early;
00036     int nFinishedTasksOnTime = 0;
00037     int nFinishedTasksEarly = 0;
00038     int nFinishedTasksLate = 0;
00039     int nFinishedDaysEarly = 0;
00040     int nFinishedDaysLate = 0;
00041   
00042     int nOngoingTasksOnTime = 0;
00043     int nOngoingTasksEarly = 0;
00044     int nOngoingTasksLate = 0;
00045     int nOngoingDaysEarly = 0;
00046     int nOngoingDaysLate = 0;
00047 
00048     if ( slippage_txt_report != NULL )
00049         ftxt = OpenOutputFile(slippage_txt_report);
00050 
00051     if ( slippage_tex_report != NULL )
00052         ftex = OpenOutputFile(slippage_tex_report);
00053 
00054     if ( slippage_html_report != NULL )
00055     {
00056         fhtml = OpenOutputFile(slippage_html_report);
00057         fprintf(fhtml, "<html>\n<body>\n\n");
00058     }
00059   
00060 //    if ( ( ftxt == NULL ) &&  ( ftex == NULL ) &&  ( fhtml == NULL ) )
00061 //      ftxt = stdout;
00062 
00063     if ( ftxt != NULL )
00064     {
00065         fprintf(ftxt, "Schedule changes:\n");
00066         fprintf(ftxt, "=================\n\n");
00067         fprintf(ftxt, "%-40s %4s %4s %4s %s %9s\n","Task", "Done", "Old",
00068                 "New", "Chg?", "Remaining");
00069         fprintf(ftxt, "%-40s %4s %4s %4s %s %9s\n","----", "----", "---",
00070                 "---", "----", "---------");
00071     }
00072     if ( ftex != NULL )
00073     {
00074         fprintf(ftex, "\\subsection{Schedule changes}\n");
00075         fprintf(ftex, "\\begin{supertabular}{|l|r|r|r|l|r|}\n");
00076         fprintf(ftex, "\\hline\n");
00077         fprintf(ftex, "{\\bf %s} & {\\bf %s} & {\\bf %s} & {\\bf %s} & {\\bf %s} & {\\bf %s} \\\\\n",
00078                 "Task", "\\% Done", "Old", "New", "Chg?", "Remaining");
00079         fprintf(ftex, "\\hline\n");
00080         fprintf(ftex, "\\hline\n");
00081     }
00082     if ( fhtml != NULL )
00083     {
00084         fprintf(fhtml, "<h1>Schedule changes</h1>\n");
00085         fprintf(fhtml, "<p><table cellpadding=2 border=1>\n");
00086         fprintf(fhtml, "<tr><th>Task</th><th>%% Done</th><th>Old</th><th>New</th><th>Chg?</th><th>Remaining</th></tr>\n");
00087     }
00088 
00089     for ( Project::TPLCI pt = project->beginTaskList() ; 
00090           pt != project->endTaskList() ; pt++ )
00091     {
00092         t = *pt;
00093         if ( t->percent_complete() == 0 )
00094             continue;                   /* no work done yet */
00095 #if 0
00096         if ( ( t->when == NULL ) && ( t->nDays == 0 ) )
00097             continue;                   /* no info on when work done */
00098 #endif
00099         // don't look at t->when here because it has been assigned by
00100         // the scheduler!
00101         if ( t->nDays() == 0 )
00102             continue;                   /* no info on when work done */
00103         
00104         // Update our statistics:
00105         if ( t->percent_complete() > 99 ) // finished task
00106         {
00107             if ( t->origfullduration() > t->fullduration() )
00108             {
00109                 nFinishedTasksEarly += 1;
00110                 nFinishedDaysEarly += (t->origfullduration() - t->fullduration() );
00111             }
00112             else if ( t->origfullduration() == t->fullduration() )
00113             {
00114                 nFinishedTasksOnTime += 1;
00115             }
00116             else if ( t->origfullduration() < t->fullduration() )
00117             {
00118                 nFinishedTasksLate += 1;
00119                 nFinishedDaysLate += (t->fullduration() - t->origfullduration() );
00120             }
00121         }
00122         else // ongoing task
00123         {
00124             if ( t->origfullduration() > t->fullduration() )
00125             {
00126                 nOngoingTasksEarly += 1;
00127                 nOngoingDaysEarly += (t->origfullduration() - t->fullduration() );
00128             }
00129             else if ( t->origfullduration() == t->fullduration() )
00130             {
00131                 nOngoingTasksOnTime += 1;
00132             }
00133             else if ( t->origfullduration() < t->fullduration() )
00134             {
00135                 nOngoingTasksLate += 1;
00136                 nOngoingDaysLate += (t->fullduration() - t->origfullduration() );
00137             }
00138         }
00139         
00140         // record changes to duration
00141         if ( t->fullduration() != t->origfullduration() )
00142         {
00143             if ( ftxt != NULL )
00144             {
00145                 char buf[128];
00146                 if ( task_ids )
00147                     sprintf(buf, "%s %s", t->id(), t->name() );
00148                 else
00149                     sprintf(buf, "%s", t->name() );
00150                 fprintf(ftxt, "%-40s %4g %4d %4d %-5s %8d\n",
00151                         buf, t->percent_complete(), 
00152                         t->origfullduration(), t->fullduration(),
00153                         t->fullduration()<t->origfullduration() ? "Early":"Late",
00154                         t->fullduration() - t->nDays() );
00155             }
00156             if ( ftex != NULL )
00157             {
00158                 if ( task_ids )
00159                     fprintf(ftex, "%s %s",
00160                             TeXFix(buf1,t->id()),
00161                             TeXFix(buf2,t->name()));
00162                 else
00163                     fprintf(ftex, "%s",
00164                             TeXFix(buf2,t->name()));
00165                 fprintf(ftex," & %g & %d & %d & %s & %d\\\\ \n",
00166                         t->percent_complete(),
00167                         t->origfullduration(), t->fullduration(),
00168                         t->fullduration()<t->origfullduration() ? "Early":"Late",
00169                         t->fullduration() - t->nDays());
00170             }
00171             if ( fhtml != NULL )
00172             {
00173                 fprintf(fhtml, "<tr>");
00174                 if ( task_ids )
00175                     fprintf(fhtml, "<td>%s %s</td>",
00176                             HTMLFix(buf1,t->id()),
00177                             HTMLFix(buf2,t->name()));
00178                 else
00179                     fprintf(fhtml, "<td>%s</td>",
00180                             HTMLFix(buf2,t->name()));
00181                 fprintf(fhtml, " <td align=right>%g</td> <td align=right>%d</td> <td align=right>%d</td> <td>%s</td> <td align=right>%d</td></tr>\n",
00182                         t->percent_complete(),
00183                         t->origfullduration(), t->fullduration(),
00184                         t->fullduration()<t->origfullduration() ? "Early":"Late",
00185                         t->fullduration() - t->nDays());
00186             }
00187         }
00188         else
00189         {
00190             if ( ftxt != NULL )
00191             {
00192                 fprintf(ftxt, "%-40s %4g %4d %4d %s\n",
00193                         t->id(), t->percent_complete(), t->origfullduration(),
00194                         t->fullduration(), "-");
00195             }
00196             if ( ftex != NULL )
00197             {
00198                 if ( task_ids )
00199                     fprintf(ftex, "%s %s",
00200                             TeXFix(buf1,t->id()),
00201                             TeXFix(buf2,t->name()));
00202                 else
00203                     fprintf(ftex, "%s",
00204                             TeXFix(buf2,t->name()));
00205                 fprintf(ftex, " & %g & %d & %d &  & \\\\ \n",
00206                         t->percent_complete(),
00207                         t->origfullduration(), t->fullduration());
00208             }
00209             if ( fhtml != NULL )
00210             {
00211                 fprintf(fhtml, "<tr>");
00212                 if ( task_ids )
00213                     fprintf(fhtml, "<td>%s %s</td>",
00214                             HTMLFix(buf1,t->id()),
00215                             HTMLFix(buf2,t->name()));
00216                 else
00217                     fprintf(fhtml, "<td>%s</td>",
00218                             HTMLFix(buf2,t->name()));
00219                 fprintf(fhtml,
00220                         "<td align=right>%g</td> <td align=right>%d</td> <td align=right>%d</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>\n",
00221                         t->percent_complete(),
00222                         t->origfullduration(), t->fullduration());
00223             }
00224         }
00225     }
00226 
00227     early = nOngoingDaysEarly + nFinishedDaysEarly -
00228         (nOngoingDaysLate + nFinishedDaysLate);
00229 
00230     if ( ftxt != NULL )
00231     {
00232         fprintf(ftxt,"\nSUMMARY:\n\n");
00233         fprintf(ftxt,"Completed tasks:\n");
00234         fprintf(ftxt,
00235                 "   On time: %d   Early: %d (%d days)   Late: %d (%d days)\n",
00236                 nFinishedTasksOnTime,
00237                 nFinishedTasksEarly, nFinishedDaysEarly,
00238                 nFinishedTasksLate, nFinishedDaysLate);
00239   
00240         fprintf(ftxt,"Ongoing tasks:\n");
00241         fprintf(ftxt,
00242                 "   On time: %d   Early: %d (%d days)   Late: %d (%d days)\n",
00243                 nOngoingTasksOnTime,
00244                 nOngoingTasksEarly, nOngoingDaysEarly,
00245                 nOngoingTasksLate, nOngoingDaysLate);
00246   
00247         fprintf(ftxt,"The project is %d days %s schedule.\n",
00248                 abs(early), early>0 ? "ahead of":"behind");
00249     }
00250     if ( ftex != NULL )
00251     {
00252         fprintf(ftex,"\\hline\n");
00253         fprintf(ftex,"\\end{supertabular}\n\n");
00254         fprintf(ftex,"\n{\\bf Summary:} \\\\ \n");
00255         fprintf(ftex,"Completed tasks: \\\\ \n");
00256         fprintf(ftex,
00257                 "\\mbox{} \\hspace{0.5in} On time: %d   Early: %d (%d days)   Late: %d (%d days) \\\\ \n",
00258                 nFinishedTasksOnTime,
00259                 nFinishedTasksEarly, nFinishedDaysEarly,
00260                 nFinishedTasksLate, nFinishedDaysLate);
00261   
00262         fprintf(ftex,"Ongoing tasks: \\\\ \n");
00263         fprintf(ftex,"\\mbox{} \\hspace{0.5in} On time: %d   Early: %d (%d days)   Late: %d (%d days) \\\\ \n",
00264                 nOngoingTasksOnTime,
00265                 nOngoingTasksEarly, nOngoingDaysEarly,
00266                 nOngoingTasksLate, nOngoingDaysLate);
00267   
00268         fprintf(ftex,"The project is %d days %s schedule.\n",
00269                 abs(early), early>0 ? "ahead of":"behind");
00270     }
00271     if ( fhtml != NULL )
00272     {
00273         fprintf(fhtml,"</table></p>\n\n");
00274         fprintf(fhtml,"<h2>Summary:</h2>\n");
00275         fprintf(fhtml,"<p>Completed tasks:</p>\n");
00276         fprintf(fhtml,"<p>&nbsp;&nbsp;&nbsp;&nbsp; On time: %d   Early: %d (%d days)   Late: %d (%d days)</p>\n",
00277                 nFinishedTasksOnTime,
00278                 nFinishedTasksEarly, nFinishedDaysEarly,
00279                 nFinishedTasksLate, nFinishedDaysLate);
00280   
00281         fprintf(fhtml,"<p>Ongoing tasks:<p>\n");
00282         fprintf(fhtml,"<p>&nbsp;&nbsp;&nbsp;&nbsp; On time: %d   Early: %d (%d days)   Late: %d (%d days)</p>\n",
00283                 nOngoingTasksOnTime,
00284                 nOngoingTasksEarly, nOngoingDaysEarly,
00285                 nOngoingTasksLate, nOngoingDaysLate);
00286   
00287         fprintf(fhtml,"<p>The project is %d days %s schedule.</p>\n",
00288                 abs(early), early>0 ? "ahead of":"behind");
00289     }
00290 
00291 
00292     if ( ( ftxt != NULL ) && ( ftxt != stdout ) )
00293         fclose(ftxt); 
00294     if ( ftex != NULL )
00295         fclose(ftex);
00296     if ( fhtml != NULL )
00297     {
00298         fprintf(fhtml, "\n\n</body>\n</html>\n");
00299         fclose(fhtml);
00300     }
00301 }

Generated on Wed Feb 18 22:23:54 2004 for Opensched by doxygen1.2.15