import string 
import math
from Tkinter import *
from tkFileDialog import askopenfilename
Tk().withdraw()
filename = askopenfilename()

LANGUAGECOLUMN = 5 #14
TESTINGNUM = 8
FORMCOLUMN = 9 #2
RAWSCORECOLUMN = 10 #3
COMPUTEDSCORECOLUMN = 21
RACECOLUMN = 3
ETHNICITYCOLUMN = 4
AGECOLUMN = 1
GENDERCOLUMN = 2

lastprinter =[]


oldlineassindex=''
#########################
# Setting up Matrix
#########################

dot = filename.rfind('.')
outputfile = filename[:dot]+"_PROCESSED.csv"
f = open(filename,"a+")
f.write('\n end')
f.seek(0)

filename2=askopenfilename()
thetasheet=open(filename2,"a+")
thetasheet.write('\n end')
thetasheet.seek(0)


#filename3=askopenfilename()
#secondarysheet=open(filename3)

#filename4=askopenfilename()
#educationsheet=open(filename4)

g = open(outputfile,'w')

#f = open('AssessmentScores.csv')
#g = open('AssessmentProcessed2.csv', 'w')

linethree=[]
count=0
amatrix=[]

for line in f:
    #if count<2:
        #count+=1
        #continue
    if count==0 or count==1 or count==2 or count==3 or count==4:
        linethree=line.split(",")
        linethree[-1].rstrip()
        #linethree.pop()
        
        #i=0
        #for x in linethree:
           #linethree[i]=x.replace('\"','')
           #i+=1
        count+=1
        continue

    templine=[]
    templine=line.split(",")
    templine[-1]=templine[-1].rstrip()
    #templine.pop()
    i=0
    for x in templine:
        templine[i]=x.strip('\"')
        i+=1
    
    amatrix.append(templine) 
    count+=1

###################
#Compiling Last Theta Value for Matrix
###################

count=0
ID=-1
theta=[-1,-1]
thetadict={}

for line in thetasheet:
    
    if count==0 or count==1 or count==2:
        count+=1
        continue
    
    templine=[]
    templine=line.split(",")
    if templine[0]=='':
        continue

    i=0
    for x in templine:
        templine[i]=x.strip('\"')
        i+=1

    if ID!=templine[0]:
        thetadict[ID]=theta   #Remember to distinguish between which is which in Oral Reading and Picture Vocab parts
        theta = [-1,-1]
        ID=templine[0]
        if len(templine)<15:
            continue
        #if theta=templine[14]
        if templine[14]=="":
            count+=1
            continue
        if templine[7].find("Picture Vocab")!=-1:
            theta[0] = float(templine[14])
        elif templine[7].find("Oral Reading")!=-1:
            theta[1] = float(templine[14])
        count+=1
        continue

    elif ID==templine[0]:
        if len(templine)<15:
            continue
        if templine[14]=="":
            count+=1
            continue
        if templine[7].find("Picture Vocab")!=-1:
            theta[0] = float(templine[14])
        elif templine[7].find("Oral Reading")!=-1:
            theta[1] = float(templine[14])
        count+=1
        continue


    count+=1

"""#####################
#Seconday Info Age,Race,Ethnicity,Gender Sheet
#####################

secondarydict={}
count=0
for line in secondarysheet:
    if count <= 2:#==0:
        count+=1
        continue
    if len(line)<4:
        continue
    templine=[]
    templine=line.split(",")

    value=[]
    value=[int(templine[3]),float(templine[4]),int(templine[6]),int(templine[7]),int(templine[51])]
    secondarydict[templine[0]]=value
    count+=1"""

#for a in amatrix:
#    a.append(thetadict[a[0]])
"""
print amatrix
print ''
print '==========================='
print ''
print amatrix[0]
print '----------------------------'
print amatrix[1]
print '----------------------------'
"""
"""
######################
# Education/Pivot Sheet
######################

educationdict={}
count=0
for line in educationsheet:
    if count==0:
        count+=1
        continue

    templine=[]
    templine=line.split(",")

    value=[]
    if templine[421]=="SKIP" or templine[421]=="":
         value=""
    else:
        value=float(templine[421])
    educationdict[templine[0]]=value
    count+=1
"""

print "Processing input sheets.."

###########################
# Tables
###########################

def AgeCorrectAdults(test, score):
    if test=="DCCS":
        if (score>=0) and (score<=1.5574):
            return 0
        elif (score>1.5574) and (score<=2.0751):
            return 1
        elif (score>2.0751) and (score<=2.1831):
            return 2
        elif (score>2.1831) and (score<=2.4393):
            return 3
        elif (score>2.4393) and (score<=3.7886):
            return 4
        elif (score>3.7886) and (score<=5.9643):
            return 5
        elif (score>5.9643) and (score<=6.6835):
            return 6
        elif (score>6.6835) and (score<=7.2009):
            return 7
        elif (score>7.2009) and (score<=7.5932):
            return 8
        elif (score>7.5932) and (score<=7.9018):
            return 9
        elif (score>7.9018) and (score<=8.1863):
            return 10
        elif (score>8.1863) and (score<=8.5195):
            return 11
        elif (score>8.5195) and (score<=8.7607):
            return 12
        elif (score>8.7607) and (score<=9.0393):
            return 13
        elif (score>9.0393) and (score<=9.3189):
            return 14
        elif (score>9.3189) and (score<=9.6504):
            return 15
        elif (score>9.6504) and (score<=9.8747):
            return 16
        elif (score>9.8747) and (score<=9.9872):
            return 17
        elif score>9.9872:
            return 18
        
    elif test=="Flanker":
        if (score>=0) and (score<=1.9266):
            return 0
        elif (score>1.9266) and (score<=4.1871):
            return 1
        elif (score>4.1871) and (score<=4.4535):
            return 2
        elif (score>4.4535) and (score<=5.1182):
            return 3
        elif (score>5.1182) and (score<=6.2401):
            return 4
        elif (score>6.2401) and (score<=6.9348):
            return 5
        elif (score>6.9348) and (score<=7.5136):
            return 6
        elif (score>7.5136) and (score<=7.9020):
            return 7
        elif (score>7.9020) and (score<=8.2019):
            return 8
        elif (score>8.2019) and (score<=8.4589):
            return 9
        elif (score>8.4589) and (score<=8.7505):
            return 10
        elif (score>8.7505) and (score<=8.9681):
            return 11
        elif (score>8.9681) and (score<=9.1904):
            return 12
        elif (score>9.1904) and (score<=9.4085):
            return 13
        elif (score>9.4085) and (score<=9.5816):
            return 14
        elif (score>9.5816) and (score<=9.7263):
            return 15
        elif (score>9.7263) and (score<=9.8788):
            return 16
        elif (score>9.8788) and (score<=9.9976):
            return 17
        elif score>9.9976:
            return 18
        
    elif test=="ListSort":
        score=round(score)
        if (score>=0.0) and (score<=2.1):
            return 0
        elif (score>2.1) and (score<=4.1):
            return 1
        elif (score>4.1) and (score<=5.1):
            return 2
        elif (score>5.1) and (score<=7.1):
            return 3
        elif (score>7.1) and (score<=9.1):
            return 4
        elif (score>9.1) and (score<=11.1):
            return 5
        elif (score>11.1) and (score<=12.1):
            return 6
        elif (score>12.1) and (score<=14.1):
            return 7
        elif (score>14.1) and (score<=15.1):
            return 8
        elif (score>15.1) and (score<=16.1):
            return 9
        elif (score>16.1) and (score<=17.1):
            return 10
        elif (score>17.1) and (score<=18.1):
            return 11
        elif (score>18.1) and (score<=19.1):
            return 12
        elif (score>19.1) and (score<=20.1):
            return 13
        elif (score>20.1) and (score<=21.1):
            return 14
        elif (score>21.1) and (score<=22.1):
            return 15
        elif (score>22.1) and (score<=24.1):
            return 16
        elif (score>24.1) and (score<=25.1):
            return 17
        elif (score>25.1) and (score<=26.1):
            return 18

    elif test=="PictureSeq":
        if (score<=217.60):
            return 0
        elif (score>217.60) and (score<=257.35):
            return 1
        elif (score>257.36) and (score<=293.24):
            return 2
        elif (score>293.24) and (score<=303.79):
            return 3
        elif (score>303.79) and (score<=333.22):
            return 4
        elif (score>333.22) and (score<=352.61):
            return 5
        elif (score>352.61) and (score<=382.38):
            return 6
        elif (score>382.38) and (score<=415.59):
            return 7
        elif (score>415.59) and (score<=442.62):
            return 8
        elif (score>442.62) and (score<=481.43):
            return 9
        elif (score>481.43) and (score<=521.53):
            return 10
        elif (score>=521.53) and (score<=552.56):
            return 11
        elif (score>552.56) and (score<=599.04):
            return 12
        elif (score>599.04) and (score<=625.89):
            return 13
        elif (score>625.89) and (score<=653.76):
            return 14
        elif (score>653.76) and (score<=677.94):
            return 15
        elif (score>677.94) and (score<=689.94):
            return 16
        elif (score>689.94) and (score<=700.89):
            return 17
        elif (score>700.89) and (score<=722.27):
            return 18
        elif (score>722.27) and (score<=778.57):
            return 19
        elif (score>778.57):
            return 20

    elif test=="PatternComp":
        score = round(score)
        if (score>=0.0) and (score<=16.1):
            return 0
        elif (score>16.1) and (score<=24.1):
            return 1
        elif (score>24.1) and (score<=27.1):
            return 2
        elif (score>27.1) and (score<=29.1):
            return 3
        elif (score>29.1) and (score<=33.1):
            return 4
        elif (score>33.1) and (score<=38.1):
            return 5
        elif (score>38.1) and (score<=42.1):
            return 6
        elif (score>42.1) and (score<=46.1):
            return 7
        elif (score>46.1) and (score<=49.1):
            return 8
        elif (score>49.1) and (score<=53.1):
            return 9
        elif (score>53.1) and (score<=57.1):
            return 10
        elif (score>57.1) and (score<=61.1):
            return 11
        elif (score>61.1) and (score<=64.1):
            return 12
        elif (score>64.1) and (score<=68.1):
            return 13
        elif (score>68.1) and (score<=72.1):
            return 14
        elif (score>72.1) and (score<=75.1):
            return 15
        elif (score>75.1) and (score<=78.1):
            return 16
        elif (score>78.1) and (score<=81.1):
            return 17
        elif (score>81.1) and (score<=84.1):
            return 18
        elif (score>84.1) and (score<=97.1):
            return 19
        elif (score>97.1) and (score<=130.1):
            return 20

    elif test=="OralReading":
        score=round(score,2)
        if (score<=-12.19):
            return 0
        elif (score>-12.19) and (score<=-4.75):
            return 1
        elif (score>-4.75) and (score<=-3.69):
            return 2
        elif (score>-3.69) and (score<=-1.97):
            return 3
        elif (score>-1.97) and (score<=-1.05):
            return 4
        elif (score>-1.05) and (score<0.00):
            return 5
        elif (score>=0.00) and (score<=1.07):
            return 6
        elif (score>1.07) and (score<=2.14):
            return 7
        elif (score>2.14) and (score<=3.03):
            return 8
        elif (score>3.03) and (score<=3.96):
            return 9
        elif (score>3.96) and (score<=4.84):
            return 10
        elif (score>4.84) and (score<=5.73):
            return 11
        elif (score>5.73) and (score<=6.81):
            return 12
        elif (score>6.81) and (score<=7.56):
            return 13
        elif (score>7.56) and (score<=8.23):
            return 14
        elif (score>8.23) and (score<=8.84):
            return 15
        elif (score>8.84) and (score<=9.16):
            return 16
        elif (score>9.16) and (score<=9.35):
            return 17
        elif (score>9.35) and (score<=9.97):
            return 18
        elif (score>9.97) and (score<=16.36):
            return 19
        elif (score>16.36):
            return 20

    elif test=="PictureVocab":
        if (score<=-10.25):
            return 0
        elif (score>-10.25) and (score<=-4.78):
            return 1
        elif (score>-4.78) and (score<=-2.94):
            return 2
        elif (score>-2.94) and (score<=-0.84):
            return 3
        elif (score>-0.84) and (score<=0.46):
            return 4
        elif (score>0.46) and (score<=1.39):
            return 5
        elif (score>1.39) and (score<=2.18):
            return 6
        elif (score>2.18) and (score<=3.00):
            return 7
        elif (score>3.00) and (score<=3.74):
            return 8
        elif (score>3.74) and (score<=4.42):
            return 9
        elif (score>4.42) and (score<=4.95):
            return 10
        elif (score>4.95) and (score<=5.57):
            return 11
        elif (score>5.57) and (score<=6.25):
            return 12
        elif (score>6.25) and (score<=7.15):
            return 13
        elif (score>7.15) and (score<=7.95):
            return 14
        elif (score>7.95) and (score<=8.77):
            return 15
        elif (score>8.77) and (score<=9.57):
            return 16
        elif (score>9.57) and (score<=9.92):
            return 17
        elif (score>9.92) and (score<=10.62):
            return 18
        elif (score>10.62) and (score<=12.73):
            return 19
        elif (score>12.73):
            return 20

def AgeCorrectChildren(test,score):
    if test=="DCCS":                                                                                                                                                                                                        
        if (score>=0.0) and (score<=0.0915):
            return 1
        elif (score>0.0915) and (score<=0.2406):
            return 2
        elif (score>0.2406) and (score<=0.4025):
            return 3
        elif (score>0.4025) and (score<=0.7689):
            return 4
        elif (score>0.7689) and (score<=1.2196):
            return 5
        elif (score>1.2196) and (score<=3.9891):
            return 6
        elif (score>3.9891) and (score<=6.0759):
            return 7
        elif (score>6.0759) and (score<=6.8511):
            return 8
        elif (score>6.8511) and (score<=7.3705):
            return 9
        elif (score>7.3705) and (score<=7.8139):
            return 10
        elif (score>7.8139) and (score<=8.1914):
            return 11
        elif (score>8.1914) and (score<=8.5338):
            return 12
        elif (score>8.5338) and (score<=8.8555):
            return 13
        elif (score>8.8555) and (score<=9.2296):
            return 14
        elif (score>9.2296) and (score<=9.5615):
            return 15
        elif (score>9.5615) and (score<=9.7969):
            return 16
        elif (score>9.7969) and (score<=9.8870):
            return 17
        elif (score>9.8870) and (score<=9.9967):
            return 18
        elif score>9.9967:
            return 19

    elif test=="Flanker":                                                                                                                                                                                                               
        if (score>=0.0) and (score<=0.1133):
            return 0
        elif (score>0.1133) and (score<=0.5814):
            return 1
        elif (score>0.5814) and (score<=0.8815):
            return 2
        elif (score>0.8815) and (score<=1.2695):
            return 3
        elif (score>1.2695) and (score<=1.6415):
            return 4
        elif (score>1.6415) and (score<=2.1666):
            return 5
        elif (score>2.1666) and (score<=5.1243):
            return 6
        elif (score>5.1243) and (score<=6.7908):
            return 7
        elif (score>6.7908) and (score<=7.5652):
            return 8
        elif (score>7.5652) and (score<=8.0800):
            return 9
        elif (score>8.0800) and (score<=8.5149):
            return 10
        elif (score>8.5149) and (score<=8.8806):
            return 11
        elif (score>8.8806) and (score<=9.1532):
            return 12
        elif (score>9.1532) and (score<=9.3768):
            return 13
        elif (score>9.3768) and (score<=9.558):
            return 14
        elif (score>9.558) and (score<=9.7344):
            return 15
        elif (score>9.7344) and (score<=9.8675):
            return 16
        elif (score>9.8675) and (score<=9.9975):
            return 17
        elif score>9.9975:
            return 18

    elif test=="ListSort":
        score = round(score)                                                                                                                                                                                                         
        if score==0.0:
            return 1
        elif score==1.0:
            return 2
        elif (score>1.0) and (score<=3.0):
            return 3
        elif (score>3.0) and (score<=5.0):
            return 4
        elif (score>5.0) and (score<=7.0):
            return 5
        elif (score>7.0) and (score<=9.0):
            return 6
        elif (score>9.0) and (score<=12.0):
            return 7
        elif (score>12.0) and (score<=14.0):
            return 8
        elif score==15.0:
            return 9
        elif score==16.0:
            return 10
        elif (score>16.0) and (score<=18.0):
            return 11
        elif score==19.0:
            return 12
        elif score==20.0:
            return 13
        elif score==21.0:
            return 14
        elif score==22.0:
            return 15
        elif score==23.0:
            return 16
        elif score==24.0:
            return 17
        elif score==25.0:
            return 18
        elif score==26.0:
            return 19


    elif test=="PictureSeq":
        score = round(score, 2)
        if (score<=213.79):
            return 0
        elif (score>213.79) and (score<=238.98):
            return 1
        elif (score>238.98) and (score<=246.40):
            return 2
        elif (score>246.40) and (score<=273.92):
            return 3
        elif (score>273.92) and (score<=301.72):
            return 4
        elif (score>301.72) and (score<=345.77):
            return 5
        elif (score>345.77) and (score<=381.96):
            return 6
        elif (score>381.96) and (score<=418.98):
            return 7
        elif (score>418.98) and (score<=459.93):
            return 8
        elif (score>459.93) and (score<=492.65):
            return 9
        elif (score>492.65) and (score<=530.76):
            return 10
        elif (score>530.76) and (score<=567.13):
            return 11
        elif (score>567.13) and (score<=594.75):
            return 12
        elif (score>594.75) and (score<=618.73):
            return 13
        elif (score>618.73) and (score<=647.45):
            return 14
        elif (score>647.45) and (score<=676.47):
            return 15
        elif (score>676.47) and (score<=682.94):
            return 16
        elif (score>682.94) and (score<=697.90):
            return 17
        elif (score>697.90) and (score<=709.23):
            return 18
        elif (score>709.23) and (score<=751.96):
            return 19
        elif (score>751.96) and (score<=794.69):
            return 20
        elif (score>794.69):
            return 21
        else:
            return input

    elif test=="PatternComp":                                                                                                                                                                                                           
        if (score>=0.0) and (score<=15.0):
            return 0
        elif (score>=16.0) and (score<=18.0):
            return 1
        elif (score>=19.0) and (score<20.0):
            return 2
        elif (score>=20.0) and (score<=23.0):
            return 3
        elif (score>=24.0) and (score<=27.0):
            return 4
        elif (score>=28.0) and (score<=32.0):
            return 5
        elif (score>=33.0) and (score<=36.0):
            return 6
        elif (score>=37.0) and (score<=40.0):
            return 7
        elif (score>=41.0) and (score<=45.0):
            return 8
        elif (score>=46.0) and (score<=50.0):
            return 9
        elif (score>=51.0) and (score<=54.0):
            return 10
        elif (score>=55.0) and (score<=58.0):
            return 11
        elif (score>=59.0) and (score<=62.0):
            return 12
        elif (score>=63.0) and (score<=66.0):
            return 13
        elif (score>=67.0) and (score<=70.0):
            return 14
        elif (score>=71.0) and (score<=73.0):
            return 15
        elif (score>=74.0) and (score<=76.0):
            return 16
        elif (score>=77.0) and (score<=80.0):
            return 17
        elif (score>=81.0) and (score<=83.0):
            return 18
        elif (score>=84.0) and (score<=86.0):
            return 19
        elif (score>=87.0) and (score<=112.0):
            return 20
        elif (score>=113.0):
            return 21
        else:
            return input

    elif test=="OralReading":                                                                                                                                                                                                           
        if (score<=-23.20):
            return 0
        elif (score>-23.20) and (score<=-23.10):
            return 1
        elif (score>-23.10) and (score<=-22.45):
            return 2
        elif (score>-22.45) and (score<=-20.82):
            return 3
        elif (score>-20.82) and (score<=-19.47):
            return 4
        elif (score>-19.47) and (score<=-16.98):
            return 5
        elif (score>-16.98) and (score<=-10.41):
            return 6
        elif (score>-10.41) and (score<=-4.05):
            return 7
        elif (score>-4.05) and (score<=-1.87):
            return 8
        elif (score>-1.87) and (score<=-0.48):
            return 9
        elif (score>-0.48) and (score<=0.63):
            return 10
        elif (score>=0.63) and (score<=1.72):
            return 11
        elif (score>1.72) and (score<=2.64):
            return 12
        elif (score>2.64) and (score<=3.53):
            return 13
        elif (score>3.53) and (score<=4.56):
            return 14
        elif (score>4.56) and (score<=5.68):
            return 15
        elif (score>5.68) and (score<=6.77):
            return 16
        elif (score>6.77) and (score<=8.02):
            return 17
        elif (score>8.02) and (score<=8.61):
            return 18
        elif (score>8.61) and (score<=9.16):
            return 19
        elif (score>9.16) and (score<=15.31):
            return 20
        elif (score>15.31):
            return 21
        else:
            return input

    elif test=="PictureVocab":                                                                                                                                                                                                           
        if (score<=-9.68):
            return 0
        elif (score>-9.68) and (score<=-8.75):
            return 1
        elif (score>-8.75) and (score<=-8.17):
            return 2
        elif (score>-8.17) and (score<=-7.15):
            return 3
        elif (score>-7.15) and (score<=-6.00):
            return 4
        elif (score>-6.00) and (score<=-4.88):
            return 5
        elif (score>-4.88) and (score<=-3.75):
            return 6
        elif (score>-3.75) and (score<=-2.59):
            return 7
        elif (score>-2.59) and (score<=-1.31):
            return 8
        elif (score>-1.31) and (score<=-0.08):
            return 9
        elif (score>-0.08) and (score<=1.01):
            return 10
        elif (score>=1.01) and (score<=1.97):
            return 11
        elif (score>1.97) and (score<=2.87):
            return 12
        elif (score>2.87) and (score<=3.67):
            return 13
        elif (score>3.67) and (score<=4.65):
            return 14
        elif (score>4.65) and (score<=5.30):
            return 15
        elif (score>5.30) and (score<=5.90):
            return 16
        elif (score>5.90) and (score<=6.29):
            return 17
        elif (score>6.29) and (score<=7.16):
            return 18
        elif (score>7.16) and (score<=8.14):
            return 19
        elif (score>8.14) and (score<=14.36):
            return 20
        elif (score>14.36):
            return 21
        else:
            return input

