Example #1
0
def on_pick(event):
    for boro in agencies.agenciesList:
        found = False
        for agcy in agencies.agenciesList[boro]:
            if agcy['square'] is event.artist:
                found = True
                agencies.selected['square'].set_lw(1)
                agencies.selected['square'].set_ec('k')
                agencies.selected = agcy
                agcy['square'].set_lw(4)
                agcy['square'].set_ec('r')
                if agencies.selected['tileArray'] == []:
                    agents.initTileArray(agencies.selected)
                agents.updateTileArray(agencies.selected)
                axes.schedTitle.set_text(boro+': '+agcy['abbrev']+' '+agcy['name'])
                axes.fig.canvas.draw()
                break
        if found == True:
            break
        
    if agents.doingLogging:
        writelog.write('In on_pick(): selected is now %s %s %s\n'%(
        agencies.selected['boro'], agencies.selected['abbrev'], agencies.selected['name']))
Example #2
0
def init_agencies():
    
    global agenciesList, nAgencies, selected
    
    fp = open('agenciesDat.txt', 'rb')
    csvReader = csv.reader(fp, delimiter='\t')
        
    bronxList     = []
    brooklynList  = []
    manhattanList = []
    statenList    = []
    queensList    = []
    
    # Read in the data
    for row in csvReader:
        # print row
        name   = row[0]
        abbrev = row[1]
        boro   = row[2]    
        matchObj = re.match('\(([0-9]+),\s([0-9]+)\)', row[3])
        if matchObj is not None:
            (xstr, ystr) = matchObj.group(1,2)
            loc    = (int(xstr), int(ystr))
        numenrolled   = 0
        maxenrolled = int(row[4])
        entry = {'name':name,
                 'abbrev':abbrev,
                 'boro':boro,
                 'loc':loc, 
                 'numenrolled':0,
                 'maxenrolled':maxenrolled}
        if boro == 'Bronx':
            bronxList.append(entry)
        elif boro == 'Brooklyn':
            brooklynList.append(entry)
        elif boro == 'Manhattan':
            manhattanList.append(entry)
        elif boro == 'StatenIsl':
            statenList.append(entry)
        elif boro == 'Queens':
            queensList.append(entry)
#        print '%s %s %s (%d, %d) %d %d'%(name.ljust(60), abbrev.ljust(6),
#                                        boro.ljust(10), loc[0], loc[1], numenrolled, maxenrolled)
        nAgencies += 1
                                        
        agenciesList = {    'Bronx':bronxList,
                         'Brooklyn':brooklynList, 
                        'Manhattan':manhattanList,
                        'StatenIsl':statenList,
                           'Queens':queensList}

    # Select agency whose sched is displayed
    selected = agenciesList['Queens'][0]
    titTxt = selected['boro']+': '+selected['abbrev']+' '+selected['name']
    axes.schedTitle.set_text(titTxt)

    for boro in boroughsList:
        dx, dy = 0., 0.
        axes.ax.text(boroOrgs[boro][0]-.01, boroOrgs[boro][1]+.02, boro)
        for agcy in agenciesList[boro]:
            (x, y) = (boroOrgs[boro][0]+dx, boroOrgs[boro][1]+dy)
            agcy['loc'] = (x, y)
            square = plt.Rectangle((x-hafSquareSize,y-hafSquareSize),
                                   squareSize, squareSize,
                                   fc=(0,1,0), ec='k')
            agcy['square'] = square
            agcy['square'].set_picker(True)
            axes.ax.add_patch(square)
            agcy['numEnrolled'] = numenrolled
            agcy['maxEnrolled'] = maxenrolled
            agcy['avgInput']  = 0.
            agcy['schedList'] = []
            agcy['tileArray'] = []
            idText = axes.ax.text(x+0.02, y, agcy['abbrev'])
            if agcy is selected:
                agents.initTileArray(agcy)
            dy -= squareSep
                                            
    selected['square'].set_lw(4)
    selected['square'].set_ec('r')

    fp.close()