Example #1
0
def printMemoryWords(db=dbAdmin("stroop_study_F07")):
	subs = db.getSubjects("memory_results")
	target, distractor = allWords()
	
	words = target + distractor

	wordDict = {}

	fileWriter = FileWriter(filename = "All_Memory_Words.txt")
	fileWriter.writeHeaderList(["subject"] + words)

	for sub in subs:
		d = copy.deepcopy(wordDict)
		for word in words:
			d[word] = ''
		for word in words:
			sql = """SELECT response FROM memory_results WHERE subject = %s and word = '%s'""" % (sub, word)
			response = db.query(sql)
			try:
				d[word] = response[0][0]
			except:
				pass
		timeList = [str(sub)]
		
		for word in words:
			timeList.append(d[word])

		fileWriter.writeList(timeList)
Example #2
0
def addSubMemoryData(sub, db=dbAdmin("stroop_study_F07")):
	abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs = generateWords()
	number = str(sub.number)
	d = os.path.join(os.getcwd(), "data", "P_%s" % number)	
	subFile = os.path.join(d, 'subInfo.pck')
	s = open(subFile, 'r')
	sub = pickle.load(s)
	s.close()
	memoryFile = os.path.join(d, str(sub.number) + "_memory.pck")
	f = open(memoryFile, 'r')
	data = pickle.load(f)
	f.close()
	
	if sub.sex == 1:
		sex = 'female'
	else:
		sex = 'male'

	for d in data:
		word = d['word']
		response = d['response']
		category = classify(word, abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs)
		if category not in ['aD', 'pD', 'nD', 'fD']:
			sql = "SELECT category FROM stroop_results WHERE subject = %s AND word = '%s'" % (number, word)
			#print sql
			#print db.query(sql)
			category = db.query(sql)[0][0]
		#print category
		sql = "INSERT INTO memory_results VALUES(NULL, %s, '%s', '%s', '%s', %s)" % (number, sex, word, category, response)
		#print sql
		db.query(sql)
Example #3
0
def printStroopWordResults(db=dbAdmin("stroop_study_F07")):
	subs = db.getSubjects("stroop_results")
	words, slug = allWords()
	wordDict = {}
	
	fileWriter = FileWriter(filename = "All_Stroop_Words.txt")
	fileWriter.writeHeaderList(["subject"] + words)

	for sub in subs:
		d = copy.deepcopy(wordDict)
		for word in words:
			d[word] = ''
		for word in words:
			sql = """SELECT rt FROM stroop_results WHERE subject = %s and word = '%s'""" % (sub, word)
			rt = db.query(sql)
			try:
				d[word] = rt[0][0]
			except:
				pass
		timeList = [str(sub)]
	
		for word in words:
			timeList.append(d[word])

		fileWriter.writeList(timeList)
Example #4
0
def addSubNumberData(sub, db = dbAdmin("stroop_study_F07")):
	globDir = os.path.join(os.getcwd(), "numberdata", "P_%s" % str(sub.number))	
	d = glob.glob(globDir)[0]
	subFile = os.path.join(d, 'subInfo.pck')
	s = open(subFile, 'r')
	sub = pickle.load(s)
	s.close()
	stroopFile = os.path.join(d, str(sub.number) + "_number_data.pck")
	f = open(stroopFile, 'r')
	data = pickle.load(f)
	f.close()
	
	if sub.sex == 1:
		sex = 'female'
	else:
		sex = 'male'

	number = str(sub.number)

	trial = 0

	for item in data:
		trial = trial + 1
		word = item[0]
		colour = item[1]
		onset = item[2]
		response = item[3]
		rt = response - onset
		sql = """
			INSERT INTO
			number_results
			VALUES (NULL, %s, "%s", "%s", "%s", "%s", %s, %s, %s);
			""" % (number, sex, word, trial, colour, onset, response, rt)
		print sql
		db.query(sql)