def WhiteAsianAdults(test,score):
    
    if test=="DCCS":
        score = round(score,4)
        if (score>=0.0) and (score<=0.5404):
            return 0
        elif (score>=0.5405) and (score<=2.0637):
            return 1
        elif (score>=2.0638) and (score<=2.2054):
            return 2
        elif (score>=2.2055) and (score<=2.9179):
            return 3
        elif (score>=2.9180) and (score<=3.8137):
            return 4
        elif (score>=3.8138) and (score<=5.8289):
            return 5
        elif (score>=5.8290) and (score<=6.6010):
            return 6
        elif (score>=6.6011) and (score<=7.1002):
            return 7
        elif (score>=7.1003) and (score<=7.5333):
            return 8
        elif (score>=7.5334) and (score<=7.8810):
            return 9
        elif (score>=7.8811) and (score<=8.1515):
            return 10
        elif (score>=8.1516) and (score<=8.5080):
            return 11
        elif (score>=8.5081) and (score<=8.7705):
            return 12
        elif (score>=8.7706) and (score<=9.0352):
            return 13
        elif (score>=9.0353) and (score<=9.3022):
            return 14
        elif (score>=9.3023) and (score<=9.6987):
            return 15
        elif (score>=9.6988) and (score<=9.8755):
            return 16
        elif (score>=9.8756) and (score<=9.9906):
            return 17
        elif score>9.9906:
            return 18

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=0.6843):
            return 0
        elif (score>=0.6844) and (score<=4.0608):
            return 1
        elif (score>=4.0609) and (score<=4.3611):
            return 2
        elif (score>=4.3612) and (score<=4.9508):
            return 3
        elif (score>=4.9509) and (score<=6.1730):
            return 4
        elif (score>=6.1731) and (score<=6.7520):
            return 5
        elif (score>=6.7521) and (score<=7.4273):
            return 6
        elif (score>=7.4274) and (score<=7.8348):
            return 7
        elif (score>=7.8349) and (score<=8.1643):
            return 8
        elif (score>=8.1644) and (score<=8.4571):
            return 9
        elif (score>=8.4572) and (score<=8.7349):
            return 10
        elif (score>=8.7350) and (score<=8.9542):
            return 11
        elif (score>=8.9543) and (score<=9.1860):
            return 12
        elif (score>=9.1861) and (score<=9.4054):
            return 13
        elif (score>=9.4055) and (score<=9.5878):
            return 14
        elif (score>=9.5879) and (score<=9.7315):
            return 15
        elif (score>=9.7316) and (score<=9.8798):
            return 16
        elif (score>=9.8799) and (score<=9.9933):
            return 17
        elif score>9.9934:
            return 18

    if test=="ListSort":
        score = round(score)
        if (score>=0.0) and (score<=1.0):
            return 0
        elif (score>=2.0) and (score<=3.0):
            return 1
        elif (score>=4.0) and (score<=5.0):
            return 2
        elif (score>=6.0) and (score<=7.0):
            return 3
        elif (score>=8.0) and (score<=9.0):
            return 4
        elif (score>=10.0) and (score<=11.0):
            return 5
        elif (score>=12.0) and (score<=13.0):
            return 6
        elif score==14.0:
            return 7
        elif score==15:
            return 8
        elif score==16:
            return 9
        elif score==17:
            return 10
        elif score==18:
            return 11
        elif score==19:
            return 12
        elif score==20:
            return 13
        elif score==21:
            return 14
        elif score==22:
            return 15
        elif score==23 or score==24:
            return 16
        elif score==25:
            return 17
        elif score==26:
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=203.32):
            return 0
        elif (score>=203.33) and (score<=244.53):
            return 1
        elif (score>=244.54) and (score<=289.78):
            return 2
        elif (score>=289.79) and (score<=300.46):
            return 3
        elif (score>=300.47) and (score<=331.71):
            return 4
        elif (score>=331.72) and (score<=352.26):
            return 5
        elif (score>=352.27) and (score<=382.36):
            return 6
        elif (score>=382.37) and (score<=417.12):
            return 7
        elif (score>=417.13) and (score<=442.95):
            return 8
        elif (score>=442.96) and (score<=480.65):
            return 9
        elif (score>=480.66) and (score<=522.65):
            return 10
        elif (score>=522.66) and (score<=550.57):
            return 11
        elif (score>=550.58) and (score<=596.90):
            return 12
        elif (score>=596.91) and (score<=624.29):
            return 13
        elif (score>=624.30) and (score<=653.19):
            return 14
        elif (score>=653.20) and (score<=677.92):
            return 15
        elif (score>=677.93) and (score<=690.73):
            return 16
        elif (score>=690.74) and (score<=700.91):
            return 17
        elif (score>=700.92) and (score<=722.91):
            return 18
        elif (score>=722.92) and (score<=794.52):
            return 19
        elif (score>=794.53):
            return 20

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=5.0):
            return 0
        elif (score>=6.0) and (score<=25.0):
            return 1
        elif (score>=26.0) and (score<=27.0):
            return 2
        elif score==28:
            return 3
        elif (score>=29.0) and (score<=32.0):
            return 4
        elif (score>=33.0) and (score<=38.0):
            return 5
        elif (score>=39.0) and (score<=42.0):
            return 6
        elif (score>=43.0) and (score<=46.0):
            return 7
        elif (score>=47.0) and (score<=49.0):
            return 8
        elif (score>=50.0) and (score<=53.0):
            return 9
        elif (score>=54.0) and (score<=56.0):
            return 10
        elif (score>=57.0) and (score<=60.0):
            return 11
        elif (score>=61.0) and (score<=65.0):
            return 12
        elif (score>=66.0) and (score<=68.0):
            return 13
        elif (score>=69.0) and (score<=72.0):
            return 14
        elif (score>=73.0) and (score<=75.0):
            return 15
        elif (score>=76.0) and (score<=78.0):
            return 16
        elif (score>=79.0) and (score<=81.0):
            return 17
        elif (score>=82.0) and (score<=87.0):
            return 18
        elif (score>=88.0) and (score<=124.0):
            return 19
        elif (score>=125.0):
            return 20

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-24.08):
            return 0
        elif (score>=-24.07) and (score<=-5.18):
            return 1
        elif (score>=-5.17) and (score<=-3.43):
            return 2
        elif (score>=-3.42) and (score<=-1.06):
            return 3
        elif (score>=-1.05) and (score<=-0.13):
            return 4
        elif (score>=-0.12) and (score<=0.70):
            return 5
        elif (score>=0.71) and (score<=1.58):
            return 6
        elif (score>=1.59) and (score<=2.58):
            return 7
        elif (score>=2.59) and (score<=3.39):
            return 8
        elif (score>=3.40) and (score<=4.27):
            return 9
        elif (score>=4.28) and (score<=5.12):
            return 10
        elif (score>=5.13) and (score<=6.03):
            return 11
        elif (score>=6.04) and (score<=6.91):
            return 12
        elif (score>=6.92) and (score<=7.71):
            return 13
        elif (score>=7.72) and (score<=8.38):
            return 14
        elif (score>=8.39) and (score<=8.94):
            return 15
        elif (score>=8.95) and (score<=9.21):
            return 16
        elif (score>=9.22) and (score<=9.63):
            return 17
        elif (score>=9.64) and (score<=11.04):
            return 18
        elif (score>=11.05) and (score<=18.78):
            return 19
        elif (score>=18.79):
            return 20

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-14.66):
            return 0
        elif (score>=-14.65) and (score<=-4.72):
            return 1
        elif (score>=-4.71) and (score<=-3.20):
            return 2
        elif (score>=-3.19) and (score<=-1.15):
            return 3
        elif (score>=-1.14) and (score<=0.53):
            return 4
        elif (score>=0.54) and (score<=1.87):
            return 5
        elif (score>=1.88) and (score<=2.77):
            return 6
        elif (score>=2.78) and (score<=3.61):
            return 7
        elif (score>=3.62) and (score<=4.16):
            return 8
        elif (score>=4.17) and (score<=4.73):
            return 9
        elif (score>=4.74) and (score<=5.26):
            return 10
        elif (score>=5.27) and (score<=5.90):
            return 11
        elif (score>=5.91) and (score<=6.60):
            return 12
        elif (score>=6.61) and (score<=7.37):
            return 13
        elif (score>=7.38) and (score<=8.09):
            return 14
        elif (score>=8.10) and (score<=8.88):
            return 15
        elif (score>=8.89) and (score<=9.62):
            return 16
        elif (score>=9.63) and (score<=10.37):
            return 17
        elif (score>=10.38) and (score<=10.75):
            return 18
        elif (score>=10.76) and (score<=14.85):
            return 19
        elif (score>=14.86):
            return 20

def AfricanAmericanAdults(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0.0) and (score<=2.1475):
            return 2
        elif (score>=2.1476) and (score<=2.5139):
            return 3
        elif (score>=2.514) and (score<=5.1099):
            return 4
        elif (score>=5.11) and (score<=6.6031):
            return 5
        elif (score>=6.6032) and (score<=7.0744):
            return 6
        elif (score>=7.0745) and (score<=7.3682):
            return 7
        elif (score>=7.3683) and (score<=7.6327):
            return 8
        elif (score>=7.6328) and (score<=7.9117):
            return 9
        elif (score>=7.9118) and (score<=8.1787):
            return 10
        elif (score>=8.1788) and (score<=8.396):
            return 11
        elif (score>=8.3961) and (score<=8.5684):
            return 12
        elif (score>=8.5685) and (score<=8.8096):
            return 13
        elif (score>=8.8097) and (score<=9.2495):
            return 14
        elif (score>=9.2496) and (score<=9.5291):
            return 15
        elif (score>=9.5292) and (score<=9.7346):
            return 16
        elif (score>=9.7347) and (score<=9.8524):
            return 17
        elif (score>=9.8525) and (score<=10.00):
            return 18

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=4.5904):
            return 2
        elif (score>=4.5905) and (score<=5.4702):
            return 3
        elif (score>=5.4703) and (score<=6.0146):
            return 4
        elif (score>=6.0147) and (score<=6.7302):
            return 5
        elif (score>=6.7303) and (score<=7.3608):
            return 6
        elif (score>=7.3609) and (score<=7.854):
            return 7
        elif (score>=7.8541) and (score<=8.0763):
            return 8
        elif (score>=8.0764) and (score<=8.3185):
            return 9
        elif (score>=8.3186) and (score<=8.5345):
            return 10
        elif (score>=8.5346) and (score<=8.7706):
            return 11
        elif (score>=8.7707) and (score<=8.983):
            return 12
        elif (score>=8.9831) and (score<=9.3043):
            return 13
        elif (score>=9.3044) and (score<=9.4427):
            return 14
        elif (score>=9.4428) and (score<=9.6596):
            return 15
        elif (score>=9.6597) and (score<=9.7763):
            return 16
        elif (score>=9.7764) and (score<=9.9821):
            return 17
        elif score>9.9821:
            return 18

    if test=="ListSort":
        score = round(score)
        if (score>=0.0) and (score<=6.0):
            return 2
        elif score==7.0 or score==8.0:
            return 3
        elif (score>=9.0) and (score<=10.0):
            return 4
        elif score==11.0:
            return 5
        elif score==12 or score==13.0:
            return 6
        #elif score==13:
            #return 7
        elif score==14:
            return 8
        elif score==15:
            return 9
        elif score==16:
            return 10
        elif score==17 or score==18.0:
            return 11
        elif score==19.0:
            return 12

        elif score==20:
            return 14
        elif (score==21.0) or (score==22.0):
            return 15
        elif score==23:
            return 16
        elif score==24:
            return 17
        elif (score==25.0) or (score==26.0):
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=311.14):
            return 2
        elif (score>=311.15) and (score<=324.52):
            return 3
        elif (score>=324.53) and (score<=333.35):
            return 4
        elif (score>=333.36) and (score<=359.23):
            return 5
        elif (score>=359.24) and (score<=376.23):
            return 6
        elif (score>=376.24) and (score<=400.45):
            return 7
        elif (score>=400.46) and (score<=428.47):
            return 8
        elif (score>=428.48) and (score<=469.41):
            return 9
        elif (score>=469.42) and (score<=500.82):
            return 10
        elif (score>=500.83) and (score<=528.54):
            return 11
        elif (score>=528.55) and (score<=585.59):
            return 12
        elif (score>=585.60) and (score<=614.46):
            return 13
        elif (score>=614.47) and (score<=639.02):
            return 14
        elif (score>=639.03) and (score<=667.76):
            return 15
        elif (score>=667.77) and (score<=689.98):
            return 16
        elif (score>=689.99) and (score<=705.78):
            return 17
        elif (score>=705.79):
            return 18

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=24.0):
            return 2
        elif (score>=25.0) and (score<=30.0):
            return 3
        elif (score>=31.0) and (score<=33.0):
            return 4
        elif (score>=34.0) and (score<=37.0):
            return 5
        elif (score>=38.0) and (score<=40.0):
            return 6
        elif (score>=41.0) and (score<=43.0):
            return 7
        elif (score>=44.0) and (score<=47.0):
            return 8
        elif (score>=48.0) and (score<=52.0):
            return 9
        elif (score>=53.0) and (score<=55.0):
            return 10
        elif (score>=56.0) and (score<=58.0):
            return 11
        elif (score>=59.0) and (score<=61.0):
            return 12
        elif (score>=62.0) and (score<=65.0):
            return 13
        elif (score>=66.0) and (score<=69.0):
            return 14
        elif (score>=70.0) and (score<=73.0):
            return 15
        elif (score>=74.0) and (score<=76.0):
            return 16
        elif (score>=77.0) and (score<=83.0):
            return 17
        elif (score>=84.0):
            return 18

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-10.91):
            return 2
        elif (score>=-10.90) and (score<=-3.66):
            return 3
        elif (score>=-3.65) and (score<=-1.97):
            return 4
        elif (score>=-1.96) and (score<=-1.32):
            return 5
        elif (score>=-1.31) and (score<=-0.57):
            return 6
        elif (score>=-0.56) and (score<=0.83):
            return 7
        elif (score>=0.84) and (score<=1.87):
            return 8
        elif (score>=1.88) and (score<=2.74):
            return 9
        elif (score>=2.75) and (score<=3.52):
            return 10
        elif (score>=3.53) and (score<=4.17):
            return 11
        elif (score>=4.18) and (score<=5.04):
            return 12
        elif (score>=5.05) and (score<=5.84):
            return 13
        elif (score>=5.85) and (score<=7.39):
            return 14
        elif (score>=7.40) and (score<=8.36):
            return 15
        elif (score>=8.37) and (score<=8.78):
            return 16
        elif (score>=8.79) and (score<=8.97):
            return 17
        elif (score>=8.98):
            return 18

    if test=="PictureVocab":
        score = round(score,2)
        if (score<=-2.24):
            return 2
        elif (score>=-2.23) and (score<=-0.45):
            return 3
        elif (score>=-0.44) and (score<=0.36):
            return 4
        elif (score>=0.37) and (score<=0.74):
            return 5
        elif (score>=0.75) and (score<=1.39):
            return 6
        elif (score>=1.40) and (score<=2.06):
            return 7
        elif (score>=2.07) and (score<=2.77):
            return 8
        elif (score>=2.78) and (score<=3.54):
            return 9
        elif (score>=3.55) and (score<=3.89):
            return 10
        elif (score>=3.90) and (score<=4.40):
            #print "HERE"
            return 11
        elif (score>=4.41) and (score<=5.08):
            return 12
        elif (score>=5.09) and (score<=5.33):
            return 13
        elif (score>=5.34) and (score<=5.94):
            return 14
        elif (score>=5.95) and (score<=7.67):
            return 15
        elif (score>=7.68) and (score<=9.16):
            return 16
        elif (score>=9.17) and (score<=9.43):
            return 17
        elif (score>=9.44):
            return 18
    
