def wealth_tester(expname):
    '''
    Checks the TotalWealth of each Behavior Type in the wealth file.
    '''
    try:
        wealthfile = open(expname + 'wealth.csv', 'r')
    except __HOLE__:
        print "Check the wealth file."
   
    try:
       transactionfile = open(expname + '.csv')    
    except IOError:
        print "Error in passing the csv file"
    
    fout = open('ultimateoutput.txt', 'a')
    
    #find the average stockprice
    #indices for readability
    #time = 0
    #transactionnum = 1
    #price = 2
    #volume = 3
    #totalprice = 0
    #numtrans = 0
    #skipfirstlines = 0
    #for line in transactionfile:
    #    if skipfirstlines == 0 or skipfirstlines == 1:
    #        skipfirstlines += 1
    #        continue
    #    splitline = line.split(';')
    #    totalprice = totalprice + (int(float(splitline[price])) * int(splitline[volume]))
    #    numtrans = numtrans + int(splitline[volume])
    #    avgtrans = totalprice / numtrans    
    avgtrans = 500 #This replaces the actual average finder
    
    totalwealth = dict()
    #indices for readability
    time = 0
    id = 1 
    behavior = 2
    wealth = 3
    stock = 4
    
    for line in wealthfile:
        splitline = line.split(';')
        agent = splitline[behavior]
        #print agent
        if agent in totalwealth.keys():
            #add wealth
            totalwealth[agent] = totalwealth[agent] + int(splitline[wealth])
            #add stock x avg transaction price
            totalwealth[agent] = totalwealth[agent] + (int(splitline[stock]) * avgtrans)
        else:
            totalwealth[agent] = 0
            #add wealth
            totalwealth[agent] = totalwealth[agent] + int(splitline[wealth])
            #add stock x avg transaction price
            totalwealth[agent] = totalwealth[agent] + (int(splitline[stock]) * avgtrans)
        
    #Order them top to bottom
    agents = [key for key, dummy in sorted(totalwealth.items(), key = lambda arg: arg[1], reverse = True)]
        #print agents
    #for agent in agents:
    #    print totalwealth[agent]        
    #print totalwealth
    #print type(totalwealth.keys())
    print totalwealth
    fout.write(expname + '\n') 
    fout.write('Agent1: ' + agents[0] + " has a total wealth of " + str(totalwealth[agents[0]]) + '\n')
    fout.write('Agent2: ' + agents[1] + " has a total wealth of " + str(totalwealth[agents[1]]) + '\n')
    
    wealthfile.close()
    fout.close()
    return totalwealth
dataset/ETHPy150Open jcbagneris/fms/fms/contrib/coleman/checksuccess.py/wealth_tester