-
Notifications
You must be signed in to change notification settings - Fork 2
/
MBTI-matching-algorithm.py
109 lines (86 loc) · 3.48 KB
/
MBTI-matching-algorithm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
#author: Angela Iredia
import time
from flask import Flask, request, jsonify
#time complexity
start = time.time()
app = Flask(__name__)
@app.route('/process_data', methods=['GET', 'POST'])
def process_data():
if request.method == 'POST':
data = request.json
global a,b,c,d
a = data.get('a') #user' first letter of his MBTI personality type
b = data.get('b') #user' second letter of his MBTI personality type
c = data.get('c') #user' third letter of his MBTI personality type
d = data.get('d') #user' fourth letter of his MBTI personality type
if None in (a, b, c, d):
return jsonify({'error': 'Missing required parameters'}), 400
q = 12.5
r = 12.5
s = 12.5
t = 12.5
global mbti_user, mbti_server
mbti_user = [[a,q], [b,r], [c,s], [d, t]]
mbti_server ={
1: [["I",q], ["N",r], ["T",s], ["J",t]],
2: [["I",q], ["N",r], ["T",s], ["P",t]],
3: [["E",q], ["N",r], ["T",s], ["J",t]],
4: [["E",q], ["N",r], ["T",s], ["P",t]],
5: [["I",q], ["N",r], ["F",s], ["J",t]],
6: [["I",q], ["N",r], ["F",s], ["P",t]],
7: [["E",q], ["N",r], ["F",s], ["J",t]],
8: [["E",q], ["N",r], ["F",s], ["P",t]],
9: [["I",q], ["S",r], ["T",s], ["J",t]],
10:[["I",q], ["S",r], ["F",s], ["J",t]],
11:[["E",q], ["S",r], ["T",s], ["J",t]],
12:[["E",q], ["S",r], ["F",s], ["J",t]],
13:[["I",q], ["S",r], ["T",s], ["P",t]],
14:[["I",q], ["S",r], ["F",s], ["P",t]],
15:[["E",q], ["S",r], ["T",s], ["P",t]],
16:[["E",q], ["S",r], ["F",s], ["P",t]]
}
def findMatch(mbti_server, mbti_user):
matches=[]
for key in mbti_server:
lst = mbti_server[key]
if mbti_user[0][0] == lst[0][0]:
u = mbti_user[0][1] + lst[0][1]
else:
u = 0;
if mbti_user[1][0] == lst[1][0]:
x = mbti_user[1][1] + lst[1][1]
else:
x = 0;
if mbti_user[2][0] == lst[2][0]:
y = mbti_user[2][1] + lst[2][1]
else:
y = 0;
if mbti_user[3][0] == lst[3][0]:
z = mbti_user[3][1] + lst[3][1]
else:
z = 0;
match_rate = u + x + y + z
if match_rate >= 50:
result = {
1: lst[0][0],
2: lst[1][0],
3: lst[2][0],
4: lst[3][0],
5: match_rate
}
matches.append(result)
if len(matches) > 0:
return (jsonify(matches), 200, {'Content-Type': 'application/json'})
else:
return ("No matches found", 404)
return findMatch(mbti_server, mbti_user)
elif request.method == 'GET':
return"It uses also GET request"
#time complexity
end = time.time()
time_c = end - start
print("Results found in: " + str(time_c) + "s") #time complexity
return "Results found in: " + str(time_c) + "s"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)