sequence
stringlengths 1.25k
34.6k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dummy_run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nthread'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '29', '42', '52', '65', '69', '83', '87', '116', '133', '156']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'seed'"},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'ndim'"},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'logl_start'"},{'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'logl_range'"},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'if_statement', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'Unexpected **kwargs: {0}'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '72', 'type': 'False', 'children': []},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '86', 'type': 'list', 'children': [], 'value': '[]'},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '93']},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'nthread'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_dummy_thread'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '107', '110', '113']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'lambda', 'children': ['126', '128']},{'id': '126', 'type': 'lambda_parameters', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '128', 'type': 'subscript', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '131', 'type': 'string', 'children': [], 'value': "'logl'"},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'for_statement', 'children': ['134', '137', '141']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '149']},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'string', 'children': [], 'value': "'thread_labels'"},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'nestcheck'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ns_run_utils'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'combine_threads'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'threads'} | def get_dummy_run(nthread, nsamples, **kwargs):
seed = kwargs.pop('seed', False)
ndim = kwargs.pop('ndim', 2)
logl_start = kwargs.pop('logl_start', -np.inf)
logl_range = kwargs.pop('logl_range', 1)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.format(kwargs))
threads = []
if seed is not False:
np.random.seed(seed)
threads = []
for _ in range(nthread):
threads.append(get_dummy_thread(
nsamples, ndim=ndim, seed=False, logl_start=logl_start,
logl_range=logl_range))
threads = sorted(threads, key=lambda th: th['logl'][0])
for i, _ in enumerate(threads):
threads[i]['thread_labels'] = np.full(nsamples, i)
return nestcheck.ns_run_utils.combine_threads(threads) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dummy_dynamic_run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '18', '28', '38', '48', '58', '71', '94', '114', '125', '148', '171', '182', '193']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'seed'"},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'ndim'"},{'id': '27', 'type': 'integer', 'children': [], 'value': '2'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'nthread_init'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'nthread_init'"},{'id': '37', 'type': 'integer', 'children': [], 'value': '2'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nthread_dyn'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'nthread_dyn'"},{'id': '47', 'type': 'integer', 'children': [], 'value': '3'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "'logl_range'"},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'raise_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'Unexpected **kwargs: {0}'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_dummy_run'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '82', '85', '91']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nthread_init'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dyn_starts'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '106', 'type': 'argument_list', 'children': ['107', '110', '111']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '109', 'type': 'string', 'children': [], 'value': "'logl'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'nthread_dyn'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '113', 'type': 'True', 'children': []},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'nestcheck'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ns_run_utils'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_run_threads'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '128', 'type': 'list_comprehension', 'children': ['129', '145']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_dummy_thread'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '136', '139', '142']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '138', 'type': 'False', 'children': []},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dyn_starts'},{'id': '148', 'type': 'for_statement', 'children': ['149', '152', '156']},{'id': '149', 'type': 'pattern_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '164']},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'string', 'children': [], 'value': "'thread_labels'"},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'nestcheck'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ns_run_utils'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'combine_threads'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'nestcheck'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'write_polychord_output'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'run_dead_birth_array'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '200']},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'nestcheck'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'data_processing'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'process_samples_array'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'samples'} | def get_dummy_dynamic_run(nsamples, **kwargs):
seed = kwargs.pop('seed', False)
ndim = kwargs.pop('ndim', 2)
nthread_init = kwargs.pop('nthread_init', 2)
nthread_dyn = kwargs.pop('nthread_dyn', 3)
logl_range = kwargs.pop('logl_range', 1)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.format(kwargs))
init = get_dummy_run(nthread_init, nsamples, ndim=ndim, seed=seed,
logl_start=-np.inf, logl_range=logl_range)
dyn_starts = list(np.random.choice(
init['logl'], nthread_dyn, replace=True))
threads = nestcheck.ns_run_utils.get_run_threads(init)
threads += [get_dummy_thread(
nsamples, ndim=ndim, seed=False, logl_start=start,
logl_range=logl_range) for start in dyn_starts]
for i, _ in enumerate(threads):
threads[i]['thread_labels'] = np.full(nsamples, i)
run = nestcheck.ns_run_utils.combine_threads(threads)
samples = nestcheck.write_polychord_output.run_dead_birth_array(run)
return nestcheck.data_processing.process_samples_array(samples) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dates_for_project'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '6', 'type': 'block', 'children': ['7', '18', '22', '88']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'file_re'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '%'},{'id': '16', 'type': 'string', 'children': [], 'value': "r'^%s_([0-9]{8})\\.json$'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'all_dates'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '32']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cache_path'},{'id': '32', 'type': 'block', 'children': ['33', '55', '64', '70']},{'id': '33', 'type': 'if_statement', 'children': ['34', '53']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cache_path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'continue_statement', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'file_re'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'continue_statement', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'all_dates'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '80', 'type': 'argument_list', 'children': ['81', '87']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'string', 'children': [], 'value': "'%Y%m%d'"},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'all_dates'} | def get_dates_for_project(self, project):
file_re = re.compile(r'^%s_([0-9]{8})\.json$' % project)
all_dates = []
for f in os.listdir(self.cache_path):
if not os.path.isfile(os.path.join(self.cache_path, f)):
continue
m = file_re.match(f)
if m is None:
continue
all_dates.append(datetime.strptime(m.group(1), '%Y%m%d'))
return sorted(all_dates) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'insort_event_right'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '23', '37', '76']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '<'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'lo must be non-negative'"},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '37', 'type': 'while_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '41', 'type': 'block', 'children': ['42', '51']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '50'], 'value': '//'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '50', 'type': 'integer', 'children': [], 'value': '2'},{'id': '51', 'type': 'if_statement', 'children': ['52', '63', '68']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '<'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'subscript', 'children': ['57', '62']},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'event'} | def insort_event_right(self, event, lo=0, hi=None):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(self.queue)
while lo < hi:
mid = (lo + hi) // 2
if event[0] < self.queue[mid][0]:
hi = mid
else:
lo = mid + 1
self.queue.insert(lo, event) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getMd5Checksum'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '27', '44', '57']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12', '17']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getReferences'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'getMd5Checksum'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'checksums'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "''"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '41']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'getMd5Checksum'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'md5checksum'},{'id': '47', 'type': 'call', 'children': ['48', '56']},{'id': '48', 'type': 'attribute', 'children': ['49', '55']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'md5'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'checksums'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'md5checksum'} | def getMd5Checksum(self):
references = sorted(
self.getReferences(),
key=lambda ref: ref.getMd5Checksum())
checksums = ''.join([ref.getMd5Checksum() for ref in references])
md5checksum = hashlib.md5(checksums).hexdigest()
return md5checksum |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'knn_impute_few_observed'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'missing_mask'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'print_interval'},{'id': '12', 'type': 'integer', 'children': [], 'value': '100'},{'id': '13', 'type': 'block', 'children': ['14', '22', '30', '42', '47', '58', '73', '85', '91', '97', '108', '126', '132', '281']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start_t'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'n_cols'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'missing_mask_column_major'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'missing_mask'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '41', 'type': 'string', 'children': [], 'value': '"F"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'observed_mask_column_major'},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '~'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'missing_mask_column_major'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'X_column_major'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '57', 'type': 'string', 'children': [], 'value': '"F"'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '64', '65']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'X_row_major'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'effective_infinity'},{'id': '64', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'knn_initialize'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'missing_mask'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'D_sorted'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'inv_D'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '/'},{'id': '89', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'D_valid_mask'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '<'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'effective_infinity'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'valid_distances_per_row'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'D_valid_mask'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'D_sorted'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '118']},{'id': '112', 'type': 'subscript', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'D_sorted'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'slice', 'children': ['116', '117']},{'id': '116', 'type': 'colon', 'children': []},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '122']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'valid_distances_per_row'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '138']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '138', 'type': 'block', 'children': ['139', '147', '158', '166', '197', '203']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'missing_row'},{'id': '142', 'type': 'subscript', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'missing_mask'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'slice', 'children': ['146']},{'id': '146', 'type': 'colon', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'missing_indices'},{'id': '150', 'type': 'subscript', 'children': ['151', '157']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'missing_row'},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'row_weights'},{'id': '161', 'type': 'subscript', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'inv_D'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'slice', 'children': ['165']},{'id': '165', 'type': 'colon', 'children': []},{'id': '166', 'type': 'if_statement', 'children': ['167', '174']},{'id': '167', 'type': 'boolean_operator', 'children': ['168', '169'], 'value': 'and'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '173'], 'value': '=='},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '%'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'print_interval'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '%'},{'id': '180', 'type': 'string', 'children': [], 'value': '"Imputing row %d/%d with %d missing, elapsed time: %0.3f"'},{'id': '181', 'type': 'tuple', 'children': ['182', '185', '186', '190']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '+'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'missing_indices'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '196'], 'value': '-'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'start_t'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'candidate_neighbor_indices'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'D_sorted'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '203', 'type': 'for_statement', 'children': ['204', '205', '206']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'missing_indices'},{'id': '206', 'type': 'block', 'children': ['207', '215', '221', '227', '235', '241', '249']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '210', 'type': 'subscript', 'children': ['211', '212', '214']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'observed_mask_column_major'},{'id': '212', 'type': 'slice', 'children': ['213']},{'id': '213', 'type': 'colon', 'children': []},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'sorted_observed'},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'observed'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'candidate_neighbor_indices'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'observed_neighbor_indices'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'candidate_neighbor_indices'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'sorted_observed'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'k_nearest_indices'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'observed_neighbor_indices'},{'id': '232', 'type': 'slice', 'children': ['233', '234']},{'id': '233', 'type': 'colon', 'children': []},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'row_weights'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'k_nearest_indices'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'weight_sum'},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'if_statement', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '>'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'weight_sum'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'block', 'children': ['254', '262', '268']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '257', 'type': 'subscript', 'children': ['258', '259', '261']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'X_column_major'},{'id': '259', 'type': 'slice', 'children': ['260']},{'id': '260', 'type': 'colon', 'children': []},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'k_nearest_indices'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '274']},{'id': '270', 'type': 'subscript', 'children': ['271', '272', '273']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'X_row_major'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '274', 'type': 'binary_operator', 'children': ['275', '280'], 'value': '/'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'weight_sum'},{'id': '281', 'type': 'return_statement', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'X_row_major'} | def knn_impute_few_observed(
X, missing_mask, k, verbose=False, print_interval=100):
start_t = time.time()
n_rows, n_cols = X.shape
missing_mask_column_major = np.asarray(missing_mask, order="F")
observed_mask_column_major = ~missing_mask_column_major
X_column_major = X.copy(order="F")
X_row_major, D, effective_infinity = \
knn_initialize(X, missing_mask, verbose=verbose)
D_sorted = np.argsort(D, axis=1)
inv_D = 1.0 / D
D_valid_mask = D < effective_infinity
valid_distances_per_row = D_valid_mask.sum(axis=1)
D_sorted = [
D_sorted[i, :count]
for i, count in enumerate(valid_distances_per_row)
]
dot = np.dot
for i in range(n_rows):
missing_row = missing_mask[i, :]
missing_indices = np.where(missing_row)[0]
row_weights = inv_D[i, :]
if verbose and i % print_interval == 0:
print(
"Imputing row %d/%d with %d missing, elapsed time: %0.3f" % (
i + 1,
n_rows,
len(missing_indices),
time.time() - start_t))
candidate_neighbor_indices = D_sorted[i]
for j in missing_indices:
observed = observed_mask_column_major[:, j]
sorted_observed = observed[candidate_neighbor_indices]
observed_neighbor_indices = candidate_neighbor_indices[sorted_observed]
k_nearest_indices = observed_neighbor_indices[:k]
weights = row_weights[k_nearest_indices]
weight_sum = weights.sum()
if weight_sum > 0:
column = X_column_major[:, j]
values = column[k_nearest_indices]
X_row_major[i, j] = dot(values, weights) / weight_sum
return X_row_major |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_converters'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'app_ready'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '21']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'''Sorts the converter functions'''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_sorting_enabled'},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'or'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_sorting_enabled'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'app_ready'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_sorting_enabled'},{'id': '25', 'type': 'block', 'children': ['26', '38']},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '31']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'converter'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'converters'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'converter'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'prepare_sort_key'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'converters'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': "'sort_key'"} | def _sort_converters(cls, app_ready=False):
'''Sorts the converter functions'''
cls._sorting_enabled = cls._sorting_enabled or app_ready
if cls._sorting_enabled:
for converter in cls.converters:
converter.prepare_sort_key()
cls.converters.sort(key=attrgetter('sort_key')) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_sort_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '80']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Triggered by view_function._sort_converters when our sort key should be created.\n This can't be called in the constructor because Django models might not be ready yet.\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '16']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'block', 'children': ['17', '47']},{'id': '17', 'type': 'try_statement', 'children': ['18', '32']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '32', 'type': 'except_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ImproperlyConfigured'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '\'"{}" is not a valid converter type. String-based converter types must be specified in "app.Model" format.\''},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '47', 'type': 'try_statement', 'children': ['48', '61']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_model'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '61', 'type': 'except_clause', 'children': ['62', '66']},{'id': '62', 'type': 'as_pattern', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'id': '64', 'type': 'as_pattern_target', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'raise_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ImproperlyConfigured'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '\'"{}" is not a valid model name. {}\''},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '85', 'type': 'tuple', 'children': ['86', '100']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '89'], 'value': '*'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'getmro'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'convert_type'},{'id': '100', 'type': 'binary_operator', 'children': ['101', '103'], 'value': '*'},{'id': '101', 'type': 'unary_operator', 'children': ['102'], 'value': '-'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'source_order'} | def prepare_sort_key(self):
'''
Triggered by view_function._sort_converters when our sort key should be created.
This can't be called in the constructor because Django models might not be ready yet.
'''
if isinstance(self.convert_type, str):
try:
app_name, model_name = self.convert_type.split('.')
except ValueError:
raise ImproperlyConfigured('"{}" is not a valid converter type. String-based converter types must be specified in "app.Model" format.'.format(self.convert_type))
try:
self.convert_type = apps.get_model(app_name, model_name)
except LookupError as e:
raise ImproperlyConfigured('"{}" is not a valid model name. {}'.format(self.convert_type, e))
self.sort_key = ( -1 * len(inspect.getmro(self.convert_type)), -1 * self.source_order ) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_key_for_numeric_suffixes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '7', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'suffix_index'},{'id': '10', 'type': 'unary_operator', 'children': ['11'], 'value': '-'},{'id': '11', 'type': 'integer', 'children': [], 'value': '2'},{'id': '12', 'type': 'block', 'children': ['13', '22', '57']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '22', 'type': 'if_statement', 'children': ['23', '30']},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'suffix_index'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'expression_list', 'children': ['33', '51']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '44'], 'value': '+'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '41', 'type': 'slice', 'children': ['42', '43']},{'id': '42', 'type': 'colon', 'children': []},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'suffix_index'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '46', 'type': 'slice', 'children': ['47', '50']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'suffix_index'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'colon', 'children': []},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'suffix_index'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'expression_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'} | def sort_key_for_numeric_suffixes(path, sep='.', suffix_index=-2):
chunks = path.split(sep)
if chunks[suffix_index].isdigit():
return sep.join(chunks[:suffix_index] + chunks[suffix_index+1:]), int(chunks[suffix_index])
return path, 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '6', 'type': 'block', 'children': ['7', '9', '27', '45', '56']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\r\n Query tempalte for source Solr, sorts by id by default.\r\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '12', 'type': 'dictionary', 'children': ['13', '16', '19', '24']},{'id': '13', 'type': 'pair', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'*:*'"},{'id': '16', 'type': 'pair', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'id desc'"},{'id': '19', 'type': 'pair', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'rows'"},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_rows'},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': "'cursorMark'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_date_field'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '36', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': '"{} asc, id desc"'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_date_field'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_per_shard'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '54', 'type': 'string', 'children': [], 'value': "'distrib'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'false'"},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'query'} | def _get_query(self, cursor):
'''
Query tempalte for source Solr, sorts by id by default.
'''
query = {'q':'*:*',
'sort':'id desc',
'rows':self._rows,
'cursorMark':cursor}
if self._date_field:
query['sort'] = "{} asc, id desc".format(self._date_field)
if self._per_shard:
query['distrib'] = 'false'
return query |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'url_params'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'except_params'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'as_is'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '20', '24', '68', '102']},{'id': '12', 'type': 'if_statement', 'children': ['13', '17']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "''"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'for_statement', 'children': ['25', '28', '35']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'and'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'except_params'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'except_params'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '53']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '45', 'type': 'call', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'},{'id': '61', 'type': 'string', 'children': [], 'value': "'%s=%s'"},{'id': '62', 'type': 'tuple', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'urlquote'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'if_statement', 'children': ['69', '70', '82']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'as_is'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str_params'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '+'},{'id': '75', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '95']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'str_params'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'},{'id': '88', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'str_params'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'urlquote'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'str_params'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mark_safe'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'str_params'} | def url_params(request, except_params=None, as_is=False):
if not request.GET:
return ''
params = []
for key, value in request.GET.items():
if except_params and key not in except_params:
for v in request.GET.getlist(key):
params.append('%s=%s' % (key, urlquote(v)))
if as_is:
str_params = '?' + '&'.join(params)
else:
str_params = '?' + '&'.join(params)
str_params = urlquote(str_params)
return mark_safe(str_params) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compose'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '14', '38', '73', '86', '98']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': '=='},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '13', 'type': 'integer', 'children': [], 'value': '2'},{'id': '14', 'type': 'block', 'children': ['15', '21']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f0'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'lambda', 'children': ['23', '28']},{'id': '23', 'type': 'lambda_parameters', 'children': ['24', '26']},{'id': '24', 'type': 'list_splat_pattern', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'f0'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '33', 'type': 'argument_list', 'children': ['34', '36']},{'id': '34', 'type': 'list_splat', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '36', 'type': 'dictionary_splat', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '38', 'type': 'elif_clause', 'children': ['39', '45']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '44', 'type': 'integer', 'children': [], 'value': '3'},{'id': '45', 'type': 'block', 'children': ['46', '53']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '52']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'f0'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'f2'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'lambda', 'children': ['55', '60']},{'id': '55', 'type': 'lambda_parameters', 'children': ['56', '58']},{'id': '56', 'type': 'list_splat_pattern', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '58', 'type': 'dictionary_splat_pattern', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'f0'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'f2'},{'id': '68', 'type': 'argument_list', 'children': ['69', '71']},{'id': '69', 'type': 'list_splat', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '71', 'type': 'dictionary_splat', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '73', 'type': 'elif_clause', 'children': ['74', '80']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '=='},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'lambda', 'children': ['83', '85']},{'id': '83', 'type': 'lambda_parameters', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'elif_clause', 'children': ['87', '93']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'else_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100', '141']},{'id': '100', 'type': 'function_definition', 'children': ['101', '102', '107']},{'id': '101', 'type': 'function_name', 'children': [], 'value': 'composed'},{'id': '102', 'type': 'parameters', 'children': ['103', '105']},{'id': '103', 'type': 'list_splat_pattern', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '105', 'type': 'dictionary_splat_pattern', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '107', 'type': 'block', 'children': ['108', '121', '139']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '111', 'type': 'call', 'children': ['112', '116']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '114', 'type': 'unary_operator', 'children': ['115'], 'value': '-'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'argument_list', 'children': ['117', '119']},{'id': '117', 'type': 'list_splat', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '119', 'type': 'dictionary_splat', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '131']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '125', 'type': 'slice', 'children': ['126', '127', '128', '129']},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'colon', 'children': []},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'composed'} | def compose(*funcs):
if len(funcs) == 2: f0,f1=funcs; return lambda *a,**kw: f0(f1(*a,**kw))
elif len(funcs) == 3: f0,f1,f2=funcs; return lambda *a,**kw: f0(f1(f2(*a,**kw)))
elif len(funcs) == 0: return lambda x:x
elif len(funcs) == 1: return funcs[0]
else:
def composed(*args,**kwargs):
y = funcs[-1](*args,**kwargs)
for f in funcs[:0:-1]: y = f(y)
return y
return composed |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_lines'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_valid_lines'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_valid_lines'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'accept_date'} | def _sort_lines(self):
self._valid_lines = sorted(
self._valid_lines,
key=lambda line: line.accept_date,
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_and_trim'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '21', '39']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '12', 'type': 'integer', 'children': [], 'value': '10'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '36']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'lambda', 'children': ['31', '33']},{'id': '31', 'type': 'lambda_parameters', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'data_info'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'data_info'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '42', 'type': 'slice', 'children': ['43', '44']},{'id': '43', 'type': 'colon', 'children': []},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'threshold'} | def _sort_and_trim(data, reverse=False):
threshold = 10
data_list = data.items()
data_list = sorted(
data_list,
key=lambda data_info: data_info[1],
reverse=reverse,
)
return data_list[:threshold] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_queryset'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '20', '29', '38']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Apply Datatables sort and search criterion to QuerySet'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '11', 'type': 'call', 'children': ['12', '19']},{'id': '12', 'type': 'attribute', 'children': ['13', '18']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'DatatablesView'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_queryset'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'global_search'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'column_search'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'list_splat', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_orders'},{'id': '49', 'type': 'argument_list', 'children': []} | def get_queryset(self):
'''Apply Datatables sort and search criterion to QuerySet'''
qs = super(DatatablesView, self).get_queryset()
qs = self.global_search(qs)
qs = self.column_search(qs)
return qs.order_by(*self.get_orders()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rangify'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'number_list'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '24', '57', '66']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'number_list'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'number_list'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'range_start'},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'prev_num'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'number_list'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'number_list'},{'id': '28', 'type': 'slice', 'children': ['29', '30']},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '53']},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '!='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'prev_num'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'block', 'children': ['40', '49']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'tuple', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'range_start'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'prev_num'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'range_start'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'prev_num'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'tuple', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'range_start'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'prev_num'},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ranges'} | def rangify(number_list):
if not number_list:
return number_list
ranges = []
range_start = prev_num = number_list[0]
for num in number_list[1:]:
if num != (prev_num + 1):
ranges.append((range_start, prev_num))
range_start = num
prev_num = num
ranges.append((range_start, prev_num))
return ranges |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_solver'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'refresh'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '13', 'type': 'block', 'children': ['14', '22', '35', '49']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': '"Requested a solver that best matches feature filters=%r"'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'if_statement', 'children': ['36', '42']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '39'], 'value': 'and'},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default_solver'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'default_solver'},{'id': '49', 'type': 'try_statement', 'children': ['50', '72']},{'id': '50', 'type': 'block', 'children': ['51', '59']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': '"Fetching solvers according to filters=%r"'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'subscript', 'children': ['61', '71']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get_solvers'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'refresh'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'refresh'},{'id': '69', 'type': 'dictionary_splat', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'except_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'raise_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'SolverNotFoundError'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Solver with the requested features not available"'} | def get_solver(self, name=None, refresh=False, **filters):
_LOGGER.debug("Requested a solver that best matches feature filters=%r", filters)
if name is not None:
filters.setdefault('name', name)
if not filters and self.default_solver:
filters = self.default_solver
try:
_LOGGER.debug("Fetching solvers according to filters=%r", filters)
return self.get_solvers(refresh=refresh, **filters)[0]
except IndexError:
raise SolverNotFoundError("Solver with the requested features not available") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_germanet_xml_files'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'xml_path'},{'id': '5', 'type': 'block', 'children': ['6', '8', '28', '55', '70', '79', '102', '117', '153', '180', '195', '204', '230', '245', '254', '263']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Globs the XML files contained in the given directory and sorts\n them into sections for import into the MongoDB database.\n Arguments:\n - `xml_path`: the path to the directory containing the GermaNet\n XML files\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'xml_path'},{'id': '27', 'type': 'string', 'children': [], 'value': "'*.xml'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lex_files'},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '33', '36']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '36', 'type': 'if_clause', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "r'(adj|nomen|verben)\\.'"},{'id': '43', 'type': 'call', 'children': ['44', '54']},{'id': '44', 'type': 'attribute', 'children': ['45', '53']},{'id': '45', 'type': 'call', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'binary_operator', 'children': ['62', '66'], 'value': '-'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lex_files'},{'id': '70', 'type': 'if_statement', 'children': ['71', '73']},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lex_files'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': "'ERROR: cannot find lexical information files'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '84', '87']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '87', 'type': 'if_clause', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '101'], 'value': '=='},{'id': '89', 'type': 'call', 'children': ['90', '100']},{'id': '90', 'type': 'attribute', 'children': ['91', '99']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'string', 'children': [], 'value': "'gn_relations.xml'"},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '113'], 'value': '-'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '117', 'type': 'if_statement', 'children': ['118', '120', '130']},{'id': '118', 'type': 'not_operator', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '120', 'type': 'block', 'children': ['121', '126']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': "'ERROR: cannot find relations file gn_relations.xml'"},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132', '147']},{'id': '132', 'type': 'if_statement', 'children': ['133', '139']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '<'},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'concatenated_string', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'WARNING: more than one relations file gn_relations.xml, '"},{'id': '146', 'type': 'string', 'children': [], 'value': "'taking first match'"},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'wiktionary_files'},{'id': '156', 'type': 'list_comprehension', 'children': ['157', '158', '161']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '161', 'type': 'if_clause', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "r'wiktionaryparaphrases-'"},{'id': '168', 'type': 'call', 'children': ['169', '179']},{'id': '169', 'type': 'attribute', 'children': ['170', '178']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '191'], 'value': '-'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'wiktionary_files'},{'id': '195', 'type': 'if_statement', 'children': ['196', '198']},{'id': '196', 'type': 'not_operator', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'wiktionary_files'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "'WARNING: cannot find wiktionary paraphrase files'"},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ili_files'},{'id': '207', 'type': 'list_comprehension', 'children': ['208', '209', '212']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '212', 'type': 'if_clause', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '228']},{'id': '214', 'type': 'attribute', 'children': ['215', '227']},{'id': '215', 'type': 'call', 'children': ['216', '226']},{'id': '216', 'type': 'attribute', 'children': ['217', '225']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'xml_file'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'string', 'children': [], 'value': "'interlingualindex'"},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '241'], 'value': '-'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ili_files'},{'id': '245', 'type': 'if_statement', 'children': ['246', '248']},{'id': '246', 'type': 'not_operator', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'ili_files'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'string', 'children': [], 'value': "'WARNING: cannot find interlingual index file'"},{'id': '254', 'type': 'if_statement', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': "'WARNING: unrecognised xml files:'"},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'xml_files'},{'id': '263', 'type': 'return_statement', 'children': ['264']},{'id': '264', 'type': 'expression_list', 'children': ['265', '266', '267', '268']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'lex_files'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'gn_rels_file'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'wiktionary_files'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'ili_files'} | def find_germanet_xml_files(xml_path):
'''
Globs the XML files contained in the given directory and sorts
them into sections for import into the MongoDB database.
Arguments:
- `xml_path`: the path to the directory containing the GermaNet
XML files
'''
xml_files = sorted(glob.glob(os.path.join(xml_path, '*.xml')))
lex_files = [xml_file for xml_file in xml_files if
re.match(r'(adj|nomen|verben)\.',
os.path.basename(xml_file).lower())]
xml_files = sorted(set(xml_files) - set(lex_files))
if not lex_files:
print('ERROR: cannot find lexical information files')
gn_rels_file = [xml_file for xml_file in xml_files if
os.path.basename(xml_file).lower() == 'gn_relations.xml']
xml_files = sorted(set(xml_files) - set(gn_rels_file))
if not gn_rels_file:
print('ERROR: cannot find relations file gn_relations.xml')
gn_rels_file = None
else:
if 1 < len(gn_rels_file):
print ('WARNING: more than one relations file gn_relations.xml, '
'taking first match')
gn_rels_file = gn_rels_file[0]
wiktionary_files = [xml_file for xml_file in xml_files if
re.match(r'wiktionaryparaphrases-',
os.path.basename(xml_file).lower())]
xml_files = sorted(set(xml_files) - set(wiktionary_files))
if not wiktionary_files:
print('WARNING: cannot find wiktionary paraphrase files')
ili_files = [xml_file for xml_file in xml_files if
os.path.basename(xml_file).lower().startswith(
'interlingualindex')]
xml_files = sorted(set(xml_files) - set(ili_files))
if not ili_files:
print('WARNING: cannot find interlingual index file')
if xml_files:
print('WARNING: unrecognised xml files:', xml_files)
return lex_files, gn_rels_file, wiktionary_files, ili_files |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_org_issues'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '11', 'type': 'string', 'children': [], 'value': "''"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '14', 'type': 'string', 'children': [], 'value': "''"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '17', 'type': 'string', 'children': [], 'value': "''"},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '20', 'type': 'string', 'children': [], 'value': "''"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '43', '55']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']},{'id': '40', 'type': 'string', 'children': [], 'value': "'orgs'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '42', 'type': 'string', 'children': [], 'value': "'issues'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'issue_params'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51', '52', '53', '54']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '60', 'type': 'argument_list', 'children': ['61', '65', '66', '67', '68']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Issue'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_org_issues(self, name, filter='', state='', labels='', sort='',
direction='', since=None, number=-1, etag=None):
url = self._build_url('orgs', name, 'issues')
params = issue_params(filter, state, labels, sort, direction, since)
return self._iter(int(number), url, Issue, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_repos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '32', '36', '55', '73', '89']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'repos'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '35', 'type': 'dictionary', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '45']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '39', 'type': 'tuple', 'children': ['40', '41', '42', '43', '44']},{'id': '40', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'owner'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'public'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'private'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'member'"},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '55', 'type': 'if_statement', 'children': ['56', '63']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '58', 'type': 'tuple', 'children': ['59', '60', '61', '62']},{'id': '59', 'type': 'string', 'children': [], 'value': "'created'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'updated'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'pushed'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'full_name'"},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '73', 'type': 'if_statement', 'children': ['74', '79']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '94', 'type': 'argument_list', 'children': ['95', '99', '100', '101', '102']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Repository'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_repos(self, type=None, sort=None, direction=None, number=-1,
etag=None):
url = self._build_url('user', 'repos')
params = {}
if type in ('all', 'owner', 'public', 'private', 'member'):
params.update(type=type)
if sort in ('created', 'updated', 'pushed', 'full_name'):
params.update(sort=sort)
if direction in ('asc', 'desc'):
params.update(direction=direction)
return self._iter(int(number), url, Repository, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_starred'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '38', '48', '55', '65']},{'id': '22', 'type': 'if_statement', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '35']},{'id': '27', 'type': 'attribute', 'children': ['28', '34']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'iter_starred'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '41', 'type': 'dictionary', 'children': ['42', '45']},{'id': '42', 'type': 'pair', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_remove_none'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'starred'"},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '70', 'type': 'argument_list', 'children': ['71', '75', '76', '77', '78']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Repository'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_starred(self, login=None, sort=None, direction=None, number=-1,
etag=None):
if login:
return self.user(login).iter_starred(sort, direction)
params = {'sort': sort, 'direction': direction}
self._remove_none(params)
url = self._build_url('user', 'starred')
return self._iter(int(number), url, Repository, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_code'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '20', 'type': 'unary_operator', 'children': ['21'], 'value': '-'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '33', '37', '48', '63', '73', '83']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '29', 'type': 'dictionary', 'children': ['30']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'string', 'children': [], 'value': "'indexed'"},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '46', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '48', 'type': 'if_statement', 'children': ['49', '56']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '51'], 'value': 'and'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '53', 'type': 'tuple', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '61', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '63', 'type': 'if_statement', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '69', 'type': 'dictionary', 'children': ['70']},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'application/vnd.github.v3.full.text-match+json'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'search'"},{'id': '82', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'SearchIterator'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89', '90', '91', '92', '93']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'CodeSearchResult'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'headers'} | def search_code(self, query, sort=None, order=None, per_page=None,
text_match=False, number=-1, etag=None):
params = {'q': query}
headers = {}
if sort == 'indexed':
params['sort'] = sort
if sort and order in ('asc', 'desc'):
params['order'] = order
if text_match:
headers = {
'Accept': 'application/vnd.github.v3.full.text-match+json'
}
url = self._build_url('search', 'code')
return SearchIterator(number, url, CodeSearchResult, self, params,
etag, headers) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_issues'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '20', 'type': 'unary_operator', 'children': ['21'], 'value': '-'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '33', '37', '51', '64', '74', '84']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '29', 'type': 'dictionary', 'children': ['30']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'tuple', 'children': ['41', '42', '43']},{'id': '41', 'type': 'string', 'children': [], 'value': "'comments'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'created'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'updated'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '49', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '62', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '64', 'type': 'if_statement', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '70', 'type': 'dictionary', 'children': ['71']},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '73', 'type': 'string', 'children': [], 'value': "'application/vnd.github.v3.full.text-match+json'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'search'"},{'id': '83', 'type': 'string', 'children': [], 'value': "'issues'"},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'SearchIterator'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89', '90', '91', '92', '93', '94']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'IssueSearchResult'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'headers'} | def search_issues(self, query, sort=None, order=None, per_page=None,
text_match=False, number=-1, etag=None):
params = {'q': query}
headers = {}
if sort in ('comments', 'created', 'updated'):
params['sort'] = sort
if order in ('asc', 'desc'):
params['order'] = order
if text_match:
headers = {
'Accept': 'application/vnd.github.v3.full.text-match+json'
}
url = self._build_url('search', 'issues')
return SearchIterator(number, url, IssueSearchResult, self, params,
etag, headers) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_users'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '20', 'type': 'unary_operator', 'children': ['21'], 'value': '-'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '33', '37', '51', '64', '74', '84']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '29', 'type': 'dictionary', 'children': ['30']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'tuple', 'children': ['41', '42', '43']},{'id': '41', 'type': 'string', 'children': [], 'value': "'followers'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'repositories'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'joined'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '49', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '62', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '64', 'type': 'if_statement', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'text_match'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '70', 'type': 'dictionary', 'children': ['71']},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '73', 'type': 'string', 'children': [], 'value': "'application/vnd.github.v3.full.text-match+json'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'search'"},{'id': '83', 'type': 'string', 'children': [], 'value': "'users'"},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'SearchIterator'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89', '90', '91', '92', '93', '94']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'UserSearchResult'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'headers'} | def search_users(self, query, sort=None, order=None, per_page=None,
text_match=False, number=-1, etag=None):
params = {'q': query}
headers = {}
if sort in ('followers', 'repositories', 'joined'):
params['sort'] = sort
if order in ('asc', 'desc'):
params['order'] = order
if text_match:
headers = {
'Accept': 'application/vnd.github.v3.full.text-match+json'
}
url = self._build_url('search', 'users')
return SearchIterator(number, url, UserSearchResult, self, params,
etag, headers) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_starred'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '26', '36', '43', '59']},{'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']},{'id': '20', 'type': 'relative_import', 'children': ['21', '22']},{'id': '21', 'type': 'import_prefix', 'children': []},{'id': '22', 'type': 'dotted_name', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'repos'},{'id': '24', 'type': 'dotted_name', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Repository'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '29', 'type': 'dictionary', 'children': ['30', '33']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_remove_none'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'starred_urlt'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '52', 'type': 'argument_list', 'children': ['53', '56']},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '64', 'type': 'argument_list', 'children': ['65', '69', '70', '71', '72']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'Repository'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_starred(self, sort=None, direction=None, number=-1, etag=None):
from .repos import Repository
params = {'sort': sort, 'direction': direction}
self._remove_none(params)
url = self.starred_urlt.expand(owner=None, repo=None)
return self._iter(int(number), url, Repository, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_forks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '10', 'type': 'unary_operator', 'children': ['11'], 'value': '-'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '30', '34', '49']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'forks'"},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '33', 'type': 'dictionary', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '41']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'tuple', 'children': ['38', '39', '40']},{'id': '38', 'type': 'string', 'children': [], 'value': "'newest'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'oldest'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'watchers'"},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '45', 'type': 'dictionary', 'children': ['46']},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '54', 'type': 'argument_list', 'children': ['55', '59', '60', '61', '62']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Repository'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_forks(self, sort='', number=-1, etag=None):
url = self._build_url('forks', base_url=self._api)
params = {}
if sort in ('newest', 'oldest', 'watchers'):
params = {'sort': sort}
return self._iter(int(number), url, Repository, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_issues'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '33']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'milestone'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'assignee'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mentioned'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '51', '61', '80', '87', '102']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'issues'"},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '54', 'type': 'dictionary', 'children': ['55', '58']},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "'assignee'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'assignee'},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'mentioned'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mentioned'},{'id': '61', 'type': 'if_statement', 'children': ['62', '73']},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '68'], 'value': 'or'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'in'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'milestone'},{'id': '65', 'type': 'tuple', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'milestone'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '78', 'type': 'string', 'children': [], 'value': "'milestone'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'milestone'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_remove_none'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'issue_params'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98', '99', '100', '101']},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '107', 'type': 'argument_list', 'children': ['108', '112', '113', '114', '115']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Issue'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_issues(self,
milestone=None,
state=None,
assignee=None,
mentioned=None,
labels=None,
sort=None,
direction=None,
since=None,
number=-1,
etag=None):
url = self._build_url('issues', base_url=self._api)
params = {'assignee': assignee, 'mentioned': mentioned}
if milestone in ('*', 'none') or isinstance(milestone, int):
params['milestone'] = milestone
self._remove_none(params)
params.update(
issue_params(None, state, labels, sort, direction,
since)
)
return self._iter(int(number), url, Issue, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_milestones'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '36', '55', '68', '97', '105']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'milestones'"},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'accepted'},{'id': '39', 'type': 'dictionary', 'children': ['40', '45', '50']},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'open'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'closed'"},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'due_date'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'completeness'"},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '52', 'type': 'tuple', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '58', 'type': 'dictionary', 'children': ['59', '62', '65']},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '68', 'type': 'for_statement', 'children': ['69', '72', '80']},{'id': '69', 'type': 'tuple_pattern', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'if_statement', 'children': ['82', '92']},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'and'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '86', 'type': '()', 'children': ['87']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'accepted'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'delete_statement', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '97', 'type': 'if_statement', 'children': ['98', '100']},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '110', 'type': 'argument_list', 'children': ['111', '115', '116', '117', '118']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'Milestone'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_milestones(self, state=None, sort=None, direction=None,
number=-1, etag=None):
url = self._build_url('milestones', base_url=self._api)
accepted = {'state': ('open', 'closed'),
'sort': ('due_date', 'completeness'),
'direction': ('asc', 'desc')}
params = {'state': state, 'sort': sort, 'direction': direction}
for (k, v) in list(params.items()):
if not (v and (v in accepted[k])):
del params[k]
if not params:
params = None
return self._iter(int(number), url, Milestone, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_pulls'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'string', 'children': [], 'value': "'created'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '19', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '22', 'type': 'unary_operator', 'children': ['23'], 'value': '-'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '42', '46', '70', '88', '95']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'pulls'"},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '45', 'type': 'dictionary', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '59']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'and'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '55'], 'value': 'in'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'tuple', 'children': ['56', '57', '58']},{'id': '56', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'open'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'closed'"},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '64', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79', '82', '85']},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_remove_none'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '100', 'type': 'argument_list', 'children': ['101', '105', '106', '107', '108']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'PullRequest'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'etag'} | def iter_pulls(self, state=None, head=None, base=None, sort='created',
direction='desc', number=-1, etag=None):
url = self._build_url('pulls', base_url=self._api)
params = {}
if state and state.lower() in ('all', 'open', 'closed'):
params['state'] = state.lower()
params.update(head=head, base=base, sort=sort, direction=direction)
self._remove_none(params)
return self._iter(int(number), url, PullRequest, params, etag) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_user_repos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '37']},{'id': '22', 'type': 'if_statement', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'gh'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'iter_user_repos'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '34', '35', '36']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'} | def iter_user_repos(login, type=None, sort=None, direction=None, number=-1,
etag=None):
if login:
return gh.iter_user_repos(login, type, sort, direction, number, etag)
return iter([]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_descendants'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '7', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '8', 'type': 'block', 'children': ['9', '23']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'node2content'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_cached_content'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20']},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'store_attr'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'container_type'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '30']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'traverse'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'if_statement', 'children': ['32', '38']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'is_leaf'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '49', 'type': 'lambda', 'children': ['50', '52']},{'id': '50', 'type': 'lambda_parameters', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'node2content'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'} | def sort_descendants(self, attr="name"):
node2content = self.get_cached_content(store_attr=attr, container_type=list)
for n in self.traverse():
if not n.is_leaf():
n.children.sort(key=lambda x: str(sorted(node2content[x]))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_backups'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '6', 'type': 'block', 'children': ['7', '11', '18', '26', '32', '192', '207']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'backups'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'coerce_location'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"Scanning %s for backups .."'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ensure_readable'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '47']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list_entries'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '47', 'type': 'block', 'children': ['48', '57']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'TIMESTAMP_PATTERN'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '57', 'type': 'if_statement', 'children': ['58', '59', '182']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '80', '89', '119']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'and'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'exclude_list'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '67', 'type': 'generator_expression', 'children': ['68', '75']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'exclude_list'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Excluded %s (it matched the exclude list)."'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '110']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'and'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'include_list'},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '97', 'type': 'generator_expression', 'children': ['98', '105']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'include_list'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"Excluded %s (it didn\'t match the include list)."'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'try_statement', 'children': ['122', '167']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'backups'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'Backup'},{'id': '131', 'type': 'argument_list', 'children': ['132', '145']},{'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '140', 'type': 'argument_list', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'list_splat', 'children': ['153']},{'id': '153', 'type': 'generator_expression', 'children': ['154', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '158', 'type': 'integer', 'children': [], 'value': '10'},{'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '167', 'type': 'except_clause', 'children': ['168', '172']},{'id': '168', 'type': 'as_pattern', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '170', 'type': 'as_pattern_target', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'notice'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181']},{'id': '179', 'type': 'string', 'children': [], 'value': '"Ignoring %s due to invalid date (%s)."'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': '"Failed to match time stamp in filename: %s"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '192', 'type': 'if_statement', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'backups'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202', '206']},{'id': '201', 'type': 'string', 'children': [], 'value': '"Found %i timestamped backups in %s."'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'backups'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '207', 'type': 'return_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'backups'} | def collect_backups(self, location):
backups = []
location = coerce_location(location)
logger.info("Scanning %s for backups ..", location)
location.ensure_readable()
for entry in natsort(location.context.list_entries(location.directory)):
match = TIMESTAMP_PATTERN.search(entry)
if match:
if self.exclude_list and any(fnmatch.fnmatch(entry, p) for p in self.exclude_list):
logger.verbose("Excluded %s (it matched the exclude list).", entry)
elif self.include_list and not any(fnmatch.fnmatch(entry, p) for p in self.include_list):
logger.verbose("Excluded %s (it didn't match the include list).", entry)
else:
try:
backups.append(Backup(
pathname=os.path.join(location.directory, entry),
timestamp=datetime.datetime(*(int(group, 10) for group in match.groups('0'))),
))
except ValueError as e:
logger.notice("Ignoring %s due to invalid date (%s).", entry, e)
else:
logger.debug("Failed to match time stamp in filename: %s", entry)
if backups:
logger.info("Found %i timestamped backups in %s.", len(backups), location)
return sorted(backups) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_bam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'paired_url'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rg_line'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '99', '156', '173', '190', '197', '204', '365']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19', '40', '87']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'run_bwa'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '23', 'type': 'call', 'children': ['24', '39']},{'id': '24', 'type': 'attribute', 'children': ['25', '38']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33', '34', '35']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'setup_and_run_bwakit'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'rg_line'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'paired_url'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'paired_url'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'encapsulate'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'elif_clause', 'children': ['41', '48']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'},{'id': '42', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'block', 'children': ['49', '60']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': '"Downloading BAM: %s"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '63', 'type': 'call', 'children': ['64', '86']},{'id': '64', 'type': 'attribute', 'children': ['65', '85']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '75', '80']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'download_url_job'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'string', 'children': [], 'value': "'toil.bam'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 's3_key_path'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ssec'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'file_size'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'encapsulate'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '98'], 'value': '%'},{'id': '94', 'type': 'concatenated_string', 'children': ['95', '96', '97']},{'id': '95', 'type': 'string', 'children': [], 'value': "'Could not generate BAM file for %s\\n'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'Provide a FASTQ URL and set run-bwa or '"},{'id': '97', 'type': 'string', 'children': [], 'value': "'provide a BAM URL that includes .bam extension.'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '99', 'type': 'if_statement', 'children': ['100', '108', '113']},{'id': '100', 'type': 'boolean_operator', 'children': ['101', '104'], 'value': 'and'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '104', 'type': 'not_operator', 'children': ['105']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'run_bwa'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'id': '114', 'type': 'block', 'children': ['115', '134']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorted_bam_disk'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '120', 'type': 'argument_list', 'children': ['121', '129']},{'id': '121', 'type': 'lambda', 'children': ['122', '124']},{'id': '122', 'type': 'lambda_parameters', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '*'},{'id': '125', 'type': 'integer', 'children': [], 'value': '3'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143', '148', '153']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'run_samtools_sort'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sorted_bam_disk'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'index_bam_disk'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '161', 'type': 'argument_list', 'children': ['162', '168']},{'id': '162', 'type': 'lambda', 'children': ['163', '165']},{'id': '163', 'type': 'lambda_parameters', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'index_bam'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182', '187']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'run_samtools_index'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'index_bam_disk'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'get_bam'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'index_bam'},{'id': '204', 'type': 'if_statement', 'children': ['205', '208', '347']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '208', 'type': 'block', 'children': ['209', '260', '267', '274', '283', '292', '306', '318', '340']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '212', 'type': 'call', 'children': ['213', '259']},{'id': '213', 'type': 'attribute', 'children': ['214', '258']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220', '225', '230', '233', '236', '239', '242', '245', '248', '253']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'run_gatk_preprocessing'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '224', 'type': 'argument_list', 'children': []},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'index_bam'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'genome_fasta'},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'genome_dict'},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'genome_fai'},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'g1k_indel'},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'mills'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'dbsnp'},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'xmx'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'encapsulate'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'index_bam'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'output_bam_promise'},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'integer', 'children': [], 'value': '0'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'output_bai_promise'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'integer', 'children': [], 'value': '1'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '295', 'type': 'call', 'children': ['296', '301']},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '301', 'type': 'argument_list', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'string', 'children': [], 'value': "'{}.preprocessed{}.bam'"},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '313', 'type': 'argument_list', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'output_bam'},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '325', 'type': 'argument_list', 'children': ['326', '327', '328', '334', '335']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'output_file_job'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'integer', 'children': [], 'value': '0'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 's3_key_path'},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'ssec'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'output_bam'},{'id': '347', 'type': 'else_clause', 'children': ['348']},{'id': '348', 'type': 'block', 'children': ['349', '357']},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'output_bam_promise'},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '356', 'type': 'argument_list', 'children': []},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'assignment', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'output_bai_promise'},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'index_bam'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '364', 'type': 'argument_list', 'children': []},{'id': '365', 'type': 'return_statement', 'children': ['366']},{'id': '366', 'type': 'expression_list', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'output_bam_promise'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'output_bai_promise'} | def prepare_bam(job, uuid, url, config, paired_url=None, rg_line=None):
if config.run_bwa:
get_bam = job.wrapJobFn(setup_and_run_bwakit,
uuid,
url,
rg_line,
config,
paired_url=paired_url).encapsulate()
elif '.bam' in url.lower():
job.fileStore.logToMaster("Downloading BAM: %s" % uuid)
get_bam = job.wrapJobFn(download_url_job,
url,
name='toil.bam',
s3_key_path=config.ssec,
disk=config.file_size).encapsulate()
else:
raise ValueError('Could not generate BAM file for %s\n'
'Provide a FASTQ URL and set run-bwa or '
'provide a BAM URL that includes .bam extension.' % uuid)
if config.sorted and not config.run_bwa:
sorted_bam = get_bam
else:
sorted_bam_disk = PromisedRequirement(lambda bam: 3 * bam.size, get_bam.rv())
sorted_bam = get_bam.addChildJobFn(run_samtools_sort,
get_bam.rv(),
cores=config.cores,
disk=sorted_bam_disk)
index_bam_disk = PromisedRequirement(lambda bam: bam.size, sorted_bam.rv())
index_bam = job.wrapJobFn(run_samtools_index, sorted_bam.rv(), disk=index_bam_disk)
job.addChild(get_bam)
sorted_bam.addChild(index_bam)
if config.preprocess:
preprocess = job.wrapJobFn(run_gatk_preprocessing,
sorted_bam.rv(),
index_bam.rv(),
config.genome_fasta,
config.genome_dict,
config.genome_fai,
config.g1k_indel,
config.mills,
config.dbsnp,
memory=config.xmx,
cores=config.cores).encapsulate()
sorted_bam.addChild(preprocess)
index_bam.addChild(preprocess)
output_bam_promise = preprocess.rv(0)
output_bai_promise = preprocess.rv(1)
output_dir = os.path.join(config.output_dir, uuid)
filename = '{}.preprocessed{}.bam'.format(uuid, config.suffix)
output_bam = job.wrapJobFn(output_file_job,
filename,
preprocess.rv(0),
output_dir,
s3_key_path=config.ssec)
preprocess.addChild(output_bam)
else:
output_bam_promise = sorted_bam.rv()
output_bai_promise = index_bam.rv()
return output_bam_promise, output_bai_promise |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alignment'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '8', 'type': 'block', 'children': ['9', '15', '25', '31', '37', '45', '59', '78', '92', '137', '168', '202', '236', '259', '283']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '14']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '30', 'type': 'string', 'children': [], 'value': "'output_dir'"},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key_path'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '36', 'type': 'string', 'children': [], 'value': "'ssec'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cpu_count'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'return_input_paths'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51', '52', '53', '54', '55', '56', '57', '58']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '52', 'type': 'string', 'children': [], 'value': "'ref.fa'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'ref.fa.amb'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'ref.fa.ann'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'ref.fa.bwt'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'ref.fa.pac'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'ref.fa.sa'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'ref.fa.fai'"},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'download_encrypted_file'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69', '70']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key_path'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '81', 'type': 'list', 'children': ['82', '83', '84', '85', '86'], 'value': "['docker', 'run', '--rm', '-v', '{}:/data'.format(work_dir)]"},{'id': '82', 'type': 'string', 'children': [], 'value': "'docker'"},{'id': '83', 'type': 'string', 'children': [], 'value': "'run'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'--rm'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'-v'"},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'{}:/data'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'bwa_command'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '117'], 'value': '+'},{'id': '96', 'type': 'list', 'children': ['97', '98', '99', '100', '106', '107', '111', '112', '116'], 'value': '["jvivian/bwa",\n "mem",\n "-R", "@RG\\tID:{0}\\tPL:Illumina\\tSM:{0}\\tLB:KapaHyper".format(uuid),\n "-T", str(0),\n "-t", str(cores),\n "/data/ref.fa"]'},{'id': '97', 'type': 'string', 'children': [], 'value': '"jvivian/bwa"'},{'id': '98', 'type': 'string', 'children': [], 'value': '"mem"'},{'id': '99', 'type': 'string', 'children': [], 'value': '"-R"'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"@RG\\tID:{0}\\tPL:Illumina\\tSM:{0}\\tLB:KapaHyper"'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '106', 'type': 'string', 'children': [], 'value': '"-T"'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'string', 'children': [], 'value': '"-t"'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '116', 'type': 'string', 'children': [], 'value': '"/data/ref.fa"'},{'id': '117', 'type': 'list_comprehension', 'children': ['118', '134']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'/data/'"},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'bamsort_command'},{'id': '140', 'type': 'list', 'children': ['141', '142', '143', '144', '145', '151', '157', '158', '159', '160'], 'value': '["jeltje/biobambam",\n "/usr/local/bin/bamsort",\n "inputformat=sam",\n "level=1",\n "inputthreads={}".format(cores),\n "outputthreads={}".format(cores),\n "calmdnm=1",\n "calmdnmrecompindetonly=1",\n "calmdnmreference=/data/ref.fa",\n "I=/data/{}".format(uuid + \'.sam\')]'},{'id': '141', 'type': 'string', 'children': [], 'value': '"jeltje/biobambam"'},{'id': '142', 'type': 'string', 'children': [], 'value': '"/usr/local/bin/bamsort"'},{'id': '143', 'type': 'string', 'children': [], 'value': '"inputformat=sam"'},{'id': '144', 'type': 'string', 'children': [], 'value': '"level=1"'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': '"inputthreads={}"'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': '"outputthreads={}"'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '157', 'type': 'string', 'children': [], 'value': '"calmdnm=1"'},{'id': '158', 'type': 'string', 'children': [], 'value': '"calmdnmrecompindetonly=1"'},{'id': '159', 'type': 'string', 'children': [], 'value': '"calmdnmreference=/data/ref.fa"'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': '"I=/data/{}"'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '+'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '167', 'type': 'string', 'children': [], 'value': "'.sam'"},{'id': '168', 'type': 'with_statement', 'children': ['169', '189']},{'id': '169', 'type': 'with_clause', 'children': ['170']},{'id': '170', 'type': 'with_item', 'children': ['171']},{'id': '171', 'type': 'as_pattern', 'children': ['172', '187']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '174', 'type': 'argument_list', 'children': ['175', '186']},{'id': '175', 'type': 'call', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '185', 'type': 'string', 'children': [], 'value': "'.sam'"},{'id': '186', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '187', 'type': 'as_pattern_target', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'f_out'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '+'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'bwa_command'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'f_out'},{'id': '202', 'type': 'with_statement', 'children': ['203', '223']},{'id': '203', 'type': 'with_clause', 'children': ['204']},{'id': '204', 'type': 'with_item', 'children': ['205']},{'id': '205', 'type': 'as_pattern', 'children': ['206', '221']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '208', 'type': 'argument_list', 'children': ['209', '220']},{'id': '209', 'type': 'call', 'children': ['210', '215']},{'id': '210', 'type': 'attribute', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '+'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '219', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '220', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '221', 'type': 'as_pattern_target', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'f_out'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233']},{'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'bamsort_command'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'f_out'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '241']},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '240', 'type': 'string', 'children': [], 'value': "'bam'"},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '254']},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '258', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '259', 'type': 'if_statement', 'children': ['260', '263']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '262', 'type': 'string', 'children': [], 'value': "'s3_dir'"},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271', '272', '273', '274', '277', '280']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'upload_bam_to_s3'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '276', 'type': 'integer', 'children': [], 'value': '32'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '279', 'type': 'string', 'children': [], 'value': "'20 G'"},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '282', 'type': 'string', 'children': [], 'value': "'30 G'"},{'id': '283', 'type': 'if_statement', 'children': ['284', '287']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '286', 'type': 'string', 'children': [], 'value': "'output_dir'"},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'move_to_output_dir'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '297']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '296', 'type': 'None', 'children': []},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '299', 'type': 'list', 'children': ['300'], 'value': "[uuid + '.bam']"},{'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '+'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '302', 'type': 'string', 'children': [], 'value': "'.bam'"} | def alignment(job, ids, input_args, sample):
uuid, urls = sample
work_dir = job.fileStore.getLocalTempDir()
output_dir = input_args['output_dir']
key_path = input_args['ssec']
cores = multiprocessing.cpu_count()
return_input_paths(job, work_dir, ids, 'ref.fa', 'ref.fa.amb', 'ref.fa.ann',
'ref.fa.bwt', 'ref.fa.pac', 'ref.fa.sa', 'ref.fa.fai')
for url in urls:
download_encrypted_file(work_dir, url, key_path, os.path.basename(url))
docker_cmd = ['docker', 'run', '--rm', '-v', '{}:/data'.format(work_dir)]
bwa_command = ["jvivian/bwa",
"mem",
"-R", "@RG\tID:{0}\tPL:Illumina\tSM:{0}\tLB:KapaHyper".format(uuid),
"-T", str(0),
"-t", str(cores),
"/data/ref.fa"] + [os.path.join('/data/', os.path.basename(x)) for x in urls]
bamsort_command = ["jeltje/biobambam",
"/usr/local/bin/bamsort",
"inputformat=sam",
"level=1",
"inputthreads={}".format(cores),
"outputthreads={}".format(cores),
"calmdnm=1",
"calmdnmrecompindetonly=1",
"calmdnmreference=/data/ref.fa",
"I=/data/{}".format(uuid + '.sam')]
with open(os.path.join(work_dir, uuid + '.sam'), 'w') as f_out:
subprocess.check_call(docker_cmd + bwa_command, stdout=f_out)
with open(os.path.join(work_dir, uuid + '.bam'), 'w') as f_out:
subprocess.check_call(docker_cmd + bamsort_command, stdout=f_out)
ids['bam'] = job.fileStore.writeGlobalFile(os.path.join(work_dir, uuid + '.bam'))
if input_args['s3_dir']:
job.addChildJobFn(upload_bam_to_s3, ids, input_args, sample, cores=32, memory='20 G', disk='30 G')
if input_args['output_dir']:
move_to_output_dir(work_dir, output_dir, uuid=None, files=[uuid + '.bam']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bamsort_and_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '6', 'type': 'block', 'children': ['7', '13', '23', '29', '39', '51', '64', '73', '89', '105', '118', '139', '156', '173']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '28', 'type': 'string', 'children': [], 'value': "'sudo'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'rg_alignments'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'return_input_paths'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '38']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '38', 'type': 'string', 'children': [], 'value': "'rg_alignments.bam'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '50', 'type': 'string', 'children': [], 'value': "'sorted.bam'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cmd1'},{'id': '54', 'type': 'list', 'children': ['55', '56', '60'], 'value': "['sort', docker_path(rg_alignments), docker_path('sorted')]"},{'id': '55', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'docker_path'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rg_alignments'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'docker_path'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "'sorted'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cmd2'},{'id': '67', 'type': 'list', 'children': ['68', '69'], 'value': "['index', docker_path(output)]"},{'id': '68', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'docker_path'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '76', 'type': 'argument_list', 'children': ['77', '80', '83', '86']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '79', 'type': 'string', 'children': [], 'value': "'quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e'"},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'cmd1'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96', '99', '102']},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '95', 'type': 'string', 'children': [], 'value': "'quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e'"},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'cmd2'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '109', 'type': 'string', 'children': [], 'value': "'sorted.bam'"},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '122', 'type': 'string', 'children': [], 'value': "'sorted.bam.bai'"},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '138', 'type': 'string', 'children': [], 'value': "'sorted.bam.bai'"},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'output_ids'},{'id': '142', 'type': 'call', 'children': ['143', '155']},{'id': '143', 'type': 'attribute', 'children': ['144', '154']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sort_bam_by_reference'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '153', 'type': 'string', 'children': [], 'value': "'50 G'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'rseq_id'},{'id': '159', 'type': 'call', 'children': ['160', '172']},{'id': '160', 'type': 'attribute', 'children': ['161', '171']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'rseq_qc'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '170', 'type': 'string', 'children': [], 'value': "'20 G'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'expression_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'rseq_id'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'output_ids'} | def bamsort_and_index(job, job_vars):
input_args, ids = job_vars
work_dir = job.fileStore.getLocalTempDir()
sudo = input_args['sudo']
rg_alignments = return_input_paths(job, work_dir, ids, 'rg_alignments.bam')
output = os.path.join(work_dir, 'sorted.bam')
cmd1 = ['sort', docker_path(rg_alignments), docker_path('sorted')]
cmd2 = ['index', docker_path(output)]
docker_call(tool='quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e',
tool_parameters=cmd1, work_dir=work_dir, sudo=sudo)
docker_call(tool='quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e',
tool_parameters=cmd2, work_dir=work_dir, sudo=sudo)
ids['sorted.bam'] = job.fileStore.writeGlobalFile(output)
ids['sorted.bam.bai'] = job.fileStore.writeGlobalFile(os.path.join(work_dir, 'sorted.bam.bai'))
output_ids = job.addChildJobFn(sort_bam_by_reference, job_vars, disk='50 G').rv()
rseq_id = job.addChildJobFn(rseq_qc, job_vars, disk='20 G').rv()
return rseq_id, output_ids |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_bam_by_reference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '6', 'type': 'block', 'children': ['7', '13', '23', '36', '48', '52', '72', '113', '119', '177', '195', '205', '212', '225', '245', '262']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'input_args'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_bai'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'return_input_paths'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '34', '35']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '34', 'type': 'string', 'children': [], 'value': "'sorted.bam'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'sorted.bam.bai'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '47', 'type': 'string', 'children': [], 'value': "'sort_by_ref.bam'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ref_seqs'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '55', 'type': 'attribute', 'children': ['56', '71']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '60', 'type': 'argument_list', 'children': ['61', '66']},{'id': '61', 'type': 'list', 'children': ['62', '63', '64', '65'], 'value': '["samtools", "view", "-H", sorted_bam]'},{'id': '62', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '63', 'type': 'string', 'children': [], 'value': '"view"'},{'id': '64', 'type': 'string', 'children': [], 'value': '"-H"'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'if_statement', 'children': ['77', '83']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': '"@SQ"'},{'id': '83', 'type': 'block', 'children': ['84', '93', '106']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '96', 'type': 'subscript', 'children': ['97', '105']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '":"'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ref_seqs'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'for_statement', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ref_seqs'},{'id': '122', 'type': 'block', 'children': ['123', '132', '151', '165']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'cmd_view'},{'id': '126', 'type': 'list', 'children': ['127', '128', '129', '130', '131'], 'value': '["samtools", "view", "-b", sorted_bam, chrom]'},{'id': '127', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '128', 'type': 'string', 'children': [], 'value': '"view"'},{'id': '129', 'type': 'string', 'children': [], 'value': '"-b"'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sorted_bam'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cmd_sort'},{'id': '135', 'type': 'list', 'children': ['136', '137', '138', '139', '140', '141', '142'], 'value': '["samtools", "sort", "-m", "3000000000", "-n", "-", os.path.join(work_dir, chrom)]'},{'id': '136', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '137', 'type': 'string', 'children': [], 'value': '"sort"'},{'id': '138', 'type': 'string', 'children': [], 'value': '"-m"'},{'id': '139', 'type': 'string', 'children': [], 'value': '"3000000000"'},{'id': '140', 'type': 'string', 'children': [], 'value': '"-n"'},{'id': '141', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'cmd_view'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cmd_sort'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'sorted_files'},{'id': '180', 'type': 'list_comprehension', 'children': ['181', '192']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '191'], 'value': '+'},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '191', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '192', 'type': 'for_in_clause', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ref_seqs'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '204'], 'value': '+'},{'id': '199', 'type': 'list', 'children': ['200', '201', '202', '203'], 'value': '["samtools", "cat", "-o", output]'},{'id': '200', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '201', 'type': 'string', 'children': [], 'value': '"cat"'},{'id': '202', 'type': 'string', 'children': [], 'value': '"-o"'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sorted_files'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '216', 'type': 'string', 'children': [], 'value': "'sort_by_ref.bam'"},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'rsem_id'},{'id': '228', 'type': 'call', 'children': ['229', '244']},{'id': '229', 'type': 'attribute', 'children': ['230', '243']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '240']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'transcriptome'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '239', 'type': 'string', 'children': [], 'value': "'30 G'"},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '242', 'type': 'string', 'children': [], 'value': "'30 G'"},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'exon_id'},{'id': '248', 'type': 'call', 'children': ['249', '261']},{'id': '249', 'type': 'attribute', 'children': ['250', '260']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256', '257']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'exon_count'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'job_vars'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '259', 'type': 'string', 'children': [], 'value': "'30 G'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'return_statement', 'children': ['263']},{'id': '263', 'type': 'expression_list', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'exon_id'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'rsem_id'} | def sort_bam_by_reference(job, job_vars):
input_args, ids = job_vars
work_dir = job.fileStore.getLocalTempDir()
sorted_bam, sorted_bai = return_input_paths(job, work_dir, ids, 'sorted.bam', 'sorted.bam.bai')
output = os.path.join(work_dir, 'sort_by_ref.bam')
ref_seqs = []
handle = subprocess.Popen(["samtools", "view", "-H", sorted_bam], stdout=subprocess.PIPE).stdout
for line in handle:
if line.startswith("@SQ"):
tmp = line.split("\t")
chrom = tmp[1].split(":")[1]
ref_seqs.append(chrom)
handle.close()
for chrom in ref_seqs:
cmd_view = ["samtools", "view", "-b", sorted_bam, chrom]
cmd_sort = ["samtools", "sort", "-m", "3000000000", "-n", "-", os.path.join(work_dir, chrom)]
p1 = subprocess.Popen(cmd_view, stdout=subprocess.PIPE)
subprocess.check_call(cmd_sort, stdin=p1.stdout)
sorted_files = [os.path.join(work_dir, chrom) + '.bam' for chrom in ref_seqs]
cmd = ["samtools", "cat", "-o", output] + sorted_files
subprocess.check_call(cmd)
ids['sort_by_ref.bam'] = job.fileStore.writeGlobalFile(output)
rsem_id = job.addChildJobFn(transcriptome, job_vars, disk='30 G', memory='30 G').rv()
exon_id = job.addChildJobFn(exon_count, job_vars, disk='30 G').rv()
return exon_id, rsem_id |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '11', '20', '28', '121']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'build_parser'},{'id': '10', 'type': 'argument_list', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Runner'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'addToilOptions'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '31', 'type': 'dictionary', 'children': ['32', '37', '42', '47', '52', '57', '62', '67', '72', '77', '82', '87', '92', '97', '102', '107', '112', '115', '118']},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'config_fastq'"},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'config_fastq'},{'id': '42', 'type': 'pair', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'input'"},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'unc.bed'"},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'unc'},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'hg19.transcripts.fa'"},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fasta'},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'composite_exons.bed'"},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'composite_exons'},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'normalize.pl'"},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '67', 'type': 'pair', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'output_dir'"},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'rsem_ref.zip'"},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rsem_ref'},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'chromosomes.zip'"},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'ebwt.zip'"},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ebwt'},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'ssec'"},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ssec'},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'s3_dir'"},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 's3_dir'},{'id': '97', 'type': 'pair', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'sudo'"},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '102', 'type': 'pair', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'single_end_reads'"},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'single_end_reads'},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'upload_bam_to_s3'"},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'upload_bam_to_s3'},{'id': '112', 'type': 'pair', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'pair', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'sample.tar'"},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'cpu_count'"},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Runner'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'startToil'},{'id': '128', 'type': 'argument_list', 'children': ['129', '136']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'download_shared_files'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'} | def main():
parser = build_parser()
Job.Runner.addToilOptions(parser)
args = parser.parse_args()
inputs = {'config': args.config,
'config_fastq': args.config_fastq,
'input': args.input,
'unc.bed': args.unc,
'hg19.transcripts.fa': args.fasta,
'composite_exons.bed': args.composite_exons,
'normalize.pl': args.normalize,
'output_dir': args.output_dir,
'rsem_ref.zip': args.rsem_ref,
'chromosomes.zip': args.chromosomes,
'ebwt.zip': args.ebwt,
'ssec': args.ssec,
's3_dir': args.s3_dir,
'sudo': args.sudo,
'single_end_reads': args.single_end_reads,
'upload_bam_to_s3': args.upload_bam_to_s3,
'uuid': None,
'sample.tar': None,
'cpu_count': None}
Job.Runner.startToil(Job.wrapJobFn(download_shared_files, inputs), args) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fourier_series'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pars'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'block', 'children': ['9', '15', '77']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pars'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '21']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'augmented_assignment', 'children': ['24', '25'], 'value': '+='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '51', '52'], 'value': '+'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '34'], 'value': '*'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pars'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '33'], 'value': '+'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '*'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'integer', 'children': [], 'value': '2'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sin'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '50'], 'value': '*'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '46'], 'value': '*'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '*'},{'id': '42', 'type': 'integer', 'children': [], 'value': '2'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '60'], 'value': '*'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pars'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '+'},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '*'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '58', 'type': 'integer', 'children': [], 'value': '2'},{'id': '59', 'type': 'integer', 'children': [], 'value': '2'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'cos'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '76'], 'value': '*'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '72'], 'value': '*'},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '*'},{'id': '68', 'type': 'integer', 'children': [], 'value': '2'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '72', 'type': '()', 'children': ['73']},{'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sum'} | def fourier_series(self, pars, x, order):
sum = pars[0]
for i in range(order):
sum += pars[i * 2 + 1] * np.sin(2 * np.pi * (i + 1) * x) \
+ pars[i * 2 + 2] * np.cos(2 * np.pi * (i + 1) * x)
return sum |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'slope_percentile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mag'},{'id': '7', 'type': 'block', 'children': ['8', '27', '46', '57', '63', '69', '75', '85', '95']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'date_diff'},{'id': '11', 'type': 'binary_operator', 'children': ['12', '17'], 'value': '-'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '14', 'type': 'slice', 'children': ['15', '16']},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'colon', 'children': []},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '19', 'type': 'slice', 'children': ['20', '21']},{'id': '20', 'type': 'colon', 'children': []},{'id': '21', 'type': 'binary_operator', 'children': ['22', '26'], 'value': '-'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mag_diff'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '36'], 'value': '-'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mag'},{'id': '33', 'type': 'slice', 'children': ['34', '35']},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mag'},{'id': '38', 'type': 'slice', 'children': ['39', '40']},{'id': '39', 'type': 'colon', 'children': []},{'id': '40', 'type': 'binary_operator', 'children': ['41', '45'], 'value': '-'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mag'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '!='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mag_diff'},{'id': '56', 'type': 'float', 'children': [], 'value': '0.'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'date_diff'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'date_diff'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mag_diff'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mag_diff'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'slope'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '/'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'date_diff'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mag_diff'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'percentile_10'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'slope'},{'id': '84', 'type': 'float', 'children': [], 'value': '10.'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'percentile_90'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'slope'},{'id': '94', 'type': 'float', 'children': [], 'value': '90.'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'expression_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'percentile_10'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'percentile_90'} | def slope_percentile(self, date, mag):
date_diff = date[1:] - date[:len(date) - 1]
mag_diff = mag[1:] - mag[:len(mag) - 1]
index = np.where(mag_diff != 0.)
date_diff = date_diff[index]
mag_diff = mag_diff[index]
slope = date_diff / mag_diff
percentile_10 = np.percentile(slope, 10.)
percentile_90 = np.percentile(slope, 90.)
return percentile_10, percentile_90 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'number_aware_alphabetical_cmp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'str1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'str2'},{'id': '6', 'type': 'block', 'children': ['7', '55', '65', '75', '89', '93', '125', '152']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'flatten_tokens'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '11', 'type': 'block', 'children': ['12', '16', '53']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '38']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40', '46']},{'id': '40', 'type': 'assert_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'flatten_tokens'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tokenize_by_number'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'str1'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'flatten_tokens'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tokenize_by_number'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'str2'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '80', 'type': 'argument_list', 'children': ['81', '85']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'while_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '<'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '97', 'type': 'block', 'children': ['98', '121']},{'id': '98', 'type': 'if_statement', 'children': ['99', '106', '110']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '<'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'elif_clause', 'children': ['111', '118']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '>'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'augmented_assignment', 'children': ['123', '124'], 'value': '+='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'if_statement', 'children': ['126', '135', '139']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '<'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'elif_clause', 'children': ['140', '149']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '145'], 'value': '>'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'seq1'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'seq2'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'} | def number_aware_alphabetical_cmp(str1, str2):
def flatten_tokens(tokens):
l = []
for token in tokens:
if isinstance(token, str):
for char in token:
l.append(char)
else:
assert isinstance(token, float)
l.append(token)
return l
seq1 = flatten_tokens(tokenize_by_number(str1))
seq2 = flatten_tokens(tokenize_by_number(str2))
l = min(len(seq1),len(seq2))
i = 0
while i < l:
if seq1[i] < seq2[i]:
return -1
elif seq1[i] > seq2[i]:
return 1
i += 1
if len(seq1) < len(seq2):
return -1
elif len(seq1) > len(seq2):
return 1
return 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_members'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tup'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '6', 'type': 'block', 'children': ['7', '30', '53']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'scalars'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '14', 'type': 'argument_list', 'children': ['15', '29']},{'id': '15', 'type': 'lambda', 'children': ['16', '18']},{'id': '16', 'type': 'lambda_parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_tuple_node'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '28']},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tup'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'unbound'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'bound'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '37', 'type': 'argument_list', 'children': ['38', '52']},{'id': '38', 'type': 'lambda', 'children': ['39', '41']},{'id': '39', 'type': 'lambda_parameters', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'call', 'children': ['42', '51']},{'id': '42', 'type': 'attribute', 'children': ['43', '50']},{'id': '43', 'type': 'attribute', 'children': ['44', '49']},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tup'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'is_unbound'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'scalars'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'expression_list', 'children': ['55', '64']},{'id': '55', 'type': 'binary_operator', 'children': ['56', '60'], 'value': '+'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'usorted'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'unbound'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'usorted'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'bound'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'usorted'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tuples'} | def sort_members(tup, names):
scalars, tuples = partition(lambda x: not is_tuple_node(tup.member[x].value), names)
unbound, bound = partition(lambda x: tup.member[x].value.is_unbound(), scalars)
return usorted(unbound) + usorted(bound), usorted(tuples) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_schemas'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'schemas'},{'id': '5', 'type': 'block', 'children': ['6', '60']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'keyfun'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '10', 'type': 'block', 'children': ['11', '24']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'call', 'children': ['15', '23']},{'id': '15', 'type': 'attribute', 'children': ['16', '22']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SQL_SCHEMA_REGEXP'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'tuple', 'children': ['26', '32', '35', '46', '54']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'conditional_expression', 'children': ['36', '42', '45'], 'value': 'if'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'integer', 'children': [], 'value': '2'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'integer', 'children': [], 'value': '2'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'conditional_expression', 'children': ['47', '50', '53'], 'value': 'if'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'integer', 'children': [], 'value': '3'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'integer', 'children': [], 'value': '3'},{'id': '53', 'type': 'string', 'children': [], 'value': "'zzz'"},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'integer', 'children': [], 'value': '4'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'schemas'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'keyfun'} | def sort_schemas(schemas):
def keyfun(v):
x = SQL_SCHEMA_REGEXP.match(v).groups()
return (int(x[0]), x[1], int(x[2]) if x[2] else None,
x[3] if x[3] else 'zzz', int(x[4]))
return sorted(schemas, key=keyfun) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmp_func'},{'id': '6', 'type': 'block', 'children': ['7', '13']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '25']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'walk_dom'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'elements_only'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '32']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'prev_sib'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'previousSibling'},{'id': '32', 'type': 'while_statement', 'children': ['33', '42']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'prev_sib'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '41'], 'value': '=='},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cmp_func'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'prev_sib'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'block', 'children': ['43', '53']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parentNode'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'insertBefore'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'prev_sib'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'prev_sib'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'previousSibling'} | def sort_nodes(dom, cmp_func):
dom.normalize()
for node in list(walk_dom(dom, elements_only=True)):
prev_sib = node.previousSibling
while prev_sib and cmp_func(prev_sib, node) == 1:
node.parentNode.insertBefore(node, prev_sib)
prev_sib = node.previousSibling |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'currentdir'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '7', 'type': 'block', 'children': ['8', '99']},{'id': '8', 'type': 'if_statement', 'children': ['9', '14']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_currentdir'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '23']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'directories'},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'availabledirs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '23', 'type': 'if_statement', 'children': ['24', '30', '39', '54']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '=='},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'directories'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'currentdir'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'directories'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'elif_clause', 'children': ['40', '45']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'in'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'DEFAULTDIR'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'directories'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'currentdir'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'DEFAULTDIR'},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56', '65', '76', '91']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'concatenated_string', 'children': ['61', '62', '63', '64']},{'id': '61', 'type': 'string', 'children': [], 'value': "f'The current working directory of the '"},{'id': '62', 'type': 'string', 'children': [], 'value': "f'{objecttools.classname(self)} object '"},{'id': '63', 'type': 'string', 'children': [], 'value': "f'has not been defined manually and cannot '"},{'id': '64', 'type': 'string', 'children': [], 'value': "f'be determined automatically:'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '68']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'directories'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'raise_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'concatenated_string', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "f'{prefix} `{objecttools.repr_(self.basepath)}` '"},{'id': '75', 'type': 'string', 'children': [], 'value': "f'does not contain any available directories.'"},{'id': '76', 'type': 'if_statement', 'children': ['77', '82']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '81'], 'value': 'is'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'DEFAULTDIR'},{'id': '81', 'type': 'None', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'concatenated_string', 'children': ['88', '89', '90']},{'id': '88', 'type': 'string', 'children': [], 'value': "f'{prefix} `{objecttools.repr_(self.basepath)}` '"},{'id': '89', 'type': 'string', 'children': [], 'value': "f'does contain multiple available directories '"},{'id': '90', 'type': 'string', 'children': [], 'value': "f'({objecttools.enumeration(directories)}).'"},{'id': '91', 'type': 'raise_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'concatenated_string', 'children': ['96', '97', '98']},{'id': '96', 'type': 'string', 'children': [], 'value': "f'{prefix} The default directory ({self.DEFAULTDIR}) '"},{'id': '97', 'type': 'string', 'children': [], 'value': "f'is not among the available directories '"},{'id': '98', 'type': 'string', 'children': [], 'value': "f'({objecttools.enumeration(directories)}).'"},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_currentdir'} | def currentdir(self) -> str:
if self._currentdir is None:
directories = self.availabledirs.folders
if len(directories) == 1:
self.currentdir = directories[0]
elif self.DEFAULTDIR in directories:
self.currentdir = self.DEFAULTDIR
else:
prefix = (f'The current working directory of the '
f'{objecttools.classname(self)} object '
f'has not been defined manually and cannot '
f'be determined automatically:')
if not directories:
raise RuntimeError(
f'{prefix} `{objecttools.repr_(self.basepath)}` '
f'does not contain any available directories.')
if self.DEFAULTDIR is None:
raise RuntimeError(
f'{prefix} `{objecttools.repr_(self.basepath)}` '
f'does contain multiple available directories '
f'({objecttools.enumeration(directories)}).')
raise RuntimeError(
f'{prefix} The default directory ({self.DEFAULTDIR}) '
f'is not among the available directories '
f'({objecttools.enumeration(directories)}).')
return self._currentdir |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zip_currentdir'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '48']},{'id': '8', 'type': 'with_statement', 'children': ['9', '21']},{'id': '9', 'type': 'with_clause', 'children': ['10']},{'id': '10', 'type': 'with_item', 'children': ['11']},{'id': '11', 'type': 'as_pattern', 'children': ['12', '19']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "f'{self.currentpath}.zip'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '19', 'type': 'as_pattern_target', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'zipfile_'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'for_statement', 'children': ['23', '26', '35']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '28', 'type': 'argument_list', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filepaths'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'zipfile_'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45']},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'arcname'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '48', 'type': 'delete_statement', 'children': ['49']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'currentdir'} | def zip_currentdir(self) -> None:
with zipfile.ZipFile(f'{self.currentpath}.zip', 'w') as zipfile_:
for filepath, filename in zip(self.filepaths, self.filenames):
zipfile_.write(filename=filepath, arcname=filename)
del self.currentdir |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keywords'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '8', 'type': 'type_parameter', 'children': ['9']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'generator_expression', 'children': ['16', '17', '20', '25']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '25', 'type': 'if_clause', 'children': ['26']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'not'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_shadowed_keywords'} | def keywords(self) -> Set[str]:
return set(keyword for device in self
for keyword in device.keywords if
keyword not in self._shadowed_keywords) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variables'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '8', 'type': 'type_parameter', 'children': ['9']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'block', 'children': ['12', '24', '39']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15', '21']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'generic_type', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '18', 'type': 'type_parameter', 'children': ['19']},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '__connections'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'variables'} | def variables(self) -> Set[str]:
variables: Set[str] = set()
for connection in self.__connections:
variables.update(connection.variables)
return variables |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'model2subs2seqs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '8', 'type': 'type_parameter', 'children': ['9', '11']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'generic_type', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '14', 'type': 'type_parameter', 'children': ['15', '17']},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'generic_type', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '20', 'type': 'type_parameter', 'children': ['21']},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'block', 'children': ['24', '39', '100']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'model2subs2seqs'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'lambda', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '47']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'sequences'"},{'id': '47', 'type': 'block', 'children': ['48', '57', '63']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '=='},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '60', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'continue_statement', 'children': []},{'id': '63', 'type': 'for_statement', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '66', 'type': 'block', 'children': ['67', '76']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'group_name'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '79', 'type': 'block', 'children': ['80', '89']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'seq_name'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '98']},{'id': '91', 'type': 'attribute', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'model2subs2seqs'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'group_name'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'seq_name'},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'model2subs2seqs'} | def model2subs2seqs(self) -> Dict[str, Dict[str, List[str]]]:
model2subs2seqs = collections.defaultdict(
lambda: collections.defaultdict(list))
for model in self.find('sequences'):
model_name = strip(model.tag)
if model_name == 'node':
continue
for group in model:
group_name = strip(group.tag)
for sequence in group:
seq_name = strip(sequence.tag)
model2subs2seqs[model_name][group_name].append(seq_name)
return model2subs2seqs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'subs2seqs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '8', 'type': 'type_parameter', 'children': ['9', '11']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'generic_type', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '14', 'type': 'type_parameter', 'children': ['15']},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'block', 'children': ['18', '27', '40', '63']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'subs2seqs'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '32', 'type': 'argument_list', 'children': ['33', '39']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'sequences'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'subs2seqs'},{'id': '54', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'subs2seqs'} | def subs2seqs(self) -> Dict[str, List[str]]:
subs2seqs = collections.defaultdict(list)
nodes = find(self.find('sequences'), 'node')
if nodes is not None:
for seq in nodes:
subs2seqs['node'].append(strip(seq.tag))
return subs2seqs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_modelnames'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'type', 'children': ['5']},{'id': '5', 'type': 'generic_type', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '7', 'type': 'type_parameter', 'children': ['8']},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '14', 'type': 'generator_expression', 'children': ['15', '26', '38']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '25']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '__path__'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'if_clause', 'children': ['39']},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '47'], 'value': 'and'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '47', 'type': '()', 'children': ['48']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '!='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '50', 'type': 'string', 'children': [], 'value': "'__init__.py'"} | def get_modelnames() -> List[str]:
return sorted(str(fn.split('.')[0])
for fn in os.listdir(models.__path__[0])
if (fn.endswith('.py') and (fn != '__init__.py'))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'toys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '8', 'type': 'type_parameter', 'children': ['9', '13']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'timetools'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'TOY'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'ellipsis', 'children': [], 'value': '...'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '19', 'type': 'generator_expression', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'toy'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '25']},{'id': '22', 'type': 'tuple_pattern', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'toy'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'} | def toys(self) -> Tuple[timetools.TOY, ...]:
return tuple(toy for (toy, _) in self) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_variables'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'insert_variables'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18', '21']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'device2target'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'targetspecs'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'selections'} | def collect_variables(self, selections) -> None:
self.insert_variables(self.device2target, self.targetspecs, selections) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_variables'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'collect_variables'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'insert_variables'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27', '30']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'device2base'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'basespecs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'selections'} | def collect_variables(self, selections) -> None:
super().collect_variables(selections)
self.insert_variables(self.device2base, self.basespecs, selections) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_controls'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parameterstep'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'simulationstep'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'auxfiler'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'save_controls'},{'id': '22', 'type': 'argument_list', 'children': ['23', '26', '29']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'parameterstep'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parameterstep'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'simulationstep'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'simulationstep'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'auxfiler'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'auxfiler'} | def save_controls(self, parameterstep=None, simulationstep=None,
auxfiler=None):
self.elements.save_controls(parameterstep=parameterstep,
simulationstep=simulationstep,
auxfiler=auxfiler) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variables'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '28']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'variables'} | def variables(self):
variables = set([])
for node in self.nodes:
variables.add(node.variable)
return sorted(variables) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_timeplaceentries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'timeentry'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'placeentry'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'generic_type', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '10', 'type': 'type_parameter', 'children': ['11', '13']},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '15', 'type': 'block', 'children': ['16', '25']},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_timeaxis'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'expression_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'placeentry'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'timeentry'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'expression_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'timeentry'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'placeentry'} | def sort_timeplaceentries(self, timeentry, placeentry) -> Tuple[Any, Any]:
if self._timeaxis:
return placeentry, timeentry
return timeentry, placeentry |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_io_example_1'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'type', 'children': ['5']},{'id': '5', 'type': 'generic_type', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '7', 'type': 'type_parameter', 'children': ['8', '12']},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'devicetools'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Nodes'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'devicetools'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Elements'},{'id': '16', 'type': 'block', 'children': ['17', '22', '28', '35', '45', '92', '103', '116', '123', '133', '141', '151', '161', '171', '180', '188', '197', '206', '215', '222', '268', '306', '367', '370', '374', '418', '434']},{'id': '17', 'type': 'import_from_statement', 'children': ['18', '20']},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'TestIO'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'TestIO'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'import_from_statement', 'children': ['29', '33']},{'id': '29', 'type': 'dotted_name', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'filetools'},{'id': '33', 'type': 'dotted_name', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'SequenceManager'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sequencemanager'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'SequenceManager'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'with_statement', 'children': ['46', '51']},{'id': '46', 'type': 'with_clause', 'children': ['47']},{'id': '47', 'type': 'with_item', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'TestIO'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'block', 'children': ['52', '62', '72', '82']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sequencemanager'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'inputdirpath'},{'id': '61', 'type': 'string', 'children': [], 'value': "'inputpath'"},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '71']},{'id': '64', 'type': 'attribute', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sequencemanager'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fluxdirpath'},{'id': '71', 'type': 'string', 'children': [], 'value': "'outputpath'"},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '81']},{'id': '74', 'type': 'attribute', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sequencemanager'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'statedirpath'},{'id': '81', 'type': 'string', 'children': [], 'value': "'outputpath'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '91']},{'id': '84', 'type': 'attribute', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sequencemanager'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'nodedirpath'},{'id': '91', 'type': 'string', 'children': [], 'value': "'nodepath'"},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'timegrids'},{'id': '99', 'type': 'expression_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'string', 'children': [], 'value': "'2000-01-01'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'2000-01-05'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'1d'"},{'id': '103', 'type': 'import_from_statement', 'children': ['104', '106', '108', '110', '112', '114']},{'id': '104', 'type': 'dotted_name', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '106', 'type': 'dotted_name', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '108', 'type': 'dotted_name', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Nodes'},{'id': '110', 'type': 'dotted_name', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '112', 'type': 'dotted_name', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Elements'},{'id': '114', 'type': 'dotted_name', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'prepare_model'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'node1'"},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'node2'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'node2'"},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '132', 'type': 'string', 'children': [], 'value': "'T'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'Nodes'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'node2'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'element1'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'element1'"},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'outlets'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'element2'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "'element2'"},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'outlets'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'element3'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'element3'"},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'outlets'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Elements'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178', '179']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'element1'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'element2'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'element3'},{'id': '180', 'type': 'import_from_statement', 'children': ['181', '184', '186']},{'id': '181', 'type': 'dotted_name', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '184', 'type': 'dotted_name', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'lland_v1'},{'id': '186', 'type': 'dotted_name', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'lland_v2'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'element1'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'prepare_model'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'lland_v1'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'element2'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'prepare_model'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'lland_v1'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'element3'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'prepare_model'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'lland_v2'},{'id': '215', 'type': 'import_from_statement', 'children': ['216', '220']},{'id': '216', 'type': 'dotted_name', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'lland'},{'id': '220', 'type': 'dotted_name', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ACKER'},{'id': '222', 'type': 'for_statement', 'children': ['223', '226', '230']},{'id': '223', 'type': 'pattern_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '230', 'type': 'block', 'children': ['231', '239', '250', '259']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '234', 'type': 'attribute', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '246']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'nhru'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '+'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '249', 'type': 'integer', 'children': [], 'value': '1'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '257']},{'id': '252', 'type': 'attribute', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'lnk'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ACKER'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'derived'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'absfhru'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'float', 'children': [], 'value': '10.0'},{'id': '268', 'type': 'with_statement', 'children': ['269', '281']},{'id': '269', 'type': 'with_clause', 'children': ['270']},{'id': '270', 'type': 'with_item', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '279']},{'id': '272', 'type': 'attribute', 'children': ['273', '278']},{'id': '273', 'type': 'attribute', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'hydpy'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'pub'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'printprogress'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'False', 'children': []},{'id': '281', 'type': 'block', 'children': ['282', '288', '294', '300']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'prepare_simseries'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'prepare_inputseries'},{'id': '293', 'type': 'argument_list', 'children': []},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'prepare_fluxseries'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'prepare_stateseries'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'function_definition', 'children': ['307', '308', '311']},{'id': '307', 'type': 'function_name', 'children': [], 'value': 'init_values'},{'id': '308', 'type': 'parameters', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'value1_'},{'id': '311', 'type': 'block', 'children': ['312', '327', '340', '353', '365']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'value2_'},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '+'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'value1_'},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '326']},{'id': '321', 'type': 'attribute', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '326', 'type': 'argument_list', 'children': []},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'values_'},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '334', 'type': 'argument_list', 'children': ['335', '336', '337']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'value1_'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'value2_'},{'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'testarray'},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'values_'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'seriesshape'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '358', 'type': 'call', 'children': ['359', '364']},{'id': '359', 'type': 'attribute', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'testarray'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '364', 'type': 'argument_list', 'children': []},{'id': '365', 'type': 'return_statement', 'children': ['366']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'value2_'},{'id': '367', 'type': 'import_statement', 'children': ['368']},{'id': '368', 'type': 'dotted_name', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'assignment', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '373', 'type': 'integer', 'children': [], 'value': '0'},{'id': '374', 'type': 'for_statement', 'children': ['375', '378', '389']},{'id': '375', 'type': 'pattern_list', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'subname'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'seqname'},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '380', 'type': 'argument_list', 'children': ['381', '385']},{'id': '381', 'type': 'list', 'children': ['382', '383', '384'], 'value': "['inputs', 'fluxes', 'states']"},{'id': '382', 'type': 'string', 'children': [], 'value': "'inputs'"},{'id': '383', 'type': 'string', 'children': [], 'value': "'fluxes'"},{'id': '384', 'type': 'string', 'children': [], 'value': "'states'"},{'id': '385', 'type': 'list', 'children': ['386', '387', '388'], 'value': "['nied', 'nkor', 'bowa']"},{'id': '386', 'type': 'string', 'children': [], 'value': "'nied'"},{'id': '387', 'type': 'string', 'children': [], 'value': "'nkor'"},{'id': '388', 'type': 'string', 'children': [], 'value': "'bowa'"},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'for_statement', 'children': ['391', '392', '393']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '393', 'type': 'block', 'children': ['394', '406']},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'assignment', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'subseqs'},{'id': '397', 'type': 'call', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '399', 'type': 'argument_list', 'children': ['400', '405']},{'id': '400', 'type': 'attribute', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'sequences'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'subname'},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'assignment', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '409', 'type': 'call', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'init_values'},{'id': '411', 'type': 'argument_list', 'children': ['412', '417']},{'id': '412', 'type': 'call', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '414', 'type': 'argument_list', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'subseqs'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'seqname'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '418', 'type': 'for_statement', 'children': ['419', '420', '421']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '421', 'type': 'block', 'children': ['422']},{'id': '422', 'type': 'expression_statement', 'children': ['423']},{'id': '423', 'type': 'assignment', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '425', 'type': 'call', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'init_values'},{'id': '427', 'type': 'argument_list', 'children': ['428', '433']},{'id': '428', 'type': 'attribute', 'children': ['429', '432']},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'sequences'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'sim'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '434', 'type': 'return_statement', 'children': ['435']},{'id': '435', 'type': 'expression_list', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'elements'} | def prepare_io_example_1() -> Tuple[devicetools.Nodes, devicetools.Elements]:
from hydpy import TestIO
TestIO.clear()
from hydpy.core.filetools import SequenceManager
hydpy.pub.sequencemanager = SequenceManager()
with TestIO():
hydpy.pub.sequencemanager.inputdirpath = 'inputpath'
hydpy.pub.sequencemanager.fluxdirpath = 'outputpath'
hydpy.pub.sequencemanager.statedirpath = 'outputpath'
hydpy.pub.sequencemanager.nodedirpath = 'nodepath'
hydpy.pub.timegrids = '2000-01-01', '2000-01-05', '1d'
from hydpy import Node, Nodes, Element, Elements, prepare_model
node1 = Node('node1')
node2 = Node('node2', variable='T')
nodes = Nodes(node1, node2)
element1 = Element('element1', outlets=node1)
element2 = Element('element2', outlets=node1)
element3 = Element('element3', outlets=node1)
elements = Elements(element1, element2, element3)
from hydpy.models import lland_v1, lland_v2
element1.model = prepare_model(lland_v1)
element2.model = prepare_model(lland_v1)
element3.model = prepare_model(lland_v2)
from hydpy.models.lland import ACKER
for idx, element in enumerate(elements):
parameters = element.model.parameters
parameters.control.nhru(idx+1)
parameters.control.lnk(ACKER)
parameters.derived.absfhru(10.0)
with hydpy.pub.options.printprogress(False):
nodes.prepare_simseries()
elements.prepare_inputseries()
elements.prepare_fluxseries()
elements.prepare_stateseries()
def init_values(seq, value1_):
value2_ = value1_ + len(seq.series.flatten())
values_ = numpy.arange(value1_, value2_, dtype=float)
seq.testarray = values_.reshape(seq.seriesshape)
seq.series = seq.testarray.copy()
return value2_
import numpy
value1 = 0
for subname, seqname in zip(['inputs', 'fluxes', 'states'],
['nied', 'nkor', 'bowa']):
for element in elements:
subseqs = getattr(element.model.sequences, subname)
value1 = init_values(getattr(subseqs, seqname), value1)
for node in nodes:
value1 = init_values(node.sequences.sim, value1)
return nodes, elements |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'comparison_table'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'caption'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '10', 'type': 'string', 'children': [], 'value': '"tab:model_comp"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'hlines'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '25', 'type': 'string', 'children': [], 'value': '"bic"'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '38', '46', '54', '63', '72', '80', '84', '100', '109', '113', '117', '124', '149', '158', '187', '216', '245', '281', '298', '314', '324', '334', '343', '352', '365', '418', '427']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'string', 'children': [], 'value': '"bic"'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'assert_statement', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '37', 'type': 'string', 'children': [], 'value': '"You cannot sort by BIC if you turn it off"'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'string', 'children': [], 'value': '"aic"'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'assert_statement', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '45', 'type': 'string', 'children': [], 'value': '"You cannot sort by AIC if you turn it off"'},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '49', 'type': 'string', 'children': [], 'value': '"dic"'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'assert_statement', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '53', 'type': 'string', 'children': [], 'value': '"You cannot sort by DIC if you turn it off"'},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'caption'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'caption'},{'id': '62', 'type': 'string', 'children': [], 'value': '""'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '71', 'type': 'string', 'children': [], 'value': '""'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'base_string'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get_latex_table_frame'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'caption'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'end_text'},{'id': '83', 'type': 'string', 'children': [], 'value': '" \\\\\\\\ \\n"'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'num_cols'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '95'], 'value': '+'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': '()', 'children': ['91']},{'id': '91', 'type': 'conditional_expression', 'children': ['92', '93', '94'], 'value': 'if'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'conditional_expression', 'children': ['97', '98', '99'], 'value': 'if'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'column_text'},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '*'},{'id': '104', 'type': 'string', 'children': [], 'value': '"c"'},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'num_cols'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '112', 'type': 'string', 'children': [], 'value': '""'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'hline_text'},{'id': '116', 'type': 'string', 'children': [], 'value': '"\\\\hline\\n"'},{'id': '117', 'type': 'if_statement', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'hlines'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'augmented_assignment', 'children': ['122', '123'], 'value': '+='},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'hline_text'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'augmented_assignment', 'children': ['126', '127'], 'value': '+='},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '148'], 'value': '+'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '142', '143'], 'value': '+'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '137'], 'value': '+'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'},{'id': '131', 'type': 'string', 'children': [], 'value': '"\\tModel"'},{'id': '132', 'type': '()', 'children': ['133']},{'id': '133', 'type': 'conditional_expression', 'children': ['134', '135', '136'], 'value': 'if'},{'id': '134', 'type': 'string', 'children': [], 'value': '" & AIC"'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '136', 'type': 'string', 'children': [], 'value': '""'},{'id': '137', 'type': '()', 'children': ['138']},{'id': '138', 'type': 'conditional_expression', 'children': ['139', '140', '141'], 'value': 'if'},{'id': '139', 'type': 'string', 'children': [], 'value': '" & BIC "'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '141', 'type': 'string', 'children': [], 'value': '""'},{'id': '142', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '143', 'type': '()', 'children': ['144']},{'id': '144', 'type': 'conditional_expression', 'children': ['145', '146', '147'], 'value': 'if'},{'id': '145', 'type': 'string', 'children': [], 'value': '" & DIC "'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '147', 'type': 'string', 'children': [], 'value': '""'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'end_text'},{'id': '149', 'type': 'if_statement', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'hlines'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '+='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'},{'id': '156', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'hline_text'},{'id': '158', 'type': 'if_statement', 'children': ['159', '160', '169']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'else_clause', 'children': ['170']},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'attribute', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '187', 'type': 'if_statement', 'children': ['188', '189', '198']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '216', 'type': 'if_statement', 'children': ['217', '218', '227']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'dics'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'dics'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '245', 'type': 'if_statement', 'children': ['246', '249', '254', '263', '272']},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': '=='},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '248', 'type': 'string', 'children': [], 'value': '"bic"'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '254', 'type': 'elif_clause', 'children': ['255', '258']},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': '=='},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '257', 'type': 'string', 'children': [], 'value': '"aic"'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '263', 'type': 'elif_clause', 'children': ['264', '267']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': '=='},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '266', 'type': 'string', 'children': [], 'value': '"dic"'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'dics'},{'id': '272', 'type': 'else_clause', 'children': ['273']},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'raise_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '%'},{'id': '279', 'type': 'string', 'children': [], 'value': '"sort %s not recognised, must be dic, aic or dic"'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '284', 'type': 'list_comprehension', 'children': ['285', '286', '294']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '286', 'type': 'for_in_clause', 'children': ['287', '290']},{'id': '287', 'type': 'pattern_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '294', 'type': 'if_clause', 'children': ['295']},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': 'is'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '297', 'type': 'None', 'children': []},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '301', 'type': 'list_comprehension', 'children': ['302', '311']},{'id': '302', 'type': 'attribute', 'children': ['303', '310']},{'id': '303', 'type': 'subscript', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '311', 'type': 'for_in_clause', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '317', 'type': 'list_comprehension', 'children': ['318', '321']},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '321', 'type': 'for_in_clause', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '327', 'type': 'list_comprehension', 'children': ['328', '331']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '331', 'type': 'for_in_clause', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'good'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '337', 'type': 'conditional_expression', 'children': ['338', '339', '342'], 'value': 'if'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '339', 'type': 'comparison_operator', 'children': ['340', '341'], 'value': '=='},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '341', 'type': 'string', 'children': [], 'value': '"bic"'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '352', 'type': 'if_statement', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '354', 'type': 'block', 'children': ['355']},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '358', 'type': 'subscript', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '360', 'type': 'slice', 'children': ['361', '362', '363']},{'id': '361', 'type': 'colon', 'children': []},{'id': '362', 'type': 'colon', 'children': []},{'id': '363', 'type': 'unary_operator', 'children': ['364'], 'value': '-'},{'id': '364', 'type': 'integer', 'children': [], 'value': '1'},{'id': '365', 'type': 'for_statement', 'children': ['366', '367', '368']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '368', 'type': 'block', 'children': ['369', '377', '388', '399', '410', '414']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '+'},{'id': '373', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '374', 'type': 'subscript', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '377', 'type': 'if_statement', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'aic'},{'id': '379', 'type': 'block', 'children': ['380']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'augmented_assignment', 'children': ['382', '383'], 'value': '+='},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '383', 'type': 'binary_operator', 'children': ['384', '385'], 'value': '%'},{'id': '384', 'type': 'string', 'children': [], 'value': '" & %5.1f "'},{'id': '385', 'type': 'subscript', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'aics'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '388', 'type': 'if_statement', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'bic'},{'id': '390', 'type': 'block', 'children': ['391']},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'augmented_assignment', 'children': ['393', '394'], 'value': '+='},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '394', 'type': 'binary_operator', 'children': ['395', '396'], 'value': '%'},{'id': '395', 'type': 'string', 'children': [], 'value': '" & %5.1f "'},{'id': '396', 'type': 'subscript', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'bics'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '399', 'type': 'if_statement', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '401', 'type': 'block', 'children': ['402']},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'augmented_assignment', 'children': ['404', '405'], 'value': '+='},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '405', 'type': 'binary_operator', 'children': ['406', '407'], 'value': '%'},{'id': '406', 'type': 'string', 'children': [], 'value': '" & %5.1f "'},{'id': '407', 'type': 'subscript', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'dics'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'augmented_assignment', 'children': ['412', '413'], 'value': '+='},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'end_text'},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'augmented_assignment', 'children': ['416', '417'], 'value': '+='},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '418', 'type': 'if_statement', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'hlines'},{'id': '420', 'type': 'block', 'children': ['421']},{'id': '421', 'type': 'expression_statement', 'children': ['422']},{'id': '422', 'type': 'augmented_assignment', 'children': ['423', '424'], 'value': '+='},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'center_text'},{'id': '424', 'type': 'binary_operator', 'children': ['425', '426'], 'value': '+'},{'id': '425', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'hline_text'},{'id': '427', 'type': 'return_statement', 'children': ['428']},{'id': '428', 'type': 'binary_operator', 'children': ['429', '430'], 'value': '%'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'base_string'},{'id': '430', 'type': 'tuple', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'column_text'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'center_text'} | def comparison_table(self, caption=None, label="tab:model_comp", hlines=True,
aic=True, bic=True, dic=True, sort="bic", descending=True):
if sort == "bic":
assert bic, "You cannot sort by BIC if you turn it off"
if sort == "aic":
assert aic, "You cannot sort by AIC if you turn it off"
if sort == "dic":
assert dic, "You cannot sort by DIC if you turn it off"
if caption is None:
caption = ""
if label is None:
label = ""
base_string = get_latex_table_frame(caption, label)
end_text = " \\\\ \n"
num_cols = 1 + (1 if aic else 0) + (1 if bic else 0)
column_text = "c" * (num_cols + 1)
center_text = ""
hline_text = "\\hline\n"
if hlines:
center_text += hline_text
center_text += "\tModel" + (" & AIC" if aic else "") + (" & BIC " if bic else "") \
+ (" & DIC " if dic else "") + end_text
if hlines:
center_text += "\t" + hline_text
if aic:
aics = self.aic()
else:
aics = np.zeros(len(self.parent.chains))
if bic:
bics = self.bic()
else:
bics = np.zeros(len(self.parent.chains))
if dic:
dics = self.dic()
else:
dics = np.zeros(len(self.parent.chains))
if sort == "bic":
to_sort = bics
elif sort == "aic":
to_sort = aics
elif sort == "dic":
to_sort = dics
else:
raise ValueError("sort %s not recognised, must be dic, aic or dic" % sort)
good = [i for i, t in enumerate(to_sort) if t is not None]
names = [self.parent.chains[g].name for g in good]
aics = [aics[g] for g in good]
bics = [bics[g] for g in good]
to_sort = bics if sort == "bic" else aics
indexes = np.argsort(to_sort)
if descending:
indexes = indexes[::-1]
for i in indexes:
line = "\t" + names[i]
if aic:
line += " & %5.1f " % aics[i]
if bic:
line += " & %5.1f " % bics[i]
if dic:
line += " & %5.1f " % dics[i]
line += end_text
center_text += line
if hlines:
center_text += "\t" + hline_text
return base_string % (column_text, center_text) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_initDevClasses'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '28', '32', '45', '153', '165', '177', '181']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_devClassTree'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_partitionTree'},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_mapDevType'},{'id': '23', 'type': 'dictionary', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'basedevs'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'otherdevs'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': 'is'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_mapMajorDevclass'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_initBlockMajorMap'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_diskStats'},{'id': '50', 'type': 'block', 'children': ['51', '59', '72']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_diskStats'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_mapMajorDevclass'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '71', 'type': 'string', 'children': [], 'value': "'major'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'block', 'children': ['77', '89']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'devdir'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sysfsBlockdevDir'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '89', 'type': 'if_statement', 'children': ['90', '98', '144']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'devdir'},{'id': '98', 'type': 'block', 'children': ['99', '118', '129', '137']},{'id': '99', 'type': 'if_statement', 'children': ['100', '109']},{'id': '100', 'type': 'not_operator', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_devClassTree'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '117']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_devClassTree'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '117', 'type': 'list', 'children': [], 'value': '[]'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '127']},{'id': '120', 'type': 'attribute', 'children': ['121', '126']},{'id': '121', 'type': 'subscript', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_devClassTree'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '136']},{'id': '131', 'type': 'subscript', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_mapDevType'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'devclass'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'basedevs'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'otherdevs'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'basedevs'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '158', 'type': 'argument_list', 'children': ['159', '162']},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '164', 'type': 'True', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'otherdevs'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '170', 'type': 'argument_list', 'children': ['171', '174']},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '184']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'partdev'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'otherdevs'},{'id': '184', 'type': 'block', 'children': ['185', '199']},{'id': '185', 'type': 'while_statement', 'children': ['186', '194']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '193'], 'value': '>'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'basedevs'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'partdev'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'augmented_assignment', 'children': ['197', '198'], 'value': '+='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'for_statement', 'children': ['200', '201', '206']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'basedevs'},{'id': '203', 'type': 'slice', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '205', 'type': 'colon', 'children': []},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'if_statement', 'children': ['208', '217']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '212', 'type': 'argument_list', 'children': ['213', '216']},{'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '%'},{'id': '214', 'type': 'string', 'children': [], 'value': '"%s(\\d+|p\\d+)$"'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'partdev'},{'id': '217', 'type': 'block', 'children': ['218', '237', '248']},{'id': '218', 'type': 'if_statement', 'children': ['219', '228']},{'id': '219', 'type': 'not_operator', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_partitionTree'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '236']},{'id': '231', 'type': 'subscript', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_partitionTree'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '236', 'type': 'list', 'children': [], 'value': '[]'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '246']},{'id': '239', 'type': 'attribute', 'children': ['240', '245']},{'id': '240', 'type': 'subscript', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_partitionTree'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'partdev'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '255']},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_mapDevType'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'partdev'},{'id': '255', 'type': 'string', 'children': [], 'value': "'part'"} | def _initDevClasses(self):
self._devClassTree = {}
self._partitionTree = {}
self._mapDevType = {}
basedevs = []
otherdevs = []
if self._mapMajorDevclass is None:
self._initBlockMajorMap()
for dev in self._diskStats:
stats = self._diskStats[dev]
devclass = self._mapMajorDevclass.get(stats['major'])
if devclass is not None:
devdir = os.path.join(sysfsBlockdevDir, dev)
if os.path.isdir(devdir):
if not self._devClassTree.has_key(devclass):
self._devClassTree[devclass] = []
self._devClassTree[devclass].append(dev)
self._mapDevType[dev] = devclass
basedevs.append(dev)
else:
otherdevs.append(dev)
basedevs.sort(key=len, reverse=True)
otherdevs.sort(key=len, reverse=True)
idx = 0
for partdev in otherdevs:
while len(basedevs[idx]) > partdev:
idx += 1
for dev in basedevs[idx:]:
if re.match("%s(\d+|p\d+)$" % dev, partdev):
if not self._partitionTree.has_key(dev):
self._partitionTree[dev] = []
self._partitionTree[dev].append(partdev)
self._mapDevType[partdev] = 'part' |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zdiffstore'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '23', '30']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''Compute the difference of multiple sorted.\r\n The difference of sets specified by ``keys`` into a new sorted set\r\n in ``dest``.\r\n '''"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '19'], 'value': '+'},{'id': '17', 'type': 'tuple', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'wscores'},{'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '29'], 'value': 'if'},{'id': '27', 'type': 'string', 'children': [], 'value': "'withscores'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '29', 'type': 'string', 'children': [], 'value': "''"},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'execute_script'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38', '39']},{'id': '36', 'type': 'string', 'children': [], 'value': "'zdiffstore'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'wscores'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'withscores'} | def zdiffstore(self, dest, keys, withscores=False):
'''Compute the difference of multiple sorted.
The difference of sets specified by ``keys`` into a new sorted set
in ``dest``.
'''
keys = (dest,) + tuple(keys)
wscores = 'withscores' if withscores else ''
return self.execute_script('zdiffstore', keys, wscores,
withscores=withscores) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'places_within_radius'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'place'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'block', 'children': ['20', '26', '32', '38', '46', '56', '119', '123', '166']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'string', 'children': [], 'value': "'withdist'"},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'string', 'children': [], 'value': "'withcoord'"},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '36', 'type': 'string', 'children': [], 'value': "'withhash'"},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'ASC'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'unit'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'km'"},{'id': '56', 'type': 'if_statement', 'children': ['57', '60', '83', '112']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'place'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'redis'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'georadiusbymember'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74', '80', '81']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_pickle'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'place'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '81', 'type': 'dictionary_splat', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '83', 'type': 'elif_clause', 'children': ['84', '93']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '89'], 'value': 'and'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': '()', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'redis'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'georadius'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107', '108', '109', '110']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '110', 'type': 'dictionary_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'raise_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': "'Must specify place, or both latitude and longitude'"},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '122', 'type': 'list', 'children': [], 'value': '[]'},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'dictionary', 'children': ['134', '144', '149', '152', '159']},{'id': '134', 'type': 'pair', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'place'"},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_unpickle'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'distance'"},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'pair', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'unit'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '152', 'type': 'pair', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "'latitude'"},{'id': '154', 'type': 'subscript', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '157', 'type': 'integer', 'children': [], 'value': '2'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "'longitude'"},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '164', 'type': 'integer', 'children': [], 'value': '2'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ret'} | def places_within_radius(
self, place=None, latitude=None, longitude=None, radius=0, **kwargs
):
kwargs['withdist'] = True
kwargs['withcoord'] = True
kwargs['withhash'] = False
kwargs.setdefault('sort', 'ASC')
unit = kwargs.setdefault('unit', 'km')
if place is not None:
response = self.redis.georadiusbymember(
self.key, self._pickle(place), radius, **kwargs
)
elif (latitude is not None) and (longitude is not None):
response = self.redis.georadius(
self.key, longitude, latitude, radius, **kwargs
)
else:
raise ValueError(
'Must specify place, or both latitude and longitude'
)
ret = []
for item in response:
ret.append(
{
'place': self._unpickle(item[0]),
'distance': item[1],
'unit': unit,
'latitude': item[2][1],
'longitude': item[2][0],
}
)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'naturalize_person'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '6', 'type': 'block', 'children': ['7', '20', '34', '44', '48', '52', '56', '60', '69', '103', '165', '178', '187']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '10', 'type': 'list', 'children': ['11', '12', '13', '14', '15', '16', '17', '18', '19'], 'value': "[\n 'Jr', 'Jr.', 'Sr', 'Sr.',\n 'I', 'II', 'III', 'IV', 'V',\n ]"},{'id': '11', 'type': 'string', 'children': [], 'value': "'Jr'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'Jr.'"},{'id': '13', 'type': 'string', 'children': [], 'value': "'Sr'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'Sr.'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'I'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'II'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'III'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'IV'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'V'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '31']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'particles'},{'id': '37', 'type': 'list', 'children': ['38', '39', '40', '41', '42', '43'], 'value': "[\n 'Le', 'La',\n 'Von', 'Van',\n 'Du', 'De',\n ]"},{'id': '38', 'type': 'string', 'children': [], 'value': "'Le'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'La'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'Von'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'Van'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'Du'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'De'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'surname'},{'id': '47', 'type': 'string', 'children': [], 'value': "''"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '51', 'type': 'string', 'children': [], 'value': "''"},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '55', 'type': 'string', 'children': [], 'value': "''"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "' '"},{'id': '69', 'type': 'if_statement', 'children': ['70', '76']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '75'], 'value': 'in'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'suffixes'},{'id': '76', 'type': 'block', 'children': ['77', '84', '94']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '89', 'type': 'slice', 'children': ['90', '91', '92']},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'colon', 'children': []},{'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "' '"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '103', 'type': 'if_statement', 'children': ['104', '110']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '109'], 'value': '>'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'block', 'children': ['111', '142']},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': 'in'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '115', 'type': 'unary_operator', 'children': ['116'], 'value': '-'},{'id': '116', 'type': 'integer', 'children': [], 'value': '2'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'particles'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '130'], 'value': '+'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '125', 'type': 'slice', 'children': ['126', '127', '128']},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'colon', 'children': []},{'id': '128', 'type': 'unary_operator', 'children': ['129'], 'value': '-'},{'id': '129', 'type': 'integer', 'children': [], 'value': '2'},{'id': '130', 'type': 'list', 'children': ['131'], 'value': "[ ' '.join(parts[-2:]) ]"},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "' '"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '138', 'type': 'slice', 'children': ['139', '141']},{'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'},{'id': '140', 'type': 'integer', 'children': [], 'value': '2'},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'{}, {}'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '149', 'type': 'argument_list', 'children': ['150', '154']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '152', 'type': 'unary_operator', 'children': ['153'], 'value': '-'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': "' '"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '161', 'type': 'slice', 'children': ['162', '163']},{'id': '162', 'type': 'colon', 'children': []},{'id': '163', 'type': 'unary_operator', 'children': ['164'], 'value': '-'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'if_statement', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': "'{} {}'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_naturalize_numbers'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sort_string'} | def naturalize_person(self, string):
suffixes = [
'Jr', 'Jr.', 'Sr', 'Sr.',
'I', 'II', 'III', 'IV', 'V',
]
suffixes = suffixes + [s.lower() for s in suffixes]
particles = [
'Le', 'La',
'Von', 'Van',
'Du', 'De',
]
surname = ''
names = ''
suffix = ''
sort_string = string
parts = string.split(' ')
if parts[-1] in suffixes:
suffix = parts[-1]
parts = parts[0:-1]
sort_string = ' '.join(parts)
if len(parts) > 1:
if parts[-2] in particles:
parts = parts[0:-2] + [ ' '.join(parts[-2:]) ]
sort_string = '{}, {}'.format(parts[-1], ' '.join(parts[:-1]))
if suffix:
sort_string = '{} {}'.format(sort_string, suffix)
sort_string = self._naturalize_numbers(sort_string)
return sort_string |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_countries'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '36', '40', '66']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '9', 'type': 'call', 'children': ['10', '34']},{'id': '10', 'type': 'attribute', 'children': ['11', '32', '33']},{'id': '11', 'type': 'call', 'children': ['12', '31']},{'id': '12', 'type': 'attribute', 'children': ['13', '29', '30']},{'id': '13', 'type': 'call', 'children': ['14', '25']},{'id': '14', 'type': 'attribute', 'children': ['15', '23', '24']},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Venue'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'country'"},{'id': '23', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '28', 'type': 'string', 'children': [], 'value': "''"},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'country'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'countries'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'countries'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'dictionary', 'children': ['51', '56']},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '55', 'type': 'string', 'children': [], 'value': "'country'"},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Venue'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_country_name'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'string', 'children': [], 'value': "'country'"},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'countries'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'lambda', 'children': ['74', '76']},{'id': '74', 'type': 'lambda_parameters', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'string', 'children': [], 'value': "'name'"} | def get_countries(self):
qs = Venue.objects.values('country') \
.exclude(country='') \
.distinct() \
.order_by('country')
countries = []
for c in qs:
countries.append({
'code': c['country'],
'name': Venue.get_country_name(c['country'])
})
return sorted(countries, key=lambda k: k['name']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dy'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'presorted'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '35', '50']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '26']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '20', '23']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dy'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_validate_inputs'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '34']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dy'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'presorted'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_fit'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44', '47']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'dy'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'} | def fit(self, t, y, dy=1, presorted=False):
self.t, self.y, self.dy = self._validate_inputs(t, y, dy, presorted)
self._fit(self.t, self.y, self.dy)
return self |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_inputs'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '29', '46', '60', '103']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'broadcast_arrays'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'list_splat', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'sort_by'"},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"unrecognized arguments: {0}"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '54']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': '!='},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"Input arrays should be one-dimensional."'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '74', '90']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'isort'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '74', 'type': 'if_statement', 'children': ['75', '84']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '!='},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isort'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': '"sort shape must equal array shape."'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'isort'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'arrays'},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'arrays'} | def validate_inputs(*arrays, **kwargs):
arrays = np.broadcast_arrays(*arrays)
sort_by = kwargs.pop('sort_by', None)
if kwargs:
raise ValueError("unrecognized arguments: {0}".format(kwargs.keys()))
if arrays[0].ndim != 1:
raise ValueError("Input arrays should be one-dimensional.")
if sort_by is not None:
isort = np.argsort(sort_by)
if isort.shape != arrays[0].shape:
raise ValueError("sort shape must equal array shape.")
arrays = tuple([a[isort] for a in arrays])
return arrays |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'multinterp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'slow'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '27', '33', '39', '51', '70']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '17']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '23', 'type': 'tuple', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '27', 'type': 'assert_statement', 'children': ['28']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'assert_statement', 'children': ['34']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '=='},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'assert_statement', 'children': ['40']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '48'], 'value': '+'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'clip'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '65']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '72', '105', '188']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'slow'},{'id': '72', 'type': 'block', 'children': ['73', '79']},{'id': '73', 'type': 'import_from_statement', 'children': ['74', '77']},{'id': '74', 'type': 'dotted_name', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'interpolate'},{'id': '77', 'type': 'dotted_name', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'interp1d'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '94']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'interp1d'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'xq'},{'id': '94', 'type': 'for_in_clause', 'children': ['95', '98']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'xq'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '105', 'type': 'elif_clause', 'children': ['106', '112']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '111'], 'value': '=='},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '111', 'type': 'integer', 'children': [], 'value': '3'},{'id': '112', 'type': 'block', 'children': ['113', '144', '175']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'yq_lower'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '120'], 'value': '+'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '136'], 'value': '/'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '128'], 'value': '*'},{'id': '122', 'type': '()', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '-'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': '()', 'children': ['129']},{'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '-'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': '()', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '141'], 'value': '-'},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'yq_upper'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '151'], 'value': '+'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '167'], 'value': '/'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '159'], 'value': '*'},{'id': '153', 'type': '()', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '-'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '-'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '163', 'type': 'integer', 'children': [], 'value': '2'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'binary_operator', 'children': ['169', '172'], 'value': '-'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'integer', 'children': [], 'value': '1'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '180', 'type': 'argument_list', 'children': ['181', '186', '187']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '<'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'yq_lower'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'yq_upper'},{'id': '188', 'type': 'else_clause', 'children': ['189']},{'id': '189', 'type': 'block', 'children': ['190', '217', '229']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'clip'},{'id': '197', 'type': 'argument_list', 'children': ['198', '210', '211']},{'id': '198', 'type': 'binary_operator', 'children': ['199', '209'], 'value': '-'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205', '206']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '208', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'integer', 'children': [], 'value': '0'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '216'], 'value': '-'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '216', 'type': 'integer', 'children': [], 'value': '2'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'binary_operator', 'children': ['231', '235'], 'value': '+'},{'id': '231', 'type': 'subscript', 'children': ['232', '233', '234']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '235', 'type': '()', 'children': ['236']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '256'], 'value': '/'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '244'], 'value': '*'},{'id': '238', 'type': '()', 'children': ['239']},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '-'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'xquery'},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '244', 'type': '()', 'children': ['245']},{'id': '245', 'type': 'binary_operator', 'children': ['246', '252'], 'value': '-'},{'id': '246', 'type': 'subscript', 'children': ['247', '248', '251']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '+'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '250', 'type': 'integer', 'children': [], 'value': '1'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '252', 'type': 'subscript', 'children': ['253', '254', '255']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '256', 'type': '()', 'children': ['257']},{'id': '257', 'type': 'binary_operator', 'children': ['258', '263'], 'value': '-'},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '262', 'type': 'integer', 'children': [], 'value': '1'},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'i'} | def multinterp(x, y, xquery, slow=False):
x, y, xquery = map(np.asarray, (x, y, xquery))
assert x.ndim == 1
assert xquery.ndim == 1
assert y.shape == x.shape + xquery.shape
xquery = np.clip(xquery, x.min(), x.max())
if slow:
from scipy.interpolate import interp1d
return np.array([interp1d(x, y)(xq) for xq, y in zip(xquery, y.T)])
elif len(x) == 3:
yq_lower = y[0] + (xquery - x[0]) * (y[1] - y[0]) / (x[1] - x[0])
yq_upper = y[1] + (xquery - x[1]) * (y[2] - y[1]) / (x[2] - x[1])
return np.where(xquery < x[1], yq_lower, yq_upper)
else:
i = np.clip(np.searchsorted(x, xquery, side='right') - 1,
0, len(x) - 2)
j = np.arange(len(xquery))
return y[i, j] + ((xquery - x[i]) *
(y[i + 1, j] - y[i, j]) / (x[i + 1] - x[i])) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_valid_time_and_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '8', 'type': 'integer', 'children': [], 'value': '5'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '34']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'timediff'},{'id': '16', 'type': 'attribute', 'children': ['17', '33']},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'binary_operator', 'children': ['19', '26'], 'value': '-'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38', '57']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '<'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'timediff'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '56']},{'id': '41', 'type': 'attribute', 'children': ['42', '55']},{'id': '42', 'type': 'call', 'children': ['43', '51']},{'id': '43', 'type': 'attribute', 'children': ['44', '50']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '54', 'type': 'True', 'children': []},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'else_clause', 'children': ['58']},{'id': '58', 'type': 'block', 'children': ['59', '124']},{'id': '59', 'type': 'if_statement', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '61', 'type': 'block', 'children': ['62', '79', '88', '105']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"\\nWarning: data generated is from more than {} days.\\n"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Likely this indicates you are combining multiple runs.\\n"'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': '"Plots based on time are invalid and therefore truncated to first {} days.\\n\\n"'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"Time plots truncated to first {} days: invalid timespan: {} days"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '115', 'type': 'argument_list', 'children': ['116', '120']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'timediff'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '155']},{'id': '126', 'type': 'attribute', 'children': ['127', '153', '154']},{'id': '127', 'type': 'call', 'children': ['128', '149']},{'id': '128', 'type': 'attribute', 'children': ['129', '147', '148']},{'id': '129', 'type': 'call', 'children': ['130', '145']},{'id': '130', 'type': 'attribute', 'children': ['131', '143', '144']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '<'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '143', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'timescol'},{'id': '147', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '152', 'type': 'True', 'children': []},{'id': '153', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '155', 'type': 'argument_list', 'children': []} | def check_valid_time_and_sort(df, timescol, days=5, warning=True):
timediff = (df[timescol].max() - df[timescol].min()).days
if timediff < days:
return df.sort_values(timescol).reset_index(drop=True).reset_index()
else:
if warning:
sys.stderr.write(
"\nWarning: data generated is from more than {} days.\n".format(str(days)))
sys.stderr.write("Likely this indicates you are combining multiple runs.\n")
sys.stderr.write(
"Plots based on time are invalid and therefore truncated to first {} days.\n\n"
.format(str(days)))
logging.warning("Time plots truncated to first {} days: invalid timespan: {} days"
.format(str(days), str(timediff)))
return df[df[timescol] < timedelta(days=days)] \
.sort_values(timescol) \
.reset_index(drop=True) \
.reset_index() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_anime_series'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'SORT_ALPHA'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'MAX_SERIES'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'block', 'children': ['19', '43']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_android_api'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'list_series'},{'id': '28', 'type': 'argument_list', 'children': ['29', '34', '37', '40']},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'media_type'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ANDROID'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'MEDIA_TYPE_ANIME'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'result'} | def list_anime_series(self, sort=META.SORT_ALPHA, limit=META.MAX_SERIES, offset=0):
result = self._android_api.list_series(
media_type=ANDROID.MEDIA_TYPE_ANIME,
filter=sort,
limit=limit,
offset=offset)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_drama_series'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'SORT_ALPHA'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'MAX_SERIES'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'block', 'children': ['19', '43']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_android_api'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'list_series'},{'id': '28', 'type': 'argument_list', 'children': ['29', '34', '37', '40']},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'media_type'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ANDROID'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'MEDIA_TYPE_DRAMA'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'result'} | def list_drama_series(self, sort=META.SORT_ALPHA, limit=META.MAX_SERIES, offset=0):
result = self._android_api.list_series(
media_type=ANDROID.MEDIA_TYPE_DRAMA,
filter=sort,
limit=limit,
offset=offset)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_media'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'SORT_DESC'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'MAX_MEDIA'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'block', 'children': ['20', '33', '45', '57']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '23', 'type': 'dictionary', 'children': ['24', '27', '30']},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'offset'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_get_series_query_dict'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_android_api'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'list_media'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'dictionary_splat', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'} | def list_media(self, series, sort=META.SORT_DESC, limit=META.MAX_MEDIA, offset=0):
params = {
'sort': sort,
'offset': offset,
'limit': limit,
}
params.update(self._get_series_query_dict(series))
result = self._android_api.list_media(**params)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'solve_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '6', 'type': 'block', 'children': ['7', '24', '30', '50', '62']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'lhs_values'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'repeated'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'getvalues'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'subscript', 'children': ['16', '23']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__solve_for_repeated'},{'id': '18', 'type': 'argument_list', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_expression'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']},{'id': '31', 'type': 'function_name', 'children': [], 'value': '_key_func'},{'id': '32', 'type': 'parameters', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '49']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'solve'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_expression'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '__nest_scope'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47', '48']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'lhs_values'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_key_func'},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Result'},{'id': '65', 'type': 'argument_list', 'children': ['66', '73']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'repeated'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'meld'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'list_splat', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '73', 'type': 'tuple', 'children': []} | def solve_sort(expr, vars):
lhs_values = repeated.getvalues(__solve_for_repeated(expr.lhs, vars)[0])
sort_expression = expr.rhs
def _key_func(x):
return solve(sort_expression, __nest_scope(expr.lhs, vars, x)).value
results = ordered.ordered(lhs_values, key_func=_key_func)
return Result(repeated.meld(*results), ()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'expression'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'previous_precedence'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'block', 'children': ['9', '17']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'previous_precedence'} | def expression(self, previous_precedence=0):
lhs = self.atom()
return self.operator(lhs, previous_precedence) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'application'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '6', 'type': 'block', 'children': ['7', '17', '53', '62', '85', '96']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '17', 'type': 'if_statement', 'children': ['18', '28']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'common_grammar'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'rparen'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Apply'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39', '48']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '56', 'type': 'list', 'children': ['57'], 'value': '[self.expression()]'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'expression'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'while_statement', 'children': ['63', '73']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'common_grammar'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'comma'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'expression'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'expect'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'common_grammar'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'rparen'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Apply'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '105', '108', '117']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '103', 'type': 'list_splat', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '110', 'type': 'attribute', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'original'} | def application(self, func):
start = self.tokens.matched.start
if self.tokens.accept(common_grammar.rparen):
return ast.Apply(func, start=start, end=self.tokens.matched.end,
source=self.original)
arguments = [self.expression()]
while self.tokens.accept(common_grammar.comma):
arguments.append(self.expression())
self.tokens.expect(common_grammar.rparen)
return ast.Apply(func, *arguments, start=start,
end=self.tokens.matched.end, source=self.original) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'value_eq'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '20', '34']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self_sorted'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'getvalues'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'other_sorted'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'repeated'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'getvalues'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self_sorted'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'other_sorted'} | def value_eq(self, other):
self_sorted = ordered.ordered(self.getvalues())
other_sorted = ordered.ordered(repeated.getvalues(other))
return self_sorted == other_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a_intervals'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b_intervals'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '7', 'type': 'block', 'children': ['8', '20', '32', '48', '53', '58', '62', '66', '70', '82', '177']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '11', 'type': 'call', 'children': ['12', '19']},{'id': '12', 'type': 'attribute', 'children': ['13', '18']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'a_intervals'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'b_intervals'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '47'], 'value': '+'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '38', 'type': 'argument_list', 'children': ['39', '43']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'augmented_assignment', 'children': ['50', '51'], 'value': '+='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '51', 'type': 'list', 'children': ['52'], 'value': '[sentinel]'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'augmented_assignment', 'children': ['55', '56'], 'value': '+='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '56', 'type': 'list', 'children': ['57'], 'value': '[sentinel]'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '69', 'type': 'list', 'children': [], 'value': '[]'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'while_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '<'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sentinel'},{'id': '86', 'type': 'block', 'children': ['87', '103', '119', '127', '143', '154', '165']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'in_a'},{'id': '90', 'type': 'not_operator', 'children': ['91']},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '99'], 'value': '^'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '<'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '%'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '102', 'type': 'integer', 'children': [], 'value': '2'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'in_b'},{'id': '106', 'type': 'not_operator', 'children': ['107']},{'id': '107', 'type': '()', 'children': ['108']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '115'], 'value': '^'},{'id': '109', 'type': '()', 'children': ['110']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '<'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'in_res'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'in_a'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'in_b'},{'id': '127', 'type': 'if_statement', 'children': ['128', '137']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '^'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'in_res'},{'id': '130', 'type': '()', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '136'], 'value': '%'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '136', 'type': 'integer', 'children': [], 'value': '2'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[scan]'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '143', 'type': 'if_statement', 'children': ['144', '149']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '=='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '153'], 'value': '+='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'augmented_assignment', 'children': ['163', '164'], 'value': '+='},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'scan'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '170', 'type': 'argument_list', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'a_endpoints'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'a_index'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'b_endpoints'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'b_index'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '187']},{'id': '179', 'type': 'attribute', 'children': ['180', '186']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'tuple', 'children': ['189', '191']},{'id': '189', 'type': 'unary_operator', 'children': ['190'], 'value': '-'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'integer', 'children': [], 'value': '2'} | def merge(a_intervals, b_intervals, op):
a_endpoints = a_intervals.flatten().tolist()
b_endpoints = b_intervals.flatten().tolist()
sentinel = max(a_endpoints[-1], b_endpoints[-1]) + 1
a_endpoints += [sentinel]
b_endpoints += [sentinel]
a_index = 0
b_index = 0
res = []
scan = min(a_endpoints[0], b_endpoints[0])
while scan < sentinel:
in_a = not ((scan < a_endpoints[a_index]) ^ (a_index % 2))
in_b = not ((scan < b_endpoints[b_index]) ^ (b_index % 2))
in_res = op(in_a, in_b)
if in_res ^ (len(res) % 2):
res += [scan]
if scan == a_endpoints[a_index]:
a_index += 1
if scan == b_endpoints[b_index]:
b_index += 1
scan = min(a_endpoints[a_index], b_endpoints[b_index])
return np.asarray(res).reshape((-1, 2)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_bam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'samtype'},{'id': '7', 'type': 'string', 'children': [], 'value': '"bam"'},{'id': '8', 'type': 'block', 'children': ['9', '16', '26', '58', '89', '143']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ut'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'check_existance'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pysam'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'AlignmentFile'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '25', 'type': 'string', 'children': [], 'value': '"rb"'},{'id': '26', 'type': 'if_statement', 'children': ['27', '33']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'has_index'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '41', '51']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pysam'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'pysam'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'AlignmentFile'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '50', 'type': 'string', 'children': [], 'value': '"rb"'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"Nanoget: No index for bam file could be found, created index."'},{'id': '58', 'type': 'if_statement', 'children': ['59', '69']},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '68'], 'value': '=='},{'id': '61', 'type': 'subscript', 'children': ['62', '67']},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '66', 'type': 'string', 'children': [], 'value': "'HD'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'SO'"},{'id': '68', 'type': 'string', 'children': [], 'value': "'coordinate'"},{'id': '69', 'type': 'block', 'children': ['70', '82']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"Nanoget: Bam file {} not sorted by coordinate!."'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': '"Please use a bam file sorted by coordinate."'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'samtype'},{'id': '92', 'type': 'string', 'children': [], 'value': '"bam"'},{'id': '93', 'type': 'block', 'children': ['94', '112']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"Nanoget: Bam file {} contains {} mapped and {} unmapped reads."'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106', '109']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mapped'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'unmapped'},{'id': '112', 'type': 'if_statement', 'children': ['113', '118']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': '=='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'mapped'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'block', 'children': ['119', '131']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '"Nanoget: Bam file {} does not contain aligned reads."'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': '"FATAL: not a single read was mapped in bam file {}"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'samfile'} | def check_bam(bam, samtype="bam"):
ut.check_existance(bam)
samfile = pysam.AlignmentFile(bam, "rb")
if not samfile.has_index():
pysam.index(bam)
samfile = pysam.AlignmentFile(bam, "rb")
logging.info("Nanoget: No index for bam file could be found, created index.")
if not samfile.header['HD']['SO'] == 'coordinate':
logging.error("Nanoget: Bam file {} not sorted by coordinate!.".format(bam))
sys.exit("Please use a bam file sorted by coordinate.")
if samtype == "bam":
logging.info("Nanoget: Bam file {} contains {} mapped and {} unmapped reads.".format(
bam, samfile.mapped, samfile.unmapped))
if samfile.mapped == 0:
logging.error("Nanoget: Bam file {} does not contain aligned reads.".format(bam))
sys.exit("FATAL: not a single read was mapped in bam file {}".format(bam))
return samfile |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_input'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '8', 'type': 'integer', 'children': [], 'value': '4'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'readtype'},{'id': '11', 'type': 'string', 'children': [], 'value': '"1D"'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'combine'},{'id': '14', 'type': 'string', 'children': [], 'value': '"simple"'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'barcoded'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '66', '77', '83', '143', '174', '181', '196']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'proc_functions'},{'id': '25', 'type': 'dictionary', 'children': ['26', '31', '36', '41', '46', '51', '56', '61']},{'id': '26', 'type': 'pair', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'fastq'"},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'process_fastq_plain'},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'process_fasta'},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'bam'"},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'process_bam'},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'summary'"},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'process_summary'},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'fastq_rich'"},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'process_fastq_rich'},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'fastq_minimal'"},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'process_fastq_minimal'},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'cram'"},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'process_cram'},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'ubam'"},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'process_ubam'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filethreads'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '71', 'type': 'argument_list', 'children': ['72', '76']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'threadsleft'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '-'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'filethreads'},{'id': '83', 'type': 'with_statement', 'children': ['84', '97']},{'id': '84', 'type': 'with_clause', 'children': ['85']},{'id': '85', 'type': 'with_item', 'children': ['86']},{'id': '86', 'type': 'as_pattern', 'children': ['87', '95']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cfutures'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ProcessPoolExecutor'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'max_workers'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'filethreads'},{'id': '95', 'type': 'as_pattern_target', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '97', 'type': 'block', 'children': ['98', '116']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'extration_function'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107', '110', '113']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'proc_functions'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'threadsleft'},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'readtype'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'readtype'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'barcoded'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'barcoded'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'combine_dfs'},{'id': '121', 'type': 'argument_list', 'children': ['122', '135', '140']},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '124', 'type': 'list_comprehension', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'extration_function'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '139'], 'value': 'or'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'combine'},{'id': '143', 'type': 'if_statement', 'children': ['144', '160']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '148'], 'value': 'and'},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'},{'id': '146', 'type': 'string', 'children': [], 'value': '"readIDs"'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '148', 'type': 'call', 'children': ['149', '159']},{'id': '149', 'type': 'attribute', 'children': ['150', '158']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'isna'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '157', 'type': 'string', 'children': [], 'value': '"readIDs"'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168', '171']},{'id': '167', 'type': 'string', 'children': [], 'value': '"readIDs"'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '170', 'type': 'string', 'children': [], 'value': "'columns'"},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'calculate_start_time'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': '"Nanoget: Gathered all metrics of {} reads"'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '196', 'type': 'if_statement', 'children': ['197', '203', '226']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '202'], 'value': '=='},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '202', 'type': 'integer', 'children': [], 'value': '0'},{'id': '203', 'type': 'block', 'children': ['204', '219']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'critical'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '"Nanoget: no reads retrieved."'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'datadf'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': '"Fatal: No reads found in input."'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'datadf'} | def get_input(source, files, threads=4, readtype="1D",
combine="simple", names=None, barcoded=False):
proc_functions = {
'fastq': ex.process_fastq_plain,
'fasta': ex.process_fasta,
'bam': ex.process_bam,
'summary': ex.process_summary,
'fastq_rich': ex.process_fastq_rich,
'fastq_minimal': ex.process_fastq_minimal,
'cram': ex.process_cram,
'ubam': ex.process_ubam, }
filethreads = min(len(files), threads)
threadsleft = threads - filethreads
with cfutures.ProcessPoolExecutor(max_workers=filethreads) as executor:
extration_function = partial(proc_functions[source],
threads=threadsleft,
readtype=readtype,
barcoded=barcoded)
datadf = combine_dfs(
dfs=[out for out in executor.map(extration_function, files)],
names=names or files,
method=combine)
if "readIDs" in datadf and pd.isna(datadf["readIDs"]).any():
datadf.drop("readIDs", axis='columns', inplace=True)
datadf = calculate_start_time(datadf)
logging.info("Nanoget: Gathered all metrics of {} reads".format(len(datadf)))
if len(datadf) == 0:
logging.critical("Nanoget: no reads retrieved.".format(len(datadf)))
sys.exit("Fatal: No reads found in input.")
else:
return datadf |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_wavelengths'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'wavelengths'},{'id': '5', 'type': 'block', 'children': ['6', '36', '49', '58', '87', '96', '145']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14', '30']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'wavelengths'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Quantity'},{'id': '14', 'type': 'block', 'children': ['15', '24']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'validate_wave_unit'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'wavelengths'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'wavelengths'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'else_clause', 'children': ['31']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'wavelengths'},{'id': '36', 'type': 'if_statement', 'children': ['37', '43']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isscalar'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '47', 'type': 'list', 'children': ['48'], 'value': '[wave]'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '58', 'type': 'if_statement', 'children': ['59', '67']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'raise_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ZeroWavelength'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'Negative or zero wavelength occurs in wavelength array'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '77', 'type': 'subscript', 'children': ['78', '86']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '<='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '96', 'type': 'if_statement', 'children': ['97', '106']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'alltrue'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'if_statement', 'children': ['108', '122', '124']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'alltrue'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '121'], 'value': '=='},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '116', 'type': 'slice', 'children': ['117', '118', '119']},{'id': '117', 'type': 'colon', 'children': []},{'id': '118', 'type': 'colon', 'children': []},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '-'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'pass_statement', 'children': []},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'UnsortedWavelength'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'Wavelength array is not monotonic'"},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '135', 'type': 'subscript', 'children': ['136', '144']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '!='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'if_statement', 'children': ['146', '151']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '>'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'block', 'children': ['152', '167']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '161'], 'value': '-'},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '158', 'type': 'slice', 'children': ['159', '160']},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'colon', 'children': []},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sorted_wave'},{'id': '163', 'type': 'slice', 'children': ['164', '165']},{'id': '164', 'type': 'colon', 'children': []},{'id': '165', 'type': 'unary_operator', 'children': ['166'], 'value': '-'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'if_statement', 'children': ['168', '176']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '=='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'raise_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'DuplicateWavelength'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': "'Wavelength array contains duplicate entries'"},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '186', 'type': 'subscript', 'children': ['187', '195']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'} | def validate_wavelengths(wavelengths):
if isinstance(wavelengths, u.Quantity):
units.validate_wave_unit(wavelengths.unit)
wave = wavelengths.value
else:
wave = wavelengths
if np.isscalar(wave):
wave = [wave]
wave = np.asarray(wave)
if np.any(wave <= 0):
raise exceptions.ZeroWavelength(
'Negative or zero wavelength occurs in wavelength array',
rows=np.where(wave <= 0)[0])
sorted_wave = np.sort(wave)
if not np.alltrue(sorted_wave == wave):
if np.alltrue(sorted_wave[::-1] == wave):
pass
else:
raise exceptions.UnsortedWavelength(
'Wavelength array is not monotonic',
rows=np.where(sorted_wave != wave)[0])
if wave.size > 1:
dw = sorted_wave[1:] - sorted_wave[:-1]
if np.any(dw == 0):
raise exceptions.DuplicateWavelength(
'Wavelength array contains duplicate entries',
rows=np.where(dw == 0)[0]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'heapify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': '__marker'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15', '44']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '__marker'},{'id': '15', 'type': 'block', 'children': ['16', '25']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_heap'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '36']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '//'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '35', 'type': 'integer', 'children': [], 'value': '2'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_sink'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'id': '45', 'type': 'block', 'children': ['46', '64']},{'id': '46', 'type': 'try_statement', 'children': ['47', '56']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_position'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'except_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'raise_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_reheapify'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pos'} | def heapify(self, key=__marker):
if key is self.__marker:
n = len(self._heap)
for pos in reversed(range(n//2)):
self._sink(pos)
else:
try:
pos = self._position[key]
except KeyError:
raise KeyError(key)
self._reheapify(pos) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__update_display_items_model'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'FilteredListModel'},{'id': '11', 'type': 'typed_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data_group'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'DataGroup'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'DataGroup'},{'id': '21', 'type': 'typed_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'type', 'children': ['30']},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'with_statement', 'children': ['33', '40']},{'id': '33', 'type': 'with_clause', 'children': ['34']},{'id': '34', 'type': 'with_item', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'changes'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '75', '124', '169', '213']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data_group'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '52', '63', '69']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'data_group'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'True', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'elif_clause', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '78', 'type': 'string', 'children': [], 'value': '"latest-session"'},{'id': '79', 'type': 'block', 'children': ['80', '88', '104', '112', '118']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'document_model'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'EqFilter'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': '"session_id"'},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'document_model'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'session_id'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'DataItem'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sort_by_date_key'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sort_reverse'},{'id': '117', 'type': 'True', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '124', 'type': 'elif_clause', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '127', 'type': 'string', 'children': [], 'value': '"temporary"'},{'id': '128', 'type': 'block', 'children': ['129', '137', '149', '157', '163']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'document_model'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'NotEqFilter'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': '"category"'},{'id': '148', 'type': 'string', 'children': [], 'value': '"persistent"'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'DataItem'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sort_by_date_key'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'sort_reverse'},{'id': '162', 'type': 'True', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '169', 'type': 'elif_clause', 'children': ['170', '173']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '172', 'type': 'string', 'children': [], 'value': '"none"'},{'id': '173', 'type': 'block', 'children': ['174', '182', '193', '201', '207']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'document_model'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'False', 'children': []},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'DataItem'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sort_by_date_key'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sort_reverse'},{'id': '206', 'type': 'True', 'children': []},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '213', 'type': 'else_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215', '223', '235', '243', '249']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'document_model'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ListModel'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'EqFilter'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'string', 'children': [], 'value': '"category"'},{'id': '234', 'type': 'string', 'children': [], 'value': '"persistent"'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'DataItem'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sort_by_date_key'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'sort_reverse'},{'id': '248', 'type': 'True', 'children': []},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'display_items_model'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'filter_id'},{'id': '254', 'type': 'None', 'children': []} | def __update_display_items_model(self, display_items_model: ListModel.FilteredListModel, data_group: typing.Optional[DataGroup.DataGroup], filter_id: typing.Optional[str]) -> None:
with display_items_model.changes():
if data_group is not None:
display_items_model.container = data_group
display_items_model.filter = ListModel.Filter(True)
display_items_model.sort_key = None
display_items_model.filter_id = None
elif filter_id == "latest-session":
display_items_model.container = self.document_model
display_items_model.filter = ListModel.EqFilter("session_id", self.document_model.session_id)
display_items_model.sort_key = DataItem.sort_by_date_key
display_items_model.sort_reverse = True
display_items_model.filter_id = filter_id
elif filter_id == "temporary":
display_items_model.container = self.document_model
display_items_model.filter = ListModel.NotEqFilter("category", "persistent")
display_items_model.sort_key = DataItem.sort_by_date_key
display_items_model.sort_reverse = True
display_items_model.filter_id = filter_id
elif filter_id == "none":
display_items_model.container = self.document_model
display_items_model.filter = ListModel.Filter(False)
display_items_model.sort_key = DataItem.sort_by_date_key
display_items_model.sort_reverse = True
display_items_model.filter_id = filter_id
else:
display_items_model.container = self.document_model
display_items_model.filter = ListModel.EqFilter("category", "persistent")
display_items_model.sort_key = DataItem.sort_by_date_key
display_items_model.sort_reverse = True
display_items_model.filter_id = None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_date_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'expression_list', 'children': ['8', '25', '28']},{'id': '8', 'type': 'conditional_expression', 'children': ['9', '19', '22'], 'value': 'if'},{'id': '9', 'type': 'binary_operator', 'children': ['10', '13'], 'value': '+'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_live'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'date_for_sorting'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'uuid'} | def sort_by_date_key(data_item):
return data_item.title + str(data_item.uuid) if data_item.is_live else str(), data_item.date_for_sorting, str(data_item.uuid) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'open_mfbpchdataset'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'concat_dim'},{'id': '7', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '10', 'type': 'string', 'children': [], 'value': "'no_conflicts'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'block', 'children': ['20', '27', '37', '46', '52', '69', '78', '91', '101', '117', '132', '141', '151', '157', '166', '182']},{'id': '20', 'type': 'import_from_statement', 'children': ['21', '25']},{'id': '21', 'type': 'dotted_name', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'xarray'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'backends'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '25', 'type': 'dotted_name', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_MultiFileCloser'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dask'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'dask'"},{'id': '36', 'type': 'False', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '40']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'dask'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'raise_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': '"Reading multiple files without dask is not supported"'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '50', 'type': 'string', 'children': [], 'value': "'dask'"},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '58']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '69', 'type': 'if_statement', 'children': ['70', '72']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"No paths to files were passed into open_mfbpchdataset"'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '81', 'type': 'list_comprehension', 'children': ['82', '88']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'open_bpchdataset'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '86', 'type': 'dictionary_splat', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'bpch_objs'},{'id': '94', 'type': 'list_comprehension', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_file_obj'},{'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '109', 'type': 'list_comprehension', 'children': ['110', '114']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'preprocess'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'combined'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'auto_combine'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '129']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'concat_dim'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'concat_dim'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'combined'},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_file_obj'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_MultiFileCloser'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bpch_objs'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'combined'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'get_timestamp'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fns_str'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': '" "'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '173']},{'id': '168', 'type': 'subscript', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'combined'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '172', 'type': 'string', 'children': [], 'value': "'history'"},{'id': '173', 'type': '()', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': '"{}: Processed/loaded by xbpch-{} from {}"'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ver'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'fns_str'},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'combined'} | def open_mfbpchdataset(paths, concat_dim='time', compat='no_conflicts',
preprocess=None, lock=None, **kwargs):
from xarray.backends.api import _MultiFileCloser
dask = kwargs.pop('dask', False)
if not dask:
raise ValueError("Reading multiple files without dask is not supported")
kwargs['dask'] = True
if isinstance(paths, basestring):
paths = sorted(glob(paths))
if not paths:
raise IOError("No paths to files were passed into open_mfbpchdataset")
datasets = [open_bpchdataset(filename, **kwargs)
for filename in paths]
bpch_objs = [ds._file_obj for ds in datasets]
if preprocess is not None:
datasets = [preprocess(ds) for ds in datasets]
combined = xr.auto_combine(datasets, compat=compat, concat_dim=concat_dim)
combined._file_obj = _MultiFileCloser(bpch_objs)
combined.attrs = datasets[0].attrs
ts = get_timestamp()
fns_str = " ".join(paths)
combined.attrs['history'] = (
"{}: Processed/loaded by xbpch-{} from {}"
.format(ts, ver, fns_str)
)
return combined |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_archive_filelist'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'block', 'children': ['6', '10', '88', '100']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'if_statement', 'children': ['11', '17', '42', '74']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tarfile'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'is_tarfile'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'with_statement', 'children': ['19', '30']},{'id': '19', 'type': 'with_clause', 'children': ['20']},{'id': '20', 'type': 'with_item', 'children': ['21']},{'id': '21', 'type': 'as_pattern', 'children': ['22', '28']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tarfile'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '28', 'type': 'as_pattern_target', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tar_file'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'tar_file'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'getnames'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'elif_clause', 'children': ['43', '49']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'is_zipfile'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'with_statement', 'children': ['51', '62']},{'id': '51', 'type': 'with_clause', 'children': ['52']},{'id': '52', 'type': 'with_item', 'children': ['53']},{'id': '53', 'type': 'as_pattern', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '60', 'type': 'as_pattern_target', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'zip_file'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'zip_file'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'namelist'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'concatenated_string', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': '"Can not get filenames from \'{!s}\'. "'},{'id': '84', 'type': 'string', 'children': [], 'value': '"Not a tar or zip file"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'},{'id': '90', 'type': 'string', 'children': [], 'value': '"./"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': '"./"'},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'names'} | def _get_archive_filelist(filename):
names = []
if tarfile.is_tarfile(filename):
with tarfile.open(filename) as tar_file:
names = sorted(tar_file.getnames())
elif zipfile.is_zipfile(filename):
with zipfile.ZipFile(filename) as zip_file:
names = sorted(zip_file.namelist())
else:
raise ValueError("Can not get filenames from '{!s}'. "
"Not a tar or zip file".format(filename))
if "./" in names:
names.remove("./")
return names |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pbar_strings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tqdm'},{'id': '14', 'type': 'argument_list', 'children': ['15', '29', '51', '54']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'lambda', 'children': ['22', '24']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '31', 'type': '()', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '50'], 'value': '+'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '49'], 'value': '+'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '+'},{'id': '35', 'type': 'string', 'children': [], 'value': "'<'"},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '47']},{'id': '40', 'type': 'attribute', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d %H:%M:%S"'},{'id': '49', 'type': 'string', 'children': [], 'value': "'> '"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dynamic_ncols'},{'id': '53', 'type': 'True', 'children': []},{'id': '54', 'type': 'dictionary_splat', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def pbar_strings(files, desc='', **kwargs):
return tqdm(
sorted(files, key=lambda s: s.lower()),
desc=('<' + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + '> ' +
desc),
dynamic_ncols=True,
**kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '18', '29', '40']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'TIME'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'aaa'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '26']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'DATA'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'zzy'"},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'SOURCE'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'zzz'"},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'} | def sort_func(self, key):
if key == self._KEYS.TIME:
return 'aaa'
if key == self._KEYS.DATA:
return 'zzy'
if key == self._KEYS.SOURCE:
return 'zzz'
return key |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '18', '29']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'VALUE'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'aaa'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '26']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'SOURCE'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'zzz'"},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'} | def sort_func(self, key):
if key == self._KEYS.VALUE:
return 'aaa'
if key == self._KEYS.SOURCE:
return 'zzz'
return key |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '18', '29', '40', '51', '62', '73', '84']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'SCHEMA'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'aaa'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '26']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'aab'"},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'SOURCES'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'aac'"},{'id': '40', 'type': 'if_statement', 'children': ['41', '48']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ALIAS'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'aad'"},{'id': '51', 'type': 'if_statement', 'children': ['52', '59']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'MODELS'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'aae'"},{'id': '62', 'type': 'if_statement', 'children': ['63', '70']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'PHOTOMETRY'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'zzy'"},{'id': '73', 'type': 'if_statement', 'children': ['74', '81']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '=='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'SPECTRA'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'zzz'"},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'} | def sort_func(self, key):
if key == self._KEYS.SCHEMA:
return 'aaa'
if key == self._KEYS.NAME:
return 'aab'
if key == self._KEYS.SOURCES:
return 'aac'
if key == self._KEYS.ALIAS:
return 'aad'
if key == self._KEYS.MODELS:
return 'aae'
if key == self._KEYS.PHOTOMETRY:
return 'zzy'
if key == self._KEYS.SPECTRA:
return 'zzz'
return key |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '18', '29', '40']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'TIME'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'aaa'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '26']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'MODEL'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'zzy'"},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_KEYS'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'SOURCE'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'zzz'"},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'} | def sort_func(self, key):
if key == self._KEYS.TIME:
return 'aaa'
if key == self._KEYS.MODEL:
return 'zzy'
if key == self._KEYS.SOURCE:
return 'zzz'
return key |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'TypeFactory'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '5', 'type': 'block', 'children': ['6', '21', '40']},{'id': '6', 'type': 'if_statement', 'children': ['7', '18']},{'id': '7', 'type': 'boolean_operator', 'children': ['8', '13'], 'value': 'and'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Type'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '__types__'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '32']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'represents'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'UnknownType'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'type_'} | def TypeFactory(type_):
if isinstance(type_, type) and issubclass(type_, Type):
return type_
for x in __types__:
if x.represents(type_):
return x.get(type_)
raise UnknownType(type_) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_dependencies'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'service_model'},{'id': '5', 'type': 'block', 'children': ['6', '21', '33', '60', '77']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'app_models'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '20']},{'id': '13', 'type': 'attribute', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'service_model'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'app_config'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_models'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '24', 'type': 'dictionary_comprehension', 'children': ['25', '30']},{'id': '25', 'type': 'pair', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'app_models'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '36', 'type': 'generator_expression', 'children': ['37', '38', '41', '48']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'relation'},{'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'app_models'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'relation'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'related_objects'},{'id': '48', 'type': 'if_clause', 'children': ['49']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': 'in'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'relation'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'on_delete'},{'id': '53', 'type': 'tuple', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'PROTECT'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'CASCADE'},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '73']},{'id': '66', 'type': 'attribute', 'children': ['67', '72']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'related_model'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'stable_topological_sort'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'app_models'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dependencies'} | def get_sorted_dependencies(service_model):
app_models = list(service_model._meta.app_config.get_models())
dependencies = {model: set() for model in app_models}
relations = (
relation
for model in app_models
for relation in model._meta.related_objects
if relation.on_delete in (models.PROTECT, models.CASCADE)
)
for rel in relations:
dependencies[rel.model].add(rel.related_model)
return stable_topological_sort(app_models, dependencies) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_time_and_value_to_segment_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'time_and_value_list'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'segments_count'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start_timestamp'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'end_timestamp'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '25', '104']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'segment_list'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'time_step'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '/'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '-'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'end_timestamp'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start_timestamp'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'segments_count'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '31']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'segments_count'},{'id': '31', 'type': 'block', 'children': ['32', '40', '46', '64', '71', '88']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'segment_start_timestamp'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'start_timestamp'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '*'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'time_step'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'segment_end_timestamp'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'segment_start_timestamp'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'time_step'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'value_list'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '56']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '55']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'time_and_value_list'},{'id': '56', 'type': 'if_clause', 'children': ['57']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'and'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '>='},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'segment_start_timestamp'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '<'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'segment_end_timestamp'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'segment_value'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'value_list'},{'id': '71', 'type': 'if_statement', 'children': ['72', '80']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '74'], 'value': 'and'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '!='},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value_list'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '/='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'segment_value'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'value_list'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'segment_list'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'dictionary', 'children': ['95', '98', '101']},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'segment_start_timestamp'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'segment_end_timestamp'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'segment_value'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'segment_list'} | def format_time_and_value_to_segment_list(time_and_value_list, segments_count, start_timestamp,
end_timestamp, average=False):
segment_list = []
time_step = (end_timestamp - start_timestamp) / segments_count
for i in range(segments_count):
segment_start_timestamp = start_timestamp + time_step * i
segment_end_timestamp = segment_start_timestamp + time_step
value_list = [
value for time, value in time_and_value_list
if time >= segment_start_timestamp and time < segment_end_timestamp]
segment_value = sum(value_list)
if average and len(value_list) != 0:
segment_value /= len(value_list)
segment_list.append({
'from': segment_start_timestamp,
'to': segment_end_timestamp,
'value': segment_value,
})
return segment_list |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_api_root_view'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'api_urls'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15', '25', '47', '154']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'api_root_dict'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list_name'},{'id': '18', 'type': 'attribute', 'children': ['19', '24']},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'routes'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'for_statement', 'children': ['26', '30', '33']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'viewset'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'api_root_dict'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list_name'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '47', 'type': 'class_definition', 'children': ['48', '49', '53']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'APIRootView'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'views'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'APIView'},{'id': '53', 'type': 'block', 'children': ['54', '58', '62']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_ignore_model_permissions'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'exclude_from_schema'},{'id': '61', 'type': 'True', 'children': []},{'id': '62', 'type': 'function_definition', 'children': ['63', '64', '71']},{'id': '63', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '64', 'type': 'parameters', 'children': ['65', '66', '67', '69']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '67', 'type': 'list_splat_pattern', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '69', 'type': 'dictionary_splat_pattern', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '71', 'type': 'block', 'children': ['72', '78', '86', '149']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'resolver_match'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '86', 'type': 'for_statement', 'children': ['87', '90', '104']},{'id': '87', 'type': 'pattern_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url_name'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93', '98']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'api_root_dict'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'block', 'children': ['105', '116']},{'id': '105', 'type': 'if_statement', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'url_name'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '115'], 'value': '+'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '+'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '114', 'type': 'string', 'children': [], 'value': "':'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'url_name'},{'id': '116', 'type': 'try_statement', 'children': ['117', '145']},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '130', '133', '136']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'url_name'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'format'"},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'except_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'continue_statement', 'children': []},{'id': '149', 'type': 'return_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '154', 'type': 'return_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'APIRootView'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'as_view'},{'id': '159', 'type': 'argument_list', 'children': []} | def get_api_root_view(self, api_urls=None):
api_root_dict = OrderedDict()
list_name = self.routes[0].name
for prefix, viewset, basename in self.registry:
api_root_dict[prefix] = list_name.format(basename=basename)
class APIRootView(views.APIView):
_ignore_model_permissions = True
exclude_from_schema = True
def get(self, request, *args, **kwargs):
ret = OrderedDict()
namespace = request.resolver_match.namespace
for key, url_name in sorted(api_root_dict.items(), key=itemgetter(0)):
if namespace:
url_name = namespace + ':' + url_name
try:
ret[key] = reverse(
url_name,
args=args,
kwargs=kwargs,
request=request,
format=kwargs.get('format', None)
)
except NoReverseMatch:
continue
return Response(ret)
return APIRootView.as_view() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_default_base_name'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'viewset'},{'id': '6', 'type': 'block', 'children': ['7', '16', '41']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14', '15']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'viewset'},{'id': '14', 'type': 'string', 'children': [], 'value': "'queryset'"},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '32']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_url_name'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30', '31']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '30', 'type': 'string', 'children': [], 'value': "'get_url_name'"},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_url_name'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_url_name'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '50']},{'id': '43', 'type': 'attribute', 'children': ['44', '49']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'SortedDefaultRouter'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_default_base_name'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'viewset'} | def get_default_base_name(self, viewset):
queryset = getattr(viewset, 'queryset', None)
if queryset is not None:
get_url_name = getattr(queryset.model, 'get_url_name', None)
if get_url_name is not None:
return get_url_name()
return super(SortedDefaultRouter, self).get_default_base_name(viewset) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '31']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '14', 'type': 'argument_list', 'children': ['15', '20', '28']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'lambda', 'children': ['23', '25']},{'id': '23', 'type': 'lambda_parameters', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'} | def sort_dict(d, desc=True):
sort = sorted(d.items(), key=lambda x: x[1], reverse=desc)
return OrderedDict(sort) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_tupleCompare'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tuple1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ineq'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tuple2'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '9', 'type': 'lambda', 'children': ['10', '13']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '13', 'type': '()', 'children': ['14']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ander'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'AND'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'orer'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'OR'},{'id': '23', 'type': 'block', 'children': ['24', '28', '87']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'orholder'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '37']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tuple1'},{'id': '37', 'type': 'block', 'children': ['38', '60', '72']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'eqconstraint'},{'id': '41', 'type': 'list_comprehension', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'elem1'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'elem2'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '51']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'elem1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'elem2'},{'id': '51', 'type': 'subscript', 'children': ['52', '57']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tuple1'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tuple2'},{'id': '57', 'type': 'slice', 'children': ['58', '59']},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ineqconstraint'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ineq'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tuple1'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'tuple2'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'orholder'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ander'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'list_splat', 'children': ['82']},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'eqconstraint'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': '[ineqconstraint]'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ineqconstraint'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'orer'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'list_splat', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'orholder'} | def _tupleCompare(tuple1, ineq, tuple2,
eq=lambda a,b: (a==b),
ander=AND,
orer=OR):
orholder = []
for limit in range(len(tuple1)):
eqconstraint = [
eq(elem1, elem2) for elem1, elem2 in zip(tuple1, tuple2)[:limit]]
ineqconstraint = ineq(tuple1[limit], tuple2[limit])
orholder.append(ander(*(eqconstraint + [ineqconstraint])))
return orer(*orholder) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_datasets'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '7', 'type': 'string', 'children': [], 'value': "'*:*'"},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '22']},{'id': '13', 'type': 'attribute', 'children': ['14', '21']},{'id': '14', 'type': 'attribute', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'hdx'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Dataset'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'search_in_hdx'},{'id': '22', 'type': 'argument_list', 'children': ['23', '26', '31', '40']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fq'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': "'organization:%s'"},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '39', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '40', 'type': 'dictionary_splat', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def get_datasets(self, query='*:*', **kwargs):
return hdx.data.dataset.Dataset.search_in_hdx(query=query,
configuration=self.configuration,
fq='organization:%s' % self.data['name'], **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all_organization_names'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '19', '25']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '23', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'all organizations'"},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_write_to_hdx'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']},{'id': '31', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '33', 'type': 'string', 'children': [], 'value': "'id'"} | def get_all_organization_names(configuration=None, **kwargs):
organization = Organization(configuration=configuration)
organization['id'] = 'all organizations'
return organization._write_to_hdx('list', kwargs, 'id') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_in_hdx'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '7', 'type': 'string', 'children': [], 'value': "'*:*'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '26', '38', '48', '52', '56', '300', '316']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Dataset'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'total_rows'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'rows'"},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'max_int'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'attempts'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'while_statement', 'children': ['57', '66']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '63'], 'value': 'and'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '<'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'attempts'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'max_attempts'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'block', 'children': ['67', '73', '79', '248']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '89']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '+'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '//'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'total_rows'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'block', 'children': ['90', '96', '104', '110', '118', '124', '146', '152']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pagetimespagesize'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '*'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '100', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pagetimespagesize'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rows_left'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '-'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'total_rows'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pagetimespagesize'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rows_left'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '122', 'type': 'string', 'children': [], 'value': "'rows'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_read_from_hdx'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136', '137', '144']},{'id': '134', 'type': 'string', 'children': [], 'value': "'dataset'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '136', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '137', 'type': 'subscript', 'children': ['138', '143']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'Dataset'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'string', 'children': [], 'value': "'search'"},{'id': '144', 'type': 'dictionary_splat', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '154', '239']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '154', 'type': 'block', 'children': ['155', '165']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'if_statement', 'children': ['166', '167', '236']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '167', 'type': 'block', 'children': ['168', '175', '184', '226', '230']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'no_results'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '183', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '184', 'type': 'for_statement', 'children': ['185', '186', '189']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'datasetdict'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '188', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '189', 'type': 'block', 'children': ['190', '199', '207', '213', '219']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Dataset'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'old_data'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '206', 'type': 'argument_list', 'children': []},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'datasetdict'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '217', 'type': 'identifier', 'children': [], 'value': '_dataset_create_resources'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'augmented_assignment', 'children': ['228', '229'], 'value': '+='},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '230', 'type': 'if_statement', 'children': ['231', '234']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': '<'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'no_results'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'break_statement', 'children': []},{'id': '236', 'type': 'else_clause', 'children': ['237']},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'break_statement', 'children': []},{'id': '239', 'type': 'else_clause', 'children': ['240']},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '248', 'type': 'if_statement', 'children': ['249', '257', '266']},{'id': '249', 'type': 'boolean_operator', 'children': ['250', '251'], 'value': 'and'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '256'], 'value': '!='},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'block', 'children': ['258', '262']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '261', 'type': 'None', 'children': []},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'augmented_assignment', 'children': ['264', '265'], 'value': '+='},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'attempts'},{'id': '265', 'type': 'integer', 'children': [], 'value': '1'},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268', '278']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '271', 'type': 'list_comprehension', 'children': ['272', '275']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '274', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '275', 'type': 'for_in_clause', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '278', 'type': 'if_statement', 'children': ['279', '291']},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '284'], 'value': '!='},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '291', 'type': 'block', 'children': ['292', '296']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '295', 'type': 'None', 'children': []},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'augmented_assignment', 'children': ['298', '299'], 'value': '+='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'attempts'},{'id': '299', 'type': 'integer', 'children': [], 'value': '1'},{'id': '300', 'type': 'if_statement', 'children': ['301', '310']},{'id': '301', 'type': 'boolean_operator', 'children': ['302', '307'], 'value': 'and'},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '304'], 'value': '=='},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'attempts'},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'max_attempts'},{'id': '307', 'type': 'comparison_operator', 'children': ['308', '309'], 'value': 'is'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'all_datasets'},{'id': '309', 'type': 'None', 'children': []},{'id': '310', 'type': 'block', 'children': ['311']},{'id': '311', 'type': 'raise_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'HDXError'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'string', 'children': [], 'value': "'Maximum attempts reached for searching for datasets!'"},{'id': '316', 'type': 'return_statement', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'all_datasets'} | def search_in_hdx(cls, query='*:*', configuration=None, page_size=1000, **kwargs):
dataset = Dataset(configuration=configuration)
total_rows = kwargs.get('rows', cls.max_int)
start = kwargs.get('start', 0)
all_datasets = None
attempts = 0
while attempts < cls.max_attempts and all_datasets is None:
all_datasets = list()
counts = set()
for page in range(total_rows // page_size + 1):
pagetimespagesize = page * page_size
kwargs['start'] = start + pagetimespagesize
rows_left = total_rows - pagetimespagesize
rows = min(rows_left, page_size)
kwargs['rows'] = rows
_, result = dataset._read_from_hdx('dataset', query, 'q', Dataset.actions()['search'], **kwargs)
datasets = list()
if result:
count = result.get('count', None)
if count:
counts.add(count)
no_results = len(result['results'])
for datasetdict in result['results']:
dataset = Dataset(configuration=configuration)
dataset.old_data = dict()
dataset.data = datasetdict
dataset._dataset_create_resources()
datasets.append(dataset)
all_datasets += datasets
if no_results < rows:
break
else:
break
else:
logger.debug(result)
if all_datasets and len(counts) != 1:
all_datasets = None
attempts += 1
else:
ids = [dataset['id'] for dataset in all_datasets]
if len(ids) != len(set(ids)):
all_datasets = None
attempts += 1
if attempts == cls.max_attempts and all_datasets is None:
raise HDXError('Maximum attempts reached for searching for datasets!')
return all_datasets |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '13']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '17']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'allow_duplicates'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'type', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '22', 'type': 'block', 'children': ['23', '93']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27', '32', '86']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '26', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'elif_clause', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '35', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '36', 'type': 'block', 'children': ['37', '48', '82']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '64']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '62'], 'value': 'and'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '!='},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'allow_duplicates'},{'id': '64', 'type': 'block', 'children': ['65', '72']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'find_duplicates'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"There are duplicates in the values: {}"'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': '"by can be \'key\' or \'value\'."'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '101', 'type': 'argument_list', 'children': ['102', '107']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '109', 'type': 'lambda', 'children': ['110', '112']},{'id': '110', 'type': 'lambda_parameters', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'} | def sort_dict(d: dict, by: str = 'key',
allow_duplicates: bool = True) -> collections.OrderedDict:
if by == 'key':
i = 0
elif by == 'value':
values = list(d.values())
if len(values) != len(set(values)) and not allow_duplicates:
duplicates = find_duplicates(values)
raise ValueError("There are duplicates in the values: {}".format(duplicates))
i = 1
else:
raise ValueError("by can be 'key' or 'value'.")
return collections.OrderedDict(sorted(d.items(), key=lambda t: t[i])) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all_users'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '19', '25', '36', '42', '75']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '23', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'all users'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_write_to_hdx'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']},{'id': '33', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'if_statement', 'children': ['43', '44', '66']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'userdict'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '48', 'type': 'block', 'children': ['49', '59']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'userdict'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'users'} | def get_all_users(configuration=None, **kwargs):
user = User(configuration=configuration)
user['id'] = 'all users'
result = user._write_to_hdx('list', kwargs, 'id')
users = list()
if result:
for userdict in result:
user = User(userdict, configuration=configuration)
users.append(user)
else:
logger.debug(result)
return users |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.