1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-29 03:32:04 +03:00

feat(skill/mbti): finish business logic

This commit is contained in:
louistiti 2022-07-03 12:17:05 +08:00
parent 0f4576c27d
commit 99a3f103e0
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
3 changed files with 154 additions and 25 deletions

View File

@ -38,16 +38,87 @@
},
"2_a": {
"utterance_samples": [
"Head in the clouds",
"My head in the clouds"
"See how others are useful"
],
"value": "2_a"
},
"2_b": {
"utterance_samples": [
"In a rut"
"See how others see"
],
"value": "2_b"
},
"3_a": {
"utterance_samples": [
"[Your|My] head"
],
"value": "3_a"
},
"3_b": {
"utterance_samples": [
"[Your|my] heart"
],
"value": "3_b"
},
"4_a": {
"utterance_samples": [
"Carefully"
],
"value": "4_a"
},
"4_b": {
"utterance_samples": [
"Impulsively"
],
"value": "4_b"
},
"5_a": {
"utterance_samples": [
"Stay [late|later] with increasing energy"
],
"value": "5_a"
},
"5_b": {
"utterance_samples": [
"Leave [early|earlier] with decreased energy"
],
"value": "5_b"
},
"6_a": {
"utterance_samples": [
"What is actual"
],
"value": "6_a"
},
"6_b": {
"utterance_samples": [
"What is possible"
],
"value": "6_b"
},
"7_a": {
"utterance_samples": [
"Principles"
],
"value": "7_a"
},
"7_b": {
"utterance_samples": [
"Emotions"
],
"value": "7_b"
},
"8_a": {
"utterance_samples": [
"Incomplete"
],
"value": "8_a"
},
"8_b": {
"utterance_samples": [
"Completed"
],
"value": "8_b"
}
}
}
@ -76,6 +147,10 @@
"17": ["%question%/20<br>In company do you:<ul><li>a. Initiate conversation</li><li>b. Wait to be approached</li></ul>"],
"18": ["%question%/20<br>Children often do not:<ul><li>a. Make themselves useful enough</li><li>b. Exercise their fantasy enough</li></ul>"],
"19": ["%question%/20<br>Are you more:<ul><li>a. Firm than gentle</li><li>b. Gentle than firm</li></ul>"],
"20": ["%question%/20<br>Are you more comfortable:<ul><li>a. After a decision</li><li>b. Before a decision</li></ul>"]
"20": ["%question%/20<br>Are you more comfortable:<ul><li>a. After a decision</li><li>b. Before a decision</li></ul>"],
"result": [
"Your personality type is: <a href=\"https://www.16personalities.com/%type_url%-personality\" target=\"_blank\">%type%</a>."
]
}
}

View File

@ -1,52 +1,87 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Questions are taken from: http://www.lrjj.cn/encrm1.0/public/upload/MBTI-personality-test.pdf
import utils
from ..lib import db
counters = {
'mind': {
'E': 0, # Extraverted
'I': 0, # Introverted
groups = [
{
'name': 'mind',
'a': 'E', # Extraverted
'b': 'I', # Introverted
'questions': [1, 5, 9, 13, 17]
},
'energy': {
'N': 0, # Intuitive
'S': 0, # Sensing
{
'name': 'energy',
'a': 'S', # Sensing
'b': 'N', # Intuitive
'questions': [2, 6, 10, 14, 18]
},
'nature': {
'T': 0, # Thinking
'F': 0, # Feeling
{
'name': 'nature',
'a': 'T', # Thinking
'b': 'F', # Feeling
'questions': [3, 7, 11, 15, 19]
},
'tactics': {
'J': 0, # Judjing
'P': 0, # Perceiving
{
'name': 'tactics',
'a': 'J', # Judjing
'b': 'P', # Perceiving
'questions': [4, 8, 12, 16, 20]
}
}
]
def quiz(params):
"""Loop over the questions and track choices"""
resolvers = params['resolvers']
choice = None
letter = None # E I S N T F
for resolver in resolvers:
if resolver['name'] == 'form':
choice = resolver['value']
# Return no speech if no value has been found
if choice == None:
return utils.output('end', None, { 'isInActionLoop': False })
question, choice = choice.split('_')
session = db.get_session()
current_question = session['current_question'] + 1
db.upsert_session(current_question)
current_question = session['current_question']
next_question = current_question + 1
# Define the letter to increment
for group in groups:
if current_question in group['questions']:
letter = group[choice]
db.increment_letter(letter)
db.upsert_session(next_question)
# Release final result
if current_question == 20:
# TODO
return utils.output('end', 'Your personality type is...', { 'isInActionLoop': False })
session_result = db.get_session()
type_arr = []
return utils.output('end', { 'key': str(current_question),
for group in groups:
group_letter = group['a'] if session_result[group['a']] >= session_result[group['b']] else group['b']
type_arr.append(group_letter)
final_type = ''.join(type_arr)
return utils.output('end', { 'key': 'result',
'data': {
'question': str(current_question)
'type': final_type,
'type_url': final_type.lower()
}
}, { 'isInActionLoop': False })
return utils.output('end', { 'key': str(next_question),
'data': {
'question': str(next_question)
}
})

View File

@ -20,7 +20,26 @@ def upsert_session(current_question):
'current_question': current_question
}, doc_id=0))
if current_question == 1:
session_table.upsert(table.Document({
'E': 0,
'I': 0,
'S': 0,
'N': 0,
'T': 0,
'F': 0,
'J': 0,
'P': 0
}, doc_id=0))
def increment_letter(letter):
"""Add one point to a letter"""
letter_score = get_session()[letter] + 1
session_table.update(table.Document({ letter: letter_score }, doc_id=0))
def get_session():
"""TODO"""
"""Get current session"""
return session_table.get(doc_id=0)