johnpaulbin commited on
Commit
ca78d43
1 Parent(s): 40f37bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -35
app.py CHANGED
@@ -69,28 +69,28 @@ traits = {
69
  'formula_pos_mult': 5,
70
  'formula_reverse_mult': 3,
71
  'formula_reverse_const': 12,
72
- 'min_score': 2, # Calculated as (1*5) + (12 - (5*3)) = 5 + (12 - 15) = 5 - 3 = 2
73
- 'max_score': 34 # Calculated as (5*5) + (12 - (1*3)) = 25 + (12 - 3) = 25 + 9 = 34
74
  },
75
  'Agreeableness': {
76
  'positive': [7, 17, 22, 32, 42],
77
  'reverse': [2, 12, 27, 37],
78
  'threshold': 1,
79
  'formula_pos_mult': 5,
80
- 'formula_reverse_mult':4,
81
- 'formula_reverse_const':16,
82
- 'min_score': 5, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 - 4 = 1
83
- 'max_score': 41 # (5*5) + (16 - (1*4)) = 25 + (16 - 4) = 25 + 12 = 37
84
  },
85
  'Conscientiousness': {
86
  'positive': [3, 13, 28, 33, 38],
87
  'reverse': [8, 18, 23, 43],
88
  'threshold': 1,
89
- 'formula_pos_mult':5,
90
- 'formula_reverse_mult':4,
91
- 'formula_reverse_const':16,
92
- 'min_score': 1, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 -4 =1
93
- 'max_score': 37 # (5*5) + (16 - (1*4)) =25 + (16-4)=25+12=37
94
  },
95
  'Neuroticism':{
96
  'positive':[4, 14, 19, 29, 39],
@@ -99,8 +99,8 @@ traits = {
99
  'formula_pos_mult':5,
100
  'formula_reverse_mult':3,
101
  'formula_reverse_const':12,
102
- 'min_score':2, # (1*5) + (12 - (5*3)) =5 + (12-15)=5-3=2
103
- 'max_score':32 # (5*5) + (12 - (1*3))=25 + (12-3)=25+9=34
104
  },
105
  'Openness':{
106
  'positive':[5, 10, 15, 20, 25, 30, 40, 44],
@@ -109,32 +109,42 @@ traits = {
109
  'formula_pos_mult':8,
110
  'formula_reverse_mult':2,
111
  'formula_reverse_const':8,
112
- 'min_score':8, # (1*8) + (8 - (5*2)) =8 + (8-10)=8-2=6
113
- 'max_score':48 # (5*8) + (8 - (1*2))=40 + (8-2)=40+6=46
114
  }
115
  }
116
 
117
- # Define explanations for each trait based on high or low scores
118
  explanations = {
119
  'Extraversion': {
120
- 'high': "You are highly outgoing, energetic, and enjoy being around people. You thrive in social situations and are often perceived as enthusiastic and lively.",
121
- 'low': "You are more reserved and prefer solitary activities. You might find large social gatherings draining and enjoy deep, meaningful interactions over casual conversations."
 
 
122
  },
123
  'Agreeableness': {
124
- 'high': "You are compassionate, cooperative, and value getting along with others. You tend to be trusting and considerate, often putting others' needs before your own.",
125
- 'low': "You are more competitive and skeptical, prioritizing your own needs and viewpoints. You might be seen as direct or even confrontational in your interactions."
 
 
126
  },
127
  'Conscientiousness': {
128
- 'high': "You are organized, dependable, and have a strong sense of duty. You strive for achievement and are meticulous in your work, often planning ahead and following through on commitments.",
129
- 'low': "You are more spontaneous and flexible, potentially preferring to adapt as situations arise rather than sticking to a strict plan. You might find rigid structures stifling."
 
 
130
  },
131
  'Neuroticism':{
132
- 'high': "You tend to experience emotions like anxiety, sadness, and mood swings more frequently. You might be more sensitive to stress and prone to feeling overwhelmed.",
133
- 'low': "You are generally calm, resilient, and emotionally stable. You handle stress well and are less likely to experience negative emotions intensely."
 
 
134
  },
135
  'Openness':{
136
- 'high': "You are imaginative, curious, and open to new experiences. You appreciate art, creativity, and value intellectual exploration and novelty.",
137
- 'low': "You prefer routine and familiarity, valuing practicality and straightforwardness over abstract ideas. You might be more focused on tangible outcomes rather than theoretical concepts."
 
 
138
  }
139
  }
140
 
@@ -162,9 +172,14 @@ def compute_bfi_scores(*args):
162
  if total_missing > info['threshold']:
163
  scores[trait] = "Incomplete"
164
  else:
 
 
 
 
 
165
  # Compute means, ignoring None
166
  pos_values = [x for x in pos_items if x is not None]
167
- rev_values = [x for x in rev_items if x is not None]
168
 
169
  mean_pos = sum(pos_values) / len(pos_values) if pos_values else 0
170
  mean_rev = sum(rev_values) / len(rev_values) if rev_values else 0
@@ -184,20 +199,32 @@ def compute_bfi_scores(*args):
184
  if score == "Incomplete":
185
  markdown_output += "Insufficient responses to compute this trait.\n\n"
186
  else:
187
- markdown_output += f"**Score**: {score}\n\n"
188
- # Determine if the score is high or low based on midpoint
189
- midpoint = (traits[trait]['min_score'] + traits[trait]['max_score']) / 2
190
- if score >= midpoint:
191
- markdown_output += f"{explanations[trait]['high']}\n\n"
 
 
 
 
 
 
 
 
192
  else:
193
- markdown_output += f"{explanations[trait]['low']}\n\n"
 
 
 
 
194
  trait_names.append(trait)
195
  trait_scores.append(score)
196
-
197
  # Generate bar chart
198
  image = None
199
  if trait_scores:
200
- fig, ax = plt.subplots(figsize=(10, 6))
201
  bars = ax.bar(trait_names, trait_scores, color='skyblue')
202
  ax.set_ylim(0, max(trait_scores) + 10)
203
  ax.set_ylabel('Score')
 
69
  'formula_pos_mult': 5,
70
  'formula_reverse_mult': 3,
71
  'formula_reverse_const': 12,
72
+ 'min_score': 2, # (1*5) + (12 - (5*3)) = 5 + (12 - 15) = 5 - 3 = 2
73
+ 'max_score': 34 # (5*5) + (12 - (1*3)) = 25 + (12 - 3) = 25 + 9 = 34
74
  },
