Birger Moell commited on
Commit
115525b
1 Parent(s): e7c2c70

Updated code

Browse files
Files changed (1) hide show
  1. app.py +35 -8
app.py CHANGED
@@ -160,32 +160,55 @@ test_dict = {
160
  def calculate_z_score(test_score, mean, std_dev):
161
  return (test_score - mean) / std_dev
162
 
163
- def z_score_calculator(value, norm_mean, norm_sd):
164
  z_value = (value - norm_mean) / norm_sd
165
- stanine_value = round(1.25 * z_value + 5.5)
 
 
166
  z_score = round(z_value, 2)
167
  return z_score, stanine_value
168
 
169
- def test_calculator(age, education, values, test):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  if age <= 60 and education <= 12:
171
  norm_mean = test_dict[test]["low_age_low_education"]["mean"]
172
  norm_sd = test_dict[test]["low_age_low_education"]["std"]
173
- z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd)
174
  return norm_mean, norm_sd, z_score, stanine_value
175
  elif age <= 60 and education > 12:
176
  norm_mean = test_dict[test]["low_age_high_education"]["mean"]
177
  norm_sd = test_dict[test]["low_age_high_education"]["std"]
178
- z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd)
179
  return norm_mean, norm_sd, z_score, stanine_value
180
  elif age > 60 and education <= 12:
181
  norm_mean = test_dict[test]["high_age_low_education"]["mean"]
182
  norm_sd = test_dict[test]["high_age_low_education"]["std"]
183
- z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd)
184
  return norm_mean, norm_sd, z_score, stanine_value
185
  elif age > 60 and education > 12:
186
  norm_mean = test_dict[test]["high_age_high_education"]["mean"]
187
  norm_sd = test_dict[test]["high_age_high_education"]["std"]
188
- z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd)
189
  return norm_mean, norm_sd, z_score, stanine_value
190
  else:
191
  print("missing value/ wrong format")
@@ -267,6 +290,8 @@ def generate_graph(test_dict):
267
 
268
  for test in reversed(list(test_dict.keys())):
269
  #print("the test is", test)
 
 
270
  ax.scatter(test_dict[test][4], i, s=50, color='black', label=test)
271
  i = i + 1
272
 
@@ -412,7 +437,9 @@ if st.button("Calculate Z-Score"):
412
  animal_mean, animal_std, animal_z, animal_stanine = test_calculator(age, education_level, animal, "animal")
413
  verb_mean, verb_std, verb_z, verb_stanine = test_calculator(age, education_level, verb, "verb")
414
  repetition_mean, repetition_std, repetition_z, repetition_stanine = test_calculator(age, education_level, repetition, "repetition")
415
- months_backward_mean, months_backward_std, months_backward_z, months_backward_stanine = test_calculator(age, education_level, months_backward, "months_backward")
 
 
416
  logicogrammatic_mean, logicogrammatic_std, logicogrammatic_z, logicogrammatic_stanine = test_calculator(age, education_level, logicogrammatic, "logicogrammatic")
417
  inference_mean, inference_std, inference_z, inference_stanine = test_calculator(age, education_level, inference, "inference")
418
  reading_speed_mean, reading_speed_std, reading_speed_z, reading_speed_stanine = test_calculator(age, education_level, reading_speed, "reading_speed")
 
160
  def calculate_z_score(test_score, mean, std_dev):
161
  return (test_score - mean) / std_dev
162
 
163
+ def z_score_calculator(value, norm_mean, norm_sd, invert=False):
164
  z_value = (value - norm_mean) / norm_sd
165
+ if invert:
166
+ z_value = -z_value
167
+ stanine_value = zscore_to_stanine(z_value)
168
  z_score = round(z_value, 2)
169
  return z_score, stanine_value
170
 
171
+ def zscore_to_stanine(zscore):
172
+ if zscore <= -1.76:
173
+ return 1
174
+ elif zscore <= -1.26:
175
+ return 2
176
+ elif zscore <= -0.76:
177
+ return 3
178
+ elif zscore <= -0.26:
179
+ return 4
180
+ elif zscore <= 0.25:
181
+ return 5
182
+ elif zscore <= 0.75:
183
+ return 6
184
+ elif zscore <= 1.25:
185
+ return 7
186
+ elif zscore <= 1.75:
187
+ return 8
188
+ else:
189
+ return 9
190
+
191
+
192
+ def test_calculator(age, education, values, test, invert=False):
193
  if age <= 60 and education <= 12:
194
  norm_mean = test_dict[test]["low_age_low_education"]["mean"]
195
  norm_sd = test_dict[test]["low_age_low_education"]["std"]
196
+ z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd, invert=invert)
197
  return norm_mean, norm_sd, z_score, stanine_value
198
  elif age <= 60 and education > 12:
199
  norm_mean = test_dict[test]["low_age_high_education"]["mean"]
200
  norm_sd = test_dict[test]["low_age_high_education"]["std"]
201
+ z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd, invert=invert)
202
  return norm_mean, norm_sd, z_score, stanine_value
203
  elif age > 60 and education <= 12:
204
  norm_mean = test_dict[test]["high_age_low_education"]["mean"]
205
  norm_sd = test_dict[test]["high_age_low_education"]["std"]
206
+ z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd, invert=invert)
207
  return norm_mean, norm_sd, z_score, stanine_value
208
  elif age > 60 and education > 12:
209
  norm_mean = test_dict[test]["high_age_high_education"]["mean"]
210
  norm_sd = test_dict[test]["high_age_high_education"]["std"]
211
+ z_score, stanine_value = z_score_calculator(values, norm_mean, norm_sd, invert=invert)
212
  return norm_mean, norm_sd, z_score, stanine_value
213
  else:
214
  print("missing value/ wrong format")
 
290
 
291
  for test in reversed(list(test_dict.keys())):
292
  #print("the test is", test)
293
+
294
+ # check if values are not empty
295
  ax.scatter(test_dict[test][4], i, s=50, color='black', label=test)
296
  i = i + 1
297
 
 
437
  animal_mean, animal_std, animal_z, animal_stanine = test_calculator(age, education_level, animal, "animal")
438
  verb_mean, verb_std, verb_z, verb_stanine = test_calculator(age, education_level, verb, "verb")
439
  repetition_mean, repetition_std, repetition_z, repetition_stanine = test_calculator(age, education_level, repetition, "repetition")
440
+ months_backward_mean, months_backward_std, months_backward_z, months_backward_stanine = test_calculator(age, education_level, months_backward, "months_backward", invert=True)
441
+ # months_backward_z = months_backward_z * -1
442
+ # print("the months backw z is: ", months_backward_z)
443
  logicogrammatic_mean, logicogrammatic_std, logicogrammatic_z, logicogrammatic_stanine = test_calculator(age, education_level, logicogrammatic, "logicogrammatic")
444
  inference_mean, inference_std, inference_z, inference_stanine = test_calculator(age, education_level, inference, "inference")
445
  reading_speed_mean, reading_speed_std, reading_speed_z, reading_speed_stanine = test_calculator(age, education_level, reading_speed, "reading_speed")