def HispanicAdults(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0) and (score<=0.8727):
            return 2
        elif (score>=0.8728) and (score<=2.1536):
            return 3
        elif (score>=2.1537) and (score<=2.2838):
            return 4
        elif (score>=2.2839) and (score<=4.7393):
            return 5
        elif (score>=4.7394) and (score<=6.7096):
            return 6
        elif (score>=6.7097) and (score<=7.438):
            return 7
        elif (score>=7.4381) and (score<=7.7477):
            return 8
        elif (score>=7.7478) and (score<=8.0516):
            return 9
        elif (score>=8.0517) and (score<=8.3232):
            return 10
        elif (score>=8.3233) and (score<=8.6759):
            return 11
        elif (score>=8.676) and (score<=8.8676):
            return 12
        elif (score>=8.8677) and (score<=9.2721):
            return 13
        elif (score>=9.2722) and (score<=9.4615):
            return 14
        elif (score>=9.4616) and (score<=9.6683):
            return 15
        elif (score>=9.6684) and (score<=9.891):
            return 16
        elif score>9.891:
            return 17

    elif test=="Flanker":
        score = round(score,2)   
        if (score>=0.0) and (score<=3.447):
            return 2
        elif (score>=3.4471) and (score<=5.6946):
            return 3
        elif (score>=5.6947) and (score<=6.7598):
            return 4
        elif (score>=6.7599) and (score<=7.6473):
            return 5
        elif (score>=7.6474) and (score<=8.0463):
            return 6
        elif (score>=8.0464) and (score<=8.2446):
            return 7
        elif (score>=8.2447) and (score<=8.3371):
            return 8
        elif (score>=8.3372) and (score<=8.7409):
            return 9
        elif (score>=8.741) and (score<=8.9815):
            return 10
        elif (score>=8.9816) and (score<=9.1626):
            return 11
        elif (score>=9.1627) and (score<=9.37):
            return 12
        elif (score>=9.3701) and (score<=9.4842):
            return 13
        elif (score>=9.4843) and (score<=9.6422):
            return 14
        elif (score>=9.6423) and (score<=9.7604):
            return 15
        elif (score>=9.7605) and (score<=9.9951):
            return 16
        elif score>9.9952:
            return 17

    if test=="ListSort":
        score = round(score)
        if (score>=0.0) and (score<=4.0):
            return 2
        elif (score>=5.0) and (score<=7.0):
            return 3
        elif (score>=8.0) and (score<=9.0):
            return 4
        elif score==10:
            return 5
        elif (score>=11.0) and (score<=12.0):
            return 6
        elif (score==13.0) or (score==14.0):
            return 7
        elif score==15:
            return 8
        elif score==16:
            return 9
        elif score==17:
            return 10
        elif score==18:
            return 11
        elif score==19:
            return 12
        elif score==20:
            return 13
        elif score==21 or score==22:
            return 14
        elif score==23:
            return 15
        elif score==24:
            return 16
        elif score==25:
            return 17
        elif score==26:
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=235.69):
            return 2
        elif (score>=235.70) and (score<=310.53):
            return 3
        elif (score>=310.54) and (score<=339.79):
            return 4
        elif (score>=339.80) and (score<=355.26):
            return 5
        elif (score>=355.27) and (score<=403.52):
            return 6
        elif (score>=403.53) and (score<=428.28):
            return 7
        elif (score>=428.29) and (score<=474.55):
            return 8
        elif (score>=474.56) and (score<=520.25):
            return 9
        elif (score>=520.26) and (score<=571.80):
            return 10
        elif (score>=571.81) and (score<=594.02):
            return 11
        elif (score>=594.03) and (score<=626.25):
            return 12
        elif (score>=626.26) and (score<=651.07):
            return 13
        elif (score>=651.08) and (score<=677.55):
            return 14
        elif (score>=677.56) and (score<=683.45):
            return 15
        elif (score>=683.46) and (score<=698.33):
            return 16
        elif (score>=698.34) and (score<=749.31):
            return 17
        elif (score>=749.32):
            return 18

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=16.0):
            return 2
        elif (score>=17.0) and (score<=32.0):
            return 3
        elif (score>=33.0) and (score<=39.0):
            return 4
        elif (score>=40.0) and (score<=44.0):
            return 5
        elif (score>=45.0) and (score<=47.0):
            return 6
        elif (score>=48.0) and (score<=49.0):
            return 7
        elif (score>=50.0) and (score<=52.0):
            return 8
        elif (score>=53.0) and (score<=57.0):
            return 9
        elif (score>=58.0) and (score<=60.0):
            return 10
        elif (score>=61.0) and (score<=63.0):
            return 11
        elif (score>=64.0) and (score<=65.0):
            return 12
        elif (score>=66.0) and (score<=69.0):
            return 13
        elif (score>=70.0) and (score<=72.0):
            return 14
        elif (score>=73.0) and (score<=74.0):
            return 15
        elif (score>=75.0) and (score<=80.0):
            return 16
        elif (score>=81.0) and (score<=102.0):
            return 17
        elif (score>=103.0):
            return 18

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-12.15):
            return 2
        elif (score>=-12.14) and (score<=-2.01):
            return 3
        elif (score>=-2.00) and (score<=-1.15):
            return 4
        elif (score>=-1.14) and (score<=0.26):
            return 5
        elif (score>=0.27) and (score<=0.86):
            return 6
        elif (score>=0.87) and (score<=2.21):
            return 7
        elif (score>=2.22) and (score<=2.82):
            return 8
        elif (score>=2.83) and (score<=3.88):
            return 9
        elif (score>=3.89) and (score<=5.08):
            return 10
        elif (score>=5.09) and (score<=6.22):
            return 11
        elif (score>=6.23) and (score<=7.02):
            return 12
        elif (score>=7.03) and (score<=7.57):
            return 13
        elif (score>=7.58) and (score<=8.00):
            return 14
        elif (score>=8.01) and (score<=8.86):
            return 15
        elif (score>=8.87) and (score<=9.03):
            return 16
        elif (score>=9.04) and (score<=12.91):
            return 17
        elif (score>=12.92):
            return 18

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-8.50):
            return 2
        elif (score>=-8.49) and (score<=-1.76):
            return 3
        elif (score>=-1.75) and (score<=0.07):
            return 4
        elif (score>=0.08) and (score<=1.29):
            return 5
        elif (score>=1.30) and (score<=1.93):
            return 6
        elif (score>=1.94) and (score<=2.60):
            return 7
        elif (score>=2.61) and (score<=3.27):
            return 8
        elif (score>=3.28) and (score<=3.68):
            return 9
        elif (score>=3.69) and (score<=4.56):
            return 10
        elif (score>=4.57) and (score<=5.63):
            return 11
        elif (score>=5.64) and (score<=6.24):
            return 12
        elif (score>=6.25) and (score<=7.33):
            return 13
        elif (score>=7.34) and (score<=7.91):
            return 14
        elif (score>=7.92) and (score<=8.64):
            return 15
        elif (score>=8.65) and (score<=9.23):
            return 16
        elif (score>=9.24) and (score<=12.38):
            return 17
        elif (score>=12.39):
            return 18

def MultiChildren(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0.00) and (score<=0.1608):
            return 2
        elif (score>=0.1609) and (score<=0.3059):
            return 3
        elif (score>=0.3060) and (score<=0.3920):
            return 4
        elif (score>=0.3921) and (score<=0.6561):
            return 5
        elif (score>=0.6562) and (score<=1.6443):
            return 6
        elif (score>=1.6444) and (score<=5.0046):
            return 7
        elif (score>=5.0047) and (score<=6.5024):
            return 8
        elif (score>=6.5025) and (score<=7.1638):
            return 9
        elif (score>=7.1639) and (score<=7.6716):
            return 10
        elif (score>=7.6717) and (score<=7.9446):
            return 11
        elif (score>=7.9447) and (score<=8.2923):
            return 12
        elif (score>=8.2924) and (score<=8.6273):
            return 13
        elif (score>=8.6274) and (score<=9.0002):
            return 14
        elif (score>=9.0003) and (score<=9.3357):
            return 15
        elif (score>=9.3358) and (score<=9.6568):
            return 16
        elif (score>=9.6569) and (score<=9.9205):
            return 17
        elif (score>=9.9206):
            return 18

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=0.8006):
            return 2
        elif (score>=0.8007) and (score<=1.4073):
            return 3
        elif (score>=1.4074) and (score<=1.6462):
            return 4
        elif (score>=1.6463) and (score<=1.8651):
            return 5
        elif (score>=1.8652) and (score<=2.9827):
            return 6
        elif (score>=2.9828) and (score<=5.2369):
            return 7
        elif (score>=5.237) and (score<=7.282):
            return 8
        elif (score>=7.2821) and (score<=8.0785):
            return 9
        elif (score>=8.0786) and (score<=8.3949):
            return 10
        elif (score>=8.395) and (score<=8.7866):
            return 11
        elif (score>=8.7867) and (score<=9.2062):
            return 12
        elif (score>=9.2063) and (score<=9.3614):
            return 13
        elif (score>=9.3615) and (score<=9.5853):
            return 14
        elif (score>=9.5854) and (score<=9.6802):
            return 15
        elif (score>=9.6803) and (score<=9.7992):
            return 16
        elif (score>=9.7993) and (score<=9.9203):
            return 17
        elif (score>=9.9204):
            return 18

    if test=="ListSort":
        score = round(score)
        if (score>=0) and (score<=1):
            return 2
        elif (score>=2) and (score<=3):
            return 3
        elif (score==4):
            return 4
        elif (score==5):
            return 5
        elif (score>=6) and (score<=8):
            return 6
        elif (score>=9) and (score<=10):
            return 7
        elif (score>=11) and (score<=13):
            return 8
        elif (score>=14) and (score<=15):
            return 9
        elif (score==16):
            return 10
        elif (score>=17) and (score<=18):
            return 11
        elif score==19:
            return 13
        elif (score>=20) and (score<=21):
            return 14
        elif score==22:
            return 15
        elif (score==23):
            return 16
        elif (score>=24) and (score<=25):
            return 17
        elif (score==26):
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=241.49):
            return 2
        elif (score>=241.50) and (score<=299.30):
            return 3
        elif (score>=299.31) and (score<=313.76):
            return 4
        elif (score>=313.77) and (score<=350.30):
            return 5
        elif (score>=350.31) and (score<=403.03):
            return 6
        elif (score>=403.04) and (score<=418.35):
            return 7
        elif (score>=418.36) and (score<=460.16):
            return 8
        elif (score>=460.17) and (score<=486.77):
            return 9
        elif (score>=486.78) and (score<=516.55):
            return 10
        elif (score>=516.56) and (score<=560.29):
            return 11
        elif (score>=560.30) and (score<=591.76):
            return 12
        elif (score>=591.77) and (score<=621.70):
            return 13
        elif (score>=621.71) and (score<=646.93):
            return 14
        elif (score>=646.94) and (score<=659.66):
            return 15
        elif (score>=659.67) and (score<=702.10):
            return 16
        elif (score>=702.11) and (score<=774.64):
            return 17
        elif (score>=774.65):
            return 18

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=11.0):
            return 2
        elif (score>=12.0) and (score<=19.0):
            return 3
        elif (score>=20.0) and (score<=22.0):
            return 4
        elif (score>=23.0) and (score<=28.0):
            return 5
        elif (score>=29.0) and (score<=31.0):
            return 6
        elif (score>=32.0) and (score<=38.0):
            return 7
        elif (score>=39.0) and (score<=42.0):
            return 8
        elif (score>=43.0) and (score<=48.0):
            return 9
        elif (score>=49.0) and (score<=52.0):
            return 10
        elif (score>=53.0) and (score<=56.0):
            return 11
        elif (score>=57.0) and (score<=60.0):
            return 12
        elif (score>=61.0) and (score<=64.0):
            return 13
        elif (score>=65.0) and (score<=68.0):
            return 14
        elif (score>=69.0) and (score<=72.0):
            return 15
        elif (score>=73.0) and (score<=75.0):
            return 16
        elif (score>=76.0) and (score<=96.0):
            return 17
        elif (score>=97.0):
            return 18


    if test=="OralReading": 
        score = round(score,2)
        if (score<=-25.79):
            return 2
        elif (score>=-25.78) and (score<=-21.95):
            return 3
        elif (score>=-21.94) and (score<=-20.82):
            return 4
        elif (score>=-20.81) and (score<=-19.64):
            return 5
        elif (score>=-19.63) and (score<=-17.54):
            return 6
        elif (score>=-17.53) and (score<=-9.29):
            return 7
        elif (score>=-9.28) and (score<=-2.57):
            return 8
        elif (score>=-2.56) and (score<=-0.47):
            return 9
        elif (score>=-0.46) and (score<=0.65):
            return 10
        elif (score>=0.66) and (score<=1.86):
            return 11
        elif (score>=1.87) and (score<=3.04):
            return 12
        elif (score>=3.05) and (score<=3.85):
            return 13
        elif (score>=3.86) and (score<=4.46):
            return 14
        elif (score>=4.47) and (score<=5.72):
            return 15
        elif (score>=5.73) and (score<=6.75):
            return 16
        elif (score>=6.76) and (score<=12.61):
            return 17
        elif (score>=12.62):
            return 18

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-12.04):
            return 2
        elif (score>=-12.03) and (score<=-6.82):
            return 3
        elif (score>=-6.81) and (score<=-6.73):
            return 4
        elif (score>=-6.72) and (score<=-5.87):
            return 5
        elif (score>=-5.86) and (score<=-4.23):
            return 6
        elif (score>=-4.22) and (score<=-3.57):
            return 7
        elif (score>=-3.56) and (score<=-2.19):
            return 8
        elif (score>=-2.18) and (score<=-0.06):
            return 9
        elif (score>=-0.05) and (score<=1.30):
            return 10
        elif (score>=1.31) and (score<=2.12):
            return 11
        elif (score>=2.13) and (score<=3.02):
            return 12
        elif (score>=3.03) and (score<=3.84):
            return 13
        elif (score>=3.85) and (score<=4.40):
            return 14
        elif (score>=4.41) and (score<=5.10):
            return 15
        elif (score>=5.11) and (score<=6.45):
            return 16
        elif (score>=6.46) and (score<=11.94):
            return 17
        elif (score>=11.95):
            return 18

def AfricanAmericanChildren(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0) and (score<=0.0267):
            return 1
        elif (score>=0.0268) and (score<=0.1926):
            return 2
        elif (score>=0.1927) and (score<=0.3383):
            return 3
        elif (score>=0.3384) and (score<=0.5836):
            return 4
        elif (score>=0.5837) and (score<=0.9244):
            return 5
        elif (score>=0.9245) and (score<=3.6775):
            return 6
        elif (score>=3.6776) and (score<=5.5766):
            return 7
        elif (score>=5.5767) and (score<=6.5491):
            return 8
        elif (score>=6.5492) and (score<=7.2127):
            return 9
        elif (score>=7.2128) and (score<=7.6161):
            return 10
        elif (score>=7.6162) and (score<=8.01):
            return 11
        elif (score>=8.0101) and (score<=8.3353):
            return 12
        elif (score>=8.3354) and (score<=8.693):
            return 13
        elif (score>=8.6931) and (score<=9.0247):
            return 14
        elif (score>=9.0248) and (score<=9.403):
            return 15
        elif (score>=9.4031) and (score<=9.7919):
            return 16
        elif (score>=9.792) and (score<=9.8875):
            return 17
        elif (score>=9.8876):
            return 18

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=0.5427):
            return 1
        elif (score>=0.5428) and (score<=0.7669):
            return 2
        elif (score>=0.767) and (score<=1.2164):
            return 3
        elif (score>=1.2165) and (score<=1.6794):
            return 4
        elif (score>=1.6795) and (score<=2.6205):
            return 5
        elif (score>=2.6206) and (score<=5.0297):
            return 6
        elif (score>=5.0298) and (score<=6.4095):
            return 7
        elif (score>=6.4096) and (score<=7.2039):
            return 8
        elif (score>=7.204) and (score<=7.8695):
            return 9
        elif (score>=7.8696) and (score<=8.368):
            return 10
        elif (score>=8.3681) and (score<=8.7415):
            return 11
        elif (score>=8.7416) and (score<=9.093):
            return 12
        elif (score>=9.0931) and (score<=9.3199):
            return 13
        elif (score>=9.32) and (score<=9.4241):
            return 14
        elif (score>=9.4242) and (score<=9.5929):
            return 15
        elif (score>=9.593) and (score<=9.8304):
            return 16
        elif (score>=9.8305) and (score<=9.9395):
            return 17
        elif (score>=9.9396) and (score<=9.9946):
            return 18
        elif score>9.9946:
            return 19

    if test=="ListSort":
        score = round(score)
        if (score==0.0):
            return 2
        elif (score>=1) and (score<=3):
            return 3
        elif (score==4):
            return 4
        elif (score>=5) and (score<=6):
            return 5
        elif (score>=7) and (score<=9):
            return 6
        elif (score>=10) and (score<=11):
            return 7
        elif (score==12):
            return 8
        elif (score>=13) and (score<=14):
            return 9
        elif (score==15):
            return 10
        elif score==16:
            return 11
        elif score==17:
            return 12
        elif score==18 or score==19:
            return 13
        elif score==20:
            return 14
        elif score==21:
            return 15
        elif (score==22):
            return 16
        elif (score==23):
            return 17
        elif (score>=24) and (score<=25):
            return 18
        elif score==26:
            return 19

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=212.74):
            return 1
        elif (score>=212.76) and (score<=246.48):
            return 2
        elif (score>=246.49) and (score<=274.80):
            return 3
        elif (score>=274.81) and (score<=298.08):
            return 4
        elif (score>=298.09) and (score<=345.46):
            return 5
        elif (score>=345.47) and (score<=369.98):
            return 6
        elif (score>=369.99) and (score<=411.03):
            return 7
        elif (score>=411.04) and (score<=436.76):
            return 8
        elif (score>=436.77) and (score<=472.53):
            return 9
        elif (score>=472.54) and (score<=501.08):
            return 10
        elif (score>=501.09) and (score<=537.51):
            return 11
        elif (score>=537.52) and (score<=570.06):
            return 12
        elif (score>=570.07) and (score<=594.17):
            return 13
        elif (score>=594.18) and (score<=618.94):
            return 14
        elif (score>=618.95) and (score<=641.91):
            return 15
        elif (score>=641.92) and (score<=679.77):
            return 16
        elif (score>=679.78) and (score<=692.02):
            return 17
        elif (score>=692.03) and (score<=748.41):
            return 18
        elif (score>=748.42):
            return 19

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=19.0):
            return 1
        elif (score==20.0):
            return 2
        elif (score>=21.0) and (score<=23.0):
            return 3
        elif (score>=24.0) and (score<=28.0):
            return 4
        elif (score>=29.0) and (score<=32.0):
            return 5
        elif (score>=33.0) and (score<=35.0):
            return 6
        elif (score>=36.0) and (score<=39.0):
            return 7
        elif (score>=40.0) and (score<=44.0):
            return 8
        elif (score>=45.0) and (score<=48.0):
            return 9
        elif (score>=49.0) and (score<=52.0):
            return 10
        elif (score>=53.0) and (score<=56.0):
            return 11
        elif (score>=57.0) and (score<=60.0):
            return 12
        elif (score>=61.0) and (score<=64.0):
            return 13
        elif (score>=65.0) and (score<=67.0):
            return 14
        elif (score>=68.0) and (score<=70.0):
            return 15
        elif (score>=71.0) and (score<=74.0):
            return 16
        elif (score>=75.0) and (score<=78.0):
            return 17
        elif (score>=79.0) and (score<=84.0):
            return 18
        elif (score>=85.0):
            return 19

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-25.67):
            return 1
        elif (score>=-25.66) and (score<=-22.21):
            return 2
        elif (score>=-22.22) and (score<=-21.22):
            return 3
        elif (score>=-21.21) and (score<=-18.90):
            return 4
        elif (score>=-18.89) and (score<=-16.02):
            return 5
        elif (score>=-16.01) and (score<=-9.31):
            return 6
        elif (score>=-9.30) and (score<=-4.29):
            return 7
        elif (score>=-4.28) and (score<=-2.50):
            return 8
        elif (score>=-2.49) and (score<=-1.20):
            return 9
        elif (score>=-1.19) and (score<=-0.23):
            return 10
        elif (score>=-0.22) and (score<=0.91):
            return 11
        elif (score>=0.92) and (score<=1.83):
            return 12
        elif (score>=1.84) and (score<=2.55):
            return 13
        elif (score>=2.56) and (score<=3.55):
            return 14
        elif (score>=3.56) and (score<=4.60):
            return 15
        elif (score>=4.61) and (score<=6.18):
            return 16
        elif (score>=6.19) and (score<=7.61):
            return 17
        elif (score>=7.62) and (score<=8.89):
            return 18
        elif (score>=8.90):
            return 19

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-9.52):
            return 1
        elif (score>=-9.51) and (score<=-8.06):
            return 2
        elif (score>=-8.05) and (score<=-6.99):
            return 3
        elif (score>=-6.98) and (score<=-5.84):
            return 4
        elif (score>=-5.83) and (score<=-4.91):
            return 5
        elif (score>=-4.90) and (score<=-4.26):
            return 6
        elif (score>=-4.25) and (score<=-2.93):
            return 7
        elif (score>=-2.92) and (score<=-1.80):
            return 8
        elif (score>=-1.79) and (score<=-0.74):
            return 9
        elif (score>=-0.73) and (score<=0.03):
            return 10
        elif (score>=0.04) and (score<=0.90):
            return 11
        elif (score>=0.91) and (score<=1.80):
            return 12
        elif (score>=1.81) and (score<=2.67):
            return 13
        elif (score>=2.68) and (score<=3.39):
            return 14
        elif (score>=3.40) and (score<=4.31):
            return 15
        elif (score>=4.32) and (score<=5.10):
            return 16
        elif (score>=5.11) and (score<=6.10):
            return 17
        elif (score>=6.11) and (score<=7.16):
            return 18
        elif (score>=7.17):
            return 19

