birgermoell commited on
Commit
cce1f27
1 Parent(s): 87110a5

Create plots.py

Browse files
Files changed (1) hide show
  1. plots.py +100 -0
plots.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+
3
+ class test_profile:
4
+ def __init__(self, age, education, bnt, fas, isw):
5
+ self.age = age
6
+ self.education = education
7
+ self.bnt = bnt
8
+ self.fas = fas
9
+ self.isw = isw
10
+
11
+ def mean_bnt(self):
12
+ if self.age <= 60 and self.education <= 12:
13
+ self.norm_mean = 54.5
14
+ self.norm_sd = 3.2
15
+ elif self.age <= 60 and self.education > 12:
16
+ self.norm_mean = 54.0
17
+ self.norm_sd = 4.4
18
+ elif self.age > 60 and self.education <= 12:
19
+ self.norm_mean = 54.8
20
+ self.norm_sd = 3.3
21
+ elif self.age > 60 and self.education > 12:
22
+ self.norm_mean = 56.2
23
+ self.norm_sd = 3.4
24
+ else:
25
+ print("missing value/ wrong format")
26
+
27
+ def z_bnt(self):
28
+ self.mean_bnt()
29
+ z_bnt = (self.bnt - self.norm_mean) / self.norm_sd
30
+ stanine_bnt = round(1.25 * z_bnt + 5.5)
31
+ return round(z_bnt, 2), stanine_bnt
32
+
33
+ def z_to_stanine(self, z_score):
34
+ stanine = round(1.25 * z_score + 5.5)
35
+ return stanine
36
+
37
+
38
+ def mean_fas(self):
39
+ if self.age <= 60 and self.education <= 12:
40
+ self.norm_mean = 42.7
41
+ self.norm_sd = 13.7
42
+ elif self.age <= 60 and self.education > 12:
43
+ self.norm_mean = 46.7
44
+ self.norm_sd = 13.7
45
+ elif self.age > 60 and self.education <= 12:
46
+ self.norm_mean = 46.9
47
+ self.norm_sd = 10.4
48
+ elif self.age > 60 and self.education > 12:
49
+ self.norm_mean = 51.6
50
+ self.norm_sd = 12.6
51
+ else:
52
+ print("missing value/ wrong format")
53
+
54
+
55
+ def z_fas(self):
56
+ self.mean_fas()
57
+ z_fas = (self.fas - self.norm_mean) / self.norm_sd
58
+ stanine_fas = round(1.25 * z_fas + 5.5)
59
+ return round(z_fas, 2), stanine_fas
60
+
61
+
62
+ def calculate_isw(self):
63
+ isw_score = 74.38 + self.isw*0.66 - self.age*0.20 + self.education*1.77
64
+ return round(isw_score, 2)
65
+
66
+ def generate_graph(self):
67
+ BNT_z, _ = self.z_bnt()
68
+ FAS_z, _ = self.z_fas()
69
+
70
+ BNT_stanine = self.z_to_stanine(BNT_z)
71
+ FAS_stanine = self.z_to_stanine(FAS_z)
72
+
73
+ # Create a plot
74
+ fig, ax = plt.subplots()
75
+
76
+ # Set axis labels and title
77
+ ax.set_xlabel('Stanine values')
78
+ ax.set_ylabel('Test')
79
+
80
+ # Set the y-axis to display the tests
81
+ ax.set_yticks([1, 2])
82
+ ax.set_yticklabels(['BNT', 'FAS'])
83
+
84
+ # Set the range of the x-axis
85
+ ax.set_xlim([0, 10])
86
+
87
+ # Add dots for BNT and FAS scores
88
+ ax.scatter(BNT_stanine, 1, s=100, label='BNT')
89
+ ax.scatter(FAS_stanine, 2, s=100, label='FAS')
90
+
91
+ # Add legend
92
+ ax.legend()
93
+
94
+ # Show the plot
95
+ # plt.show()
96
+
97
+ # Save the graph as a png file
98
+ fig.savefig('test_profile.png')
99
+ return 'test_profile.png'
100
+