Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created May 12, 2018 00:10
Show Gist options
  • Select an option

  • Save rg3915/6b3f35d3e541c4ac85a642510c3381d5 to your computer and use it in GitHub Desktop.

Select an option

Save rg3915/6b3f35d3e541c4ac85a642510c3381d5 to your computer and use it in GitHub Desktop.
Test personality with 36 questions
#!/usr/bin/python
# William Thing
# March 29, 2015
# Personality Test
#
# The Keirsey test measures four independent dimensions of personality:
# Extrovert versus Introvert (E vs I): what energizes you
# Sensation versus iNtuition (S vs N): what you focus on
# Thinking versus Feeling (T vs F): how you interpret what you focus on
# Judging versus Perceiving (J vs P): how you approach life
# Individuals are categorized as being on one side or the other of each of these dimensions.
# The corresponding letters are put together to form a personality type.
# For example, if you are an extravert, intuitive, thinking, perceiving
# person then you are referred to as an ENTP.
# This program will take people's Keirsey test answers to determine their
# personality type based on the four dimensions. Takes answer from given input
# file and writes results to a given output file.
# Returns number of times a specific answer was recorded in each
# of the four categories.
def sort_answers_old(answers, char):
my_list = [0, 0, 0, 0]
for i in range(10):
if answers[i * 7].upper() == char:
my_list[0] += 1
for j in range(3):
for k in range(1, 3):
if answers[i * 7 + j * 2 + k].upper() == char:
my_list[j + 1] += 1
return my_list
def sort_answers(answers, char):
print(answers)
my_list = [0, 0, 0, 0]
# for i in range(10):
# if answers[i * 7].upper() == char:
# my_list[0] += 1
# for j in range(3):
# for k in range(1, 3):
# if answers[i * 7 + j * 2 + k].upper() == char:
# my_list[j + 1] += 1
for i in answers:
print(i)
return my_list
# Returns percentage of B answers in the Keirsey test to determine a personality
# type
def percent_of_B(A_list, B_list):
result = []
for i in range(len(B_list)):
percentage = int(round(float(B_list[i]) / (A_list[i]
+ B_list[i]) * 100))
result.append(percentage)
return result
# Returns a person's personality type based on their responses
# 'X' signifies that a specific personality type for that dimension
# cannot be determined.
def extract_personality(B_list):
result = ""
# dimension one: Extrovert versus Introvert (E vs I): what energizes you
if B_list[0] > 50:
result += "I"
elif B_list[0] < 50:
result += "E"
else:
result += "X"
# dimension two: Sensation versus iNtuition (S vs N): what you focus on
if B_list[1] < 50:
result += "S"
elif B_list[1] > 50:
result += "N"
else:
result += "X"
# dimension three: Thinking versus Feeling (T vs F): how you interpret
# what you focus on
if B_list[2] < 50:
result += "T"
elif B_list[2] > 50:
result += "F"
else:
result += "X"
# dimension four: Judging versus Perceiving (J vs P): how you approach life
if B_list[3] < 50:
result += "J"
elif B_list[3] > 50:
result += "P"
else:
result += "X"
return result
# Introduction to Personality Test Software
def extract_result(a, b, index):
list1 = ['E', 'S', 'T', 'J']
list2 = ['I', 'N', 'F', 'P']
if a > b:
result = list1[index]
else:
result = list2[index]
return result
def extract_personality2(answers):
list_all = []
result = []
letras = (
('E', 'I'),
('S', 'N'),
('T', 'F'),
('J', 'P')
)
for c, i in enumerate(answers):
if c % 4 == 0:
list_all.append(
(answers[c], answers[c + 1], answers[c + 2], answers[c + 3]))
# Transpose
list_transpose = zip(*list_all)
for c, i in enumerate(list_transpose):
a_ocurrence = ''.join(i).count('A')
b_ocurrence = ''.join(i).count('B')
if a_ocurrence > b_ocurrence:
r = 0
else:
r = 1
result.append(letras[c][r])
return ''.join(result)
def intro():
print("""This program processes a file of answers to the
Keirsey Temperament Personality Sorter. It converts
the various A and B answers for each person into
a sequence of B-percentages and then into a
four-letter personality type.""")
def main():
intro()
personality_test = 'BBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAA'
personality = extract_personality2(personality_test)
print(personality)
if __name__ == "__main__":
main()
# -*- coding: utf-8 -*-
'''
Objetivo:
Dado o usertype: 'ESTJ'
Retornar answerlist: 'AAAAAAAAABABABAABABABAABABABAABABABAABABABBABABABBABABABBABABABBABABAB
'
Neste caso eu quero:
ENFJ
ENFP
ENTJ
ENTP
ESFJ
ESFP
ESTJ
ESTP
INFJ
INFP
INTJ
INTP
ISFJ
ISFP
ISTJ
ISTP
'''
from mypersonality_test36 import extract_personality2
usertypes = (
'ENFJ',
'ENFP',
'ENTJ',
'ENTP',
'ESFJ',
'ESFP',
'ESTJ',
'ESTP',
'INFJ',
'INFP',
'INTJ',
'INTP',
'ISFJ',
'ISFP',
'ISTJ',
'ISTP',
)
list_EI = []
list_SN = []
list_TF = []
list_JP = []
list_all = []
# Primeiro fiz um teste com os indices.
for i in range(1, 37, 4):
list_EI.append(i)
for i in range(2, 37, 4):
list_SN.append(i)
for i in range(3, 37, 4):
list_TF.append(i)
for i in range(4, 37, 4):
list_JP.append(i)
# print(list_EI)
# print(list_SN)
# print(list_TF)
# print(list_JP)
# Agora são letras
list_EI = ['B', 'B', 'B', 'B', 'A', 'A', 'A', 'A', 'A']
list_SN = ['B', 'B', 'B', 'B', 'A', 'A', 'A', 'A', 'A']
list_TF = ['B', 'B', 'B', 'B', 'A', 'A', 'A', 'A', 'A']
list_JP = ['B', 'B', 'B', 'B', 'A', 'A', 'A', 'A', 'A']
'''
As letras (AB) tem uma posição única.
As letras (AB) que mudam o resultado (E,I), (S,N), (T,F), (J,P) estão na posição,
respectivamente, 17, 18, 19 e 20 (esta posição encontra-se em kersey_test.xlsx).
Nas listas list_EI, list_SN, list_TF, list_JP está na posição de indice 4.
'''
def trocar_letra(index, letra):
letras = (
('E', 'I'),
('S', 'N'),
('T', 'F'),
('J', 'P')
)
if letra == letras[index][0]:
return 'A'
else:
return 'B'
letras = raw_input("Digite as 4 letras desejadas, ex: ESTJ, INFP: ")
r = []
for index, letra in enumerate(letras):
r.append(trocar_letra(index, letra))
print(''.join(r))
list_EI[4] = r[0]
list_SN[4] = r[1]
list_TF[4] = r[2]
list_JP[4] = r[3]
print(list_EI)
print(list_SN)
print(list_TF)
print(list_JP)
print('')
'''
Reescreve novamente a lista com os 4 grupos sabendo a posição e a letra
de cada um.
A ordem é importante, pois cada letra tem uma posição única e fundamental.
'''
for i1, i2, i3, i4 in zip(list_EI, list_SN, list_TF, list_JP):
list_all.extend([i1, i2, i3, i4])
# print(list_all)
answerlist = ''.join(list_all)
print(answerlist)
personality = extract_personality2(answerlist)
print(personality)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment