-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummary_scores_util.py
39 lines (29 loc) · 1.52 KB
/
summary_scores_util.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
import os, glob, stat, sys, imp
import sibispy
class SummaryScoresCollector():
def __init__(self, module_init_script):
self.fields_list = dict()
self.functions = dict()
self.output_form = dict()
self.instrument_list = []
module_dir = os.path.dirname(os.path.abspath(module_init_script))
instruments = [ os.path.basename( d ) for d in glob.glob(os.path.join(module_dir,'*')) if stat.S_ISDIR( os.stat( d ).st_mode ) and os.path.exists( os.path.join( d, '__init__.py' ) ) ]
sys.path.append( os.path.abspath(os.path.dirname(module_init_script) ) )
for i in instruments:
module_found = imp.find_module( i, [module_dir] )
module = imp.load_module( i, module_found[0], module_found[1], module_found[2] )
self.instrument_list.append( i )
self.fields_list[i] = module.input_fields
self.functions[i] = module.compute_scores
self.output_form[i] = module.output_form
# dataframe and errorFlag
def compute_scores(self, instrument, input_data, demographics, log, **kwargs):
if log != sibispy.sibislogger:
raise TypeError("Call must include a sibislogger!")
scoresDF = self.functions[instrument](input_data, demographics, log=log, **kwargs)
# remove nan entries as they corrupt data ingest (REDCAP cannot handle it correctly) and superfluous zeros
# this gave an error as it only works for float values to replace
if len(scoresDF):
# Only execute it not empty
return (scoresDF.astype(object).fillna(''), False)
return (scoresDF, False)