[portland] Need Help With a For Loop

Rich Shepard rshepard at appl-ecosys.com
Fri Mar 21 16:32:43 CET 2008


On Fri, 21 Mar 2008, kirby urner wrote:

> Note:  my recommendation at the last PPUG, among a smattering of I hoped
> useful comments, was for Rich to publish to this list a black box unit
> test we could simply cut and paste and help out with the missing part.

Kirby,

   I posted the code and data, but that required NumPy and Matplotlib.
Attached is a stripped down version (only 5 tuples in the lis) that prints
instead of plots. (The plotting code is commented out; instead of printing
the curve shape I will call the appropriate function.) It's stand-alone and
runs.

   The output is:

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  Variety
 	Decay S-Curve
Ending this plot ...

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  Variety
 	Growth S-Curve
Ending this plot ...

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  SpecialConcern
 	Decay S-Curve
Ending this plot ...

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  SpecialConcern
 	Bell Curve
Ending this plot ...

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  SpecialConcern
 	Growth S-Curve
Ending this plot ...

   What I'm trying to see is output like this:

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  Variety
 	Decay S-Curve
 	Growth S-Curve
Ending this plot ...

Starting a new plot ...
Component:  Wildlife Subcomponent:  Fish Parent:  SpecialConcern
 	Decay S-Curve
 	Bell Curve
 	Growth S-Curve
Ending this plot ...

   I hope this makes it easy for you!

Thanks,

Rich

-- 
Richard B. Shepard, Ph.D.               |  Integrity            Credibility
Applied Ecosystem Services, Inc.        |            Innovation
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
-------------- next part --------------
#!/usr/bin/env python

import os, config
#, testFunctions
#import matplotlib
#import matplotlib.numerix as nx
#import pylab

varData = [("Low","Variety","Fish","Wildlife","Decay S-Curve",1,0.0,100.0,0.0,50.0,0.0,50.0,50.0,50.0,100.0,1.0,2),
("High","Variety","Fish","Wildlife","Growth S-Curve",2,0.0,100.0,0.0,50.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","SpecialConcern","Fish","Wildlife","Decay S-Curve",1,0.0,50.0,0.0,50.0,0.0,50.0,50.0,0.0,50.0,1.0,3),
("Moderate","SpecialConcern","Fish","Wildlife","Bell Curve",2,0.0,100.0,0.0,100.0,0.0,50.0,50.0,50.0,50.0,1.0,3),
("Many","SpecialConcern","Fish","Wildlife","Growth S-Curve",3,50.0,100.0,50.0,50.0,0.0,100.0,50.0,100.0,50.0,1.0,3)]

def testCode():
  for row in varData:
    compList = []
    curComp = row[3]
    if row[3] == curComp:
      compList.append(row)

      subList = []
      curSub = compList[0][2]
      if compList[0][3] == curComp:
        subList.append(compList[0][2])

        varList = []
        curVar = compList[0][1]
        print "Starting a new plot ..."
        print "Component: ", curComp, "Subcomponent: ", curSub, "Parent: ", curVar
        if compList[0][1] == curVar:
          varList.append(compList[0][1])
          print '\t', compList[0][4]
        print "Ending this plot ...", '\n'
        
  """      
  for item in row:
    print curVar
    pylab.hold(True)
    if row[0][4] == 'Decay S-Curve':
      testFunctions.zCurve(row[0][10],row[0][9])
    elif row[0][4] == 'Bell Curve':
      testFunctions.gaussCurve(row[0][14],row[0][14])
    elif row[0][4] == 'Grow[0]th S-Curve':
      testFunctions.sCurve(row[0][8],row[0][11])
    elif row[0][4] == 'Beta':
      testFunctions.betaCurve(row[0][13],row[0][12],row[0][14])
    elif row[0][4] == 'Data':
      continue
    elif row[0][4] == 'Linear Increasing':
      testFunctions.linearIncrCurve(row[0][8],row[0][11])
    elif row[0][4] == 'Linear Decreasing':
      testFunctions.linearDecrCurve(row[0][10],row[0][9])
    elif row[0][4] == 'Left Shoulder':
      testFunctions.leftShoulderCurve(row[0][10],row[0][11],row[0][9])
    elif row[0][4] == 'Trapezoid':
      testFunctions.trapezoidCurve(row[0][8],row[0][10],row[0][11],row[0][9])
    elif row[0][4] == 'Right Shoulder':
      testFunctions.rightShoulderCurve(row[0][8],row[0][10],row[0][11])
    elif row[0][4] == 'Triangle':
      testFunctions.triangleCurve(row[0][8],row[0][13],row[0][9])
    elif row[0][4] == 'Singleton':
      testFunctions.singletonCurve(row[0][13],row[0][14])
    elif row[0][4] == 'Rectangle':
      testFunctions.rectangleCurve(row[0][8],row[0][10],row[0][11],row[0][9])
    elif row[0][4] == 'Outcome':
      testFunctions.outcomeCurve()
  pylab.savefig(curVar+'.png')
  print "Wrote ", curVar, item, row[0][16]
  pylab.hold(False)
  """

      
if __name__ == "__main__":
  testCode()


More information about the Portland mailing list