def handStrenthAnalysis(folder):
    files_in_dir = os.listdir(folder)
    handAnalysisFile = csv.writer(open("handStrengthAnalysis2.csv", "w+"))
    handAnalysisFile.writerow(["Opponent","Strength of 2","#2","2 avg", "Strength of 3","#3s","3 avg","Strength of 4","#4", "4 avg" ,"Strength of 5", "#5","Avg 5"])
    p = Player()
    handStrength = 0 
    for f in files_in_dir:
        is_dealer = False
        our_bankroll = 0
        textFile = open(folder + "/" + f,"r")
        players = textFile.readline().split("-")[1].split("(")[0].split()
        two = 0
        two_dealer = 0
        two_count = 0
        two_dealer_count = 0
        three = 0
        three_dealer = 0
        three_count = 0
        three_dealer_count = 0
        four = 0
        four_dealer = 0 
        four_count = 0
        four_dealer_count = 0
        five = 0
        five_dealer = 0
        five_count = 0
        five_dealer_count = 0

        strength_map = {2:two,3:three,4:four,5:five}

        if players[0]!="Juggles":
            opponent =players[0]
        else:
            opponent = players[2]

        print "Opponent: "+ opponent
        for line in textFile:
            if "Dealt to Juggles" in line:
                cards = line.split("[")[1][:-2].split()
                handStrength = p.calculate_strength(cards[0],cards[1],cards[2])
            elif "Hand #" in line:
                tokens = line.split(" ")
                profit = 0 
                for i in range(len(tokens)):
                    if tokens[i] == "Juggles":

                        new_bankroll = int(tokens[i+1].replace("(","").replace(")","").replace(" ","").replace(",",""))
                        if "," in tokens[i+1]:
                            is_dealer = True
                        else:
                            is_dealer = False

                        profit = new_bankroll - our_bankroll
                        our_bankroll = new_bankroll
                        break
                    if "Juggles" not in tokens:
                        print line
                if profit == 0:
                    print "parker sucks"
                    print line
                if opponent in line:
                    profit = -1 * profit
                if handStrength == 2:
                    if is_dealer:
                        two_dealer += profit
                        two_dealer_count += 1
                    else:
                        two += profit
                        two_count +=1
                elif handStrength == 3:
                    if is_dealer:
                        three_dealer += profit
                        three_dealer_count += 1
                    else:
                        three += profit
                        three_count += 1
                elif handStrength == 4:
                    if is_dealer:
                        four_dealer += profit
                        four_dealer_count += 1
                    else:
                        four += profit
                        four_count += 1
                elif handStrength == 5:
                    if is_dealer:
                        five_dealer += profit
                        five_dealer_count += 1
                    else:
                        five += profit
                        five_count += 1

        handAnalysisFile.writerow([opponent + "-them dealing",two,two_count,two/two_count,three,three_count,three/three_count, four, four_count, four / four_count, five, five_count, five/five_count])
        handAnalysisFile.writerow([opponent + "- us dealing",two_dealer,two_dealer_count,two_dealer/two_dealer_count,three_dealer,three_dealer_count,three_dealer/three_dealer_count, four_dealer, four_dealer_count, four_dealer / four_dealer_count, five_dealer, five_dealer_count, five_dealer/five_dealer_count])
        handAnalysisFile.writerow(["  "])