Example #5
0
def printMemoryWords(db=dbAdmin("stroop_study_F07")):
    subs = db.getSubjects("memory_results")
    target, distractor = allWords()

    words = target + distractor

    wordDict = {}

    fileWriter = FileWriter(filename="All_Memory_Words.txt")
    fileWriter.writeHeaderList(["subject"] + words)

    for sub in subs:
        d = copy.deepcopy(wordDict)
        for word in words:
            d[word] = ''
        for word in words:
            sql = """SELECT response FROM memory_results WHERE subject = %s and word = '%s'""" % (
                sub, word)
            response = db.query(sql)
            try:
                d[word] = response[0][0]
            except:
                pass
        timeList = [str(sub)]

        for word in words:
            timeList.append(d[word])

        fileWriter.writeList(timeList)
Example #6
0
def printStroopWordResults(db=dbAdmin("stroop_study_F07")):
    subs = db.getSubjects("stroop_results")
    words, slug = allWords()
    wordDict = {}

    fileWriter = FileWriter(filename="All_Stroop_Words.txt")
    fileWriter.writeHeaderList(["subject"] + words)

    for sub in subs:
        d = copy.deepcopy(wordDict)
        for word in words:
            d[word] = ''
        for word in words:
            sql = """SELECT rt FROM stroop_results WHERE subject = %s and word = '%s'""" % (
                sub, word)
            rt = db.query(sql)
            try:
                d[word] = rt[0][0]
            except:
                pass
        timeList = [str(sub)]

        for word in words:
            timeList.append(d[word])

        fileWriter.writeList(timeList)
Example #7
0
def addSubMemoryData(sub, db=dbAdmin("stroop_study_F07")):
    abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs = generateWords(
    )
    number = str(sub.number)
    d = os.path.join(os.getcwd(), "data", "P_%s" % number)
    subFile = os.path.join(d, 'subInfo.pck')
    s = open(subFile, 'r')
    sub = pickle.load(s)
    s.close()
    memoryFile = os.path.join(d, str(sub.number) + "_memory.pck")
    f = open(memoryFile, 'r')
    data = pickle.load(f)
    f.close()

    if sub.sex == 1:
        sex = 'female'
    else:
        sex = 'male'

    for d in data:
        word = d['word']
        response = d['response']
        category = classify(word, abuse, positive, neutral, Ns, fakeabuse,
                            fakepositive, fakeneutral, fakeNs)
        if category not in ['aD', 'pD', 'nD', 'fD']:
            sql = "SELECT category FROM stroop_results WHERE subject = %s AND word = '%s'" % (
                number, word)
            #print sql
            #print db.query(sql)
            category = db.query(sql)[0][0]
        #print category
        sql = "INSERT INTO memory_results VALUES(NULL, %s, '%s', '%s', '%s', %s)" % (
            number, sex, word, category, response)
        #print sql
        db.query(sql)
Example #8
0
def addSubNumberData(sub, db=dbAdmin("stroop_study_F07")):
    globDir = os.path.join(os.getcwd(), "numberdata", "P_%s" % str(sub.number))
    d = glob.glob(globDir)[0]
    subFile = os.path.join(d, 'subInfo.pck')
    s = open(subFile, 'r')
    sub = pickle.load(s)
    s.close()
    stroopFile = os.path.join(d, str(sub.number) + "_number_data.pck")
    f = open(stroopFile, 'r')
    data = pickle.load(f)
    f.close()

    if sub.sex == 1:
        sex = 'female'
    else:
        sex = 'male'

    number = str(sub.number)

    trial = 0

    for item in data:
        trial = trial + 1
        word = item[0]
        colour = item[1]
        onset = item[2]
        response = item[3]
        rt = response - onset
        sql = """
			INSERT INTO
			number_results
			VALUES (NULL, %s, "%s", "%s", "%s", "%s", %s, %s, %s);
			""" % (number, sex, word, trial, colour, onset, response, rt)
        print sql
        db.query(sql)
