This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblood_type_agglutination_test.py
executable file
·143 lines (131 loc) · 4.75 KB
/
blood_type_agglutination_test.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
import os
import random
def coagulated_blood():
table = ''
table += '<table style="border-collapse: collapse; border: 0px solid white;" cellpading="150" cellspacing="150">'
table += '<tbody><tr>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">●</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 20px; color: darkred;">●</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '</tr><tr>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 30px; color: darkred;">●</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 15px; color: darkred;">●</span></td>'
table += '</tr><tr>'
table += '<td style="border: 0px solid white;"><span style="font-size: 20px; color: darkred;">●</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">●</span></td>'
table += '<td style="border: 0px solid white;"><span style="font-size: 25px; color: darkred;">.</span></td>'
table += '</tr></tbody></table>'
return table
def normal_blood():
symbol = '<span style="font-size: 100px; color: red;">⬮</span>'
return symbol
def createHtmlTable(code):
table = ''
table += '<table style="border-collapse: collapse; border: 1px; border-color: black;">'
table += '<tbody>'
table += '<tr>'
#blood results row
count = 0
data_style = 'style="border: 2px solid gray; align: center;"'
empty_style = 'style="border: 0px solid white;"'
for c in list(code):
count += 1
table += '<td {0}>'.format(data_style)
if c == '1':
table += normal_blood()
else:
table += coagulated_blood()
table += '</td>'
table += '<td {0}> </td>'.format(empty_style)
table += '<tr>'
table += '<td {0}>A antigen</td>'.format(data_style)
table += '<td {0}> </td>'.format(empty_style)
table += '<td {0}>B antigen</td>'.format(data_style)
table += '<td {0}> </td>'.format(empty_style)
table += '<td {0}>D antigen</td>'.format(data_style)
table += '<td {0}> </td>'.format(empty_style)
table += '<td {0}>control</td>'.format(data_style)
table += '<td {0}> </td>'.format(empty_style)
table += '</tr></tbody></table>'
return table
code2type = {
'111': 'O-',
'011': 'A-',
'101': 'B-',
'001': 'AB-',
'110': 'O+',
'010': 'A+',
'100': 'B+',
'000': 'AB+',
}
def getInvertCode(bcode):
invert = bcode
invert = invert.replace('0', '2')
invert = invert.replace('1', '0')
invert = invert.replace('2', '1')
return invert
def flipPlace(bcode, place=3):
newcode = bcode[:place-1]
newcode += getInvertCode(bcode[place-1])
newcode += bcode[place:]
return newcode
def getWrongChoices(bcode):
invert = getInvertCode(bcode)
choices = []
choices.append(bcode+'1')
choices.append(bcode+'0')
choices.append(invert+'1')
choices.append(invert+'0')
extras = []
for choice in choices:
extras.append(flipPlace(choice, 3))
random.shuffle(extras)
#choices.extend(extras)
choices.append(extras.pop())
choices.append(extras.pop())
random.shuffle(choices)
return choices
def code2display(bcode):
display_txt = bcode
display_txt = display_txt.replace("0", "%")
display_txt = display_txt.replace("1", "O")
return display_txt
if __name__ == '__main__':
bcodes = list(code2type.keys())
N = 0
letters = "ABCDEFG"
outfile = 'bbq-' + os.path.splitext(os.path.basename(__file__))[0] + '-questions.txt'
print('writing to file: '+outfile)
f = open(outfile, 'w')
for bcode in bcodes:
N += 1
answer = bcode+"1"
choices = getWrongChoices(bcode)
question = ''
#question += "{0}. ".format(N)
question += "What will the results of a blood test look like for a person "
question += "with <b>{0} blood type</b>?".format(code2type[bcode])
print(question)
f.write("MC\t")
f.write("{0}\t".format(question))
i = 0
for choice in choices:
prefix = "Incorrect"
if choice == answer:
prefix = 'Correct'
ltr = letters[i]
table = createHtmlTable(choice)
display_txt = code2display(choice)
choice_txt = "<p>{0}</p><p>image of blood type result, looks like {1}</p>".format(table, display_txt)
print("{0}{1}. {2}".format(prefix, ltr, display_txt))
f.write("{0}\t".format(choice_txt))
f.write("{0}\t".format(prefix))
i += 1
print("")
f.write('\n')
f.close()