def HispanicChildren(test,score):
    if test=="DCCS":
        score = round(score,2)                                                                                                                                   
        if (score>=0) and (score<=0.0375):
            return 1
        elif (score>=0.0376) and (score<=0.258):
            return 2
        elif (score>=0.2581) and (score<=0.5712):
            return 3
        elif (score>=0.5713) and (score<=0.925):
            return 4
        elif (score>=0.9251) and (score<=2.2714):
            return 5
        elif (score>=2.2715) and (score<=4.0406):
            return 6
        elif (score>=4.0407) and (score<=6.0608):
            return 7
        elif (score>=6.0609) and (score<=6.7552):
            return 8
        elif (score>=6.7553) and (score<=7.2913):
            return 9
        elif (score>=7.2914) and (score<=7.6287):
            return 10
        elif (score>=7.6288) and (score<=8.0987):
            return 11
        elif (score>=8.0988) and (score<=8.4094):
            return 12
        elif (score>=8.4095) and (score<=8.73):
            return 13
        elif (score>=8.7301) and (score<=9.0468):
            return 14
        elif (score>=9.0469) and (score<=9.3708):
            return 15
        elif (score>=9.3709) and (score<=9.7091):
            return 16
        elif (score>=9.7092) and (score<=9.7948):
            return 17
        elif (score>=9.7949) and (score<=9.9698):
            return 18
        elif (score>=9.9699):
            return 19

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=0.0325):
            return 1
        elif (score>=0.0326) and (score<=0.7754):
            return 2
        elif (score>=0.7755) and (score<=1.1768):
            return 3
        elif (score>=1.1769) and (score<=1.5592):
            return 4
        elif (score>=1.5593) and (score<=2.0789):
            return 5
        elif (score>=2.079) and (score<=4.9421):
            return 6
        elif (score>=4.9422) and (score<=6.4768):
            return 7
        elif (score>=6.4769) and (score<=7.2789):
            return 8
        elif (score>=7.279) and (score<=7.9292):
            return 9
        elif (score>=7.9293) and (score<=8.4059):
            return 10
        elif (score>=8.406) and (score<=8.8151):
            return 11
        elif (score>=8.8152) and (score<=9.1093):
            return 12
        elif (score>=9.1094) and (score<=9.3571):
            return 13
        elif (score>=9.3572) and (score<=9.5269):
            return 14
        elif (score>=9.527) and (score<=9.6762):
            return 15
        elif (score>=9.6763) and (score<=9.8174):
            return 16
        elif (score>=9.8175) and (score<=9.9827):
            return 17
        elif score>9.9827:
            return 18

    if test=="ListSort":
        score = round(score)
        if (score==0.0):
            return 2
        elif (score>=1) and (score<=3):
            return 3
        elif (score==4):
            return 4
        elif (score>=5) and (score<=7):
            return 5
        elif (score>=8) and (score<=9):
            return 6
        elif (score>=10) and (score<=11):
            return 7
        elif (score>=12) and (score<=13):
            return 8
        elif (score>=14) and (score<=15):
            return 9
        elif (score==16):
            return 10
        elif score==17:
            return 11
        elif (score==18):
            return 12
        elif score==19:
            return 13
        elif score==20:
            return 14
        elif score==21:
            return 15
        elif (score==22):
            return 16
        elif (score>=23) and (score<=24):
            return 17
        elif (score>=25) and (score<=26):
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=246.43):
            return 1
        elif (score>=246.44) and (score<=265.64):
            return 2
        elif (score>=265.65) and (score<=280.96):
            return 3
        elif (score>=280.97) and (score<=319.17):
            return 4
        elif (score>=319.18) and (score<=349.51):
            return 5
        elif (score>=349.52) and (score<=383.37):
            return 6
        elif (score>=383.38) and (score<=416.43):
            return 7
        elif (score>=416.44) and (score<=456.10):
            return 8
        elif (score>=456.11) and (score<=495.43):
            return 9
        elif (score>=495.44) and (score<=528.70):
            return 10
        elif (score>=528.71) and (score<=558.42):
            return 11
        elif (score>=558.43) and (score<=588.69):
            return 12
        elif (score>=588.70) and (score<=614.27):
            return 13
        elif (score>=614.28) and (score<=645.28):
            return 14
        elif (score>=645.29) and (score<=670.54):
            return 15
        elif (score>=670.55) and (score<=683.22):
            return 16
        elif (score>=683.23) and (score<=702.22):
            return 17
        elif (score>=702.23) and (score<=754.11):
            return 18
        elif (score>=754.12):
            return 19

    if test=="PatternComp": 
        score = round(score)
        if (score<=13.0):
            return 1
        elif (score>=14.0) and (score<=18.0):
            return 2
        elif (score>=19.0) and (score<=20.0):
            return 3
        elif (score>=21.0) and (score<=26.0):
            return 4
        elif (score>=27.0) and (score<=31.0):
            return 5
        elif (score>=32.0) and (score<=35.0):
            return 6
        elif (score>=36.0) and (score<=39.0):
            return 7
        elif (score>=40.0) and (score<=44.0):
            return 8
        elif (score>=45.0) and (score<=48.0):
            return 9
        elif (score>=49.0) and (score<=52.0):
            return 10
        elif (score>=53.0) and (score<=56.0):
            return 11
        elif (score>=57.0) and (score<=61.0):
            return 12
        elif (score>=62.0) and (score<=65.0):
            return 13
        elif (score>=66.0) and (score<=68.0):
            return 14
        elif (score>=69.0) and (score<=71.0):
            return 15
        elif (score>=72.0) and (score<=75.0):
            return 16
        elif (score>=76.0) and (score<=77.0):
            return 17
        elif (score>=78.0) and (score<=79.0):
            return 18
        elif (score>=80.0):
            return 19


    if test=="OralReading": 
        score = round(score,2)
        if (score<=-24.62):
            return 1
        elif (score>=-24.61) and (score<=-23.10):
            return 2
        elif (score>=-23.09) and (score<=-21.58):
            return 3
        elif (score>=-21.57) and (score<=-19.84):
            return 4
        elif (score>=-19.83) and (score<=-18.28):
            return 5
        elif (score>=-18.27) and (score<=-11.90):
            return 6
        elif (score>=-11.89) and (score<=-5.02):
            return 7
        elif (score>=-5.01) and (score<=-2.31):
            return 8
        elif (score>=-2.30) and (score<=-0.83):
            return 9
        elif (score>=-0.82) and (score<=0.32):
            return 10
        elif (score>=0.33) and (score<=1.26):
            return 11
        elif (score>=1.27) and (score<=2.24):
            return 12
        elif (score>=2.25) and (score<=3.26):
            return 13
        elif (score>=3.27) and (score<=3.92):
            return 14
        elif (score>=3.93) and (score<=5.25):
            return 15
        elif (score>=5.26) and (score<=6.54):
            return 16
        elif (score>=6.55) and (score<=8.23):
            return 17
        elif (score>=8.24) and (score<=8.57):
            return 18
        elif (score>=8.58):
            return 19

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-9.91):
            return 1
        elif (score>=-9.90) and (score<=-8.49):
            return 2
        elif (score>=-8.48) and (score<=-7.43):
            return 3
        elif (score>=-7.42) and (score<=-6.34):
            return 4
        elif (score>=-6.33) and (score<=-5.26):
            return 5
        elif (score>=-5.25) and (score<=-3.95):
            return 6
        elif (score>=-3.94) and (score<=-3.23):
            return 7
        elif (score>=-3.22) and (score<=-1.99):
            return 8
        elif (score>=-1.98) and (score<=-0.80):
            return 9
        elif (score>=-0.79) and (score<=0.29):
            return 10
        elif (score>=0.30) and (score<=1.15):
            return 11
        elif (score>=1.16) and (score<=2.08):
            return 12
        elif (score>=2.09) and (score<=3.17):
            return 13
        elif (score>=3.18) and (score<=3.62):
            return 14
        elif (score>=3.63) and (score<=4.76):
            return 15
        elif (score>=4.77) and (score<=5.42):
            return 16
        elif (score>=5.43) and (score<=5.97):
            return 17
        elif (score>=5.98) and (score<=7.41):
            return 18
        elif (score>=7.42):
            return 19


def WhiteAsianChildren(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0) and (score<=0.0226):
            return 0
        elif (score>=0.0227) and (score<=0.107):
            return 1
        elif (score>=0.1071) and (score<=0.2542):
            return 2
        elif (score>=0.2543) and (score<=0.4544):
            return 3
        elif (score>=0.4545) and (score<=0.8264):
            return 4
        elif (score>=0.8265) and (score<=2.1263):
            return 5
        elif (score>=2.1264) and (score<=4.6848):
            return 6
        elif (score>=4.6849) and (score<=6.2428):
            return 7
        elif (score>=6.2429) and (score<=6.9815):
            return 8
        elif (score>=6.9816) and (score<=7.503):
            return 9
        elif (score>=7.5031) and (score<=7.9222):
            return 10
        elif (score>=7.9223) and (score<=8.2866):
            return 11
        elif (score>=8.2867) and (score<=8.6306):
            return 12
        elif (score>=8.6307) and (score<=8.9782):
            return 13
        elif (score>=8.9783) and (score<=9.3486):
            return 14
        elif (score>=9.3487) and (score<=9.6264):
            return 15
        elif (score>=9.6265) and (score<=9.8639):
            return 16
        elif (score>=9.864) and (score<=9.9026):
            return 17
        elif (score>=9.9027):
            return 18

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=0.2399):
            return 0
        elif (score>=0.24) and (score<=0.6253):
            return 1
        elif (score>=0.6254) and (score<=0.937):
            return 2
        elif (score>=0.9371) and (score<=1.3075):
            return 3
        elif (score>=1.3076) and (score<=1.707):
            return 4
        elif (score>=1.7071) and (score<=2.2431):
            return 5
        elif (score>=2.2432) and (score<=5.5402):
            return 6
        elif (score>=5.5403) and (score<=7.0145):
            return 7
        elif (score>=7.0146) and (score<=7.6936):
            return 8
        elif (score>=7.6937) and (score<=8.1867):
            return 9
        elif (score>=8.1868) and (score<=8.5906):
            return 10
        elif (score>=8.5907) and (score<=8.9212):
            return 11
        elif (score>=8.9213) and (score<=9.1799):
            return 12
        elif (score>=9.18) and (score<=9.404):
            return 13
        elif (score>=9.4041) and (score<=9.5766):
            return 14
        elif (score>=9.5767) and (score<=9.7501):
            return 15
        elif (score>=9.7502) and (score<=9.8752):
            return 16
        elif (score>=9.8753) and (score<=9.9987):
            return 17
        elif score>9.9988:
            return 18

    if test=="ListSort":
        score = round(score)
        if (score==0.0):
            return 1
        elif (score==1):
            return 2
        elif (score>=2) and (score<=3):
            return 3
        elif (score>=4) and (score<=5):
            return 4
        elif (score>=6) and (score<=7):
            return 5
        elif (score>=8) and (score<=10):
            return 6
        elif (score>=11) and (score<=12):
            return 7
        elif (score>=13) and (score<=14):
            return 8
        elif (score>=15) and (score<=16):
            return 9
        elif score==17:
            return 10
        elif score==18:
            return 11
        elif score==19:
            return 12
        elif score==20:
            return 13
        elif score==21:
            return 14
        elif (score==22):
            return 15
        elif (score>=23) and (score<=24):
            return 16
        elif score==25:
            return 17
        elif score==26:
            return 18

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=220.69):
            return 0
        elif (score>=220.70) and (score<=238.89):
            return 1
        elif (score>=238.90) and (score<=244.73):
            return 2
        elif (score>=244.74) and (score<=272.49):
            return 3
        elif (score>=272.50) and (score<=301.72):
            return 4
        elif (score>=301.73) and (score<=345.66):
            return 5
        elif (score>=345.67) and (score<=385.43):
            return 6
        elif (score>=385.44) and (score<=434.58):
            return 7
        elif (score>=434.59) and (score<=471.92):
            return 8
        elif (score>=471.93) and (score<=504.89):
            return 9
        elif (score>=504.90) and (score<=543.81):
            return 10
        elif (score>=543.82) and (score<=575.26):
            return 11
        elif (score>=575.27) and (score<=603.67):
            return 12
        elif (score>=603.68) and (score<=627.12):
            return 13
        elif (score>=627.13) and (score<=650.15):
            return 14
        elif (score>=650.16) and (score<=677.27):
            return 15
        elif (score>=677.28) and (score<=686.47):
            return 16
        elif (score>=686.48) and (score<=700.02):
            return 17
        elif (score>=700.03) and (score<=719.19):
            return 18
        elif (score>=719.19) and (score<=766.05):
            return 19
        elif (score>=766.06):
            return 20

    if test=="PatternComp": 
        score = round(score)
        if (score<=15.0):
            return 0
        elif (score>=16.0) and (score<=18.0):
            return 1
        elif (score>=19.0) and (score<=20.0):
            return 2
        elif (score>=21.0) and (score<=23.0):
            return 3
        elif (score>=24.0) and (score<=28.0):
            return 4
        elif (score>=29.0) and (score<=32.0):
            return 5
        elif (score>=33.0) and (score<=36.0):
            return 6
        elif (score>=37.0) and (score<=41.0):
            return 7
        elif (score>=42.0) and (score<=46.0):
            return 8
        elif (score>=47.0) and (score<=51.0):
            return 9
        elif (score>=52.0) and (score<=55.0):
            return 10
        elif (score>=56.0) and (score<=59.0):
            return 11
        elif (score>=60.0) and (score<=63.0):
            return 12
        elif (score>=64.0) and (score<=67.0):
            return 13
        elif (score>=68.0) and (score<=70.0):
            return 14
        elif (score>=71.0) and (score<=74.0):
            return 15
        elif (score>=75.0) and (score<=77.0):
            return 16
        elif (score>=78.0) and (score<=81.0):
            return 17
        elif (score>=82.0) and (score<=84.0):
            return 18
        elif (score>=85.0) and (score<=89.0):
            return 19
        elif (score>=90.0):
            return 20

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-23.94):
            return 0
        elif (score>=-23.93) and (score<=-23.04):
            return 1
        elif (score>=-23.03) and (score<=-21.72):
            return 2
        elif (score>=-21.71) and (score<=-20.13):
            return 3
        elif (score>=-20.12) and (score<=-18.83):
            return 4
        elif (score>=-18.82) and (score<=-16.53):
            return 5
        elif (score>=-16.52) and (score<=-9.64):
            return 6
        elif (score>=-9.63) and (score<=-3.51):
            return 7
        elif (score>=-3.50) and (score<=-1.30):
            return 8
        elif (score>=-1.29) and (score<=-0.10):
            return 9
        elif (score>=-0.09) and (score<=1.03):
            return 10
        elif (score>=1.04) and (score<=2.08):
            return 11
        elif (score>=2.09) and (score<=3.00):
            return 12
        elif (score>=3.01) and (score<=3.83):
            return 13
        elif (score>=3.84) and (score<=4.94):
            return 14
        elif (score>=4.95) and (score<=6.03):
            return 15
        elif (score>=6.04) and (score<=6.96):
            return 16
        elif (score>=6.97) and (score<=8.14):
            return 17
        elif (score>=8.15) and (score<=8.63):
            return 18
        elif (score>=8.64) and (score<=9.23):
            return 19
        elif (score>=9.24):
            return 20

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-8.39):
            return 0
        elif (score>=-8.38) and (score<=-8.23):
            return 1
        elif (score>=-8.22) and (score<=-7.77):
            return 2
        elif (score>=-7.76) and (score<=-6.72):
            return 3
        elif (score>=-6.71) and (score<=-5.61):
            return 4
        elif (score>=-5.60) and (score<=-4.60):
            return 5
        elif (score>=-4.59) and (score<=-3.30):
            return 6
        elif (score>=-3.29) and (score<=-2.04):
            return 7
        elif (score>=-2.03) and (score<=-0.74):
            return 8
        elif (score>=-0.73) and (score<=0.51):
            return 9
        elif (score>=0.52) and (score<=1.53):
            return 10
        elif (score>=1.54) and (score<=2.54):
            return 11
        elif (score>=2.55) and (score<=3.29):
            return 12
        elif (score>=3.30) and (score<=4.20):
            return 13
        elif (score>=4.21) and (score<=4.93):
            return 14
        elif (score>=4.94) and (score<=5.56):
            return 15
        elif (score>=5.57) and (score<=6.01):
            return 16
        elif (score>=6.02) and (score<=6.50):
            return 17
        elif (score>=6.51) and (score<=7.79):
            return 18
        elif (score>=7.80) and (score<=8.21):
            return 19
        elif (score>=8.22):
            return 20