Example #9
0
def addSubData(sub, db=dbAdmin("stroop_study_F07")):
    abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs = generateWords(
    )
    globDir = os.path.join(os.getcwd(), "data", "P_%s" % str(sub.number))
    d = glob.glob(globDir)[0]
    subFile = os.path.join(d, 'subInfo.pck')
    s = open(subFile, 'r')
    sub = pickle.load(s)
    s.close()
    stroopFile = os.path.join(d, str(sub.number) + "_stroop_data.pck")
    f = open(stroopFile, 'r')
    data = pickle.load(f)
    f.close()

    if sub.sex == 1:
        sex = 'female'
    else:
        sex = 'male'

    number = str(sub.number)
    order = 1
    last = 0
    lastcat = ""
    acount = 0
    pcount = 0
    ncount = 0
    for item in data:
        word = item[0]
        colour = item[1]
        onset = item[2]
        response = item[3]
        rt = response - onset
        category = classify(word, abuse, positive, neutral, Ns, fakeabuse,
                            fakepositive, fakeneutral, fakeNs)
        if category != None:
            if category == 'f':
                last = last + 1
                category = lastcat + "_" + category + str(last)
            else:
                if category == "a":
                    acount = acount + 1
                    trial = acount
                elif category == "p":
                    pcount = pcount + 1
                    trial = pcount
                elif category == "n":
                    ncount = ncount + 1
                    trial = ncount
                last = 0
                lastcat = category
            sql = """
				INSERT INTO
				stroop_results
				VALUES (NULL, %s, "%s", "%s", %s, "%s", "%s", %s, %s, %s);
				""" % (number, sex, word, trial, category, colour, onset, response, rt)
            print sql
            db.query(sql)
Example #10
0
def addSubData(sub, db = dbAdmin("stroop_study_F07")):
	abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs = generateWords()
	globDir = os.path.join(os.getcwd(), "data", "P_%s" % str(sub.number))	
	d = glob.glob(globDir)[0]
	subFile = os.path.join(d, 'subInfo.pck')
	s = open(subFile, 'r')
	sub = pickle.load(s)
	s.close()
	stroopFile = os.path.join(d, str(sub.number) + "_stroop_data.pck")
	f = open(stroopFile, 'r')
	data = pickle.load(f)
	f.close()
	
	if sub.sex == 1:
		sex = 'female'
	else:
		sex = 'male'
	
	number = str(sub.number)
	order = 1
	last = 0
	lastcat = ""		
	acount = 0
	pcount = 0
	ncount = 0
	for item in data:
		word = item[0]
		colour = item[1]
		onset = item[2]
		response = item[3]
		rt = response - onset
		category = classify(word, abuse, positive, neutral, Ns, fakeabuse, fakepositive, fakeneutral, fakeNs)
		if category != None:
			if category == 'f':
				last = last + 1
				category = lastcat + "_" + category + str(last)
			else:
				if category == "a":
					acount = acount + 1
					trial = acount					
				elif category == "p":
					pcount = pcount + 1
					trial = pcount
				elif category == "n":
					ncount = ncount + 1
					trial = ncount
				last = 0
				lastcat = category
			sql = """
				INSERT INTO
				stroop_results
				VALUES (NULL, %s, "%s", "%s", %s, "%s", "%s", %s, %s, %s);
				""" % (number, sex, word, trial, category, colour, onset, response, rt)
			print sql
			db.query(sql)
Example #11
0
			print "t" + str(k)

			if d[k]:
				avg = d[k]
			else:
				avg = "NA"

			string = string + "," + str(avg)
		
		f.write(string)
		f.write("," + str(percCorrect) + "\n")

	f.close()


db = dbAdmin("stroop_study_F07")
table = "stroop_results"

writeByTrial(db, table)

#for t in ["number_results", "color_results", "stroop_results"]:
#	db.addColumn(t, "zscore", "REAL")

#calculateZ(db, table)
#wordSummary(db, table)

#addGrades(db, "stroop_results", "emot_errors.csv")

#createStroop(db)
#createMemory(db)
Example #12
0
		"""
    db.query(sql)


def createColors(db):
    sql = """
		CREATE TABLE
		color_results
		(cr_id integer primary key not null, subject integer, 
		sex varchar(20), 
		word text,
		trial integer,
		colour varchar(20),
		onset real,
		response real,
		rt real
		);
		"""
    db.query(sql)


db = dbAdmin("stroop_study_F07")

#createMemory(db)
#createStroop(db)
createNumbers(db)
createColors(db)

#stroop_stats.populateStroop(db)
#stroop_stats.populateMemory(db)