75
  'Agreeableness': {
76
  'positive': [7, 17, 22, 32, 42],
77
  'reverse': [2, 12, 27, 37],
78
  'threshold': 1,
79
  'formula_pos_mult': 5,
80
+ 'formula_reverse_mult': 4,
81
+ 'formula_reverse_const': 16,
82
+ 'min_score': 1, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 - 4 = 1
83
+ 'max_score': 37 # (5*5) + (16 - (1*4)) = 25 + (16 - 4) = 25 + 12 = 37
84
  },
85
  'Conscientiousness': {
86
  'positive': [3, 13, 28, 33, 38],
87
  'reverse': [8, 18, 23, 43],
88
  'threshold': 1,
89
+ 'formula_pos_mult': 5,
90
+ 'formula_reverse_mult': 4,
91
+ 'formula_reverse_const': 16,
92
+ 'min_score': 1, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 - 4 = 1
93
+ 'max_score': 37 # (5*5) + (16 - (1*4)) = 25 + (16 - 4) = 25 + 12 = 37
94
  },
95
  'Neuroticism':{
96
  'positive':[4, 14, 19, 29, 39],
 
99
  'formula_pos_mult':5,
100
  'formula_reverse_mult':3,
101
  'formula_reverse_const':12,
102
+ 'min_score':2, # (1*5) + (12 - (5*3)) = 5 + (12 - 15) = 5 - 3 = 2
103
+ 'max_score':34 # (5*5) + (12 - (1*3)) = 25 + (12 - 3) = 25 + 9 = 34
104
  },
105
  'Openness':{
106
  'positive':[5, 10, 15, 20, 25, 30, 40, 44],
 
109
  'formula_pos_mult':8,
110
  'formula_reverse_mult':2,
111
  'formula_reverse_const':8,
112
+ 'min_score':6, # (1*8) + (8 - (5*2)) = 8 + (8 - 10) = 8 - 2 = 6
113
+ 'max_score':46 # (5*8) + (8 - (1*2)) = 40 + (8 - 2) = 40 + 6 = 46
114
  }
115
  }
116
 