def SpanishAdults(test,score):
    if test=="DCCS":
        score = round(score,4)
        if (score>=0) and (score<=2.0054):
            return 1
        elif (score>=2.0055) and (score<=2.045):
            return 2
        elif (score>=2.0451) and (score<=2.0846):
            return 3
        elif (score>=2.0847) and (score<=2.1242):
            return 4
        elif (score>=2.1243) and (score<=2.2337):
            return 5
        elif (score>=2.2338) and (score<=2.9854):
            return 6
        elif (score>=2.9855) and (score<=5.1967):
            return 7
        elif (score>=5.1968) and (score<=6.6663):
            return 8
        elif (score>=6.6664) and (score<=7.1996):
            return 9
        elif (score>=7.1997) and (score<=7.7081):
            return 10
        elif (score>=7.7082) and (score<=8.0149):
            return 11
        elif (score>=8.015) and (score<=8.3414):
            return 12
        elif (score>=8.3415) and (score<=8.6681):
            return 13
        elif (score>=8.6682) and (score<=8.9667):
            return 14
        elif (score>=8.9668) and (score<=9.2697):
            return 15
        elif (score>=9.2698) and (score<=9.5231):
            return 16
        elif (score>=9.5232) and (score<=9.7529):
            return 17
        elif (score>=9.753) and (score<=9.8465):
            return 18
        elif (score>=9.8466):
            return 19

    elif test=="Flanker":
        score = round(score,4)
        if (score>=0.0) and (score<=2.2167):
            return 1
        elif (score>=2.2168) and (score<=3.5511):
            return 2
        elif (score>=3.5512) and (score<=3.8782):
            return 3
        elif (score>=3.8783) and (score<=4.2561):
            return 4
        elif (score>=4.2562) and (score<=4.8558):
            return 5
        elif (score>=4.8559) and (score<=5.8047):
            return 6
        elif (score>=5.8048) and (score<=6.6628):
            return 7
        elif (score>=6.6629) and (score<=7.2813):
            return 8
        elif (score>=7.2814) and (score<=7.8747):
            return 9
        elif (score>=7.8748) and (score<=8.2511):
            return 10
        elif (score>=8.2512) and (score<=8.61):
            return 11
        elif (score>=8.6101) and (score<=8.8794):
            return 12
        elif (score>=8.8795) and (score<=9.2239):
            return 13
        elif (score>=9.224) and (score<=9.4928):
            return 14
        elif (score>=9.4929) and (score<=9.6015):
            return 15
        elif (score>=9.6016) and (score<=9.7463):
            return 16
        elif (score>=9.7464) and (score<=9.9189):
            return 17
        elif (score>=9.919):
            return 18

    if test=="ListSort":
        score = round(score)
        if (score>=0) and (score<=2):
            return 1
        elif (score>=3) and (score<=5):
            return 2
        elif (score==6):
            return 3
        elif (score==7):
            return 4
        elif (score==8):
            return 5
        elif (score>=9) and (score<=10):
            return 6
        elif (score==11):
            return 7
        elif (score>=12) and (score<=13):
            return 8
        elif (score==14):
            return 9
        elif (score>=15) and (score<=16):
            return 11
        elif score==17:
            return 12
        elif score==18:
            return 13
        elif score==19:
            return 14
        elif (score>=20) and (score<=21):
            return 15
        elif (score==22):
            return 16
        elif (score>=23) and (score<=24):
            return 17
        elif score==25:
            return 18
        elif score==26:
            return 19

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=240.57):
            return 1
        elif (score>=240.58) and (score<=302.92):
            return 2
        elif (score>=302.93) and (score<=314.85):
            return 3
        elif (score>=314.86) and (score<=328.02):
            return 4
        elif (score>=328.03) and (score<=347.98):
            return 5
        elif (score>=347.99) and (score<=382.29):
            return 6
        elif (score>=382.30) and (score<=415.60):
            return 7
        elif (score>=415.61) and (score<=447.02):
            return 8
        elif (score>=447.03) and (score<=486.02):
            return 9
        elif (score>=486.03) and (score<=524.13):
            return 10
        elif (score>=524.14) and (score<=553.85):
            return 11
        elif (score>=553.86) and (score<=581.32):
            return 12
        elif (score>=581.33) and (score<=614.50):
            return 13
        elif (score>=614.51) and (score<=647.19):
            return 14
        elif (score>=647.20) and (score<=679.22):
            return 15
        elif (score>=679.23) and (score<=700.22):
            return 16
        elif (score>=700.23) and (score<=727.13):
            return 17
        elif (score>=727.14) and (score<=777.14):
            return 18
        elif (score>=777.15):
            return 19

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=19.0):
            return 1
        elif (score>=20.0) and (score<=24.0):
            return 2
        elif (score>=25.0) and (score<=27.0):
            return 3
        elif (score>=28.0) and (score<=32.0):
            return 4
        elif (score>=33.0) and (score<=34.0):
            return 5
        elif (score>=35.0) and (score<=38.0):
            return 6
        elif (score>=39.0) and (score<=42.0):
            return 7
        elif (score>=43.0) and (score<=46.0):
            return 8
        elif (score>=47.0) and (score<=49.0):
            return 9
        elif (score>=50.0) and (score<=53.0):
            return 10
        elif (score>=54.0) and (score<=56.0):
            return 11
        elif (score>=57.0) and (score<=60.0):
            return 12
        elif (score>=61.0) and (score<=63.0):
            return 13
        elif (score>=64.0) and (score<=66.0):
            return 14
        elif (score>=67.0) and (score<=70.0):
            return 15
        elif (score>=71.0) and (score<=72.0):
            return 16
        elif (score>=73.0) and (score<=75.0):
            return 17
        elif (score>=76.0) and (score<=80.0):
            return 18
        elif (score>=81.0):
            return 19

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-12.27):
            return 1
        elif (score>=-12.26) and (score<=-8.55):
            return 2
        elif (score>=-8.54) and (score<=-4.25):
            return 3
        elif (score>=-4.24) and (score<=-2.24):
            return 4
        elif (score>=-2.23) and (score<=-0.99):
            return 5
        elif (score>=-0.98) and (score<=0.19):
            return 6
        elif (score>=0.20) and (score<=1.17):
            return 7
        elif (score>=1.18) and (score<=2.20):
            return 8
        elif (score>=2.21) and (score<=2.84):
            return 9
        elif (score>=2.85) and (score<=3.45):
            return 10
        elif (score>=3.46) and (score<=3.92):
            return 11
        elif (score>=3.93) and (score<=4.52):
            return 12
        elif (score>=4.53) and (score<=5.21):
            return 13
        elif (score>=5.22) and (score<=5.84):
            return 14
        elif (score>=5.85) and (score<=6.68):
            return 15
        elif (score>=6.69) and (score<=7.60):
            return 16
        elif (score>=7.61) and (score<=10.26):
            return 17
        elif (score>=10.27) and (score<=12.97):
            return 18
        elif (score>=12.98):
            return 19

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-3.29):
            return 1
        elif (score>=-3.28) and (score<=-2.53):
            return 2
        elif (score>=-2.52) and (score<=-1.91):
            return 3
        elif (score>=-1.90) and (score<=-0.78):
            return 4
        elif (score>=-0.77) and (score<=-0.08):
            return 5
        elif (score>=-0.07) and (score<=0.62):
            return 6
        elif (score>=0.63) and (score<=1.44):
            return 7
        elif (score>=1.45) and (score<=2.15):
            return 8
        elif (score>=2.16) and (score<=3.02):
            return 9
        elif (score>=3.03) and (score<=3.72):
            return 10
        elif (score>=3.73) and (score<=4.28):
            return 11
        elif (score>=4.29) and (score<=5.01):
            return 12
        elif (score>=5.02) and (score<=5.59):
            return 13
        elif (score>=5.60) and (score<=5.91):
            return 14
        elif (score>=5.92) and (score<=6.32):
            return 15
        elif (score>=6.33) and (score<=6.95):
            return 16
        elif (score>=6.96) and (score<=7.80):
            return 17
        elif (score>=7.81) and (score<=10.38):
            return 18
        elif (score>=10.39):
            return 19

def SpanishChildren(test,score):

    if test=="DCCS":
        score = round(score,4)
        if (score>=0) and (score<=0.045):
            return 1
        elif (score>=0.0451) and (score<=0.1006):
            return 2
        elif (score>=0.1007) and (score<=0.1699):
            return 3
        elif (score>=0.17) and (score<=0.2501):
            return 4
        elif (score>=0.2502) and (score<=0.3711):
            return 5
        elif (score>=0.3712) and (score<=0.5848):
            return 6
        elif (score>=0.5849) and (score<=0.7446):
            return 7
        elif (score>=0.7447) and (score<=0.9366):
            return 8
        elif (score>=0.9367) and (score<=2.1315):
            return 9
        elif (score>=2.1316) and (score<=3.4622):
            return 10
        elif (score>=3.4623) and (score<=4.9085):
            return 11
        elif (score>=4.9086) and (score<=6.1072):
            return 12
        elif (score>=6.1073) and (score<=6.4982):
            return 13
        elif (score>=6.4983) and (score<=6.8405):
            return 14
        elif (score>=6.8406) and (score<=7.2028):
            return 15
        elif (score>=7.2029) and (score<=7.6234):
            return 16
        elif (score>=7.6235) and (score<=8.7665):
            return 17
        elif (score>=8.7666) and (score<=9.5623):
            return 18
        elif (score>=9.5624):
            return 19

    elif test=="Flanker":
        score = round(score,2)   
        if (score>=0.0) and (score<=0.1431):
            return 1
        elif (score>=0.1432) and (score<=0.3668):
            return 2
        elif (score>=0.3669) and (score<=0.5851):
            return 3
        elif (score>=0.5852) and (score<=0.7633):
            return 4
        elif (score>=0.7634) and (score<=1.0106):
            return 5
        elif (score>=1.0107) and (score<=1.2479):
            return 6
        elif (score>=1.248) and (score<=1.4969):
            return 7
        elif (score>=1.497) and (score<=1.8443):
            return 8
        elif (score>=1.8444) and (score<=2.1975):
            return 9
        elif (score>=2.1976) and (score<=4.9949):
            return 10
        elif (score>=4.995) and (score<=5.8689):
            return 11
        elif (score>=5.869) and (score<=6.6244):
            return 12
        elif (score>=6.6245) and (score<=7.151):
            return 13
        elif (score>=7.1511) and (score<=7.5392):
            return 14
        elif (score>=7.5393) and (score<=7.8889):
            return 15
        elif (score>=7.889) and (score<=8.321):
            return 16
        elif (score>=8.3211) and (score<=8.5352):
            return 17
        elif (score>=8.5353) and (score<=9.3765):
            return 18
        elif (score>=9.3766):
            return 19

    if test=="ListSort":
        score = round(score)
        if (score==0):
            return 4
        elif (score==1):
            return 5
        elif (score>=2) and (score<=3):
            return 6
        elif (score==4):
            return 7
        elif (score==5):
            return 8
        elif (score==6):
            return 9
        elif (score>=7) and (score<=8):
            return 10
        elif score==9:
            return 11
        elif score==10:
            return 12
        elif (score>=11) and (score<=12):
            return 13
        elif (score==13):
            return 14
        elif (score==14):
            return 15
        elif (score>=15) and (score<=16):
            return 16
        elif score==17:
            return 17
        elif (score>=18) and (score<=23):
            return 18
        elif (score>=24) and (score<=26):
            return 19

    if test=="PictureSeq": 
        score = round(score,2)
        if (score<=211.06):
            return 1
        elif (score>=211.07) and (score<=212.18):
            return 2
        elif (score>=212.19) and (score<=221.32):
            return 3
        elif (score>=221.33) and (score<=234.64):
            return 4
        elif (score>=234.65) and (score<=264.95):
            return 5
        elif (score>=264.96) and (score<=278.17):
            return 6
        elif (score>=278.18) and (score<=299.52):
            return 7
        elif (score>=299.53) and (score<=331.51):
            return 8
        elif (score>=331.52) and (score<=349.91):
            return 9
        elif (score>=349.92) and (score<=385.37):
            return 10
        elif (score>=385.38) and (score<=416.84):
            return 11
        elif (score>=416.85) and (score<=455.47):
            return 12
        elif (score>=455.48) and (score<=470.96):
            return 13
        elif (score>=470.97) and (score<=480.91):
            return 14
        elif (score>=480.92) and (score<=489.55):
            return 15
        elif (score>=489.56) and (score<=518.43):
            return 16
        elif (score>=518.44) and (score<=538.57):
            return 17
        elif (score>=538.58) and (score<=572.01):
            return 18
        elif (score>=572.02):
            return 19
        #else:
        #    return 1

    if test=="PatternComp": 
        score = round(score)
        if (score>=0.0) and (score<=9.0):
            return 1
        elif (score>=10.0) and (score<=17.0):
            return 2
        elif (score>=18.0) and (score<=19.0):
            return 3
        elif (score==20.0):
            return 4
        elif (score>=21.0) and (score<=22.0):
            return 5
        elif (score==23.0):
            return 6
        elif (score>=24.0) and (score<=27.0):
            return 7
        elif (score>=28.0) and (score<=30.0):
            return 8
        elif (score>=31.0) and (score<=35.0):
            return 9
        elif (score>=36.0) and (score<=38.0):
            return 10
        elif (score>=39.0) and (score<=41.0):
            return 11
        elif (score>=42.0) and (score<=44.0):
            return 12
        elif (score>=45.0) and (score<=47.0):
            return 13
        elif (score>=48.0) and (score<=51.0):
            return 14
        elif (score>=52.0) and (score<=53.0):
            return 15
        elif (score>=54.0) and (score<=55.0):
            return 16
        elif (score>=56.0) and (score<=59.0):
            return 17
        elif (score>=60.0) and (score<=72.0):
            return 18
        elif (score>=73.0):
            return 19

    if test=="OralReading": 
        score = round(score,2)
        if (score<=-13.72):
            return 0
        elif (score>=-13.71) and (score<=-12.16):
            return 1
        elif (score>=-12.15) and (score<=-11.14):
            return 2
        elif (score>=-11.13) and (score<=-11.11):
            return 3
        elif (score>=-11.10) and (score<=-11.08):
            return 4
        elif (score>=-11.07) and (score<=-11.05):
            return 5
        elif (score>=-11.04) and (score<=-11.02):
            return 6
        elif (score>=-11.01) and (score<=-10.99):
            return 7
        elif (score>=-10.98) and (score<=-10.94):
            return 8
        elif (score>=-10.93) and (score<=-10.89):
            return 9
        elif (score>=-10.88) and (score<=-8.72):
            return 10
        elif (score>=-8.71) and (score<=-6.91):
            return 11
        elif (score>=-6.90) and (score<=-5.05):
            return 12
        elif (score>=-5.04) and (score<=-4.01):
            return 13
        elif (score>=-4.00) and (score<=-2.87):
            return 14
        elif (score>=-2.86) and (score<=-1.56):
            return 15
        elif (score>=-1.55) and (score<=-0.65):
            return 16
        elif (score>=-0.64) and (score<=0.30):
            return 17
        elif (score>=0.31) and (score<=1.50):
            return 18
        elif (score>=1.51) and (score<=5.37):
            return 19
        elif (score>=5.38):
            return 20

    if test=="PictureVocab": 
        score = round(score,2)
        if (score<=-8.09):
            return 1
        elif (score>=-8.08) and (score<=-7.32):
            return 2
        elif (score>=-7.31) and (score<=-6.74):
            return 3
        elif (score>=-6.73) and (score<=-6.00):
            return 4
        elif (score>=-5.99) and (score<=-5.57):
            return 5
        elif (score>=-5.56) and (score<=-5.05):
            return 6
        elif (score>=-5.04) and (score<=-4.31):
            return 7
        elif (score>=-4.30) and (score<=-3.69):
            return 8
        elif (score>=-3.68) and (score<=-2.89):
            return 9
        elif (score>=-2.88) and (score<=-2.19):
            return 10
        elif (score>=-2.18) and (score<=-1.69):
            return 11
        elif (score>=-1.68) and (score<=-1.22):
            return 12
        elif (score>=-1.21) and (score<=-0.71):
            return 13
        elif (score>=-0.70) and (score<=-0.09):
            return 14
        elif (score>=-0.08) and (score<=0.42):
            return 15
        elif (score>=0.43) and (score<=1.04):
            return 16
        elif (score>=1.05) and (score<=1.24):
            return 17
        elif (score>=1.25) and (score<=2.32):
            return 18
        elif (score>=2.33):
            return 19


def EduConverter(edu):
    if (edu>=1) and (edu<=3):
        return 0
    elif edu==4:
        return 1
    elif edu==5:
        return 2
    elif edu==6:
        return 3
    elif edu==7:
        return 4
    elif edu==8:
        return 5
    elif edu==9:
        return 6
    elif edu==10:
        return 7
    elif edu==11:
        return 8
    elif edu==12:
        return 9
    elif edu==13:
        return 10
    elif edu==14 or edu==15:
        return 11
    elif edu==16:
        return 12
    elif edu==17:
        return 11
    elif edu==18:
        return 12
    elif edu==19 or edu==20:
        return 14
    elif edu==21:
        return 16
    elif edu==22:
        return 18
    elif edu==23:
        return 20
    elif edu==24:
        return 20
    elif edu==25:
        return 13
    elif edu==26:
        return 13
    elif edu==27:
        return 14
    elif edu>=28:
        return 15


print "Norming Data..."


############################
# Formulas
############################
lastprint=0
lastprint2=0
lastprint3=0
skiploop = 0

