11import xmltodict
22
3+ from openml .study import OpenMLStudy
34from .._api_calls import _perform_api_call
45
6+ def _multitag_to_list (result_dict , tag ):
7+ if isinstance (result_dict [tag ], list ):
8+ return result_dict [tag ]
9+ elif isinstance (result_dict [tag ], dict ):
10+ return [result_dict [tag ]]
11+ else :
12+ raise TypeError ()
13+
14+
515def get_study (study_id ):
6- xml_string = _perform_api_call ("study/" % (study_id ))
7- result_dict = xmltodict .parse (xml_string )
8-
9- pass
16+ xml_string = _perform_api_call ("study/%d" % (study_id ))
17+ result_dict = xmltodict .parse (xml_string )['oml:study' ]
18+ id = int (result_dict ['oml:id' ])
19+ name = result_dict ['oml:name' ]
20+ description = result_dict ['oml:description' ]
21+ creation_date = result_dict ['oml:creation_date' ]
22+ creator = result_dict ['oml:creator' ]
23+ tags = []
24+ for tag in _multitag_to_list (result_dict , 'oml:tag' ):
25+ tags .append ({'name' : tag ['oml:name' ],
26+ 'window_start' : tag ['oml:window_start' ],
27+ 'write_access' : tag ['oml:write_access' ]})
28+
29+ datasets = None
30+ tasks = None
31+ flows = None
32+ setups = None
33+
34+ if 'oml:data' in result_dict :
35+ datasets = [int (x ) for x in result_dict ['oml:data' ]['oml:data_id' ]]
36+
37+ if 'oml:tasks' in result_dict :
38+ tasks = [int (x ) for x in result_dict ['oml:tasks' ]['oml:task_id' ]]
39+
40+ if 'oml:flows' in result_dict :
41+ flows = [int (x ) for x in result_dict ['oml:flows' ]['oml:flow_id' ]]
42+
43+ if 'oml:setups' in result_dict :
44+ setups = [int (x ) for x in result_dict ['oml:setups' ]['oml:setup_id' ]]
45+
46+ study = OpenMLStudy (id , name , description , creation_date , creator , tags ,
47+ datasets , tasks , flows , setups )
48+ return study
0 commit comments