2.4 Another Scenario

In this section we plan an additional worst case scenario for our waterfall project in section 2.2:
   1 # -*- coding: iso8859-15 -*-
   2 from faces import *
   3 from faces.lib import report
   4 from faces.lib import gantt
   5 
   6 def My_Project():
   7     start = "1.11.2005"
   8     
   9     def Specification():
  10         effort = Multi("1w", worst="1.5w")
  11 	
  12     def Design():
  13         start = up.Specification.end
  14         effort = Multi("1w", worst="1.2w")
  15 	
  16     def Implementation():
  17         start = up.Design.end
  18 		    
  19         def Module1():
  20             effort = Multi("1w", worst="2w")
  21 	    
  22         def Module2():
  23             effort = "1w 2d"
  24 	    
  25     def Installation():
  26         start = max(up.Implementation.Module1.end, 
  27                     up.Implementation.Module2.end)
  28         effort = "2d"
  29     	
  30     def Finished(my_project):
  31         start = up.Installation.end
  32         milestone = True
  33 
  34 worst = Project(My_Project, scenario="worst")
  35 project = Project(My_Project)
  36 
  37 class Gantt(gantt.Standard):
  38     data = project
  39     
  40 class Worst_Gantt(gantt.Standard):
  41     data = worst
  42 
  43 class Cmp_Gantt(gantt.Compare):
  44     data = intersect(project, worst)
  45     
  46 class Report(report.Standard):
  47     data = project
  48     
  49     def make_report(self, data):
  50         for t in data: 
  51             yield (t.indent_name(), t.start, t.end, t.effort)
  52 	    
  53 class Worst_Report(Report):
  54     data = worst
  55 
  56 class Cmp_Report(report.Standard):
  57     data = intersect(project, worst)
  58     headers = ("Name", "Start", "Start(worst)", "End", "End(worst)")
  59         
  60     def make_report(self, data):
  61         for task_default, task_worst in data: 
  62             yield (task_default.indent_name(), task_default.start, \
  63                    task_worst.start, task_default.end, task_worst.end)
lines 10, 14, 20
The effort values are now replaced by the the function Multi. The first argument in Multi is the default value as defined without Multi. The next arguments have to be named and define the values for different scenarios. You can define as many scenarios as you want. (for python experts: Multi("10d", worst="20d") is equivalent dict(_default="10d", worst="20d"))

lines 23, 28
The efforts of these tasks have no extra value for the "worst"-scenario, therefore the worst-case values and the default values are the same.

line 35
This line compiles the project for the "worst"-scenario. Now you can define all kind of reports and charts with the worst variable.

line 40
A new gantt chart for the "worst"-scenario.

line 43,44
These lines define a new gantt chart for comparing the two scenarios (figure 2.7). The command intersect delivers a list of all tasks of project and worst. The resulting list is used by the special chart type gantt.compare .
Figure 2.7: Comparing Gantt Chart
\includegraphics[width=\textwidth,height=.4\textheight]{tutorial/fourth1}

lines 53,54
define a new report for the "worst"-scenario. It is defined as a subclass of Report, therefore it inherits the make_report() method of report, we just have to change the data attribute.

lines 56-63
define a report comparing the two scenarios (figure 2.8). the intersect function returns a sequence of two Task objects per item. The first task comes from project the second task comes from worst. Therefore the for statement in line 61 has to get both Task objects. The headers attribute define custom header labels for each column.

Figure 2.8: Comparing Report
\includegraphics[width=\textwidth,height=.4\textheight]{tutorial/fourth2}