i = 0
ID=''
idmatrix=[]
idarray=['']*157
idscaled=['']*28
for assess in amatrix:

    #print assess
    #print '-----------------'
    #print idarray
    #print '======================'
    #if assess[0]=='':
     #   continue

    if len(assess)<22:
        continue
    newlineassindex= ''+assess[0]+assess[8]
    print ":"
    print newlineassindex
    print ":"
    print oldlineassindex
    print ":"
    
    if newlineassindex!=oldlineassindex:
        print "line"
        print assess[0]
        print assess[8]
        #FLUID COMPOSITE
        if idarray[7]!='' and idarray[8]!='' and idarray[9]!='' and idarray[10]!='' and idarray[11]!='':
            idarray[14] = (( ((idarray[7]+idarray[8]+idarray[9]+idarray[10]+idarray[11])/5)-100.39)/11.83)*15+100

        if idarray[17]!='' and idarray[18]!='' and idarray[19]!='' and idarray[20]!='' and idarray[21]!='': #Age-Corrected Adults
            idarray[24] = 100+15*(( ((idarray[17]+idarray[18]+idarray[19]+idarray[20]+idarray[21])/5)-100.15)/10.10)
            if idarray[37]!='' and idarray[38]!='' and idarray[39]!='' and idarray[40]!='' and idarray[41]!='': #AfricanAmerican Adults
                idarray[44] = 50+10*(( ((idarray[37]+idarray[38]+idarray[39]+idarray[40]+idarray[41])/5)-50.05)/6.48)
            elif idarray[47]!='' and idarray[48]!='' and idarray[49]!='' and idarray[50]!='' and idarray[51]!='': #Hispanic Adults
                idarray[54] = (( ((idarray[47]+idarray[48]+idarray[49]+idarray[50]+idarray[51])/5)-50.28)/6.99)*10+50
            elif idarray[57]!='' and idarray[58]!='' and idarray[59]!='' and idarray[60]!='' and idarray[61]!='': #WhiteAsian Adults
                idarray[64] = (( ((idarray[57]+idarray[58]+idarray[59]+idarray[60]+idarray[61])/5)-50.13)/6.60)*10+50
                
        if idarray[27]!='' and idarray[28]!='' and idarray[29]!='' and idarray[30]!='' and idarray[31]!='':  #Age-Corrected Children
            idarray[34] = (( ((idarray[27]+idarray[28]+idarray[29]+idarray[30]+idarray[31])/5)-100.24)/9.24)*15+100
            if idarray[67]!='' and idarray[68]!='' and idarray[69]!='' and idarray[70]!='' and idarray[71]!='':  #MultiRacialed Children
                idarray[74] = (( ((idarray[67]+idarray[68]+idarray[69]+idarray[70]+idarray[71])/5.0)-50.53)/6.51)*10+50
            elif idarray[77]!='' and idarray[78]!='' and idarray[79]!='' and idarray[80]!='' and idarray[81]!='':  #AfricanAmerican Children
                idarray[84] = (( ((idarray[77]+idarray[78]+idarray[79]+idarray[80]+idarray[81])/5.0)-50.15)/6.24)*10+50
            elif idarray[87]!='' and idarray[88]!='' and idarray[89]!='' and idarray[90]!='' and idarray[91]!='':  #Hispanic Children
                idarray[94] = (( ((idarray[87]+idarray[88]+idarray[89]+idarray[90]+idarray[91])/5.0)-50.06)/6.18)*10+50
            elif idarray[97]!='' and idarray[98]!='' and idarray[99]!='' and idarray[100]!='' and idarray[101]!='':  #WhiteAsian Children
                idarray[104] = (( ((idarray[97]+idarray[98]+idarray[99]+idarray[100]+idarray[101])/5.0)-50.09)/5.95)*10+50

        if idarray[107]!='' and idarray[108]!='' and idarray[109]!='' and idarray[110]!='' and idarray[111]!='':  #Spanish RAW
            idarray[114] = (( ((idarray[107]+idarray[108]+idarray[109]+idarray[110]+idarray[111])/5)-100.47)/13.34)*15+100
        if idscaled[0]!='' and idscaled[1]!='' and idscaled[2]!='' and idscaled[3]!='' and idscaled[4]!='':  #Spanish Age-Correct Adults #these two should be the same average
            idscaled[14]=(idscaled[0]+idscaled[1]+idscaled[2]+idscaled[3]+idscaled[4])/5.0
            idarray[124] = 100+15*(( ((idscaled[0]+idscaled[1]+idscaled[2]+idscaled[3]+idscaled[4])/5.0)-(13.36-7.41*(age/100.0)))/(1.64-0.31*(age/100.0)))/1.26
            idarray[144] = 50+10*(( ((idscaled[0]+idscaled[1]+idscaled[2]+idscaled[3]+idscaled[4])/5.0)-(9.79-6.58*(age/100.0)+2.55*((edu+1)/10.0)+0.33*gender))/(1.57-0.33*(age/100.0)-0.14*((edu+1)/10.0)+0.12*gender))/1.25
        if idscaled[7]!='' and idscaled[8]!='' and idscaled[9]!='' and idscaled[10]!='' and idscaled[11]!='':  #Spanish Age-Correct Children
            idscaled[15]=(idscaled[7]+idscaled[8]+idscaled[9]+idscaled[10]+idscaled[11])/5.0
            idarray[134] = 100+15*(( ((idscaled[7]+idscaled[8]+idscaled[9]+idscaled[10]+idscaled[11])/5.0)-(3.53+12.82*(age/10.0)))/(1.11+0.11*(age/10.0)))/1.23
            idarray[154] = 50+10*(( ((idscaled[7]+idscaled[8]+idscaled[9]+idscaled[10]+idscaled[11])/5.0)-(2.51+13.03*(age/10.0)+0.89*((edu+1)/10.0)-0.12*gender))/(1.11+0.24*(age/10.0)-0.07*((edu+1)/10.0)-0.04*gender))/1.22

        #CRYSTALLIZED COMPOSITE
        if idarray[12]!='' and idarray[13]!='':
            idarray[15] = (( ((idarray[12]+idarray[13])/2)-100.38)/13.99)*15+100

        if idarray[22]!='' and idarray[23]!='': #Age-Corrected Adults
            idarray[25] = (( ((idarray[22]+idarray[23])/2)-100.18)/13.64)*15+100
            if idarray[42]!='' and idarray[43]!='': #African American Adults
                idarray[45] = 50+10*(( ((idarray[42]+idarray[43])/2)-50.0)/9.19)
            elif idarray[52]!='' and idarray[53]!='': #Hispanic Adults
                idarray[55] = (( ((idarray[52]+idarray[53])/2)-50.11)/8.89)*10+50
            elif idarray[62]!='' and idarray[63]!='': #WhiteAsian Adults
                idarray[65] = (( ((idarray[62]+idarray[63])/2)-50.1)/8.95)*10+50
            

        if idarray[32]!='' and idarray[33]!='': #Age-Corrected Children
            idarray[35] = (( ((idarray[32]+idarray[33])/2)-100.05)/12.81)*15+100
            if idarray[72]!='' and idarray[73]!='': #MultiRacial Children
                idarray[75] = (( ((idarray[72]+idarray[73])/2)-50.29)/8.03)*10+50
            elif idarray[82]!='' and idarray[83]!='': #AfricanAmerican Children
                idarray[85] = (( ((idarray[82]+idarray[83])/2)-49.96)/8.52)*10+50
            elif idarray[92]!='' and idarray[93]!='': #Hispanic Children
                idarray[95] = (( ((idarray[92]+idarray[93])/2)-49.99)/8.58)*10+50
            elif idarray[102]!='' and idarray[103]!='': #WhiteAsian Children
                idarray[105] = (( ((idarray[102]+idarray[103])/2)-49.96)/8.45)*10+50

        if idarray[112]!='' and idarray[113]!='': #Spanish RAW
            idarray[115] = (( ((idarray[112]+idarray[113])/2)-100.50)/14.48)*15+100
        if idscaled[5]!='' and idscaled[6]!='': #Spanish Age-Correct Adults #these two should be the same
            idscaled[16] = (idscaled[5]+idscaled[6])/2.0
            idarray[125] = 100+15*(( ((idscaled[5]+idscaled[6])/2)-(3.02+16.27*((age/100.0)**0.5)-16.23*((age/100.0)**2)))/(1.7+0.74*(age/100.0)))/1.24
            idarray[145] = 50+10*(( ((idscaled[5]+idscaled[6])/2)-(5.09+15.77*(age/100.0)-19.13*((age/100.0)**2)+1.9*((edu+1)/10.0)-0.03*gender))/(2.66+0.73*(age/100.0)+0.04*(((edu+1)/10.0)**-2)-1.32*(((edu+1)/10.0)**-0.5)+0.44*gender))/1.23
        if idscaled[12]!='' and idscaled[13]!='': #Spanish Age-Correct Children
            idscaled[17] = (idscaled[12]+idscaled[13])/2.0
            idarray[135] = 100+15*(( ((idscaled[12]+idscaled[13])/2)-(4.35+10.99*(age/10.0)))/(2.12-0.75*(age/10.0)))/1.26
            idarray[155] = 50+10*(( ((idscaled[12]+idscaled[13])/2)-(3.81+11.22*(age/10.0)+0.56*((edu+1)/10.0)-0.48*gender))/(1.72-0.55*(age/10.0)+0.24*((edu+1)/10.0)+0.06*gender))/1.24

        #TOTAL COGNITION COMPOSITE                                                                                                                                                                                
        if idarray[14]!='' and idarray[15]!='':
            idarray[16] = (( ((idarray[14]+idarray[15])/2)-100.84)/12.04)*15+100

        if idarray[24]!='' and idarray[25]!='': #Age-Corrected Adults
            idarray[26] = (( ((idarray[24]+idarray[25])/2)-100.02)/12.93)*15+100
            if idarray[44]!='' and idarray[45]!='': #AfricanAmerican Adults
                idarray[46] = 50+10*(( ((idarray[44]+idarray[45])/2)-50.02)/8.68)
            elif idarray[54]!='' and idarray[55]!='': #Hispanic Adults
                idarray[56] = (( ((idarray[54]+idarray[55])/2)-49.83)/8.46)*10+50
            elif idarray[64]!='' and idarray[65]!='': #WhiteAsian Adults
                idarray[66] = (( ((idarray[64]+idarray[65])/2)-50.07)/8.34)*10+50

        if idarray[34]!='' and idarray[35]!='': #Age-Corrected Children
            idarray[36] = (( ((idarray[34]+idarray[35])/2)-100.25)/12.48)*15+100
            if idarray[74]!='' and idarray[75]!='': #MultiRacial Children
                idarray[76] = (( ((idarray[74]+idarray[75])/2)-50.86)/8.48)*10+50
            elif idarray[84]!='' and idarray[85]!='': #AfricanAmerican Children
                idarray[86] = (( ((idarray[84]+idarray[85])/2)-50.37)/8.30)*10+50
            elif idarray[94]!='' and idarray[95]!='': #Hispanic Children
                idarray[96] = (( ((idarray[94]+idarray[95])/2)-50.21)/8.03)*10+50
            elif idarray[104]!='' and idarray[105]!='': #AsianWhite Children
                idarray[106] = (( ((idarray[104]+idarray[105])/2)-50.08)/8.11)*10+50

        if idarray[114]!='' and idarray[115]!='': #Spanish RAW
            idarray[116] = (( ((idarray[114]+idarray[115])/2)-103.86)/12.81)*15+100
        if idscaled[14]!='' and idscaled[16]!='': #Spanish Age-Corrected Adults
            idarray[126] = 100+15*(( ((idscaled[14]+idscaled[16])/2)-(12.04-4.3*(age/100.0)))/(1.11+0.84*(age/100.0)))/1.28
            idarray[146] = 50+10*(( ((idscaled[14]+idscaled[16])/2)-(8.46-3.3*(age/100.0)+2.55*((edu+1)/10.0)+0.08*gender))/(1.09+0.49*(age/100.0)-0.1*((edu+1)/10.0)+0.2*gender))/1.26
        if idscaled[15]!='' and idscaled[17]!='': #Spanish Age-Corrected Children 
            idarray[136] = 100+15*(( ((idscaled[15]+idscaled[17])/2)-(5.27+9.91*(age/10.0)))/(1.51-0.55*(age/10.0)))/1.22
            idarray[156] = 50+10*(( ((idscaled[15]+idscaled[17])/2)-(4.66+10.23*(age/10.0)+0.5*((edu+1)/10.0)-0.28*gender))/(1.58-0.64*(age/10.0)-0.03*((edu+1)/10.0)+0.03*gender))/1.22

        idscaled=['']*18
        idmatrix.append(idarray)
        #print idarray
        idarray=['']*152 #11 is currently how many columns/tests
        ID=assess[0]
        testindex=assess[8]
        oldlineassindex=ID+testindex
        idarray[0]=oldlineassindex
        

#if assess[0] in secondarydict.keys():
#print assess
#print assess[3]


    if assess[0]!='':
        if assess[4]=='':
            continue

        ethnic=int(assess[4])
        race='{0:07b}'.format(int(assess[3]))   #int(assess[3]))
        if ((int(assess[3]) == 8) or (int(assess[3]) == 9) or (int(assess[3]) == 32)):
            race = "0000010"
            

        age=float(assess[1])
        gender=float(assess[2]) % 2 #maybe -1 instead of %1
        tempedu=assess[6]
        if tempedu=='00000000-0000-0000-0000-000000000000':
            tempedu=''
        if tempedu!='':
            eduone = EduConverter(int(assess[6]))
            edu = float(eduone)  #not in final version
            idarray[6]=edu
        
        #print "testloop"
        #print oldlineassindex
        #print assess
        #print idarray
        idarray[2]=age
        idarray[3]=gender
        idarray[4]=assess[3]  #race
        idarray[5]=ethnic

        #else:
