File size: 2,919 Bytes
0de5d5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt

class test_profile:
    def __init__(self, age, education, bnt, fas, isw):
        self.age = age
        self.education = education
        self.bnt = bnt
        self.fas = fas
        self.isw = isw
    
    def mean_bnt(self):
        if self.age <= 60 and self.education <= 12:
            self.norm_mean = 54.5
            self.norm_sd = 3.2
        elif self.age <= 60 and self.education > 12:
            self.norm_mean = 54.0
            self.norm_sd = 4.4
        elif self.age > 60 and self.education <= 12:
            self.norm_mean = 54.8
            self.norm_sd = 3.3
        elif self.age > 60 and self.education > 12:
            self.norm_mean = 56.2
            self.norm_sd = 3.4
        else:
            print("missing value/ wrong format")
    
    def z_bnt(self):
        self.mean_bnt()
        z_bnt = (self.bnt - self.norm_mean) / self.norm_sd
        stanine_bnt = round(1.25 * z_bnt + 5.5)
        return round(z_bnt, 2), stanine_bnt
    
    def z_to_stanine(self, z_score):
        stanine = round(1.25 * z_score + 5.5)
        return stanine


    def mean_fas(self):
        if self.age <= 60 and self.education <= 12:
            self.norm_mean = 42.7
            self.norm_sd = 13.7
        elif self.age <= 60 and self.education > 12:
            self.norm_mean = 46.7
            self.norm_sd = 13.7
        elif self.age > 60 and self.education <= 12:
            self.norm_mean = 46.9
            self.norm_sd = 10.4
        elif self.age > 60 and self.education > 12:
            self.norm_mean = 51.6
            self.norm_sd = 12.6
        else:
            print("missing value/ wrong format")
    

    def z_fas(self):
        self.mean_fas()
        z_fas = (self.fas - self.norm_mean) / self.norm_sd
        stanine_fas = round(1.25 * z_fas + 5.5)
        return round(z_fas, 2), stanine_fas


    def calculate_isw(self):
        isw_score = 74.38 + self.isw*0.66 - self.age*0.20 + self.education*1.77
        return round(isw_score, 2)

    def generate_graph(self):
        BNT_z, _ = self.z_bnt()
        FAS_z, _ = self.z_fas()

        BNT_stanine = self.z_to_stanine(BNT_z)
        FAS_stanine = self.z_to_stanine(FAS_z)

        # Create a plot
        fig, ax = plt.subplots()

        # Set axis labels and title
        ax.set_xlabel('Stanine values')
        ax.set_ylabel('Test')

        # Set the y-axis to display the tests
        ax.set_yticks([1, 2])
        ax.set_yticklabels(['BNT', 'FAS'])

        # Set the range of the x-axis
        ax.set_xlim([0, 10])

        # Add dots for BNT and FAS scores
        ax.scatter(BNT_stanine, 1, s=100, label='BNT')
        ax.scatter(FAS_stanine, 2, s=100, label='FAS')

        # Add legend
        ax.legend()

        # Show the plot
        # plt.show()

        # Save the graph as a png file
        fig.savefig('test_profile.png')
        return 'test_profile.png'