-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGetBMI.py
62 lines (60 loc) · 2.4 KB
/
GetBMI.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
'''
Created on 2 Mar 2016
@author: mbaxkhm4
Created at the University of Manchester, School of Computer Science
Licence GNU/GPL 3.0
'''
from QueryDBClass import QueryDBCalss
from Data.Table import Table
import re
if __name__=="__main__":
queryclass = QueryDBCalss("localhost","root","","table_db" )
queryclass.DeleteAttribute("BMI")
queryclass.CreateAdditionalTables()
results = queryclass.getArticles()
articleIds = []
for row in results:
articleIds.append(row[0])
del results
#articleIds = [1501]
for id in articleIds:
results = queryclass.getArticleTables(id)
tables = []
for t in results:
table = Table()
table.tableId = t[0]
table.tableOrder = t[1]
table.tableCaption = t[2]
table.tableFooter = t[3]
table.StructureType = t[4]
table.PrgamaticType = t[5]
table.hasXML = t[6]
table.articleId = t[7]
tables.append(table)
resulta = queryclass.getCellsContainingInStubListOR(table.tableId, ['BMI','bmi','body mass index','Body Mass Index','Body mass index'])
for res in resulta:
m2 = re.search('[\d\.]+',res[9])
if(m2==None):
continue
totalNum = float(m2.group(0))
if "range" in res[10].lower():
continue
if(totalNum>12 and totalNum<50):
print 'BMI:'+str(totalNum)
armid = queryclass.SaveArm(res[10], id,table.tableId)
queryclass.SaveAttribute(armid, "BMI", totalNum)
resulta = queryclass.getCellsContainingInSuperRowListOR(table.tableId, ['BMI','bmi','body mass index','Body Mass Index','Body mass index'])
for res in resulta:
m2 = re.search('[\d\.]+',res[9])
if(m2==None or m2.group(0)=='.'):
continue
if('range' in res[11].lower() or '%' in res[11].lower()):
continue
totalNum = float(m2.group(0))
if "range" in res[10].lower():
continue
if(totalNum>12 and totalNum<50):
print 'BMI:'+str(totalNum)
armid = queryclass.SaveArm(res[10], id,table.tableId)
queryclass.SaveAttribute(armid, "BMI", totalNum)
print "Done"