#continue #Change this for REAL VERSION


    """if assess[6]=='':
        continue
    else:
        edu=float(assess[6])"""
    
    """
        print assess[0]
        print "This key/participant not in secondary dictionary sheet with race, ethnicity, age, and gender."
        continue"""

    if assess[0] in thetadict.keys():
        thetavocab=thetadict[assess[0]][0]
        thetaoral=thetadict[assess[0]][1]
        skiploop = 0
    else:
        #print assess[0]
        #print "This key/participant not in theta dictionary sheet with theta values."
        skiploop = 1
        #continue

    rawscore=assess[RAWSCORECOLUMN]
    computedscore=assess[COMPUTEDSCORECOLUMN]

    #if assess[14]=="en-US":
    if assess[LANGUAGECOLUMN]=="en-US":
        idarray[1] = "en-US"

        ######
        #DCCS
        ######
        if string.find(assess[FORMCOLUMN],"Dimensional Change Card")!=-1:
            if computedscore!='':
                input=float(computedscore)
                if input==-99.0:
                    continue
                lastprinter.append(computedscore) ####
                idarray[7] = ((float(input)-7.71)/1.71)*15+100 #Raw
                lastprinter.append(idarray[7])
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idarray[17] = 100+15*((AgeCorrectAdults("DCCS",input)-(14.82-9.83*(float(age)/100.0)))/(2.17 - 0.62*(age/100.0)))/1.29
                    lastprinter.append(idarray[17])
                    
                    if race[5]=="1": #African Americans
                        idarray[37] = 50+10*( (AfricanAmericanAdults("DCCS",input)-(11.82-11.22*(float(age)/100.0)+2.13*(float(edu/10.0))+0.32*float(gender)))/(3.04-1.17*(age/100.0)-0.44*(edu/10.0)+0.1*(gender)))/1.26
                        lastprinter.append(idarray[37])
                        if idarray[37]<0:
                            idarray[37]=0.0

                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[47] = 50+10*((HispanicAdults("DCCS",input) - (9.17 - 10.11 * (age/100) + 3.51 * (edu/10) + 0.18 * gender)) / (2.18-0.36*(age/100.0)-0.11*(edu/10.0)+0.06*gender))/1.29
                        if idarray[47]<0:
                            idarray[47]=0.0

                    elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                        idarray[57] = 50+10*((WhiteAsianAdults("DCCS",input) - (12.92 - 9.84*(age/100.0) + 1.45*(edu/10.0) + 0.3*gender))/ (1.78-0.63*(age/100.0)+0.16*(edu/10.0)+0.32*gender))/1.28
                        if idarray[57]<0:
                            idarray[57]=0.0

                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican      
                        idarray[37] = 50+10*( (AfricanAmericanAdults("DCCS",input)-(11.82-11.22*(float(age)/100.0)+2.13*(float(edu/10.0))+0.32*float(gender)))/(3.04-1.17*(age/100.0)-0.44*(edu/10.0)+0.1*(gender)))/1.26
                        if idarray[37]<0:
                            idarray[37]=0.0

                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[37] = 50+10*( (AfricanAmericanAdults("DCCS",input)-(11.82-11.22*(float(age)/100.0)+2.13*(float(edu/10.0))+0.32*float(gender)))/(3.04-1.17*(age/100.0)-0.44*(edu/10.0)+0.1*(gender)))/1.26
                        if idarray[37]<0:
                            idarray[37]=0.0

                    else:
                        continue
            
                        
                if age!='' and (age >=3) and (age < 18): #Children
                    idarray[27] = 100+15*((AgeCorrectChildren("DCCS",input) - (-2.02+11.67*((float(age)/10.0))**0.5))/(1.35 + 0.69*math.log(age/10.0)+0.71*(math.log(age/10.0))**2 ) )/1.28
                    
                    #if race[1:].count("1")>=2: #Multi-Racial
                    #    idarray[67] = 50+10*(( MultiChildren("DCCS",input) - (2.23 + 5.94 * (age/10) + 1.31 * (edu/10) + 0.07 * gender)) / (0.03+0.3*(age/10.0)+0.87*(edu/10.0)+0.02*gender))/1.23
                    #    if idarray[67]<0:
                    #        idarray[67]=0.0
                        
                    #elif race[5]=="1": #African Americans
                    #    idarray[77] = 50+10*((AfricanAmericanChildren("DCCS",input) - (9.35 + 5.30 * math.log(age/10.0) + 0.42*(edu/10.0)- 0.10*gender))/(1.3+0.44*(age/10.0)-0.10*(edu/10.0)-0.07*gender))/1.27
                    #    if idarray[77]<0:
                    #        idarray[77]=0.0

                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[87] = 50+10*((HispanicChildren("DCCS",input) - (-2.27 + 11.50 * ((age/10.0)**0.5) + 0.48 * ((edu)/10) - 0.05 * gender)) /(1.06 + 0.43*(age/10.0)-0.09*(edu/10.0)+0.1*gender))/1.3
                    #    if idarray[87]<0:
                    #        idarray[87]=0.0

                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                    #    idarray[97] = 50+10*((WhiteAsianChildren("DCCS",input) - (-3.61 + 12.13 * ((age/10)**0.5) + 0.85 * (((edu+1)/10)**3) - 1.08*math.log((edu+1)/10) * (((edu+1)/10)**3) - 0.24*gender)) / (0.88+0.6*(age/10.0)-0.13*(edu/10.0)+0.08*gender))/1.29
                    #    if idarray[97]<0:
                    #        idarray[97]=0.0

                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[77] = 50+10*((AfricanAmericanChildren("DCCS",input) - (9.35 + 5.30 * math.log(age/10.0) + 0.42*(edu/10.0)- 0.10*gender))/(1.3+0.44*(age/10.0)-0.10*(edu/10.0)-0.07*gender))/1.27
                    #    if idarray[77]<0:
                    #        idarray[77]=0.0
                        
                else:
                    continue
            continue
        
        ######
        #Flanker
        ######
        elif string.find(assess[FORMCOLUMN],"Flank")!=-1:
            if computedscore!='':
                input = float(computedscore)
                if input==-99.0:
                    continue
                idarray[8] = ((float(computedscore)-8.29)/1.48)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults  
                    idarray[18] = 100+15*( (AgeCorrectAdults("Flanker",input)-(14.38-8.92*(float(age)/100.0)))/(2.28-0.63*(age/100.0)))/1.29
                    
                    if race[5]=="1": #African Americans
                        idarray[38] = 50+10*( (AfricanAmericanAdults("Flanker",input)-(11.77-7.52*(float(age)/100.0)+1.07*(float(edu)/10.0)+0.002*float(gender)))/(1.76+0.18*(age/100.0)+0.22*(edu/10.0)+0.37*gender))/1.24
                        if idarray[38]<0:
                            idarray[38]=0.0
                        
                    elif race[5]!=1 and ethnic==2: #Hispanic Whites 
                        idarray[48] = 50+10*((HispanicAdults("Flanker",input) - (11.56 - 10.32 * (age/100) + 1.68 * (edu/10) + 0.99 * gender)) / (2.07-1.0*(age/100.0)+0.29*(edu/10.0)-0.46*gender))/1.3
                        if idarray[48]<0:
                            idarray[48]=0.0
                        
                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[58] = 50+10*(( WhiteAsianAdults("Flanker",input) - (15.52 - 9.25*(age/100.0) - 1.53*((edu/10.0)**-2)+0.29*gender))/(2.23-0.72*(age/100.0)-0.1*(edu/10.0)+0.33*gender))/1.3
                        if idarray[58]<0:
                            idarray[58]=0.0
                        
                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican
                        idarray[38] = 50+10*( (AfricanAmericanAdults("Flanker",input)-(11.77-7.52*(float(age)/100.0)+1.07*(float(edu)/10.0)+0.002*float(gender)))/(1.76+0.18*(age/100.0)+0.22*(edu/10.0)+0.37*gender))/1.24
                        if idarray[38]<0:
                            idarray[38]=0.0

                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[38] = 50+10*( (AfricanAmericanAdults("Flanker",input)-(11.77-7.52*(float(age)/100.0)+1.07*(float(edu)/10.0)+0.002*float(gender)))/(1.76+0.18*(age/100.0)+0.22*(edu/10.0)+0.37*gender))/1.24
                        if idarray[38]<0:
                            idarray[38]=0.0

                    else: 
                        continue

                if age!='' and (age >=3) and (age < 18): #Children                                                                              
                    idarray[28] = 100+15*((AgeCorrectChildren("Flanker",input)-(-3.71+13.96*(float(age)/10.0)**0.5-0.33*((float(age)/10.0)**3)))/(-3.0+4.3*((age/10.0)**-0.5)+3.07*math.log(age/10.0)))/1.29
                    if idarray[28]<0:
                        idarray[28]=0.0
                    
                    #if race[1:].count("1")>=2: #Multi-Racial
                    #    idarray[68] = 50+10*((MultiChildren("Flanker",input) - (-4.21 + 11.60 * ((age/10)**0.5) + 2.12 * (edu/10.0) + 0.24*gender)) /(1.61+0.47*(age/10.0)-0.59*(edu/10.0)-0.19*gender))/1.23
                    #    if idarray[68]<0:
                    #        idarray[68]=0.0

                    #elif race[5]=="1": #African Americans
                    #    idarray[78] = 50+10*((AfricanAmericanChildren("Flanker",input) - (9.51 + 5.53 * math.log(age/10.0) + 0.29*((edu)/10.0) - 0.06*gender)) / (0.48+0.86*(age/10.0)+0.07*(edu/10.0)+0.02*gender))/1.26
                    #    if idarray[78]<0:
                    #        idarray[78]=0.0
                        

                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[88] = 50+10*((HispanicChildren("Flanker",input) - (9.58 + 5.25 * math.log(age/10.0) + 0.31 * ((edu)/10.0) + 0.37 * gender)) / (0.91+0.72*(age/10.0)-0.41*((edu/10.0)**3)+0.74*math.log(edu/10.0)*((edu/10.0)**3)+0.2*gender))/1.31
                    #    if idarray[88]<0:
                    #        idarray[88]=0.0

                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                    #    idarray[98] = 50+10*((WhiteAsianChildren("Flanker",input) - (0.09 + 11.66 *(age/10.0) - 2.71*((age/10)**2) + 0.60*(edu/10.0) + 0.02*gender)) / (8.45-7.31*((age/10.0)**-0.5)-2.7*math.log(age/10.0)*((age/10.0)**-0.5)+0.09*(edu/10.0)+0.07*gender))/1.28
                    #    if idarray[98]<0:
                    #        idarray[98]=0.0
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[78] = 50+10*((AfricanAmericanChildren("Flanker",input) - (9.51 + 5.53 * math.log(age/10.0) + 0.29*((edu)/10.0) - 0.06*gender)) / (0.48+0.86*(age/10.0)+0.07*(edu/10.0)+0.02*gender))/1.26
                    #    if idarray[78]<0:
                    #        idarray[78]=0.0
                        
                else:
                    continue
            continue

        ######
        #List Sort
        ######
        elif string.find(assess[FORMCOLUMN],"List Sort")!=-1:
            if rawscore!='':
                input = float(rawscore)
                idarray[9] = ((float(rawscore)-16.69)/3.9)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults  
                    idarray[19] = 100+15*( (AgeCorrectAdults("ListSort",input)-(11.98 - 7.37* ((float(age)/100.0)**2) ))/(2.36-0.34*(age/100.0)))/1.23
                    
                    if race[5]=="1": #African Americans
                        idarray[39] = 50+10*( (AfricanAmericanAdults("ListSort",input)-(12.42-7.41*(float(age)/100.0)+0.57*(float(edu)/10.0)+0.58*float(gender)))/(2.14+0.43*(age/100.0)-0.15*(edu/10.0)+0.06*gender))/1.3
                        if idarray[39]<0:
                            idarray[39]=0.0
                        
                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[49] = 50+10*((HispanicAdults("ListSort",input) - (11.27 - 9.35 * (age/100) + 1.27 * (edu/10.0) + 1.53 * gender)) /(2.69-0.54*(age/100.0)-0.3*(edu/10.0)+0.3*gender))/1.2
                        if idarray[49]<0:
                            idarray[49]=0.0
                        
                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[59] = 50+10*(( WhiteAsianAdults("ListSort",input) - (12.89 - 8.36*(age/100.0) + 1.12*(edu/10.0) - 0.25*gender))/(1.8+0.06*(age/100.0)+0.25*(edu/10.0)-0.04*gender))/1.22
                        if idarray[59]<0:
                            idarray[59]=0.0

                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican
                        idarray[39] = 50+10*( (AfricanAmericanAdults("ListSort",input)-(12.42-7.41*(float(age)/100.0)+0.57*(float(edu)/10.0)+0.58*float(gender)))/(2.14+0.43*(age/100.0)-0.15*(edu/10.0)+0.06*gender))/1.3
                        if idarray[39]<0:
                            idarray[39]=0.0

                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[39] = 50+10*( (AfricanAmericanAdults("ListSort",input)-(12.42-7.41*(float(age)/100.0)+0.57*(float(edu)/10.0)+0.58*float(gender)))/(2.14+0.43*(age/100.0)-0.15*(edu/10.0)+0.06*gender))/1.3
                        if idarray[39]<0:
                            idarray[39]=0.0
                        
                    else: 
                        continue

                if age!='' and (age >=3) and (age < 18): #Children
                    idarray[29] = 100+15*( (AgeCorrectChildren("ListSort",input) - (13.21-3.18*((float(age)/10.0)**-2) - 1.98*math.log(age/10.0)*((float(age)/10.0)**-2)))/(2.04-0.33*((age/10.0)**-1)))/1.30

                    #if race[1:].count("1")>=2: #Multi-Racial
                    #    idarray[69] = 50+10*((MultiChildren("ListSort",input) - (17.96 - 8.02 * ((age/10)**-0.5) + 0.33 * (edu/10.0) + 0.12 * gender)) / (1.8+0.36*(age/10.0)-0.18*(edu/10.0)-0.28*gender))/1.22
                    #    if idarray[69]<0:
                    #        idarray[69]=0.0

                    #elif race[5]=="1": #African Americans
                    #    idarray[79] = 50+10*((AfricanAmericanChildren("ListSort",input) - (18.20 - 9.53*((age/10.0)**-0.5) + 0.91 * ((edu)/10.0) + 0.41 * gender)) /(0.86+0.57*(age/10.0)+0.16*(edu/10.0)+0.16*gender))/1.26
                    #    if idarray[79]<0:
                    #        idarray[79]=0.0
                        
                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[89] = 50+10*((HispanicChildren("ListSort",input) - (17.70 - 8.99*((age/10.0)**-0.5) + 1.17*((edu)/10.0) + 0.26*gender)) / (1.12+0.48*(age/10.0)-0.004*(edu/10.0)+0.12*gender))/1.24
                    #    if idarray[89]<0:
                    #        idarray[89]=0.0

                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                     #   idarray[99] = 50+10*(( WhiteAsianChildren("ListSort",input) - (11.9 - 3.31 * ((age/10)**-2) - 2.09 * math.log(age/10) * ((age/10.0)**-2) + 1.17*((edu)/10.0) -0.05*gender))/(2.06-0.56*((age/10.0)**-2)-0.39*math.log(age/10.0)*((age/10.0)**-2)+0.16*(edu/10.0)+0.05*gender))/1.27
                     #   if idarray[99]<0:
                     #       idarray[99]=0.0
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[79] = 50+10*((AfricanAmericanChildren("ListSort",input) - (18.20 - 9.53*((age/10.0)**-0.5) + 0.91 * ((edu)/10.0) + 0.41 * gender)) /(0.86+0.57*(age/10.0)+0.16*(edu/10.0)+0.16*gender))/1.26
                    #    if idarray[79]<0:
                    #        idarray[79]=0.0
                        
                else:
                    continue
            continue

        ######
        #Picture Sequence Memory
        ######
        elif string.find(assess[FORMCOLUMN],"Picture Sequence")!=-1:
            
            """print assess
            print '-----------------'
            print idarray
            print '======================'
            if thetascore!='':
                print "age: " + str(age)
                print "edu: " + str(edu)
                print "gender: " + str(gender)
                print thetascore"""
            
            if computedscore!='':
                input = float(computedscore)
                if input==-99.0:
                    continue
                idarray[10] = ((float(computedscore)-505.59)/99.83)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults  
                    idarray[20] = 100+15*( (AgeCorrectAdults("PictureSeq",input)-(14.06-8.48*(float(age)/100.0)))/(2.43-0.72*(age/100.0)))/1.25
                    if race[5]=="1": #African Americans
                        idarray[40] = 50+10*((AfricanAmericanAdults("PictureSeq",input) - (13.73-5.86*(age/100.0)-0.67*(edu/10.0)-1.15*gender))/(3.53-1.44*(age/100.0)-0.6*(edu/10.0)+0.72*gender))/1.25
                        if idarray[40]<0:
                            idarray[40]=0.0

                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[50] = 50+10*((HispanicAdults("PictureSeq",input) - (11.19 - 8.84 * (age/100.0) + 1.63 * (edu/10.0) + 0.39 * gender)) / (1.07+0.09*(age/100.0)+0.58*(edu/10.0)+0.44*gender))/1.27
                        if idarray[50]<0:
                            idarray[50]=0.0

                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[60] = 50+10*(( WhiteAsianAdults("PictureSeq",input) - (12.72 - 8.91*(age/100.0) + 1.51*(edu/10.0) - 0.97*gender))/(2.42-0.49*(age/100.0)-0.17*(edu/10.0)-0.05*gender))/1.25
                        if idarray[60]<0:
                            idarray[60]=0.0
                        
                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican 
                        idarray[40] = 50+10*((AfricanAmericanAdults("PictureSeq",input) - (13.73-5.86*(age/100.0)-0.67*(edu/10.0)-1.15*gender))/(3.53-1.44*(age/100.0)-0.6*(edu/10.0)+0.72*gender))/1.25
                        if idarray[40]<0:
                            idarray[40]=0.0

                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[40] = 50+10*((AfricanAmericanAdults("PictureSeq",input) - (13.73-5.86*(age/100.0)-0.67*(edu/10.0)-1.15*gender))/(3.53-1.44*(age/100.0)-0.6*(edu/10.0)+0.72*gender))/1.25
                        if idarray[40]<0:
                            idarray[40]=0.0

                    else:
                        continue
                        
                if age!='' and (age >=3) and (age < 18): #Children
                    idarray[30] = 100+15*( (AgeCorrectChildren("PictureSeq",input) - (-2.14+12.32*(float(age)/10.0)-7.84*math.log(float(age)/10.0)*(float(age)/10.0)))/(1.14+0.64*(float(age)/10.0)))/1.25

                    #if race[1:].count("1") >= 2: #Multi-Racial
                    #    idarray[70] = 50+10*(( MultiChildren("PictureSeq",input) - (5.70 + 4.34 * math.log(age/10.0) + 3.23 * (edu/10.0) + 0.91 * gender)) / (1.56+0.43*(age/10.0)-0.38*(edu/10.0)+0.16*gender))/1.24
                    #    if idarray[70]<0:
                    #        idarray[70]=0.0
                        
                    #elif race[5]=="1": #African Americans
                    #    idarray[80] = 50+10*(( AfricanAmericanChildren("PictureSeq",input) - (16.40 - 7.70 * ((age/10)**-0.5) + 1.03 * (edu/10.0) - 0.09 * gender)) / (1.14+0.6*(age/10.0)+0.15*(edu/10.0)-0.02*gender))/1.22
                    #    if idarray[80]<0:
                    #        idarray[80]=0.0
                        
                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[90] = 50+10*(( HispanicChildren("PictureSeq",input) - (16.35 - 7.57 * ((age/10)**-0.5) + 1.22 * ((edu)/10.0) + 0.12 * gender)) / (1.44+0.75*(age/10.0)-0.43*(edu/10.0)+0.07*gender))/1.25
                    #    if idarray[90]<0:
                    #        idarray[90]=0.0
                        
                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                    #    idarray[100] = 50+10*(( WhiteAsianChildren("PictureSeq",input) - (17.14 - 7.68 * ((age/10)**-0.5) + 0.56 * (edu/10.0) - 0.11 * gender)) / (1.07+0.6*(age/10.0)+0.08*(edu/10.0)-0.001*gender))/1.25
                    #    if idarray[100]<0:
                    #        idarray[100]=0.0
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[80] = 50+10*(( AfricanAmericanChildren("PictureSeq",input) - (16.40 - 7.70 * ((age/10)**-0.5) + 1.03 * (edu/10.0) - 0.09 * gender)) / (1.14+0.6*(age/10.0)+0.15*(edu/10.0)-0.02*gender))/1.22
                    #    if idarray[80]<0:
                    #        idarray[80]=0.0
                        
                    #else:
                    #    continue
                else:
                    continue

        ######
        #Pattern Comparison
        ######
        elif string.find(assess[FORMCOLUMN],"Pattern Comparison")!=-1:
            if rawscore!='':
                input = float(rawscore)

                idarray[11] = ((float(rawscore)-55.32)/11.88)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults  
                    idarray[21] = 100+15*( (AgeCorrectAdults("PatternComp",input) -(14.68-9.62*(float(age)/100.0)))/(2.33-0.74*(age/100.0)))/1.24
                    if race[5]=="1": #African Americans
                        idarray[41] = 50+10*((AfricanAmericanAdults("PatternComp",input) - (15.27 - 10.82 * (age/100.0) - (0.51 * (edu/10.0))+0.66*gender))/(2.5-0.72*(age/100.0)-0.24*(edu/10.0)+0.58*gender))/1.24
                        if idarray[41]<0:
                            idarray[41]=0.0

                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[51] = 50+10*((HispanicAdults("PatternComp",input) - (12.15 - 11.01 * (age/100.0) + 1.71 * (edu/10) - 0.13 * gender)) / (1.83-0.63*(age/100.0)+0.34*(edu/10.0)+0.02*gender))/1.21
                        if idarray[51]<0:
                            idarray[51]=0.0

                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[61] = 50+10*(( WhiteAsianAdults("PatternComp",input) - (10.5 - 9.42*(age/100.0) + 3.75*((edu/10.0)**2) - 4.03*math.log(edu/10.0)*((edu/10.0)**2) - 0.28*gender))/(2.06-0.82*(age/100.0)+0.08*(edu/10.0)+0.34*gender))/1.24
                        if idarray[61]<0:
                            idarray[61]=0.0

                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican
                        idarray[41] = 50+10*((AfricanAmericanAdults("PatternComp",input) - (15.27 - 10.82 * (age/100.0) - (0.51 * (edu/10) )+0.66*gender))/(2.5-0.72*(age/100.0)-0.24*(edu/10.0)+0.58*gender))/1.24
                        if idarray[41]<0:
                            idarray[41]=0.0

                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[41] = 50+10*((AfricanAmericanAdults("PatternComp",input) - (15.27 - 10.82 * (age/100.0) - (0.51 * (edu/10) )+0.66*gender))/(2.5-0.72*(age/100.0)-0.24*(edu/10.0)+0.58*gender))/1.24
                        if idarray[41]<0:
                            idarray[41]=0.0
                        
                    else:
                        continue
                        
                if age!='' and (age >=3) and (age < 18): #Children
                    idarray[31] = 100+15*( (AgeCorrectChildren("PatternComp",input) - (-1.2+10.85*((float(age)/10.0)**0.5)))/(-4.47+5.88*((age/10.0)**-0.5)+3.67*math.log(age/10.0)))/1.29

                    #if race[1:].count("1")>=2: #Multi-Racial
                    #    idarray[71] = 50+10*((MultiChildren("PatternComp",input) - (2.83 + 5.98 * (age/10) + 0.81 * (edu/10) + 0.15 * gender)) /(0.69+0.47*(age/10.0)+0.03*(edu/10.0)+0.29*gender))/1.25
                    #    if idarray[71]<0:
                    #        idarray[71]=0.0

                    #elif race[5]=="1": #African Americans
                    #    idarray[81] = 50+10*(( AfricanAmericanChildren("PatternComp",input) - (23.35 + 1.02 * ((age/10)**-2) - 15.13 * ((age/10)**-0.5) + 0.54 * ((edu)/10) - 0.29 * gender)) /(2.92-0.88*((age/10.0)**-2)-0.88*math.log(age/10.0)*((age/10.0)**-2)-0.37*(edu/10.0)+0.06*gender))/1.27
                    #    if idarray[71]<0:
                    #        idarray[71]=0.0
                        

                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[91] = 50+10*(( HispanicChildren("PatternComp",input) - (-1.06 + 10.96 * ((age/10)**0.5) + 0.07 * ((edu)/10) - 0.21 * gender)) /(0.32+0.63*(age/10.0)+0.42*(edu/10.0)+0.07*gender))/1.29
                    #    if idarray[91]<0:
                    #        idarray[91]=0.0
                        
                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                     #   idarray[101] = 50+10*(( WhiteAsianChildren("PatternComp",input) - (-2.04 + 11.23 * ((age/10)**0.5) + 0.47 * ((edu)/10) - 0.29 * gender)) /(1.31+0.71*math.log(age/10.0)+0.74*(math.log(age/10.0)**2)+0.03*(edu/10.0)+0.06*gender))/1.31
                    #    if idarray[101]<0:
                     #       idarray[101]=0.0
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[81] = 50+10*(( AfricanAmericanChildren("PatternComp",input) - (23.35 + 1.02 * ((age/10)**-2) - 15.13 * ((age/10)**-0.5) + 0.54 * ((edu)/10) - 0.29 * gender))/(2.92-0.88*((age/10.0)**-2)-0.88*math.log(age/10.0)*((age/10.0)**-2)-0.37*(edu/10.0)+0.06*gender))/1.27
                    #    if idarray[81]<0:
                    #        idarray[81]=0.0
                        
                else:
                    continue


        ######
        #Oral Reading
        ######
        elif string.find(assess[FORMCOLUMN],"Oral")!=-1:
            if skiploop == 1:
                skiploop = 0
                continue
            
            if thetaoral!=-1:
                #print "Theta Oral: " + str(thetaoral)
                input = float(thetaoral)
                idarray[12] = ((float(input)-2.8)/5.2)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults  
                    #error caused by theta being 33.8, when max in sheet allowed was up to 20 for oral reading score
                    if input<=20.0:
                        idarray[22] = 100+15*( (AgeCorrectAdults("OralReading",input) - (9.68-0.65*(float(age)/100.0)))/(1.81+1.19*(age/100.0)))/1.26
                    else:
                        continue

                    if race[5]=="1": #African Americans
                        idarray[42] = 50+10*((AfricanAmericanAdults("OralReading",input) - (6.05 - 1.40*(age/100)+3.23*(edu/10)+0.17*gender))/(1.95+1.09*(age/100.0)-0.16*(edu/10.0)+0.45*gender))/1.26
                        
                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[52] = 50+10*((HispanicAdults("OralReading",input) - (1.37 + 0.51 * (age/100) + 5.84 * (edu/10) + 0.40 * gender)) /(1.66+2.08*(age/100.0)-0.33*(edu/10.0)+0.07*gender))/1.22
                        
                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[62] = 50+10*(( WhiteAsianAdults("OralReading",input) - (3.55 + 0.87*(age/100.0) + 4.2*(edu/10.0) + 0.18*gender))/(-2.1+0.73*(age/100.0)+2.02*((edu/10.0)**-2)+2.04*(edu/10.0)-0.16*gender))/1.25
                        
                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican
                        idarray[42] = 50+10*((AfricanAmericanAdults("OralReading",input) - (6.05 - 1.40*(age/100)+3.23*(edu/10)+0.17*gender))/(1.95+1.09*(age/100.0)-0.16*(edu/10.0)+0.45*gender))/1.26
                        
                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[42] = 50+10*((AfricanAmericanAdults("OralReading",input) - (6.05 - 1.40*(age/100)+3.23*(edu/10)+0.17*gender))/(1.95+1.09*(age/100.0)-0.16*(edu/10.0)+0.45*gender))/1.26
                        
                    else:
                        continue
                        
                if age!='' and (age >=3) and (age < 18): #Children
                    idarray[32] = 100+15*( (AgeCorrectChildren("OralReading",input) - (21.06-11.09*((float(age)/10.0)**-1) - 5.05*math.log(float(age)/10.0)*((float(age)/10.0)**-1)))/(9.97-8.81*((age/10.0)**-0.5)-3.28*math.log(age/10.0)*((age/10.0)**-0.5)))/1.31

                    #if race[1:].count("1")>=2: #Multi-Racial
                    #    idarray[72] = 50+10*(( MultiChildren("OralReading",input) - (7.68 + 5.02 * math.log(age/10) + 2.11 * (edu/10) + 0.32 * gender)) /(-0.87+0.86*(age/10.0)+0.93*(edu/10.0)+0.04*gender))/1.35

                    #elif race[5]=="1": #African Americans
                    #    idarray[82] = 50+10*((AfricanAmericanChildren("OralReading",input) - (-0.73 + 10.54 * (age/10) - 1.31 * ((age/10)**3) + 1.26 * ((edu)/10) - 0.01 * gender))/(0.04+1.02*(age/10.0)+0.11*(edu/10.0)+0.19*gender))/1.31

                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[92] =  50+10*(( HispanicChildren("OralReading",input) - (16.38 + 1.43 * ((age/10)**-2) - 8.60 * ((age/10)**-1) + 0.93 * ((edu)/10) - 0.03 * gender)) /(0.72+0.84*(age/10.0)-0.37*((edu/10.0)**3)+0.68*math.log(edu/10.0)*((edu/10.0)**3)+0.03*gender))/1.35

                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                    #    idarray[102] = 50+10*(( WhiteAsianChildren("OralReading",input) - (7.68 + 0.26 * ((age/10)**-2) + 6.78 * math.log(age/10) + 1.42 * ((edu)/10) - 0.03 * gender)) /(5.48+2.46*((age/10.0)**-1)-7.02*((age/10.0)**-0.5)+0.13*(edu/10.0)+0.09*gender))/1.3
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                    #    idarray[82] = 50+10*((AfricanAmericanChildren("OralReading",input) - (-0.73 + 10.54 * (age/10) - 1.31 * ((age/10)**3) + 1.26 * ((edu)/10) - 0.01 * gender))/(0.04+1.02*(age/10.0)+0.11*(edu/10.0)+0.19*gender))/1.31
                        
                else:
                    continue
            continue

        ######
        #Picture Vocabulary
        ######
        elif string.find(assess[FORMCOLUMN],"Picture Vocabulary")!=-1:
            
            if skiploop == 1:
                skiploop = 0
                continue

            
            if thetavocab!=-1:
                input = float(thetavocab)
                #print "Theta Vocab: " + str(thetavocab)
                #print "Scaled Conversion: " + str(AfricanAmericanAdults("PictureVocab",input))
                """scaledconvert = AfricanAmericanAdults("PictureVocab",input)
                print "age: " + str(age)
                print "edu: " + str(edu)
                print "gender: " + str(gender)
                print "theta: " + str(thetascore)
                print "race: " + str(race)
                print "ethnicity: " + str(ethnic)
                print "input: " + str(input)
                print "scaled conversion: " + str(scaledconvert)"""


                idarray[13] = ((float(input)-3.73)/3.14)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    if input>15.0:
                        continue
                    idarray[23] = 100+15*( (AgeCorrectAdults("PictureVocab",input)-(11.41-0.57*((float(age)/100.0)**-1)))/(1.86+1.12*(age/100.0)))/1.24
                    
                    if race[5]=="1": #African Americans
                        idarray[43] = 50+10*((AfricanAmericanAdults("PictureVocab",input) - (0.56 + 3.11 * (age/100) + 5.81 * (edu/10) - 0.39*gender))/(2.03-0.45*(age/100.0)+0.14*(edu/10.0)+0.2*gender))/1.27

                    elif race[5]!=1 and ethnic==2: #Hispanic Whites
                        idarray[53] = 50+10*((HispanicAdults("PictureVocab",input) - (0.74 + 5.17 * (age/100) + 4.91 * (edu/10) + 0.74 * gender)) / (1.74+1.16*(age/100.0)-0.15*(edu/10.0)+0.07*gender))/1.23

                    elif race[6]=="1" or race[4]=="1" and ethnic!=2: #Asian/White
                        idarray[63] = 50+10*(( WhiteAsianAdults("PictureVocab",input) - (2.69 + 18.5*((age/100.0)**2) - 19.7*((age/100.0)**3) + 3.92*(edu/10.0) - 0.09*gender))/(0.82+1.09*(age/100.0)+0.52*(edu/10.0)+0.35*gender))/1.25

                    elif (race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI to AfricanAmerican
                        idarray[43] = 50+10*((AfricanAmericanAdults("PictureVocab",input) - (0.56 + 3.11 * (age/100) + 5.81 * (edu/10) - 0.39*gender))/(2.03-0.45*(age/100.0)+0.14*(edu/10.0)+0.2*gender))/1.27
                        
                    elif (race[1]=="1") and ethnic!=2: #Other to AfricanAmerican
                        idarray[43] = 50+10*((AfricanAmericanAdults("PictureVocab",input) - (0.56 + 3.11 * (age/100) + 5.81 * (edu/10) - 0.39*gender))/(2.03-0.45*(age/100.0)+0.14*(edu/10.0)+0.2*gender))/1.27
                        
                    else:
                        continue
                    
                if age!='' and (age >=3) and (age < 18): #Children 
                    idarray[33] = 100+15*( (AgeCorrectChildren("PictureVocab",input) - (2.19+8.25*(float(age)/10.0) - 0.64*((float(age)/10)**3)))/(1.15+0.9*math.log(age/10.0)+0.88*(math.log(age/10.0)**2)))/1.29

                    #if race[1:].count("1")>=2: #Multi-Racial
                        #idarray[73] = 50+10*(( MultiChildren("PictureVocab",input) - (7.10 + 5.15 * math.log(age/10) + 3.01 * (edu/10) - 0.76 * gender)) /(0.49+0.76*(age/10.0)-0.1*(edu/10.0)-0.16*gender))/1.23
                        
                    #elif race[5]=="1": #African Americans
                     #   idarray[83] = 50+10*((AfricanAmericanChildren("PictureVocab",input) - (1.9 + 9.41 * ((age/10)**2) - 3.82 * ((age/10)**3) + 1.58 * ((edu+1)/10) + 0.34 * gender)) /(0.89+0.63*(age/10.0)-0.2*(edu/10.0)+0.22*gender))/1.3
                        
                    #elif ethnic==2: #Hispanic Whites
                    #    idarray[93] = 50+10*(( HispanicChildren("PictureVocab",input) - (-3.46 + 11.91 * ((age/10)**0.5) + 1.18 * ((edu)/10) + 0.04 * gender)) /(0.67+0.56*(age/10.0)-0.1*(edu/10.0)+0.16*gender))/1.29

                    #elif (race[6]=="1" or race[4]=="1") and ethnic!=2: #Asian/White
                    #    idarray[103] = 50+10*(( WhiteAsianChildren("PictureVocab",input) - (0.52 + 8.27 * (age/10) - 0.58 * ((age/10)**3) + 0.98*((edu/10)**3)-1.15*math.log(edu/10.0)*((edu/10.0)**3) + 0.19 * gender)) /(9.71-9.04*((age/10.0)**-0.5)-3.56*math.log(age/10.0)*((age/10.0)**-0.5)+0.26*(edu/10.0)+0.15*gender))/1.27
                        
                    #elif (race[1]=="1" or race[2]=="1" or race[3]=="1") and ethnic!=2: #Native/PI/Other to AfricanAmerican
                     #   idarray[83] = 50+10*((AfricanAmericanChildren("PictureVocab",input) - (1.9 + 9.41 * ((age/10)**2) - 3.82 * ((age/10)**3) + 1.58 * ((edu+1)/10) + 0.34 * gender)) /(0.89+0.63*(age/10.0)-0.2*(edu/10.0)+0.22*gender))/1.3
                        
                else:
                    continue
            continue


        

    #elif assess[14]=="es":
    elif assess[LANGUAGECOLUMN]=="es":
        idarray[1] = "es"

        ###### 
        #DCCS  
        ######  
        if string.find(assess[FORMCOLUMN],"Dimensional Change Card")!=-1:
            if computedscore!='':
                input = float(computedscore)
                if input==-99.0:
                    continue
                idarray[107] = ((input - 4.89)/2.93)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[0] = SpanishAdults("DCCS",input)
                    idarray[117] = 100+15*((SpanishAdults("DCCS",input) - (13.48 - 7.84*(age/100.0)))/(2.52-1.11*(age/100.0)))/1.3
                    idarray[137] = 50+10*((SpanishAdults("DCCS",input) - (11.0 - 7.24*(age/100.0) + 1.27*(((edu+1.0)/10.0)**2) + 0.61*gender))/(1.56-0.18*(age/100.0)+0.16*((edu+1/10.0))+0.34*gender))/1.3
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[7] = SpanishChildren("DCCS",input)
                    #idarray[127] = 100+15*((SpanishChildren("DCCS",input) - (4.04+11.68*(age/10.0)))/(1.86+0.32*(age/10.0)))/1.25
                    #idarray[147] = 50+10*((SpanishChildren("DCCS",input) - (2.91+11.8*(age/10.0) + 1.13*((edu+1.0)/10.0) - 0.28*gender))/(1.68+0.31*(age/10.0)+0.11*((edu+1)/10.0)+0.03*gender))/1.26
                    
            continue

        ###### 
        #Flanker 
        ###### 
        elif string.find(assess[FORMCOLUMN],"Flank")!=-1:
            if computedscore!='':
                input = float(computedscore)
                if input==-99.0:
                    continue
                idarray[108] = ((input - 5.81)/2.77)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[1] = SpanishAdults("Flanker",input)
                    idarray[118] = 100+15*((SpanishAdults("Flanker",input) - (13.91 - 8.89*(age/100)))/(1.87-0.52*(age/100.0)))/1.25
                    idarray[138] = 50+10*((SpanishAdults("Flanker",input) - (10.16 - 7.95*(age/100.0) + 2.64*((edu+1.0)/10.0) + 0.7*gender))/(1.25+0.63*(age/100.0)+0.14*((edu+1)/10.0)+0.46*gender))/1.26
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[8] = SpanishChildren("Flanker,input")
                    #idarray[128] = 100+15*((SpanishChildren("Flanker",input) - (2.76+14.10*(age/10.0)))/(1.83-0.12*(age/10.0)))/1.3
                    #idarray[148] = 50+10*((SpanishChildren("Flanker",input) - (1.97+14.23*(age/10.0) + 0.61*((edu+1.0)/10.0) + 0.14*gender))/(1.73-0.06*(age/10.0)+0.03*((edu+1)/10.0)+0.08*gender))/1.29

            continue

        ######  
        #List Sort  
        ###### 
        elif string.find(assess[FORMCOLUMN],"List Sort")!=-1:
            if rawscore!='':
                input = float(rawscore)
                idarray[109] = ((input - 11.37)/5.09)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[2] = SpanishAdults("ListSort",input)
                    idarray[119] = 100+15*((SpanishAdults("ListSort",input) - (13.37 - 7.97*(age/100)))/(2.78-1.31*(age/100.0)))/1.26
                    idarray[139] = 50+10*((SpanishAdults("ListSort",input) - (10.68 - 7.14*(age/100.0) + 1.95*((edu+1.0)/10) + 0.05*gender))/(2.55-1.2*(age/100.0)+0.08*((edu+1)/10.0)-0.03*gender))/1.26
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[9] = SpanishChildren("ListSort",input)
                    #idarray[129] = 100+15*((SpanishChildren("ListSort",input) - (3.04+12.79*(age/10.0)))/(2.03-0.18*(age/10.0)))/1.26
                    #idarray[149] = 50+10*((SpanishChildren("ListSort",input) - (2.10+13.09*(age/10.0) + 0.97*((edu+1.0)/10.0) - 0.55*gender))/(1.72-0.07*(age/10.0)+0.06*((edu+1)/10.0)+0.34*gender))/1.26

            continue

        ######  
        #Picture Sequence Memory 
        ######  
        elif string.find(assess[FORMCOLUMN],"Picture Sequence")!=-1:
            if computedscore!='':
                input = float(computedscore)
                if input==-99.0:
                    continue
                idarray[110] = ((input - 432.24)/107.60)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[3] = SpanishAdults("PictureSeq",input)
                    idarray[120] = 100+15*((SpanishAdults("PictureSeq",input) - (13.40 - 8.57*(age/100)))/(2.66-1.27*(age/100.0)))/1.27
                    idarray[140] = 50+10*((SpanishAdults("PictureSeq",input) - (9.95 - 7.34*(age/100.0) + 2.51*((edu+1.0)/10.0) - 0.45*gender))/(2.68-0.89*(age/100.0)-0.29*((edu+1)/10.0)+0.16*gender))/1.28
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[10] = SpanishChildren("PictureSeq",input)
                    #idarray[130] = 100+15*((SpanishChildren("PictureSeq",input) - (14.93+6.86*math.log(age/10.0)))/(1.49+0.63*(age/10.0)))/1.23
                    #idarray[150] = 50+10*((SpanishChildren("PictureSeq",input) - (2.07 + 14.2*(age/10.0) + 0.5*((edu+1.0)/10.0) + 0.33*gender))/(1.14+0.78*(age/10.0)+0.3*((edu+1.0)/10.0)-0.17*gender))/1.25

            continue


        ######  
        #Pattern Comparison   
        ###### 
        elif string.find(assess[FORMCOLUMN],"Pattern Comparison")!=-1:
            if rawscore!='':
                input = float(rawscore)
                idarray[111] = ((input - 43.55)/12.56)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[4] = SpanishAdults("PatternComp",input)
                    idarray[121] = 100+15*((SpanishAdults("PatternComp",input) - (13.97 - 9.07*(age/100)))/(2.44-0.78*(age/100.0)))/1.26
                    idarray[141] = 50+10*((SpanishAdults("PatternComp",input) - (11.98 - 8.68*(age/100.0) + 1.41*((edu+1.0)/10.0) + 0.46*gender))/(1.34-0.35*(age/100.0)+0.67*((edu+1.0)/10.0)+0.15*gender))/1.25
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[11] = SpanishChildren("PatternComp",input)
                    #idarray[131] = 100+15*((SpanishChildren("PatternComp",input) - (3.36+12.88*(age/10.0)))/(2.87-2.07*(age/10.0)))/1.32
                    #idarray[151] = 50+10*((SpanishChildren("PatternComp",input) - (2.9 + 12.94*(age/10.0) + 0.32*((edu+1.0)/10.0) + 0.21*gender))/(3.45-2.2*(age/10.0)-0.58*((edu+1.0)/10.0)+0.21*gender))/1.33

            continue

        ###### 
        #Oral Reading 
        ###### 
        elif string.find(assess[FORMCOLUMN],"Oral")!=-1:
            if skiploop == 1:
                skiploop = 0
                continue
            
            if thetaoral!=-1:
                input = float(thetaoral)
                if input>15.0:
                    continue
                idarray[112] = ((input - 2.97)/6.27)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[5] = SpanishAdults("OralReading",input)
                    idarray[122] = 100+15*((SpanishAdults("OralReading",input) - (11.95 - 4.43*(age/100)))/(1.96+0.81*(age/100.0)))/1.26
                    idarray[142] = 50+10*((SpanishAdults("OralReading",input) - (9.37 - 3.65*(age/100.0) + 1.86*((edu+1.0)/10.0)+0.09*gender))/(3.21+0.46*(age/100.0)+0.04*(((edu+1)/10.0)**-2)-1.49*(((edu+1)/10.0)**-0.5)+0.54*gender))/1.23
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[12] = SpanishChildren("OralReading",input)
                    #idarray[132] = 100+15*((SpanishChildren("OralReading",input) - (3.69+10.95*(age/10.0)))/(1.51+1.13*(age/10.0)))/1.32
                    #idarray[152] = 50+10*((SpanishChildren("OralReading",input) - (3.33+11.1*(age/10.0)+0.35*((edu+1)/10.0)-0.24*gender))/(1.48+1.02*(age/10.0)+0.13*((edu+1)/10.0)-0.11*gender))/1.22

            continue
                
        ######
        #Picture Vocabulary
        ######
        elif string.find(assess[FORMCOLUMN],"Picture Vocabulary")!=-1:
            if skiploop == 1:
                skiploop = 0
                continue
            
            if thetavocab!=-1:
                input = float(thetavocab)
                if input>15.0:
                    continue
                idarray[113] = ((input - (-0.06))/3.52)*15+100
                if age!='' and (age >= 18) and (age < 86): #Adults
                    idscaled[6] = SpanishAdults("PictureVocab",input)
                    idarray[123] = 100+15*((SpanishAdults("PictureVocab",input) - (3.90 + 32.00*(age/100.0) - 36.02*((age/100)**2)))/(1.45+1.78*(age/100.0)))/1.25
                    idarray[143] = 50+10*((SpanishAdults("PictureVocab",input) - (1.71+28.94*(age/100.0) - 31.6*((age/100.0)**2)+2.23*((edu+1.0)/10.0)-0.2*gender))/(0.64+1.74*(age/100.0)+0.49*((edu+1)/10.0)+0.39*gender))/1.25
                if age!='' and (age >=3) and (age < 18): #Children
                    idscaled[13] = SpanishChildren("PictureVocab",input)
                    #idarray[133] = 100+15*((SpanishChildren("PictureVocab",input) - (3.84+12.48*(age/10.0)))/(2.16-0.59*(age/10.0)))/1.3
                    #idarray[153] = 50+10*((SpanishChildren("PictureVocab",input) - (3.74 + 12.51*(age/10.0) + 0.43*((edu+1.0)/10.0) - 0.78*gender))/(1.96-0.41*(age/10.0)+0.09*((edu+1)/10.0)-0.04*gender))/1.31

            continue

    
idmatrix.append(idarray)
############################
# Writing to CSV File
############################

#g.write('"PIN","DCCS","Flanker","List Sort","Picture Sequence Memory","Pattern Comparison","Oral Reading","Picture Vocabulary","Fluid Composite","Crystaliized Composite","Total Cognition Composite",\n')

#g.write('"PIN","Language",')
columnheader = '"PIN","Language","ENGLISH","Age","Gender","Race","Ethnic","Education",'
#columnheader2= '"ENGLISH"'+","*102 +"SPANISH"+"\n"

assessments = ['DCCS','Flanker','List Sort','Picture Sequence Memory','Pattern Comaprison','Oral Reading','Picture Vocabulary','Fluid Composite','Crystallized Composite','Total Cognition Composite']
correcteds = ['(Eng Uncorrected Census-Weight SS)','(Eng Adults Age-Corrected SS)','(Eng Children Age-Corrected SS)','(Eng Adult AfAm T-Score)','(Eng Adult Hispanic T-Score)','(Eng Adult Asian/White T-Score)','(Eng Children Multi-Racial T-Score)','(Eng Children AfAm T-Score)','(Eng Children Hispanic T-Score)','(Eng Children White/Asian T-Score)','(Span Uncorrected SS)','(Span Adults Age-Corrected SS)','(Span Children Age-Corrected SS)','(Span Adults T-Score)','(Span Children T-Score)']

count=1
for x in correcteds:
    for y in assessments:
       if count==101:
            adder = "\"" + "SPANISH" + "\"" + ","
            columnheader = columnheader + adder
            count+=1
       adder = "\"" + y + " " + x + "\"" + ","
       columnheader = columnheader + adder
       count+=1

columnheader = columnheader+"\n"
g.write(columnheader)
#g.write(columnheader2)

idnumber=0
count=1
numrows=len(idmatrix)
print numrows
for id in idmatrix:
    count=1
    idnumber=idnumber+1
   

    for score in id:
        if count==3:
            scorestring = "\""+""+"\""
            g.write(scorestring)
            g.write(",")
            count+=1
        if count==109:
            scorestring = "\""+""+"\""
            g.write(scorestring)
            g.write(",")
            count+=1
        scorestring = "\""+str(score)+"\""
        g.write(scorestring)
        g.write(",")
        count+=1
    #g.write("^M^M")
        
    g.write("\n")


print "Complete!"
print "Filename of normed data is " + outputfile
print "--------------------"
print idmatrix[0]

#print lastprint
#print lastprint2
"""for x in thetadict:
    print x, thetadict[x]"""