117
+ # Define explanations for each trait based on score category
118
  explanations = {
119
  'Extraversion': {
120
+ 'low': "You are more reserved and prefer solitary activities. You might find large social gatherings draining and enjoy deep, meaningful interactions over casual conversations.",
121
+ 'medium_low': "You have a balanced approach to social interactions. While you enjoy spending time with others, you also value your alone time and can adapt to different social settings.",
122
+ 'medium_high': "You are fairly outgoing and enjoy social interactions, but you also appreciate moments of solitude. You strike a good balance between being sociable and introspective.",
123
+ 'high': "You are highly outgoing, energetic, and enjoy being around people. You thrive in social situations and are often perceived as enthusiastic and lively."
124
  },
125
  'Agreeableness': {
126
+ 'low': "You are more competitive and skeptical, prioritizing your own needs and viewpoints. You might be seen as direct or even confrontational in your interactions.",
127
+ 'medium_low': "You balance assertiveness with cooperativeness. While you can stand up for yourself, you also recognize the value of collaboration and compromise.",
128
+ 'medium_high': "You are generally cooperative and considerate but also maintain your own opinions and boundaries. You strive to get along with others while asserting your needs when necessary.",
129
+ 'high': "You are compassionate, cooperative, and value getting along with others. You tend to be trusting and considerate, often putting others' needs before your own."
130
  },
131
  'Conscientiousness': {
132
+ 'low': "You are more spontaneous and flexible, potentially preferring to adapt as situations arise rather than sticking to a strict plan. You might find rigid structures stifling.",
133
+ 'medium_low': "You exhibit a moderate level of organization and dependability. You can be both disciplined and adaptable, adjusting your approach based on the situation.",
134
+ 'medium_high': "You are generally organized and dependable but also allow for flexibility when needed. You balance meticulousness with adaptability, ensuring tasks are completed while accommodating changes.",
135
+ 'high': "You are organized, dependable, and have a strong sense of duty. You strive for achievement and are meticulous in your work, often planning ahead and following through on commitments."
136
  },
137
  'Neuroticism':{
138
+ 'low': "You are generally calm, resilient, and emotionally stable. You handle stress well and are less likely to experience negative emotions intensely.",
139
+ 'medium_low': "You maintain a good level of emotional stability but may occasionally experience stress or negative emotions. Overall, you manage your emotions effectively.",
140
+ 'medium_high': "You experience emotional fluctuations more frequently but still retain the ability to manage and cope with stress. You are aware of your emotions and work towards maintaining balance.",
141
+ 'high': "You tend to experience emotions like anxiety, sadness, and mood swings more frequently. You might be more sensitive to stress and prone to feeling overwhelmed."
142
  },
143
  'Openness':{
144
+ 'low': "You prefer routine and familiarity, valuing practicality and straightforwardness over abstract ideas. You might be more focused on tangible outcomes rather than theoretical concepts.",
145
+ 'medium_low': "You have a balanced approach to new experiences. While you appreciate some creativity and novelty, you also value tradition and established methods.",
146
+ 'medium_high': "You are quite open to new experiences and enjoy exploring creative and intellectual pursuits. You balance your curiosity with practicality, allowing you to adapt and innovate when necessary.",
147
+ 'high': "You are imaginative, curious, and open to new experiences. You appreciate art, creativity, and value intellectual exploration and novelty."
148
  }
149
  }
150
 
 
172
  if total_missing > info['threshold']:
173
  scores[trait] = "Incomplete"
174
  else:
175
+ # Reverse the reverse-scored items
176
+ reversed_rev_values = []
177
+ for r in rev_items:
178
+ if r is not None:
179
+ reversed_rev_values.append(6 - r) # Reverse the score: 1↔5, 2↔4, 3↔3
180
  # Compute means, ignoring None
181
  pos_values = [x for x in pos_items if x is not None]
182
+ rev_values = [x for x in reversed_rev_values if x is not None]
183
 
184
  mean_pos = sum(pos_values) / len(pos_values) if pos_values else 0
185
  mean_rev = sum(rev_values) / len(rev_values) if rev_values else 0
 
199
  if score == "Incomplete":
200
  markdown_output += "Insufficient responses to compute this trait.\n\n"
201
  else:
202
+ markdown_output += f"**Score**: {score} (Range: {traits[trait]['min_score']} - {traits[trait]['max_score']})\n\n"
203
+ # Determine the score category based on the trait's score range
204
+ min_s = traits[trait]['min_score']
205
+ max_s = traits[trait]['max_score']
206
+ midpoint_low = min_s + (max_s - min_s) / 3
207
+ midpoint_high = min_s + 2 * (max_s - min_s) / 3
208
+
209
+ if score < midpoint_low:
210
+ category = 'low'
211
+ elif score < midpoint_high:
212
+ category = 'medium_low'
213
+ elif score < midpoint_high + (max_s - min_s)/3:
214
+ category = 'medium_high'
215
  else:
216
+ category = 'high'
217
+
218
+ # Assign explanations based on the category
219
+ explanation = explanations[trait].get(category, "")
220
+ markdown_output += f"{explanation}\n\n"
221
  trait_names.append(trait)
222
  trait_scores.append(score)
223
+
224
  # Generate bar chart
225
  image = None
226
  if trait_scores:
227
+ fig, ax = plt.subplots(figsize=(12, 7))
228
  bars = ax.bar(trait_names, trait_scores, color='skyblue')
229
  ax.set_ylim(0, max(trait_scores) + 10)
230
  ax.set_ylabel('Score')