sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:previous; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 28; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_order_by; 11, string:'oldest'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:older; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:==; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_order_by; 22, string:'newest'; 23, block; 23, 24; 24, return_statement; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:newer; 28, return_statement; 28, 29; 29, None
def previous(self): if self._order_by == 'oldest': return self.older if self._order_by == 'newest': return self.newer return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:next; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 28; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_order_by; 11, string:'oldest'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:newer; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:==; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_order_by; 22, string:'newest'; 23, block; 23, 24; 24, return_statement; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:older; 28, return_statement; 28, 29; 29, None
def next(self): if self._order_by == 'oldest': return self.newer if self._order_by == 'newest': return self.older return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:newest; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 28; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_order_by; 11, string:'newest'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:first; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:==; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_order_by; 22, string:'oldest'; 23, block; 23, 24; 24, return_statement; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:last; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:max; 31, argument_list; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:entries; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:x; 40, tuple; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:date; 44, attribute; 44, 45; 44, 46; 45, identifier:x; 46, identifier:id
def newest(self): if self._order_by == 'newest': return self.first if self._order_by == 'oldest': return self.last return max(self.entries, key=lambda x: (x.date, x.id))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:oldest; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 28; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_order_by; 11, string:'newest'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:last; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:==; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_order_by; 22, string:'oldest'; 23, block; 23, 24; 24, return_statement; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:first; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:min; 31, argument_list; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:entries; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:x; 40, tuple; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:date; 44, unary_operator:-; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:x; 47, identifier:id
def oldest(self): if self._order_by == 'newest': return self.last if self._order_by == 'oldest': return self.first return min(self.entries, key=lambda x: (x.date, -x.id))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_dataframe_cols; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 38; 5, 47; 5, 51; 5, 69; 5, 79; 5, 83; 5, 97; 5, 116; 5, 123; 5, 156; 5, 166; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:cols; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:df; 13, identifier:columns; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:groups; 17, call; 17, 18; 17, 19; 18, identifier:list; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:map; 22, argument_list; 22, 23; 22, 37; 23, lambda; 23, 24; 23, 26; 24, lambda_parameters; 24, 25; 25, identifier:x; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:data_model; 31, identifier:get_group_for_col; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:dtype; 36, identifier:x; 37, identifier:cols; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:sorted_cols; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:cols; 44, identifier:groupby; 45, argument_list; 45, 46; 46, identifier:groups; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ordered_cols; 50, list:[]; 51, try_statement; 51, 52; 51, 62; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:names; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:sorted_cols; 59, identifier:pop; 60, argument_list; 60, 61; 61, string:'Names'; 62, except_clause; 62, 63; 62, 64; 63, identifier:KeyError; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:names; 68, list:[]; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:ordered_cols; 73, identifier:extend; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:list; 77, argument_list; 77, 78; 78, identifier:names; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:no_group; 82, list:[]; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:in; 84, 85; 84, 86; 85, string:''; 86, identifier:sorted_cols; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:no_group; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:sorted_cols; 94, identifier:pop; 95, argument_list; 95, 96; 96, string:''; 97, for_statement; 97, 98; 97, 99; 97, 103; 98, identifier:k; 99, call; 99, 100; 99, 101; 100, identifier:sorted; 101, argument_list; 101, 102; 102, identifier:sorted_cols; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:ordered_cols; 108, identifier:extend; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:sorted; 112, argument_list; 112, 113; 113, subscript; 113, 114; 113, 115; 114, identifier:sorted_cols; 115, identifier:k; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:ordered_cols; 120, identifier:extend; 121, argument_list; 121, 122; 122, identifier:no_group; 123, try_statement; 123, 124; 123, 152; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 131; 126, comparison_operator:in; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:name; 130, identifier:ordered_cols; 131, block; 131, 132; 131, 141; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:ordered_cols; 136, identifier:remove; 137, argument_list; 137, 138; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:name; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 148; 143, subscript; 143, 144; 143, 145; 144, identifier:ordered_cols; 145, slice; 145, 146; 145, 147; 146, colon; 147, integer:0; 148, list:[self.name]; 148, 149; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:name; 152, except_clause; 152, 153; 152, 154; 153, identifier:AttributeError; 154, block; 154, 155; 155, pass_statement; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:df; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:df; 165, identifier:ordered_cols; 166, return_statement; 166, 167; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:df
def sort_dataframe_cols(self): cols = self.df.columns groups = list(map(lambda x: self.data_model.get_group_for_col(self.dtype, x), cols)) sorted_cols = cols.groupby(groups) ordered_cols = [] try: names = sorted_cols.pop('Names') except KeyError: names = [] ordered_cols.extend(list(names)) no_group = [] if '' in sorted_cols: no_group = sorted_cols.pop('') for k in sorted(sorted_cols): ordered_cols.extend(sorted(sorted_cols[k])) ordered_cols.extend(no_group) try: if self.name in ordered_cols: ordered_cols.remove(self.name) ordered_cols[:0] = [self.name] except AttributeError: pass self.df = self.df[ordered_cols] return self.df
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_diclist; 3, parameters; 3, 4; 3, 5; 4, identifier:undecorated; 5, identifier:sort_on; 6, block; 6, 7; 6, 38; 6, 44; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:decorated; 10, list_comprehension; 10, 11; 10, 30; 11, tuple; 11, 12; 11, 29; 12, conditional_expression:if; 12, 13; 12, 19; 12, 26; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, subscript; 16, 17; 16, 18; 17, identifier:dict_; 18, identifier:sort_on; 19, call; 19, 20; 19, 21; 20, identifier:hasattr; 21, argument_list; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:dict_; 24, identifier:sort_on; 25, string:'__len__'; 26, subscript; 26, 27; 26, 28; 27, identifier:dict_; 28, identifier:sort_on; 29, identifier:index; 30, for_in_clause; 30, 31; 30, 34; 31, tuple_pattern; 31, 32; 31, 33; 32, identifier:index; 33, identifier:dict_; 34, call; 34, 35; 34, 36; 35, identifier:enumerate; 36, argument_list; 36, 37; 37, identifier:undecorated; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:decorated; 42, identifier:sort; 43, argument_list; 44, return_statement; 44, 45; 45, list_comprehension; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:undecorated; 48, identifier:index; 49, for_in_clause; 49, 50; 49, 53; 50, tuple_pattern; 50, 51; 50, 52; 51, identifier:key; 52, identifier:index; 53, identifier:decorated
def sort_diclist(undecorated, sort_on): decorated = [(len(dict_[sort_on]) if hasattr(dict_[sort_on], '__len__') else dict_[ sort_on], index) for (index, dict_) in enumerate(undecorated)] decorated.sort() return[undecorated[index] for (key, index) in decorated]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:process_data_for_mean; 3, parameters; 3, 4; 3, 5; 4, identifier:data; 5, identifier:direction_type_key; 6, block; 6, 7; 6, 17; 6, 38; 6, 46; 6, 54; 6, 61; 6, 358; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 13; 9, pattern_list; 9, 10; 9, 11; 9, 12; 10, identifier:dec_key; 11, identifier:inc_key; 12, identifier:meth_key; 13, expression_list; 13, 14; 13, 15; 13, 16; 14, string:'dec'; 15, string:'inc'; 16, string:'magic_method_codes'; 17, if_statement; 17, 18; 17, 27; 18, comparison_operator:in; 18, 19; 18, 20; 19, string:'dir_dec'; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:data; 24, integer:0; 25, identifier:keys; 26, argument_list; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 34; 30, pattern_list; 30, 31; 30, 32; 30, 33; 31, identifier:dec_key; 32, identifier:inc_key; 33, identifier:meth_key; 34, expression_list; 34, 35; 34, 36; 34, 37; 35, string:'dir_dec'; 36, string:'dir_inc'; 37, string:'method_codes'; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, pattern_list; 40, 41; 40, 42; 41, identifier:n_lines; 42, identifier:n_planes; 43, expression_list; 43, 44; 43, 45; 44, integer:0; 45, integer:0; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:L; 50, identifier:fdata; 51, expression_list; 51, 52; 51, 53; 52, list:[]; 53, list:[]; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:E; 57, list:[0, 0, 0]; 57, 58; 57, 59; 57, 60; 58, integer:0; 59, integer:0; 60, integer:0; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:rec; 63, identifier:data; 64, block; 64, 65; 64, 86; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:cart; 68, subscript; 68, 69; 68, 85; 69, call; 69, 70; 69, 71; 70, identifier:dir2cart; 71, argument_list; 71, 72; 72, list:[float(rec[dec_key]), float(rec[inc_key])]; 72, 73; 72, 79; 73, call; 73, 74; 73, 75; 74, identifier:float; 75, argument_list; 75, 76; 76, subscript; 76, 77; 76, 78; 77, identifier:rec; 78, identifier:dec_key; 79, call; 79, 80; 79, 81; 80, identifier:float; 81, argument_list; 81, 82; 82, subscript; 82, 83; 82, 84; 83, identifier:rec; 84, identifier:inc_key; 85, integer:0; 86, if_statement; 86, 87; 86, 97; 86, 166; 86, 240; 86, 314; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:direction_type_key; 89, call; 89, 90; 89, 91; 90, identifier:list; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:rec; 95, identifier:keys; 96, argument_list; 97, block; 97, 98; 98, if_statement; 98, 99; 98, 104; 98, 116; 99, comparison_operator:==; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:rec; 102, identifier:direction_type_key; 103, string:'p'; 104, block; 104, 105; 104, 109; 105, expression_statement; 105, 106; 106, augmented_assignment:+=; 106, 107; 106, 108; 107, identifier:n_planes; 108, integer:1; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:L; 113, identifier:append; 114, argument_list; 114, 115; 115, identifier:cart; 116, else_clause; 116, 117; 117, block; 117, 118; 117, 122; 117, 142; 117, 150; 117, 158; 118, expression_statement; 118, 119; 119, augmented_assignment:+=; 119, 120; 119, 121; 120, identifier:n_lines; 121, integer:1; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:fdata; 126, identifier:append; 127, argument_list; 127, 128; 128, list:[float(rec[dec_key]), float(rec[inc_key]), 1.]; 128, 129; 128, 135; 128, 141; 129, call; 129, 130; 129, 131; 130, identifier:float; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:rec; 134, identifier:dec_key; 135, call; 135, 136; 135, 137; 136, identifier:float; 137, argument_list; 137, 138; 138, subscript; 138, 139; 138, 140; 139, identifier:rec; 140, identifier:inc_key; 141, float:1.; 142, expression_statement; 142, 143; 143, augmented_assignment:+=; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:E; 146, integer:0; 147, subscript; 147, 148; 147, 149; 148, identifier:cart; 149, integer:0; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:E; 154, integer:1; 155, subscript; 155, 156; 155, 157; 156, identifier:cart; 157, integer:1; 158, expression_statement; 158, 159; 159, augmented_assignment:+=; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:E; 162, integer:2; 163, subscript; 163, 164; 163, 165; 164, identifier:cart; 165, integer:2; 166, elif_clause; 166, 167; 166, 177; 167, comparison_operator:in; 167, 168; 167, 169; 168, string:'method_codes'; 169, call; 169, 170; 169, 171; 170, identifier:list; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:rec; 175, identifier:keys; 176, argument_list; 177, block; 177, 178; 178, if_statement; 178, 179; 178, 184; 178, 196; 179, comparison_operator:in; 179, 180; 179, 181; 180, string:"DE-BFP"; 181, subscript; 181, 182; 181, 183; 182, identifier:rec; 183, identifier:meth_key; 184, block; 184, 185; 184, 189; 185, expression_statement; 185, 186; 186, augmented_assignment:+=; 186, 187; 186, 188; 187, identifier:n_planes; 188, integer:1; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:L; 193, identifier:append; 194, argument_list; 194, 195; 195, identifier:cart; 196, else_clause; 196, 197; 197, block; 197, 198; 197, 202; 197, 216; 197, 224; 197, 232; 198, expression_statement; 198, 199; 199, augmented_assignment:+=; 199, 200; 199, 201; 200, identifier:n_lines; 201, integer:1; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:fdata; 206, identifier:append; 207, argument_list; 207, 208; 208, list:[rec[dec_key], rec[inc_key], 1.]; 208, 209; 208, 212; 208, 215; 209, subscript; 209, 210; 209, 211; 210, identifier:rec; 211, identifier:dec_key; 212, subscript; 212, 213; 212, 214; 213, identifier:rec; 214, identifier:inc_key; 215, float:1.; 216, expression_statement; 216, 217; 217, augmented_assignment:+=; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:E; 220, integer:0; 221, subscript; 221, 222; 221, 223; 222, identifier:cart; 223, integer:0; 224, expression_statement; 224, 225; 225, augmented_assignment:+=; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:E; 228, integer:1; 229, subscript; 229, 230; 229, 231; 230, identifier:cart; 231, integer:1; 232, expression_statement; 232, 233; 233, augmented_assignment:+=; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:E; 236, integer:2; 237, subscript; 237, 238; 237, 239; 238, identifier:cart; 239, integer:2; 240, elif_clause; 240, 241; 240, 251; 241, comparison_operator:in; 241, 242; 241, 243; 242, identifier:meth_key; 243, call; 243, 244; 243, 245; 244, identifier:list; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:rec; 249, identifier:keys; 250, argument_list; 251, block; 251, 252; 252, if_statement; 252, 253; 252, 258; 252, 270; 253, comparison_operator:in; 253, 254; 253, 255; 254, string:"DE-BFP"; 255, subscript; 255, 256; 255, 257; 256, identifier:rec; 257, identifier:meth_key; 258, block; 258, 259; 258, 263; 259, expression_statement; 259, 260; 260, augmented_assignment:+=; 260, 261; 260, 262; 261, identifier:n_planes; 262, integer:1; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:L; 267, identifier:append; 268, argument_list; 268, 269; 269, identifier:cart; 270, else_clause; 270, 271; 271, block; 271, 272; 271, 276; 271, 290; 271, 298; 271, 306; 272, expression_statement; 272, 273; 273, augmented_assignment:+=; 273, 274; 273, 275; 274, identifier:n_lines; 275, integer:1; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:fdata; 280, identifier:append; 281, argument_list; 281, 282; 282, list:[rec[dec_key], rec[inc_key], 1.]; 282, 283; 282, 286; 282, 289; 283, subscript; 283, 284; 283, 285; 284, identifier:rec; 285, identifier:dec_key; 286, subscript; 286, 287; 286, 288; 287, identifier:rec; 288, identifier:inc_key; 289, float:1.; 290, expression_statement; 290, 291; 291, augmented_assignment:+=; 291, 292; 291, 295; 292, subscript; 292, 293; 292, 294; 293, identifier:E; 294, integer:0; 295, subscript; 295, 296; 295, 297; 296, identifier:cart; 297, integer:0; 298, expression_statement; 298, 299; 299, augmented_assignment:+=; 299, 300; 299, 303; 300, subscript; 300, 301; 300, 302; 301, identifier:E; 302, integer:1; 303, subscript; 303, 304; 303, 305; 304, identifier:cart; 305, integer:1; 306, expression_statement; 306, 307; 307, augmented_assignment:+=; 307, 308; 307, 311; 308, subscript; 308, 309; 308, 310; 309, identifier:E; 310, integer:2; 311, subscript; 311, 312; 311, 313; 312, identifier:cart; 313, integer:2; 314, else_clause; 314, 315; 315, block; 315, 316; 315, 320; 315, 334; 315, 342; 315, 350; 316, expression_statement; 316, 317; 317, augmented_assignment:+=; 317, 318; 317, 319; 318, identifier:n_lines; 319, integer:1; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:fdata; 324, identifier:append; 325, argument_list; 325, 326; 326, list:[rec[dec_key], rec[inc_key], 1.]; 326, 327; 326, 330; 326, 333; 327, subscript; 327, 328; 327, 329; 328, identifier:rec; 329, identifier:dec_key; 330, subscript; 330, 331; 330, 332; 331, identifier:rec; 332, identifier:inc_key; 333, float:1.; 334, expression_statement; 334, 335; 335, augmented_assignment:+=; 335, 336; 335, 339; 336, subscript; 336, 337; 336, 338; 337, identifier:E; 338, integer:0; 339, subscript; 339, 340; 339, 341; 340, identifier:cart; 341, integer:0; 342, expression_statement; 342, 343; 343, augmented_assignment:+=; 343, 344; 343, 347; 344, subscript; 344, 345; 344, 346; 345, identifier:E; 346, integer:1; 347, subscript; 347, 348; 347, 349; 348, identifier:cart; 349, integer:1; 350, expression_statement; 350, 351; 351, augmented_assignment:+=; 351, 352; 351, 355; 352, subscript; 352, 353; 352, 354; 353, identifier:E; 354, integer:2; 355, subscript; 355, 356; 355, 357; 356, identifier:cart; 357, integer:2; 358, return_statement; 358, 359; 359, expression_list; 359, 360; 359, 361; 359, 362; 359, 363; 359, 364; 360, identifier:fdata; 361, identifier:n_lines; 362, identifier:L; 363, identifier:n_planes; 364, identifier:E
def process_data_for_mean(data, direction_type_key): dec_key, inc_key, meth_key = 'dec', 'inc', 'magic_method_codes' if 'dir_dec' in data[0].keys(): dec_key, inc_key, meth_key = 'dir_dec', 'dir_inc', 'method_codes' n_lines, n_planes = 0, 0 L, fdata = [], [] E = [0, 0, 0] for rec in data: cart = dir2cart([float(rec[dec_key]), float(rec[inc_key])])[0] if direction_type_key in list(rec.keys()): if rec[direction_type_key] == 'p': n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([float(rec[dec_key]), float(rec[inc_key]), 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] elif 'method_codes' in list(rec.keys()): if "DE-BFP" in rec[meth_key]: n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] elif meth_key in list(rec.keys()): if "DE-BFP" in rec[meth_key]: n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] return fdata, n_lines, L, n_planes, E
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main; 3, parameters; 4, block; 4, 5; 4, 9; 4, 13; 4, 41; 4, 61; 4, 89; 4, 103; 4, 111; 4, 121; 4, 132; 4, 149; 4, 159; 4, 247; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:dir_path; 8, string:'.'; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:inspec; 12, string:"pmag_specimens.txt"; 13, if_statement; 13, 14; 13, 19; 14, comparison_operator:in; 14, 15; 14, 16; 15, string:'-WD'; 16, attribute; 16, 17; 16, 18; 17, identifier:sys; 18, identifier:argv; 19, block; 19, 20; 19, 31; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ind; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:sys; 27, identifier:argv; 28, identifier:index; 29, argument_list; 29, 30; 30, string:'-WD'; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:dir_path; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:sys; 37, identifier:argv; 38, binary_operator:+; 38, 39; 38, 40; 39, identifier:ind; 40, integer:1; 41, if_statement; 41, 42; 41, 47; 42, comparison_operator:in; 42, 43; 42, 44; 43, string:'-h'; 44, attribute; 44, 45; 44, 46; 45, identifier:sys; 46, identifier:argv; 47, block; 47, 48; 47, 55; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:print; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:main; 54, identifier:__doc__; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:sys; 59, identifier:exit; 60, argument_list; 61, if_statement; 61, 62; 61, 67; 62, comparison_operator:in; 62, 63; 62, 64; 63, string:'-f'; 64, attribute; 64, 65; 64, 66; 65, identifier:sys; 66, identifier:argv; 67, block; 67, 68; 67, 79; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:ind; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:sys; 75, identifier:argv; 76, identifier:index; 77, argument_list; 77, 78; 78, string:'-f'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:inspec; 82, subscript; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:sys; 85, identifier:argv; 86, binary_operator:+; 86, 87; 86, 88; 87, identifier:ind; 88, integer:1; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:basename; 92, subscript; 92, 93; 92, 99; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:inspec; 96, identifier:split; 97, argument_list; 97, 98; 98, string:'.'; 99, slice; 99, 100; 99, 101; 100, colon; 101, unary_operator:-; 101, 102; 102, integer:1; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:inspec; 106, binary_operator:+; 106, 107; 106, 110; 107, binary_operator:+; 107, 108; 107, 109; 108, identifier:dir_path; 109, string:"/"; 110, identifier:inspec; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:ofile_base; 114, binary_operator:+; 114, 115; 114, 118; 115, binary_operator:+; 115, 116; 115, 117; 116, identifier:dir_path; 117, string:"/"; 118, subscript; 118, 119; 118, 120; 119, identifier:basename; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, pattern_list; 123, 124; 123, 125; 124, identifier:prior_spec_data; 125, identifier:file_type; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:pmag; 129, identifier:magic_read; 130, argument_list; 130, 131; 131, identifier:inspec; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:!=; 133, 134; 133, 135; 134, identifier:file_type; 135, string:'pmag_specimens'; 136, block; 136, 137; 136, 143; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:print; 140, argument_list; 140, 141; 140, 142; 141, identifier:file_type; 142, string:" this is not a valid pmag_specimens file"; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:sys; 147, identifier:exit; 148, argument_list; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 155; 151, pattern_list; 151, 152; 151, 153; 151, 154; 152, identifier:specs; 153, identifier:comps; 154, identifier:coords; 155, expression_list; 155, 156; 155, 157; 155, 158; 156, list:[]; 157, list:[]; 158, list:[]; 159, for_statement; 159, 160; 159, 161; 159, 162; 160, identifier:spec; 161, identifier:prior_spec_data; 162, block; 162, 163; 162, 179; 162, 197; 162, 215; 162, 231; 163, if_statement; 163, 164; 163, 169; 164, comparison_operator:not; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:spec; 167, string:'er_specimen_name'; 168, identifier:specs; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:specs; 174, identifier:append; 175, argument_list; 175, 176; 176, subscript; 176, 177; 176, 178; 177, identifier:spec; 178, string:'er_specimen_name'; 179, if_statement; 179, 180; 179, 190; 180, comparison_operator:not; 180, 181; 180, 182; 181, string:'specimen_comp_name'; 182, call; 182, 183; 182, 184; 183, identifier:list; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:spec; 188, identifier:keys; 189, argument_list; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:spec; 195, string:'specimen_comp_name'; 196, string:'A'; 197, if_statement; 197, 198; 197, 208; 198, comparison_operator:not; 198, 199; 198, 200; 199, string:'specimen_tilt_correction'; 200, call; 200, 201; 200, 202; 201, identifier:list; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:spec; 206, identifier:keys; 207, argument_list; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:spec; 213, string:'tilt_correction'; 214, string:'-1'; 215, if_statement; 215, 216; 215, 221; 216, comparison_operator:not; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:spec; 219, string:'specimen_comp_name'; 220, identifier:comps; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:comps; 226, identifier:append; 227, argument_list; 227, 228; 228, subscript; 228, 229; 228, 230; 229, identifier:spec; 230, string:'specimen_comp_name'; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:not; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:spec; 235, string:'specimen_tilt_correction'; 236, identifier:coords; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:coords; 242, identifier:append; 243, argument_list; 243, 244; 244, subscript; 244, 245; 244, 246; 245, identifier:spec; 246, string:'specimen_tilt_correction'; 247, for_statement; 247, 248; 247, 249; 247, 250; 248, identifier:coord; 249, identifier:coords; 250, block; 250, 251; 250, 256; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:print; 254, argument_list; 254, 255; 255, identifier:coord; 256, for_statement; 256, 257; 256, 258; 256, 259; 257, identifier:comp; 258, identifier:comps; 259, block; 259, 260; 259, 265; 259, 269; 259, 293; 259, 307; 259, 316; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 263; 262, identifier:print; 263, argument_list; 263, 264; 264, identifier:comp; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:speclist; 268, list:[]; 269, for_statement; 269, 270; 269, 271; 269, 272; 270, identifier:spec; 271, identifier:prior_spec_data; 272, block; 272, 273; 273, if_statement; 273, 274; 273, 285; 274, boolean_operator:and; 274, 275; 274, 280; 275, comparison_operator:==; 275, 276; 275, 279; 276, subscript; 276, 277; 276, 278; 277, identifier:spec; 278, string:'specimen_tilt_correction'; 279, identifier:coord; 280, comparison_operator:==; 280, 281; 280, 284; 281, subscript; 281, 282; 281, 283; 282, identifier:spec; 283, string:'specimen_comp_name'; 284, identifier:comp; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:speclist; 290, identifier:append; 291, argument_list; 291, 292; 292, identifier:spec; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:ofile; 296, binary_operator:+; 296, 297; 296, 306; 297, binary_operator:+; 297, 298; 297, 305; 298, binary_operator:+; 298, 299; 298, 304; 299, binary_operator:+; 299, 300; 299, 303; 300, binary_operator:+; 300, 301; 300, 302; 301, identifier:ofile_base; 302, string:'_'; 303, identifier:coord; 304, string:'_'; 305, identifier:comp; 306, string:'.txt'; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:pmag; 311, identifier:magic_write; 312, argument_list; 312, 313; 312, 314; 312, 315; 313, identifier:ofile; 314, identifier:speclist; 315, string:'pmag_specimens'; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:print; 319, argument_list; 319, 320; 319, 321; 319, 322; 319, 323; 319, 324; 319, 325; 320, string:'coordinate system: '; 321, identifier:coord; 322, string:' component name: '; 323, identifier:comp; 324, string:' saved in '; 325, identifier:ofile
def main(): dir_path='.' inspec="pmag_specimens.txt" if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print(main.__doc__) sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') inspec=sys.argv[ind+1] basename=inspec.split('.')[:-1] inspec=dir_path+"/"+inspec ofile_base=dir_path+"/"+basename[0] prior_spec_data,file_type=pmag.magic_read(inspec) if file_type != 'pmag_specimens': print(file_type, " this is not a valid pmag_specimens file") sys.exit() specs,comps,coords=[],[],[] for spec in prior_spec_data: if spec['er_specimen_name'] not in specs:specs.append(spec['er_specimen_name']) if 'specimen_comp_name' not in list(spec.keys()):spec['specimen_comp_name']='A' if 'specimen_tilt_correction' not in list(spec.keys()):spec['tilt_correction']='-1' if spec['specimen_comp_name'] not in comps:comps.append(spec['specimen_comp_name']) if spec['specimen_tilt_correction'] not in coords:coords.append(spec['specimen_tilt_correction']) for coord in coords: print(coord) for comp in comps: print(comp) speclist=[] for spec in prior_spec_data: if spec['specimen_tilt_correction']==coord and spec['specimen_comp_name']==comp:speclist.append(spec) ofile=ofile_base+'_'+coord+'_'+comp+'.txt' pmag.magic_write(ofile,speclist,'pmag_specimens') print('coordinate system: ',coord,' component name: ',comp,' saved in ',ofile)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:read_magic_file; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:path; 6, identifier:sort_by_this_name; 7, block; 7, 8; 7, 12; 7, 46; 7, 52; 7, 66; 7, 70; 7, 166; 7, 172; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:DATA; 11, dictionary; 12, try_statement; 12, 13; 12, 41; 13, block; 13, 14; 14, with_statement; 14, 15; 14, 25; 15, with_clause; 15, 16; 16, with_item; 16, 17; 17, as_pattern; 17, 18; 17, 23; 18, call; 18, 19; 18, 20; 19, identifier:open; 20, argument_list; 20, 21; 20, 22; 21, identifier:path; 22, string:'r'; 23, as_pattern_target; 23, 24; 24, identifier:finput; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:lines; 29, call; 29, 30; 29, 31; 30, identifier:list; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 38; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:finput; 36, identifier:readlines; 37, argument_list; 38, slice; 38, 39; 38, 40; 39, integer:1; 40, colon; 41, except_clause; 41, 42; 41, 43; 42, identifier:FileNotFoundError; 43, block; 43, 44; 44, return_statement; 44, 45; 45, list:[]; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:line; 49, subscript; 49, 50; 49, 51; 50, identifier:lines; 51, integer:0; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:header; 55, call; 55, 56; 55, 64; 56, attribute; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:line; 60, identifier:strip; 61, argument_list; 61, 62; 62, string:'\n'; 63, identifier:split; 64, argument_list; 64, 65; 65, string:'\t'; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:error_strings; 69, list:[]; 70, for_statement; 70, 71; 70, 72; 70, 77; 71, identifier:line; 72, subscript; 72, 73; 72, 74; 73, identifier:lines; 74, slice; 74, 75; 74, 76; 75, integer:1; 76, colon; 77, block; 77, 78; 77, 82; 77, 96; 77, 116; 77, 158; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:tmp_data; 81, dictionary; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:tmp_line; 85, call; 85, 86; 85, 94; 86, attribute; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:line; 90, identifier:strip; 91, argument_list; 91, 92; 92, string:'\n'; 93, identifier:split; 94, argument_list; 94, 95; 95, string:'\t'; 96, for_statement; 96, 97; 96, 98; 96, 105; 97, identifier:i; 98, call; 98, 99; 98, 100; 99, identifier:range; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:len; 103, argument_list; 103, 104; 104, identifier:tmp_line; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 113; 108, subscript; 108, 109; 108, 110; 109, identifier:tmp_data; 110, subscript; 110, 111; 110, 112; 111, identifier:header; 112, identifier:i; 113, subscript; 113, 114; 113, 115; 114, identifier:tmp_line; 115, identifier:i; 116, if_statement; 116, 117; 116, 129; 117, comparison_operator:in; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:tmp_data; 120, identifier:sort_by_this_name; 121, call; 121, 122; 121, 123; 122, identifier:list; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:DATA; 127, identifier:keys; 128, argument_list; 129, block; 129, 130; 129, 141; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:error_string; 133, binary_operator:%; 133, 134; 133, 135; 134, string:"-E- ERROR: magic file %s has more than one line for %s %s"; 135, tuple; 135, 136; 135, 137; 135, 138; 136, identifier:path; 137, identifier:sort_by_this_name; 138, subscript; 138, 139; 138, 140; 139, identifier:tmp_data; 140, identifier:sort_by_this_name; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:not; 142, 143; 142, 144; 143, identifier:error_string; 144, identifier:error_strings; 145, block; 145, 146; 145, 151; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:print; 149, argument_list; 149, 150; 150, identifier:error_string; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:error_strings; 155, identifier:append; 156, argument_list; 156, 157; 157, identifier:error_string; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 165; 160, subscript; 160, 161; 160, 162; 161, identifier:DATA; 162, subscript; 162, 163; 162, 164; 163, identifier:tmp_data; 164, identifier:sort_by_this_name; 165, identifier:tmp_data; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:finput; 170, identifier:close; 171, argument_list; 172, return_statement; 172, 173; 173, parenthesized_expression; 173, 174; 174, identifier:DATA
def read_magic_file(self, path, sort_by_this_name): DATA = {} try: with open(path, 'r') as finput: lines = list(finput.readlines()[1:]) except FileNotFoundError: return [] line = lines[0] header = line.strip('\n').split('\t') error_strings = [] for line in lines[1:]: tmp_data = {} tmp_line = line.strip('\n').split('\t') for i in range(len(tmp_line)): tmp_data[header[i]] = tmp_line[i] if tmp_data[sort_by_this_name] in list(DATA.keys()): error_string = "-E- ERROR: magic file %s has more than one line for %s %s" % ( path, sort_by_this_name, tmp_data[sort_by_this_name]) if error_string not in error_strings: print(error_string) error_strings.append(error_string) DATA[tmp_data[sort_by_this_name]] = tmp_data finput.close() return(DATA)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:plot_teq; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:fignum; 5, identifier:araiblock; 6, identifier:s; 7, identifier:pars; 8, block; 8, 9; 8, 21; 8, 30; 8, 36; 8, 46; 8, 85; 8, 90; 8, 132; 8, 174; 8, 197; 8, 210; 8, 224; 8, 239; 8, 253; 8, 268; 8, 282; 8, 297; 8, 304; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list; 11, 12; 11, 13; 12, identifier:first_Z; 13, identifier:first_I; 14, expression_list; 14, 15; 14, 18; 15, subscript; 15, 16; 15, 17; 16, identifier:araiblock; 17, integer:0; 18, subscript; 18, 19; 18, 20; 19, identifier:araiblock; 20, integer:1; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:plt; 25, identifier:figure; 26, argument_list; 26, 27; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:num; 29, identifier:fignum; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:plt; 34, identifier:clf; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 42; 38, pattern_list; 38, 39; 38, 40; 38, 41; 39, identifier:ZIblock; 40, identifier:IZblock; 41, identifier:pTblock; 42, expression_list; 42, 43; 42, 44; 42, 45; 43, list:[]; 44, list:[]; 45, list:[]; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:zrec; 48, identifier:first_Z; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 56; 50, 70; 51, comparison_operator:==; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:zrec; 54, integer:4; 55, integer:1; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:ZIblock; 61, identifier:append; 62, argument_list; 62, 63; 63, list:[zrec[1], zrec[2]]; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:zrec; 66, integer:1; 67, subscript; 67, 68; 67, 69; 68, identifier:zrec; 69, integer:2; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:IZblock; 76, identifier:append; 77, argument_list; 77, 78; 78, list:[zrec[1], zrec[2]]; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:zrec; 81, integer:1; 82, subscript; 82, 83; 82, 84; 83, identifier:zrec; 84, integer:2; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:plot_net; 88, argument_list; 88, 89; 89, identifier:fignum; 90, if_statement; 90, 91; 90, 94; 90, 113; 91, comparison_operator:!=; 91, 92; 91, 93; 92, identifier:pars; 93, string:""; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, pattern_list; 97, 98; 97, 99; 98, identifier:min; 99, identifier:max; 100, expression_list; 100, 101; 100, 107; 101, call; 101, 102; 101, 103; 102, identifier:float; 103, argument_list; 103, 104; 104, subscript; 104, 105; 104, 106; 105, identifier:pars; 106, string:"measurement_step_min"; 107, call; 107, 108; 107, 109; 108, identifier:float; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 112; 111, identifier:pars; 112, string:"measurement_step_max"; 113, else_clause; 113, 114; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, pattern_list; 117, 118; 117, 119; 118, identifier:min; 119, identifier:max; 120, expression_list; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:first_I; 124, integer:0; 125, integer:0; 126, subscript; 126, 127; 126, 131; 127, subscript; 127, 128; 127, 129; 128, identifier:first_I; 129, unary_operator:-; 129, 130; 130, integer:1; 131, integer:0; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:irec; 134, identifier:first_I; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 160; 137, boolean_operator:and; 137, 138; 137, 155; 138, boolean_operator:and; 138, 139; 138, 150; 139, boolean_operator:and; 139, 140; 139, 145; 140, comparison_operator:!=; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:irec; 143, integer:1; 144, integer:0; 145, comparison_operator:!=; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:irec; 148, integer:1; 149, integer:0; 150, comparison_operator:>=; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:irec; 153, integer:0; 154, identifier:min; 155, comparison_operator:<=; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:irec; 158, integer:0; 159, identifier:max; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:pTblock; 165, identifier:append; 166, argument_list; 166, 167; 167, list:[irec[1], irec[2]]; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:irec; 170, integer:1; 171, subscript; 171, 172; 171, 173; 172, identifier:irec; 173, integer:2; 174, if_statement; 174, 175; 174, 195; 175, boolean_operator:and; 175, 176; 175, 189; 176, boolean_operator:and; 176, 177; 176, 183; 177, comparison_operator:<; 177, 178; 177, 182; 178, call; 178, 179; 178, 180; 179, identifier:len; 180, argument_list; 180, 181; 181, identifier:ZIblock; 182, integer:1; 183, comparison_operator:<; 183, 184; 183, 188; 184, call; 184, 185; 184, 186; 185, identifier:len; 186, argument_list; 186, 187; 187, identifier:IZblock; 188, integer:1; 189, comparison_operator:<; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:len; 192, argument_list; 192, 193; 193, identifier:pTblock; 194, integer:1; 195, block; 195, 196; 196, return_statement; 197, if_statement; 197, 198; 197, 200; 198, not_operator; 198, 199; 199, identifier:isServer; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:plt; 205, identifier:figtext; 206, argument_list; 206, 207; 206, 208; 206, 209; 207, float:.02; 208, float:.01; 209, identifier:version_num; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:sym; 213, dictionary; 213, 214; 213, 219; 214, pair; 214, 215; 214, 216; 215, string:'lower'; 216, list:['o', 'r']; 216, 217; 216, 218; 217, string:'o'; 218, string:'r'; 219, pair; 219, 220; 219, 221; 220, string:'upper'; 221, list:['o', 'm']; 221, 222; 221, 223; 222, string:'o'; 223, string:'m'; 224, if_statement; 224, 225; 224, 231; 225, comparison_operator:>; 225, 226; 225, 230; 226, call; 226, 227; 226, 228; 227, identifier:len; 228, argument_list; 228, 229; 229, identifier:ZIblock; 230, integer:0; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 235; 234, identifier:plot_di_sym; 235, argument_list; 235, 236; 235, 237; 235, 238; 236, identifier:fignum; 237, identifier:ZIblock; 238, identifier:sym; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:sym; 242, dictionary; 242, 243; 242, 248; 243, pair; 243, 244; 243, 245; 244, string:'lower'; 245, list:['s', 'b']; 245, 246; 245, 247; 246, string:'s'; 247, string:'b'; 248, pair; 248, 249; 248, 250; 249, string:'upper'; 250, list:['s', 'c']; 250, 251; 250, 252; 251, string:'s'; 252, string:'c'; 253, if_statement; 253, 254; 253, 260; 254, comparison_operator:>; 254, 255; 254, 259; 255, call; 255, 256; 255, 257; 256, identifier:len; 257, argument_list; 257, 258; 258, identifier:IZblock; 259, integer:0; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:plot_di_sym; 264, argument_list; 264, 265; 264, 266; 264, 267; 265, identifier:fignum; 266, identifier:IZblock; 267, identifier:sym; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:sym; 271, dictionary; 271, 272; 271, 277; 272, pair; 272, 273; 272, 274; 273, string:'lower'; 274, list:['^', 'g']; 274, 275; 274, 276; 275, string:'^'; 276, string:'g'; 277, pair; 277, 278; 277, 279; 278, string:'upper'; 279, list:['^', 'y']; 279, 280; 279, 281; 280, string:'^'; 281, string:'y'; 282, if_statement; 282, 283; 282, 289; 283, comparison_operator:>; 283, 284; 283, 288; 284, call; 284, 285; 284, 286; 285, identifier:len; 286, argument_list; 286, 287; 287, identifier:pTblock; 288, integer:0; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:plot_di_sym; 293, argument_list; 293, 294; 293, 295; 293, 296; 294, identifier:fignum; 295, identifier:pTblock; 296, identifier:sym; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:plt; 301, identifier:axis; 302, argument_list; 302, 303; 303, string:"equal"; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:plt; 308, identifier:text; 309, argument_list; 309, 310; 309, 312; 309, 313; 310, unary_operator:-; 310, 311; 311, float:1.1; 312, float:1.15; 313, identifier:s
def plot_teq(fignum, araiblock, s, pars): first_Z, first_I = araiblock[0], araiblock[1] plt.figure(num=fignum) plt.clf() ZIblock, IZblock, pTblock = [], [], [] for zrec in first_Z: if zrec[4] == 1: ZIblock.append([zrec[1], zrec[2]]) else: IZblock.append([zrec[1], zrec[2]]) plot_net(fignum) if pars != "": min, max = float(pars["measurement_step_min"]), float( pars["measurement_step_max"]) else: min, max = first_I[0][0], first_I[-1][0] for irec in first_I: if irec[1] != 0 and irec[1] != 0 and irec[0] >= min and irec[0] <= max: pTblock.append([irec[1], irec[2]]) if len(ZIblock) < 1 and len(IZblock) < 1 and len(pTblock) < 1: return if not isServer: plt.figtext(.02, .01, version_num) sym = {'lower': ['o', 'r'], 'upper': ['o', 'm']} if len(ZIblock) > 0: plot_di_sym(fignum, ZIblock, sym) sym = {'lower': ['s', 'b'], 'upper': ['s', 'c']} if len(IZblock) > 0: plot_di_sym(fignum, IZblock, sym) sym = {'lower': ['^', 'g'], 'upper': ['^', 'y']} if len(pTblock) > 0: plot_di_sym(fignum, pTblock, sym) plt.axis("equal") plt.text(-1.1, 1.15, s)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_records_map; 3, parameters; 3, 4; 4, identifier:records; 5, block; 5, 6; 5, 14; 5, 21; 5, 28; 5, 35; 5, 73; 5, 80; 5, 89; 5, 96; 5, 104; 5, 113; 5, 122; 5, 157; 5, 165; 5, 177; 5, 206; 5, 213; 5, 219; 5, 238; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ctx; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:context; 12, identifier:get; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:l; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:records; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:key_records; 24, binary_operator:*; 24, 25; 24, 27; 25, list:[None]; 25, 26; 26, None; 27, identifier:l; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:logging; 32, identifier:debug; 33, argument_list; 33, 34; 34, string:"Parsing"; 35, for_statement; 35, 36; 35, 37; 35, 41; 36, identifier:i; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, identifier:l; 41, block; 41, 42; 41, 50; 41, 59; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:proto; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:kv_pb; 48, identifier:KeyValue; 49, argument_list; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:proto; 54, identifier:ParseFromString; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:records; 58, identifier:i; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:key_records; 63, identifier:i; 64, tuple; 64, 65; 64, 70; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:proto; 68, identifier:key; 69, argument_list; 70, subscript; 70, 71; 70, 72; 71, identifier:records; 72, identifier:i; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:logging; 77, identifier:debug; 78, argument_list; 78, 79; 79, string:"Sorting"; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:key_records; 84, identifier:sort; 85, argument_list; 85, 86; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:cmp; 88, identifier:_compare_keys; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:logging; 93, identifier:debug; 94, argument_list; 94, 95; 95, string:"Writing"; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:mapper_spec; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:ctx; 102, identifier:mapreduce_spec; 103, identifier:mapper; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:params; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:input_readers; 110, identifier:_get_params; 111, argument_list; 111, 112; 112, identifier:mapper_spec; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:bucket_name; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:params; 119, identifier:get; 120, argument_list; 120, 121; 121, string:"bucket_name"; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:filename; 125, parenthesized_expression; 125, 126; 126, binary_operator:+; 126, 127; 126, 146; 127, binary_operator:+; 127, 128; 127, 145; 128, binary_operator:+; 128, 129; 128, 142; 129, binary_operator:+; 129, 130; 129, 141; 130, binary_operator:+; 130, 131; 130, 138; 131, binary_operator:+; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:ctx; 135, identifier:mapreduce_spec; 136, identifier:name; 137, string:"/"; 138, attribute; 138, 139; 138, 140; 139, identifier:ctx; 140, identifier:mapreduce_id; 141, string:"/output-"; 142, attribute; 142, 143; 142, 144; 143, identifier:ctx; 144, identifier:shard_id; 145, string:"-"; 146, call; 146, 147; 146, 148; 147, identifier:str; 148, argument_list; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:int; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:time; 155, identifier:time; 156, argument_list; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:full_filename; 160, binary_operator:%; 160, 161; 160, 162; 161, string:"/%s/%s"; 162, tuple; 162, 163; 162, 164; 163, identifier:bucket_name; 164, identifier:filename; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:filehandle; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:cloudstorage; 171, identifier:open; 172, argument_list; 172, 173; 172, 174; 173, identifier:full_filename; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:mode; 176, string:"w"; 177, with_statement; 177, 178; 177, 192; 178, with_clause; 178, 179; 179, with_item; 179, 180; 180, as_pattern; 180, 181; 180, 190; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:output_writers; 184, identifier:GCSRecordsPool; 185, argument_list; 185, 186; 185, 187; 186, identifier:filehandle; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:ctx; 189, identifier:ctx; 190, as_pattern_target; 190, 191; 191, identifier:pool; 192, block; 192, 193; 193, for_statement; 193, 194; 193, 195; 193, 196; 194, identifier:key_record; 195, identifier:key_records; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:pool; 201, identifier:append; 202, argument_list; 202, 203; 203, subscript; 203, 204; 203, 205; 204, identifier:key_record; 205, integer:1; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:logging; 210, identifier:debug; 211, argument_list; 211, 212; 212, string:"Finalizing"; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:filehandle; 217, identifier:close; 218, argument_list; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:entity; 222, call; 222, 223; 222, 224; 223, identifier:_OutputFile; 224, argument_list; 224, 225; 224, 228; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:key_name; 227, identifier:full_filename; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:parent; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:_OutputFile; 233, identifier:get_root_key; 234, argument_list; 234, 235; 235, attribute; 235, 236; 235, 237; 236, identifier:ctx; 237, identifier:mapreduce_id; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:entity; 242, identifier:put; 243, argument_list
def _sort_records_map(records): ctx = context.get() l = len(records) key_records = [None] * l logging.debug("Parsing") for i in range(l): proto = kv_pb.KeyValue() proto.ParseFromString(records[i]) key_records[i] = (proto.key(), records[i]) logging.debug("Sorting") key_records.sort(cmp=_compare_keys) logging.debug("Writing") mapper_spec = ctx.mapreduce_spec.mapper params = input_readers._get_params(mapper_spec) bucket_name = params.get("bucket_name") filename = (ctx.mapreduce_spec.name + "/" + ctx.mapreduce_id + "/output-" + ctx.shard_id + "-" + str(int(time.time()))) full_filename = "/%s/%s" % (bucket_name, filename) filehandle = cloudstorage.open(full_filename, mode="w") with output_writers.GCSRecordsPool(filehandle, ctx=ctx) as pool: for key_record in key_records: pool.append(key_record[1]) logging.debug("Finalizing") filehandle.close() entity = _OutputFile(key_name=full_filename, parent=_OutputFile.get_root_key(ctx.mapreduce_id)) entity.put()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_all_by_mapreduce_state; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:mapreduce_state; 6, block; 6, 7; 6, 16; 6, 20; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:keys; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:cls; 13, identifier:calculate_keys_by_mapreduce_state; 14, argument_list; 14, 15; 15, identifier:mapreduce_state; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:i; 19, integer:0; 20, while_statement; 20, 21; 20, 27; 21, comparison_operator:<; 21, 22; 21, 23; 22, identifier:i; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:keys; 27, block; 27, 28; 27, 54; 27, 61; 28, decorated_definition; 28, 29; 28, 33; 29, decorator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:db; 32, identifier:non_transactional; 33, function_definition; 33, 34; 33, 35; 33, 37; 34, function_name:no_tx_get; 35, parameters; 35, 36; 36, identifier:i; 37, block; 37, 38; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:db; 42, identifier:get; 43, argument_list; 43, 44; 44, subscript; 44, 45; 44, 46; 45, identifier:keys; 46, slice; 46, 47; 46, 48; 46, 49; 47, identifier:i; 48, colon; 49, binary_operator:+; 49, 50; 49, 51; 50, identifier:i; 51, attribute; 51, 52; 51, 53; 52, identifier:cls; 53, identifier:_MAX_STATES_IN_MEMORY; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:states; 57, call; 57, 58; 57, 59; 58, identifier:no_tx_get; 59, argument_list; 59, 60; 60, identifier:i; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:s; 63, identifier:states; 64, block; 64, 65; 64, 69; 65, expression_statement; 65, 66; 66, augmented_assignment:+=; 66, 67; 66, 68; 67, identifier:i; 68, integer:1; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:s; 72, None; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, yield; 75, 76; 76, identifier:s
def find_all_by_mapreduce_state(cls, mapreduce_state): keys = cls.calculate_keys_by_mapreduce_state(mapreduce_state) i = 0 while i < len(keys): @db.non_transactional def no_tx_get(i): return db.get(keys[i:i+cls._MAX_STATES_IN_MEMORY]) states = no_tx_get(i) for s in states: i += 1 if s is not None: yield s
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:calculate_keys_by_mapreduce_state; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:mapreduce_state; 6, block; 6, 7; 6, 14; 6, 18; 6, 61; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:mapreduce_state; 10, None; 11, block; 11, 12; 12, return_statement; 12, 13; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:keys; 17, list:[]; 18, for_statement; 18, 19; 18, 20; 18, 30; 19, identifier:i; 20, call; 20, 21; 20, 22; 21, identifier:range; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:mapreduce_state; 27, identifier:mapreduce_spec; 28, identifier:mapper; 29, identifier:shard_count; 30, block; 30, 31; 30, 49; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:shard_id; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:cls; 37, identifier:shard_id_from_number; 38, argument_list; 38, 39; 38, 48; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:mapreduce_state; 44, identifier:key; 45, argument_list; 46, identifier:name; 47, argument_list; 48, identifier:i; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:keys; 53, identifier:append; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:cls; 58, identifier:get_key_by_shard_id; 59, argument_list; 59, 60; 60, identifier:shard_id; 61, return_statement; 61, 62; 62, identifier:keys
def calculate_keys_by_mapreduce_state(cls, mapreduce_state): if mapreduce_state is None: return [] keys = [] for i in range(mapreduce_state.mapreduce_spec.mapper.shard_count): shard_id = cls.shard_id_from_number(mapreduce_state.key().name(), i) keys.append(cls.get_key_by_shard_id(shard_id)) return keys
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:split; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 29; 4, identifier:cls; 5, identifier:n; 6, identifier:contiguous; 7, default_parameter; 7, 8; 7, 9; 8, identifier:can_query; 9, attribute; 9, 10; 9, 28; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:itertools; 13, identifier:chain; 14, argument_list; 14, 15; 14, 22; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:itertools; 18, identifier:repeat; 19, argument_list; 19, 20; 19, 21; 20, True; 21, integer:50; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:itertools; 25, identifier:repeat; 26, argument_list; 26, 27; 27, False; 28, identifier:next; 29, default_parameter; 29, 30; 29, 31; 30, identifier:_app; 31, None; 32, block; 32, 33; 32, 43; 32, 47; 32, 193; 32, 197; 32, 278; 32, 295; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:<; 34, 35; 34, 36; 35, identifier:n; 36, integer:1; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:ValueError; 41, argument_list; 41, 42; 42, string:'n must be >= 1'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:ranges; 46, None; 47, if_statement; 47, 48; 47, 51; 47, 181; 48, call; 48, 49; 48, 50; 49, identifier:can_query; 50, argument_list; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 55; 52, 148; 53, not_operator; 53, 54; 54, identifier:contiguous; 55, block; 55, 56; 55, 66; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:ns_keys; 59, call; 59, 60; 59, 61; 60, identifier:get_namespace_keys; 61, argument_list; 61, 62; 61, 63; 62, identifier:_app; 63, binary_operator:+; 63, 64; 63, 65; 64, identifier:n; 65, integer:1; 66, if_statement; 66, 67; 66, 69; 66, 72; 67, not_operator; 67, 68; 68, identifier:ns_keys; 69, block; 69, 70; 70, return_statement; 70, 71; 71, list:[]; 72, else_clause; 72, 73; 73, block; 73, 74; 73, 129; 74, if_statement; 74, 75; 74, 81; 75, comparison_operator:<=; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:ns_keys; 80, identifier:n; 81, block; 81, 82; 81, 86; 81, 116; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:ns_range; 85, list:[]; 86, for_statement; 86, 87; 86, 88; 86, 89; 87, identifier:ns_key; 88, identifier:ns_keys; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:ns_range; 94, identifier:append; 95, argument_list; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:NamespaceRange; 98, argument_list; 98, 99; 98, 106; 98, 113; 99, boolean_operator:or; 99, 100; 99, 105; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:ns_key; 103, identifier:name; 104, argument_list; 105, string:''; 106, boolean_operator:or; 106, 107; 106, 112; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:ns_key; 110, identifier:name; 111, argument_list; 112, string:''; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:_app; 115, identifier:_app; 116, return_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:sorted; 119, argument_list; 119, 120; 119, 121; 120, identifier:ns_range; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:key; 123, lambda; 123, 124; 123, 126; 124, lambda_parameters; 124, 125; 125, identifier:ns_range; 126, attribute; 126, 127; 126, 128; 127, identifier:ns_range; 128, identifier:namespace_start; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:ranges; 132, list:[NamespaceRange(ns_keys[0].name() or '', _app=_app)]; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:NamespaceRange; 135, argument_list; 135, 136; 135, 145; 136, boolean_operator:or; 136, 137; 136, 144; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:ns_keys; 141, integer:0; 142, identifier:name; 143, argument_list; 144, string:''; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:_app; 147, identifier:_app; 148, else_clause; 148, 149; 149, block; 149, 150; 149, 163; 149, 176; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:ns_range; 153, call; 153, 154; 153, 162; 154, attribute; 154, 155; 154, 161; 155, call; 155, 156; 155, 157; 156, identifier:NamespaceRange; 157, argument_list; 157, 158; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:_app; 160, identifier:_app; 161, identifier:normalized_start; 162, argument_list; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:ns_range; 166, None; 167, block; 167, 168; 168, return_statement; 168, 169; 169, list:[NamespaceRange(_app=_app)]; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:NamespaceRange; 172, argument_list; 172, 173; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:_app; 175, identifier:_app; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:ranges; 179, list:[ns_range]; 179, 180; 180, identifier:ns_range; 181, else_clause; 181, 182; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:ranges; 186, list:[NamespaceRange(_app=_app)]; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:NamespaceRange; 189, argument_list; 189, 190; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:_app; 192, identifier:_app; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:singles; 196, list:[]; 197, while_statement; 197, 198; 197, 212; 198, boolean_operator:and; 198, 199; 198, 200; 199, identifier:ranges; 200, comparison_operator:<; 200, 201; 200, 211; 201, parenthesized_expression; 201, 202; 202, binary_operator:+; 202, 203; 202, 207; 203, call; 203, 204; 203, 205; 204, identifier:len; 205, argument_list; 205, 206; 206, identifier:ranges; 207, call; 207, 208; 207, 209; 208, identifier:len; 209, argument_list; 209, 210; 210, identifier:singles; 211, identifier:n; 212, block; 212, 213; 212, 222; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:namespace_range; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:ranges; 219, identifier:pop; 220, argument_list; 220, 221; 221, integer:0; 222, if_statement; 222, 223; 222, 226; 222, 234; 223, attribute; 223, 224; 223, 225; 224, identifier:namespace_range; 225, identifier:is_single_namespace; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:singles; 231, identifier:append; 232, argument_list; 232, 233; 233, identifier:namespace_range; 234, else_clause; 234, 235; 235, block; 235, 236; 235, 246; 235, 259; 235, 271; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 241; 238, pattern_list; 238, 239; 238, 240; 239, identifier:left; 240, identifier:right; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:namespace_range; 244, identifier:split_range; 245, argument_list; 246, if_statement; 246, 247; 246, 250; 247, call; 247, 248; 247, 249; 248, identifier:can_query; 249, argument_list; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:right; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:right; 257, identifier:normalized_start; 258, argument_list; 259, if_statement; 259, 260; 259, 263; 260, comparison_operator:is; 260, 261; 260, 262; 261, identifier:right; 262, None; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:ranges; 268, identifier:append; 269, argument_list; 269, 270; 270, identifier:right; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:ranges; 275, identifier:append; 276, argument_list; 276, 277; 277, identifier:left; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:ns_ranges; 281, call; 281, 282; 281, 283; 282, identifier:sorted; 283, argument_list; 283, 284; 283, 287; 284, binary_operator:+; 284, 285; 284, 286; 285, identifier:singles; 286, identifier:ranges; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:key; 289, lambda; 289, 290; 289, 292; 290, lambda_parameters; 290, 291; 291, identifier:ns_range; 292, attribute; 292, 293; 292, 294; 293, identifier:ns_range; 294, identifier:namespace_start; 295, if_statement; 295, 296; 295, 297; 295, 393; 296, identifier:contiguous; 297, block; 297, 298; 297, 310; 297, 314; 297, 391; 298, if_statement; 298, 299; 298, 301; 299, not_operator; 299, 300; 300, identifier:ns_ranges; 301, block; 301, 302; 302, return_statement; 302, 303; 303, list:[NamespaceRange(_app=_app)]; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:NamespaceRange; 306, argument_list; 306, 307; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:_app; 309, identifier:_app; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:continuous_ns_ranges; 313, list:[]; 314, for_statement; 314, 315; 314, 316; 314, 323; 315, identifier:i; 316, call; 316, 317; 316, 318; 317, identifier:range; 318, argument_list; 318, 319; 319, call; 319, 320; 319, 321; 320, identifier:len; 321, argument_list; 321, 322; 322, identifier:ns_ranges; 323, block; 323, 324; 323, 343; 323, 377; 324, if_statement; 324, 325; 324, 328; 324, 333; 325, comparison_operator:==; 325, 326; 325, 327; 326, identifier:i; 327, integer:0; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:namespace_start; 332, identifier:MIN_NAMESPACE; 333, else_clause; 333, 334; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:namespace_start; 338, attribute; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:ns_ranges; 341, identifier:i; 342, identifier:namespace_start; 343, if_statement; 343, 344; 343, 352; 343, 357; 344, comparison_operator:==; 344, 345; 344, 346; 345, identifier:i; 346, binary_operator:-; 346, 347; 346, 351; 347, call; 347, 348; 347, 349; 348, identifier:len; 349, argument_list; 349, 350; 350, identifier:ns_ranges; 351, integer:1; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, assignment; 354, 355; 354, 356; 355, identifier:namespace_end; 356, identifier:MAX_NAMESPACE; 357, else_clause; 357, 358; 358, block; 358, 359; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 362; 361, identifier:namespace_end; 362, call; 362, 363; 362, 364; 363, identifier:_ord_to_namespace; 364, argument_list; 364, 365; 365, binary_operator:-; 365, 366; 365, 376; 366, call; 366, 367; 366, 368; 367, identifier:_namespace_to_ord; 368, argument_list; 368, 369; 369, attribute; 369, 370; 369, 375; 370, subscript; 370, 371; 370, 372; 371, identifier:ns_ranges; 372, binary_operator:+; 372, 373; 372, 374; 373, identifier:i; 374, integer:1; 375, identifier:namespace_start; 376, integer:1; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:continuous_ns_ranges; 381, identifier:append; 382, argument_list; 382, 383; 383, call; 383, 384; 383, 385; 384, identifier:NamespaceRange; 385, argument_list; 385, 386; 385, 387; 385, 388; 386, identifier:namespace_start; 387, identifier:namespace_end; 388, keyword_argument; 388, 389; 388, 390; 389, identifier:_app; 390, identifier:_app; 391, return_statement; 391, 392; 392, identifier:continuous_ns_ranges; 393, else_clause; 393, 394; 394, block; 394, 395; 395, return_statement; 395, 396; 396, identifier:ns_ranges
def split(cls, n, contiguous, can_query=itertools.chain(itertools.repeat(True, 50), itertools.repeat(False)).next, _app=None): if n < 1: raise ValueError('n must be >= 1') ranges = None if can_query(): if not contiguous: ns_keys = get_namespace_keys(_app, n + 1) if not ns_keys: return [] else: if len(ns_keys) <= n: ns_range = [] for ns_key in ns_keys: ns_range.append(NamespaceRange(ns_key.name() or '', ns_key.name() or '', _app=_app)) return sorted(ns_range, key=lambda ns_range: ns_range.namespace_start) ranges = [NamespaceRange(ns_keys[0].name() or '', _app=_app)] else: ns_range = NamespaceRange(_app=_app).normalized_start() if ns_range is None: return [NamespaceRange(_app=_app)] ranges = [ns_range] else: ranges = [NamespaceRange(_app=_app)] singles = [] while ranges and (len(ranges) + len(singles)) < n: namespace_range = ranges.pop(0) if namespace_range.is_single_namespace: singles.append(namespace_range) else: left, right = namespace_range.split_range() if can_query(): right = right.normalized_start() if right is not None: ranges.append(right) ranges.append(left) ns_ranges = sorted(singles + ranges, key=lambda ns_range: ns_range.namespace_start) if contiguous: if not ns_ranges: return [NamespaceRange(_app=_app)] continuous_ns_ranges = [] for i in range(len(ns_ranges)): if i == 0: namespace_start = MIN_NAMESPACE else: namespace_start = ns_ranges[i].namespace_start if i == len(ns_ranges) - 1: namespace_end = MAX_NAMESPACE else: namespace_end = _ord_to_namespace( _namespace_to_ord(ns_ranges[i+1].namespace_start) - 1) continuous_ns_ranges.append(NamespaceRange(namespace_start, namespace_end, _app=_app)) return continuous_ns_ranges else: return ns_ranges
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_parse_raw_members; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:leaderboard_name; 6, identifier:members; 7, default_parameter; 7, 8; 7, 9; 8, identifier:members_only; 9, False; 10, dictionary_splat_pattern; 10, 11; 11, identifier:options; 12, block; 12, 13; 12, 15; 12, 29; 13, expression_statement; 13, 14; 14, string:''' Parse the raw leaders data as returned from a given leader board query. Do associative lookups with the member to rank, score and potentially sort the results. @param leaderboard_name [String] Name of the leaderboard. @param members [List] A list of members as returned from a sorted set range query @param members_only [bool] Set True to return the members as is, Default is False. @param options [Hash] Options to be used when retrieving the page from the named leaderboard. @return a list of members. '''; 15, if_statement; 15, 16; 15, 17; 16, identifier:members_only; 17, block; 17, 18; 18, return_statement; 18, 19; 19, list_comprehension; 19, 20; 19, 26; 20, dictionary; 20, 21; 21, pair; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:MEMBER_KEY; 25, identifier:m; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:m; 28, identifier:members; 29, if_statement; 29, 30; 29, 31; 29, 42; 30, identifier:members; 31, block; 31, 32; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:ranked_in_list_in; 37, argument_list; 37, 38; 37, 39; 37, 40; 38, identifier:leaderboard_name; 39, identifier:members; 40, dictionary_splat; 40, 41; 41, identifier:options; 42, else_clause; 42, 43; 43, block; 43, 44; 44, return_statement; 44, 45; 45, list:[]
def _parse_raw_members( self, leaderboard_name, members, members_only=False, **options): ''' Parse the raw leaders data as returned from a given leader board query. Do associative lookups with the member to rank, score and potentially sort the results. @param leaderboard_name [String] Name of the leaderboard. @param members [List] A list of members as returned from a sorted set range query @param members_only [bool] Set True to return the members as is, Default is False. @param options [Hash] Options to be used when retrieving the page from the named leaderboard. @return a list of members. ''' if members_only: return [{self.MEMBER_KEY: m} for m in members] if members: return self.ranked_in_list_in(leaderboard_name, members, **options) else: return []
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 163; 2, function_name:search; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 3, 43; 3, 46; 3, 49; 3, 52; 3, 55; 3, 58; 3, 61; 3, 64; 3, 67; 3, 70; 3, 73; 3, 76; 3, 79; 3, 82; 3, 85; 3, 88; 3, 91; 3, 94; 3, 97; 3, 100; 3, 103; 3, 106; 3, 109; 3, 112; 3, 115; 3, 118; 3, 121; 3, 124; 3, 127; 3, 130; 3, 133; 3, 136; 3, 139; 3, 142; 3, 145; 3, 148; 3, 151; 3, 154; 3, 157; 3, 160; 4, default_parameter; 4, 5; 4, 6; 5, identifier:title; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:artist; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:artist_id; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:combined; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:description; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:style; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:mood; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:results; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:start; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:max_tempo; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:min_tempo; 36, None; 37, default_parameter; 37, 38; 37, 39; 38, identifier:max_duration; 39, None; 40, default_parameter; 40, 41; 40, 42; 41, identifier:min_duration; 42, None; 43, default_parameter; 43, 44; 43, 45; 44, identifier:max_loudness; 45, None; 46, default_parameter; 46, 47; 46, 48; 47, identifier:min_loudness; 48, None; 49, default_parameter; 49, 50; 49, 51; 50, identifier:artist_max_familiarity; 51, None; 52, default_parameter; 52, 53; 52, 54; 53, identifier:artist_min_familiarity; 54, None; 55, default_parameter; 55, 56; 55, 57; 56, identifier:artist_max_hotttnesss; 57, None; 58, default_parameter; 58, 59; 58, 60; 59, identifier:artist_min_hotttnesss; 60, None; 61, default_parameter; 61, 62; 61, 63; 62, identifier:song_max_hotttnesss; 63, None; 64, default_parameter; 64, 65; 64, 66; 65, identifier:song_min_hotttnesss; 66, None; 67, default_parameter; 67, 68; 67, 69; 68, identifier:mode; 69, None; 70, default_parameter; 70, 71; 70, 72; 71, identifier:min_energy; 72, None; 73, default_parameter; 73, 74; 73, 75; 74, identifier:max_energy; 75, None; 76, default_parameter; 76, 77; 76, 78; 77, identifier:min_danceability; 78, None; 79, default_parameter; 79, 80; 79, 81; 80, identifier:max_danceability; 81, None; 82, default_parameter; 82, 83; 82, 84; 83, identifier:key; 84, None; 85, default_parameter; 85, 86; 85, 87; 86, identifier:max_latitude; 87, None; 88, default_parameter; 88, 89; 88, 90; 89, identifier:min_latitude; 90, None; 91, default_parameter; 91, 92; 91, 93; 92, identifier:max_longitude; 93, None; 94, default_parameter; 94, 95; 94, 96; 95, identifier:min_longitude; 96, None; 97, default_parameter; 97, 98; 97, 99; 98, identifier:sort; 99, None; 100, default_parameter; 100, 101; 100, 102; 101, identifier:buckets; 102, None; 103, default_parameter; 103, 104; 103, 105; 104, identifier:limit; 105, False; 106, default_parameter; 106, 107; 106, 108; 107, identifier:test_new_things; 108, None; 109, default_parameter; 109, 110; 109, 111; 110, identifier:rank_type; 111, None; 112, default_parameter; 112, 113; 112, 114; 113, identifier:artist_start_year_after; 114, None; 115, default_parameter; 115, 116; 115, 117; 116, identifier:artist_start_year_before; 117, None; 118, default_parameter; 118, 119; 118, 120; 119, identifier:artist_end_year_after; 120, None; 121, default_parameter; 121, 122; 121, 123; 122, identifier:artist_end_year_before; 123, None; 124, default_parameter; 124, 125; 124, 126; 125, identifier:song_type; 126, None; 127, default_parameter; 127, 128; 127, 129; 128, identifier:min_song_currency; 129, None; 130, default_parameter; 130, 131; 130, 132; 131, identifier:max_song_currency; 132, None; 133, default_parameter; 133, 134; 133, 135; 134, identifier:min_song_discovery; 135, None; 136, default_parameter; 136, 137; 136, 138; 137, identifier:max_song_discovery; 138, None; 139, default_parameter; 139, 140; 139, 141; 140, identifier:max_acousticness; 141, None; 142, default_parameter; 142, 143; 142, 144; 143, identifier:min_acousticness; 144, None; 145, default_parameter; 145, 146; 145, 147; 146, identifier:max_liveness; 147, None; 148, default_parameter; 148, 149; 148, 150; 149, identifier:min_liveness; 150, None; 151, default_parameter; 151, 152; 151, 153; 152, identifier:max_speechiness; 153, None; 154, default_parameter; 154, 155; 154, 156; 155, identifier:min_speechiness; 156, None; 157, default_parameter; 157, 158; 157, 159; 158, identifier:max_valence; 159, None; 160, default_parameter; 160, 161; 160, 162; 161, identifier:min_valence; 162, None; 163, block; 163, 164; 163, 175; 163, 181; 163, 187; 163, 191; 163, 205; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:limit; 167, call; 167, 168; 167, 174; 168, attribute; 168, 169; 168, 173; 169, call; 169, 170; 169, 171; 170, identifier:str; 171, argument_list; 171, 172; 172, identifier:limit; 173, identifier:lower; 174, argument_list; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:kwargs; 178, call; 178, 179; 178, 180; 179, identifier:locals; 180, argument_list; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, subscript; 183, 184; 183, 185; 184, identifier:kwargs; 185, string:'bucket'; 186, identifier:buckets; 187, delete_statement; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:kwargs; 190, string:'buckets'; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:result; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:util; 197, identifier:callm; 198, argument_list; 198, 199; 198, 204; 199, binary_operator:%; 199, 200; 199, 201; 200, string:"%s/%s"; 201, tuple; 201, 202; 201, 203; 202, string:'song'; 203, string:'search'; 204, identifier:kwargs; 205, return_statement; 205, 206; 206, list_comprehension; 206, 207; 206, 217; 207, call; 207, 208; 207, 209; 208, identifier:Song; 209, argument_list; 209, 210; 210, dictionary_splat; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:util; 214, identifier:fix; 215, argument_list; 215, 216; 216, identifier:s_dict; 217, for_in_clause; 217, 218; 217, 219; 218, identifier:s_dict; 219, subscript; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:result; 222, string:'response'; 223, string:'songs'
def search(title=None, artist=None, artist_id=None, combined=None, description=None, style=None, mood=None, results=None, start=None, max_tempo=None, min_tempo=None, max_duration=None, min_duration=None, max_loudness=None, min_loudness=None, artist_max_familiarity=None, artist_min_familiarity=None, artist_max_hotttnesss=None, artist_min_hotttnesss=None, song_max_hotttnesss=None, song_min_hotttnesss=None, mode=None, min_energy=None, max_energy=None, min_danceability=None, max_danceability=None, key=None, max_latitude=None, min_latitude=None, max_longitude=None, min_longitude=None, sort=None, buckets=None, limit=False, test_new_things=None, rank_type=None, artist_start_year_after=None, artist_start_year_before=None, artist_end_year_after=None, artist_end_year_before=None,song_type=None,min_song_currency=None,max_song_currency=None, min_song_discovery=None, max_song_discovery=None, max_acousticness=None, min_acousticness=None, max_liveness=None, min_liveness=None, max_speechiness=None, min_speechiness=None, max_valence=None, min_valence=None): limit = str(limit).lower() kwargs = locals() kwargs['bucket'] = buckets del kwargs['buckets'] result = util.callm("%s/%s" % ('song', 'search'), kwargs) return [Song(**util.fix(s_dict)) for s_dict in result['response']['songs']]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:list_campaigns; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 17; 7, 28; 7, 39; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:kwargs; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_verify_sort_options; 15, argument_list; 15, 16; 16, identifier:kwargs; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:kwargs; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_verify_filters; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, identifier:kwargs; 26, identifier:Campaign; 27, True; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:api; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_get_api; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:update_service; 38, identifier:DefaultApi; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:PaginatedResponse; 42, argument_list; 42, 43; 42, 46; 42, 49; 43, attribute; 43, 44; 43, 45; 44, identifier:api; 45, identifier:update_campaign_list; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:lwrap_type; 48, identifier:Campaign; 49, dictionary_splat; 49, 50; 50, identifier:kwargs
def list_campaigns(self, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, Campaign, True) api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.update_campaign_list, lwrap_type=Campaign, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:list_campaign_device_states; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:campaign_id; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 18; 8, 29; 8, 35; 8, 46; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:kwargs; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_verify_sort_options; 16, argument_list; 16, 17; 17, identifier:kwargs; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:kwargs; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_verify_filters; 25, argument_list; 25, 26; 25, 27; 25, 28; 26, identifier:kwargs; 27, identifier:CampaignDeviceState; 28, True; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:kwargs; 33, string:"campaign_id"; 34, identifier:campaign_id; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:api; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_get_api; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:update_service; 45, identifier:DefaultApi; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:PaginatedResponse; 49, argument_list; 49, 50; 49, 53; 49, 56; 50, attribute; 50, 51; 50, 52; 51, identifier:api; 52, identifier:update_campaign_metadata_list; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:lwrap_type; 55, identifier:CampaignDeviceState; 56, dictionary_splat; 56, 57; 57, identifier:kwargs
def list_campaign_device_states(self, campaign_id, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, CampaignDeviceState, True) kwargs["campaign_id"] = campaign_id api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.update_campaign_metadata_list, lwrap_type=CampaignDeviceState, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:list_firmware_manifests; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 17; 7, 28; 7, 39; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:kwargs; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_verify_sort_options; 15, argument_list; 15, 16; 16, identifier:kwargs; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:kwargs; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_verify_filters; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, identifier:kwargs; 26, identifier:FirmwareManifest; 27, True; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:api; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_get_api; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:update_service; 38, identifier:DefaultApi; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:PaginatedResponse; 42, argument_list; 42, 43; 42, 46; 42, 49; 43, attribute; 43, 44; 43, 45; 44, identifier:api; 45, identifier:firmware_manifest_list; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:lwrap_type; 48, identifier:FirmwareManifest; 49, dictionary_splat; 49, 50; 50, identifier:kwargs
def list_firmware_manifests(self, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, FirmwareManifest, True) api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.firmware_manifest_list, lwrap_type=FirmwareManifest, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:merge_bams; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:input_bams; 6, identifier:merged_bam; 7, default_parameter; 7, 8; 7, 9; 8, identifier:in_sorted; 9, string:"TRUE"; 10, default_parameter; 10, 11; 10, 12; 11, identifier:tmp_dir; 12, None; 13, block; 13, 14; 13, 30; 13, 43; 13, 73; 13, 87; 13, 98; 13, 114; 13, 126; 13, 130; 13, 136; 13, 145; 13, 149; 13, 153; 13, 162; 14, if_statement; 14, 15; 14, 22; 15, not_operator; 15, 16; 16, comparison_operator:>; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:input_bams; 21, integer:1; 22, block; 22, 23; 22, 28; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:print; 26, argument_list; 26, 27; 27, string:"No merge required"; 28, return_statement; 28, 29; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, pattern_list; 32, 33; 32, 34; 33, identifier:outdir; 34, identifier:_; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:path; 40, identifier:split; 41, argument_list; 41, 42; 42, identifier:merged_bam; 43, if_statement; 43, 44; 43, 55; 44, boolean_operator:and; 44, 45; 44, 46; 45, identifier:outdir; 46, not_operator; 46, 47; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:os; 51, identifier:path; 52, identifier:exists; 53, argument_list; 53, 54; 54, identifier:outdir; 55, block; 55, 56; 55, 66; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:print; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:"Creating path to merge file's folder: '{}'"; 63, identifier:format; 64, argument_list; 64, 65; 65, identifier:outdir; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:makedirs; 71, argument_list; 71, 72; 72, identifier:outdir; 73, if_statement; 73, 74; 73, 79; 74, comparison_operator:in; 74, 75; 74, 76; 75, identifier:in_sorted; 76, list:[False, True]; 76, 77; 76, 78; 77, False; 78, True; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:in_sorted; 83, conditional_expression:if; 83, 84; 83, 85; 83, 86; 84, string:"TRUE"; 85, identifier:in_sorted; 86, string:"FALSE"; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:input_string; 90, binary_operator:+; 90, 91; 90, 92; 91, string:" INPUT="; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:" INPUT="; 95, identifier:join; 96, argument_list; 96, 97; 97, identifier:input_bams; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:cmd; 101, binary_operator:+; 101, 102; 101, 109; 102, binary_operator:+; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:tools; 107, identifier:java; 108, string:" -Xmx"; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:pm; 113, identifier:javamem; 114, expression_statement; 114, 115; 115, augmented_assignment:+=; 115, 116; 115, 117; 116, identifier:cmd; 117, binary_operator:+; 117, 118; 117, 125; 118, binary_operator:+; 118, 119; 118, 120; 119, string:" -jar "; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:tools; 124, identifier:picard; 125, string:" MergeSamFiles"; 126, expression_statement; 126, 127; 127, augmented_assignment:+=; 127, 128; 127, 129; 128, identifier:cmd; 129, identifier:input_string; 130, expression_statement; 130, 131; 131, augmented_assignment:+=; 131, 132; 131, 133; 132, identifier:cmd; 133, binary_operator:+; 133, 134; 133, 135; 134, string:" OUTPUT="; 135, identifier:merged_bam; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:cmd; 139, binary_operator:+; 139, 140; 139, 141; 140, string:" ASSUME_SORTED="; 141, call; 141, 142; 141, 143; 142, identifier:str; 143, argument_list; 143, 144; 144, identifier:in_sorted; 145, expression_statement; 145, 146; 146, augmented_assignment:+=; 146, 147; 146, 148; 147, identifier:cmd; 148, string:" CREATE_INDEX=TRUE"; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:cmd; 152, string:" VALIDATION_STRINGENCY=SILENT"; 153, if_statement; 153, 154; 153, 155; 154, identifier:tmp_dir; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, augmented_assignment:+=; 157, 158; 157, 159; 158, identifier:cmd; 159, binary_operator:+; 159, 160; 159, 161; 160, string:" TMP_DIR="; 161, identifier:tmp_dir; 162, return_statement; 162, 163; 163, identifier:cmd
def merge_bams(self, input_bams, merged_bam, in_sorted="TRUE", tmp_dir=None): if not len(input_bams) > 1: print("No merge required") return 0 outdir, _ = os.path.split(merged_bam) if outdir and not os.path.exists(outdir): print("Creating path to merge file's folder: '{}'".format(outdir)) os.makedirs(outdir) if in_sorted in [False, True]: in_sorted = "TRUE" if in_sorted else "FALSE" input_string = " INPUT=" + " INPUT=".join(input_bams) cmd = self.tools.java + " -Xmx" + self.pm.javamem cmd += " -jar " + self.tools.picard + " MergeSamFiles" cmd += input_string cmd += " OUTPUT=" + merged_bam cmd += " ASSUME_SORTED=" + str(in_sorted) cmd += " CREATE_INDEX=TRUE" cmd += " VALIDATION_STRINGENCY=SILENT" if tmp_dir: cmd += " TMP_DIR=" + tmp_dir return cmd
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:samtools_view; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:file_name; 6, identifier:param; 7, default_parameter; 7, 8; 7, 9; 8, identifier:postpend; 9, string:""; 10, block; 10, 11; 10, 27; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:cmd; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"{} view {} {} {}"; 17, identifier:format; 18, argument_list; 18, 19; 18, 24; 18, 25; 18, 26; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:tools; 23, identifier:samtools; 24, identifier:param; 25, identifier:file_name; 26, identifier:postpend; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:subprocess; 31, identifier:check_output; 32, argument_list; 32, 33; 32, 34; 33, identifier:cmd; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:shell; 36, True
def samtools_view(self, file_name, param, postpend=""): cmd = "{} view {} {} {}".format( self.tools.samtools, param, file_name, postpend) return subprocess.check_output(cmd, shell=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sam_conversions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sam_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:depth; 8, True; 9, block; 9, 10; 9, 34; 9, 64; 9, 84; 9, 117; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:cmd; 13, binary_operator:+; 13, 14; 13, 33; 14, binary_operator:+; 14, 15; 14, 26; 15, binary_operator:+; 15, 16; 15, 25; 16, binary_operator:+; 16, 17; 16, 24; 17, binary_operator:+; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:tools; 22, identifier:samtools; 23, string:" view -bS "; 24, identifier:sam_file; 25, string:" > "; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:sam_file; 29, identifier:replace; 30, argument_list; 30, 31; 30, 32; 31, string:".sam"; 32, string:".bam"; 33, string:"\n"; 34, expression_statement; 34, 35; 35, augmented_assignment:+=; 35, 36; 35, 37; 36, identifier:cmd; 37, binary_operator:+; 37, 38; 37, 63; 38, binary_operator:+; 38, 39; 38, 56; 39, binary_operator:+; 39, 40; 39, 55; 40, binary_operator:+; 40, 41; 40, 48; 41, binary_operator:+; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:tools; 46, identifier:samtools; 47, string:" sort "; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:sam_file; 51, identifier:replace; 52, argument_list; 52, 53; 52, 54; 53, string:".sam"; 54, string:".bam"; 55, string:" -o "; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:sam_file; 59, identifier:replace; 60, argument_list; 60, 61; 60, 62; 61, string:".sam"; 62, string:"_sorted.bam"; 63, string:"\n"; 64, expression_statement; 64, 65; 65, augmented_assignment:+=; 65, 66; 65, 67; 66, identifier:cmd; 67, binary_operator:+; 67, 68; 67, 83; 68, binary_operator:+; 68, 69; 68, 76; 69, binary_operator:+; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:tools; 74, identifier:samtools; 75, string:" index "; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:sam_file; 79, identifier:replace; 80, argument_list; 80, 81; 80, 82; 81, string:".sam"; 82, string:"_sorted.bam"; 83, string:"\n"; 84, if_statement; 84, 85; 84, 86; 85, identifier:depth; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:cmd; 90, binary_operator:+; 90, 91; 90, 116; 91, binary_operator:+; 91, 92; 91, 109; 92, binary_operator:+; 92, 93; 92, 108; 93, binary_operator:+; 93, 94; 93, 101; 94, binary_operator:+; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:tools; 99, identifier:samtools; 100, string:" depth "; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:sam_file; 104, identifier:replace; 105, argument_list; 105, 106; 105, 107; 106, string:".sam"; 107, string:"_sorted.bam"; 108, string:" > "; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:sam_file; 112, identifier:replace; 113, argument_list; 113, 114; 113, 115; 114, string:".sam"; 115, string:"_sorted.depth"; 116, string:"\n"; 117, return_statement; 117, 118; 118, identifier:cmd
def sam_conversions(self, sam_file, depth=True): cmd = self.tools.samtools + " view -bS " + sam_file + " > " + sam_file.replace(".sam", ".bam") + "\n" cmd += self.tools.samtools + " sort " + sam_file.replace(".sam", ".bam") + " -o " + sam_file.replace(".sam", "_sorted.bam") + "\n" cmd += self.tools.samtools + " index " + sam_file.replace(".sam", "_sorted.bam") + "\n" if depth: cmd += self.tools.samtools + " depth " + sam_file.replace(".sam", "_sorted.bam") + " > " + sam_file.replace(".sam", "_sorted.depth") + "\n" return cmd
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:bam_conversions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:bam_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:depth; 8, True; 9, block; 9, 10; 9, 34; 9, 58; 9, 78; 9, 111; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:cmd; 13, binary_operator:+; 13, 14; 13, 33; 14, binary_operator:+; 14, 15; 14, 26; 15, binary_operator:+; 15, 16; 15, 25; 16, binary_operator:+; 16, 17; 16, 24; 17, binary_operator:+; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:tools; 22, identifier:samtools; 23, string:" view -h "; 24, identifier:bam_file; 25, string:" > "; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:bam_file; 29, identifier:replace; 30, argument_list; 30, 31; 30, 32; 31, string:".bam"; 32, string:".sam"; 33, string:"\n"; 34, expression_statement; 34, 35; 35, augmented_assignment:+=; 35, 36; 35, 37; 36, identifier:cmd; 37, binary_operator:+; 37, 38; 37, 57; 38, binary_operator:+; 38, 39; 38, 50; 39, binary_operator:+; 39, 40; 39, 49; 40, binary_operator:+; 40, 41; 40, 48; 41, binary_operator:+; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:tools; 46, identifier:samtools; 47, string:" sort "; 48, identifier:bam_file; 49, string:" -o "; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:bam_file; 53, identifier:replace; 54, argument_list; 54, 55; 54, 56; 55, string:".bam"; 56, string:"_sorted.bam"; 57, string:"\n"; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:cmd; 61, binary_operator:+; 61, 62; 61, 77; 62, binary_operator:+; 62, 63; 62, 70; 63, binary_operator:+; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:tools; 68, identifier:samtools; 69, string:" index "; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:bam_file; 73, identifier:replace; 74, argument_list; 74, 75; 74, 76; 75, string:".bam"; 76, string:"_sorted.bam"; 77, string:"\n"; 78, if_statement; 78, 79; 78, 80; 79, identifier:depth; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 84; 83, identifier:cmd; 84, binary_operator:+; 84, 85; 84, 110; 85, binary_operator:+; 85, 86; 85, 103; 86, binary_operator:+; 86, 87; 86, 102; 87, binary_operator:+; 87, 88; 87, 95; 88, binary_operator:+; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:tools; 93, identifier:samtools; 94, string:" depth "; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:bam_file; 98, identifier:replace; 99, argument_list; 99, 100; 99, 101; 100, string:".bam"; 101, string:"_sorted.bam"; 102, string:" > "; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:bam_file; 106, identifier:replace; 107, argument_list; 107, 108; 107, 109; 108, string:".bam"; 109, string:"_sorted.depth"; 110, string:"\n"; 111, return_statement; 111, 112; 112, identifier:cmd
def bam_conversions(self, bam_file, depth=True): cmd = self.tools.samtools + " view -h " + bam_file + " > " + bam_file.replace(".bam", ".sam") + "\n" cmd += self.tools.samtools + " sort " + bam_file + " -o " + bam_file.replace(".bam", "_sorted.bam") + "\n" cmd += self.tools.samtools + " index " + bam_file.replace(".bam", "_sorted.bam") + "\n" if depth: cmd += self.tools.samtools + " depth " + bam_file.replace(".bam", "_sorted.bam") + " > " + bam_file.replace(".bam", "_sorted.depth") + "\n" return cmd
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_checkpoint; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:stage; 6, block; 6, 7; 6, 14; 6, 96; 6, 106; 6, 132; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:stage; 10, None; 11, block; 11, 12; 12, return_statement; 12, 13; 13, False; 14, try_statement; 14, 15; 14, 22; 14, 72; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:is_checkpoint; 19, attribute; 19, 20; 19, 21; 20, identifier:stage; 21, identifier:checkpoint; 22, except_clause; 22, 23; 22, 24; 23, identifier:AttributeError; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 31; 25, 38; 26, call; 26, 27; 26, 28; 27, identifier:hasattr; 28, argument_list; 28, 29; 28, 30; 29, identifier:stage; 30, string:"__call__"; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:stage; 35, attribute; 35, 36; 35, 37; 36, identifier:stage; 37, identifier:__name__; 38, else_clause; 38, 39; 39, block; 39, 40; 39, 53; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, pattern_list; 42, 43; 42, 44; 43, identifier:base; 44, identifier:ext; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:path; 50, identifier:splitext; 51, argument_list; 51, 52; 52, identifier:stage; 53, if_statement; 53, 54; 53, 59; 54, boolean_operator:and; 54, 55; 54, 56; 55, identifier:ext; 56, comparison_operator:not; 56, 57; 56, 58; 57, string:"."; 58, identifier:base; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:print; 63, argument_list; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, concatenated_string; 66, 67; 66, 68; 67, string:"WARNING: '{}' looks like it may be the name or path of "; 68, string:"a file; for such a checkpoint, use touch_checkpoint."; 69, identifier:format; 70, argument_list; 70, 71; 71, identifier:stage; 72, else_clause; 72, 73; 73, block; 73, 74; 73, 90; 74, if_statement; 74, 75; 74, 77; 75, not_operator; 75, 76; 76, identifier:is_checkpoint; 77, block; 77, 78; 77, 88; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:print; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:"Not a checkpoint: {}"; 85, identifier:format; 86, argument_list; 86, 87; 87, identifier:stage; 88, return_statement; 88, 89; 89, False; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:stage; 93, attribute; 93, 94; 93, 95; 94, identifier:stage; 95, identifier:name; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:print; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, string:"Checkpointing: '{}'"; 103, identifier:format; 104, argument_list; 104, 105; 105, identifier:stage; 106, if_statement; 106, 107; 106, 115; 106, 120; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:os; 111, identifier:path; 112, identifier:isabs; 113, argument_list; 113, 114; 114, identifier:stage; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:check_fpath; 119, identifier:stage; 120, else_clause; 120, 121; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:check_fpath; 125, call; 125, 126; 125, 127; 126, identifier:checkpoint_filepath; 127, argument_list; 127, 128; 127, 129; 128, identifier:stage; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:pm; 131, identifier:self; 132, return_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:_touch_checkpoint; 137, argument_list; 137, 138; 138, identifier:check_fpath
def _checkpoint(self, stage): if stage is None: return False try: is_checkpoint = stage.checkpoint except AttributeError: if hasattr(stage, "__call__"): stage = stage.__name__ else: base, ext = os.path.splitext(stage) if ext and "." not in base: print("WARNING: '{}' looks like it may be the name or path of " "a file; for such a checkpoint, use touch_checkpoint.". format(stage)) else: if not is_checkpoint: print("Not a checkpoint: {}".format(stage)) return False stage = stage.name print("Checkpointing: '{}'".format(stage)) if os.path.isabs(stage): check_fpath = stage else: check_fpath = checkpoint_filepath(stage, pm=self) return self._touch_checkpoint(check_fpath)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:geolocation_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:field_name; 5, identifier:argument; 6, identifier:unit; 7, default_parameter; 7, 8; 7, 9; 8, identifier:mode; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:distance_type; 12, None; 13, block; 13, 14; 13, 76; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:inner; 16, parameters; 16, 17; 17, identifier:asc; 18, block; 18, 19; 18, 33; 18, 52; 18, 63; 18, 74; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:locations; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:request; 26, identifier:values; 27, identifier:getlist; 28, argument_list; 28, 29; 28, 30; 29, identifier:argument; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:type; 32, identifier:str; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:field; 36, dictionary; 36, 37; 37, pair; 37, 38; 37, 39; 38, string:'_geo_distance'; 39, dictionary; 39, 40; 39, 43; 39, 49; 40, pair; 40, 41; 40, 42; 41, identifier:field_name; 42, identifier:locations; 43, pair; 43, 44; 43, 45; 44, string:'order'; 45, conditional_expression:if; 45, 46; 45, 47; 45, 48; 46, string:'asc'; 47, identifier:asc; 48, string:'desc'; 49, pair; 49, 50; 49, 51; 50, string:'unit'; 51, identifier:unit; 52, if_statement; 52, 53; 52, 54; 53, identifier:mode; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:field; 60, string:'_geo_distance'; 61, string:'mode'; 62, identifier:mode; 63, if_statement; 63, 64; 63, 65; 64, identifier:distance_type; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:field; 71, string:'_geo_distance'; 72, string:'distance_type'; 73, identifier:distance_type; 74, return_statement; 74, 75; 75, identifier:field; 76, return_statement; 76, 77; 77, identifier:inner
def geolocation_sort(field_name, argument, unit, mode=None, distance_type=None): def inner(asc): locations = request.values.getlist(argument, type=str) field = { '_geo_distance': { field_name: locations, 'order': 'asc' if asc else 'desc', 'unit': unit, } } if mode: field['_geo_distance']['mode'] = mode if distance_type: field['_geo_distance']['distance_type'] = distance_type return field return inner
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:eval_field; 3, parameters; 3, 4; 3, 5; 4, identifier:field; 5, identifier:asc; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 7, 60; 7, 71; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:field; 12, identifier:dict; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 16; 14, 19; 15, identifier:asc; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:field; 19, else_clause; 19, 20; 20, block; 20, 21; 20, 30; 20, 43; 20, 58; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:field; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:copy; 27, identifier:deepcopy; 28, argument_list; 28, 29; 29, identifier:field; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:key; 33, subscript; 33, 34; 33, 42; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:field; 40, identifier:keys; 41, argument_list; 42, integer:0; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:field; 48, identifier:key; 49, string:'order'; 50, call; 50, 51; 50, 52; 51, identifier:reverse_order; 52, argument_list; 52, 53; 53, subscript; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:field; 56, identifier:key; 57, string:'order'; 58, return_statement; 58, 59; 59, identifier:field; 60, elif_clause; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:callable; 63, argument_list; 63, 64; 64, identifier:field; 65, block; 65, 66; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:field; 69, argument_list; 69, 70; 70, identifier:asc; 71, else_clause; 71, 72; 72, block; 72, 73; 72, 82; 72, 91; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, pattern_list; 75, 76; 75, 77; 76, identifier:key; 77, identifier:key_asc; 78, call; 78, 79; 78, 80; 79, identifier:parse_sort_field; 80, argument_list; 80, 81; 81, identifier:field; 82, if_statement; 82, 83; 82, 85; 83, not_operator; 83, 84; 84, identifier:asc; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:key_asc; 89, not_operator; 89, 90; 90, identifier:key_asc; 91, return_statement; 91, 92; 92, dictionary; 92, 93; 93, pair; 93, 94; 93, 95; 94, identifier:key; 95, dictionary; 95, 96; 96, pair; 96, 97; 96, 98; 97, string:'order'; 98, conditional_expression:if; 98, 99; 98, 100; 98, 101; 99, string:'asc'; 100, identifier:key_asc; 101, string:'desc'
def eval_field(field, asc): if isinstance(field, dict): if asc: return field else: field = copy.deepcopy(field) key = list(field.keys())[0] field[key]['order'] = reverse_order(field[key]['order']) return field elif callable(field): return field(asc) else: key, key_asc = parse_sort_field(field) if not asc: key_asc = not key_asc return {key: {'order': 'asc' if key_asc else 'desc'}}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:default_sorter_factory; 3, parameters; 3, 4; 3, 5; 4, identifier:search; 5, identifier:index; 6, block; 6, 7; 6, 11; 6, 26; 6, 69; 6, 78; 6, 97; 6, 106; 6, 126; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sort_arg_name; 10, string:'sort'; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:urlfield; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:request; 18, identifier:values; 19, identifier:get; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:sort_arg_name; 22, string:''; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:type; 25, identifier:str; 26, if_statement; 26, 27; 26, 29; 27, not_operator; 27, 28; 28, identifier:urlfield; 29, block; 29, 30; 29, 46; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:has_query; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:request; 37, identifier:values; 38, identifier:get; 39, argument_list; 39, 40; 39, 41; 40, string:'q'; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:type; 43, attribute; 43, 44; 43, 45; 44, identifier:six; 45, identifier:text_type; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:urlfield; 49, call; 49, 50; 49, 63; 50, attribute; 50, 51; 50, 62; 51, call; 51, 52; 51, 59; 52, attribute; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:current_app; 56, identifier:config; 57, string:'RECORDS_REST_DEFAULT_SORT'; 58, identifier:get; 59, argument_list; 59, 60; 59, 61; 60, identifier:index; 61, dictionary; 62, identifier:get; 63, argument_list; 63, 64; 63, 68; 64, conditional_expression:if; 64, 65; 64, 66; 64, 67; 65, string:'query'; 66, identifier:has_query; 67, string:'noquery'; 68, string:''; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, pattern_list; 71, 72; 71, 73; 72, identifier:key; 73, identifier:asc; 74, call; 74, 75; 74, 76; 75, identifier:parse_sort_field; 76, argument_list; 76, 77; 77, identifier:urlfield; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:sort_options; 81, call; 81, 82; 81, 95; 82, attribute; 82, 83; 82, 94; 83, call; 83, 84; 83, 91; 84, attribute; 84, 85; 84, 90; 85, subscript; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:current_app; 88, identifier:config; 89, string:'RECORDS_REST_SORT_OPTIONS'; 90, identifier:get; 91, argument_list; 91, 92; 91, 93; 92, identifier:index; 93, dictionary; 94, identifier:get; 95, argument_list; 95, 96; 96, identifier:key; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:sort_options; 100, None; 101, block; 101, 102; 102, return_statement; 102, 103; 103, tuple; 103, 104; 103, 105; 104, identifier:search; 105, dictionary; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:search; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:search; 112, identifier:sort; 113, argument_list; 113, 114; 114, list_splat; 114, 115; 115, list_comprehension; 115, 116; 115, 121; 116, call; 116, 117; 116, 118; 117, identifier:eval_field; 118, argument_list; 118, 119; 118, 120; 119, identifier:f; 120, identifier:asc; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:f; 123, subscript; 123, 124; 123, 125; 124, identifier:sort_options; 125, string:'fields'; 126, return_statement; 126, 127; 127, tuple; 127, 128; 127, 129; 128, identifier:search; 129, dictionary; 129, 130; 130, pair; 130, 131; 130, 132; 131, identifier:sort_arg_name; 132, identifier:urlfield
def default_sorter_factory(search, index): sort_arg_name = 'sort' urlfield = request.values.get(sort_arg_name, '', type=str) if not urlfield: has_query = request.values.get('q', type=six.text_type) urlfield = current_app.config['RECORDS_REST_DEFAULT_SORT'].get( index, {}).get('query' if has_query else 'noquery', '') key, asc = parse_sort_field(urlfield) sort_options = current_app.config['RECORDS_REST_SORT_OPTIONS'].get( index, {}).get(key) if sort_options is None: return (search, {}) search = search.sort( *[eval_field(f, asc) for f in sort_options['fields']] ) return (search, {sort_arg_name: urlfield})
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:MakeHistFromList; 3, parameters; 3, 4; 3, 5; 4, identifier:t; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, string:''; 8, block; 8, 9; 8, 18; 8, 29; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:hist; 12, call; 12, 13; 12, 14; 13, identifier:Hist; 14, argument_list; 14, 15; 15, keyword_argument; 15, 16; 15, 17; 16, identifier:name; 17, identifier:name; 18, expression_statement; 18, 19; 19, list_comprehension; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:hist; 23, identifier:Incr; 24, argument_list; 24, 25; 25, identifier:x; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:x; 28, identifier:t; 29, return_statement; 29, 30; 30, identifier:hist
def MakeHistFromList(t, name=''): hist = Hist(name=name) [hist.Incr(x) for x in t] return hist
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:MakePmfFromList; 3, parameters; 3, 4; 3, 5; 4, identifier:t; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, string:''; 8, block; 8, 9; 8, 16; 8, 24; 8, 32; 8, 38; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:hist; 12, call; 12, 13; 12, 14; 13, identifier:MakeHistFromList; 14, argument_list; 14, 15; 15, identifier:t; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:d; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:hist; 22, identifier:GetDict; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:pmf; 27, call; 27, 28; 27, 29; 28, identifier:Pmf; 29, argument_list; 29, 30; 29, 31; 30, identifier:d; 31, identifier:name; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:pmf; 36, identifier:Normalize; 37, argument_list; 38, return_statement; 38, 39; 39, identifier:pmf
def MakePmfFromList(t, name=''): hist = MakeHistFromList(t) d = hist.GetDict() pmf = Pmf(d, name) pmf.Normalize() return pmf
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:MakeSuiteFromList; 3, parameters; 3, 4; 3, 5; 4, identifier:t; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, string:''; 8, block; 8, 9; 8, 16; 8, 24; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:hist; 12, call; 12, 13; 12, 14; 13, identifier:MakeHistFromList; 14, argument_list; 14, 15; 15, identifier:t; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:d; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:hist; 22, identifier:GetDict; 23, argument_list; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:MakeSuiteFromDict; 27, argument_list; 27, 28; 28, identifier:d
def MakeSuiteFromList(t, name=''): hist = MakeHistFromList(t) d = hist.GetDict() return MakeSuiteFromDict(d)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_precursor; 3, parameters; 3, 4; 3, 5; 4, identifier:c; 5, identifier:loci; 6, block; 6, 7; 6, 59; 6, 75; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:data_loci; 10, list_comprehension; 10, 11; 10, 47; 11, list:[x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])]; 11, 12; 11, 13; 11, 18; 11, 26; 11, 34; 11, 39; 12, identifier:x; 13, attribute; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:loci; 16, identifier:x; 17, identifier:chr; 18, call; 18, 19; 18, 20; 19, identifier:int; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:loci; 24, identifier:x; 25, identifier:start; 26, call; 26, 27; 26, 28; 27, identifier:int; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:loci; 32, identifier:x; 33, identifier:end; 34, attribute; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:loci; 37, identifier:x; 38, identifier:strand; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:c; 45, identifier:loci2seq; 46, identifier:x; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:x; 49, call; 49, 50; 49, 51; 50, identifier:list; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:c; 56, identifier:loci2seq; 57, identifier:keys; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:data_loci; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 64, 66; 64, 72; 65, identifier:data_loci; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:key; 68, call; 68, 69; 68, 70; 69, identifier:itemgetter; 70, argument_list; 70, 71; 71, integer:5; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:reverse; 74, True; 75, return_statement; 75, 76; 76, identifier:data_loci
def sort_precursor(c, loci): data_loci = [[x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])] for x in list(c.loci2seq.keys())] data_loci = sorted(data_loci, key=itemgetter(5), reverse=True) return data_loci
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_merge_similar; 3, parameters; 3, 4; 3, 5; 4, identifier:loci; 5, identifier:loci_similarity; 6, block; 6, 7; 6, 11; 6, 15; 6, 19; 6, 41; 6, 306; 6, 318; 6, 334; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:n_cluster; 10, integer:0; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:internal_cluster; 14, dictionary; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:clus_seen; 18, dictionary; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:loci_sorted; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 24, 30; 24, 38; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:loci_similarity; 28, identifier:iteritems; 29, argument_list; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:key; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:operator; 35, identifier:itemgetter; 36, argument_list; 36, 37; 37, integer:1; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:reverse; 40, True; 41, for_statement; 41, 42; 41, 45; 41, 46; 42, pattern_list; 42, 43; 42, 44; 43, identifier:pairs; 44, identifier:sim; 45, identifier:loci_sorted; 46, block; 46, 47; 46, 55; 46, 59; 46, 68; 46, 75; 46, 83; 46, 111; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:common; 50, comparison_operator:>; 50, 51; 50, 52; 51, identifier:sim; 52, attribute; 52, 53; 52, 54; 53, identifier:parameters; 54, identifier:similar; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:n_cluster; 58, integer:1; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:logger; 63, identifier:debug; 64, argument_list; 64, 65; 65, binary_operator:%; 65, 66; 65, 67; 66, string:"_merge_similar:try new cluster %s"; 67, identifier:n_cluster; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:new_c; 71, call; 71, 72; 71, 73; 72, identifier:cluster; 73, argument_list; 73, 74; 74, identifier:n_cluster; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, pattern_list; 77, 78; 77, 79; 78, identifier:p_seen; 79, identifier:p_unseen; 80, expression_list; 80, 81; 80, 82; 81, list:[]; 82, list:[]; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:size; 86, call; 86, 87; 86, 88; 87, identifier:min; 88, argument_list; 88, 89; 88, 100; 89, call; 89, 90; 89, 91; 90, identifier:len; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:_get_seqs; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:loci; 97, subscript; 97, 98; 97, 99; 98, identifier:pairs; 99, integer:0; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:_get_seqs; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:loci; 108, subscript; 108, 109; 108, 110; 109, identifier:pairs; 110, integer:1; 111, if_statement; 111, 112; 111, 113; 111, 294; 112, identifier:common; 113, block; 113, 114; 113, 124; 113, 133; 113, 147; 113, 152; 113, 177; 113, 202; 113, 254; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:consistent; 117, call; 117, 118; 117, 119; 118, identifier:_is_consistent; 119, argument_list; 119, 120; 119, 121; 119, 122; 119, 123; 120, identifier:pairs; 121, identifier:common; 122, identifier:clus_seen; 123, identifier:loci_similarity; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:debug; 129, argument_list; 129, 130; 130, binary_operator:%; 130, 131; 130, 132; 131, string:"_merge_similar: clusters seen: %s"; 132, identifier:clus_seen; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:logger; 137, identifier:debug; 138, argument_list; 138, 139; 139, binary_operator:%; 139, 140; 139, 141; 140, string:"_merge_similar: id %s common %s|%s total %s consistent %s"; 141, tuple; 141, 142; 141, 143; 141, 144; 141, 145; 141, 146; 142, identifier:pairs; 143, identifier:sim; 144, identifier:common; 145, identifier:size; 146, identifier:consistent; 147, if_statement; 147, 148; 147, 150; 148, not_operator; 148, 149; 149, identifier:consistent; 150, block; 150, 151; 151, continue_statement; 152, if_statement; 152, 153; 152, 158; 153, comparison_operator:in; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:pairs; 156, integer:0; 157, identifier:clus_seen; 158, block; 158, 159; 158, 168; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:p_seen; 163, identifier:append; 164, argument_list; 164, 165; 165, subscript; 165, 166; 165, 167; 166, identifier:pairs; 167, integer:0; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:p_unseen; 172, identifier:append; 173, argument_list; 173, 174; 174, subscript; 174, 175; 174, 176; 175, identifier:pairs; 176, integer:1; 177, if_statement; 177, 178; 177, 183; 178, comparison_operator:in; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:pairs; 181, integer:1; 182, identifier:clus_seen; 183, block; 183, 184; 183, 193; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:p_seen; 188, identifier:append; 189, argument_list; 189, 190; 190, subscript; 190, 191; 190, 192; 191, identifier:pairs; 192, integer:1; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:p_unseen; 197, identifier:append; 198, argument_list; 198, 199; 199, subscript; 199, 200; 199, 201; 200, identifier:pairs; 201, integer:0; 202, if_statement; 202, 203; 202, 209; 203, comparison_operator:==; 203, 204; 203, 208; 204, call; 204, 205; 204, 206; 205, identifier:len; 206, argument_list; 206, 207; 207, identifier:p_seen; 208, integer:0; 209, block; 209, 210; 209, 222; 209, 234; 209, 248; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:new_c; 213, call; 213, 214; 213, 215; 214, identifier:_merge_cluster; 215, argument_list; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 218; 217, identifier:loci; 218, subscript; 218, 219; 218, 220; 219, identifier:pairs; 220, integer:0; 221, identifier:new_c; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:new_c; 225, call; 225, 226; 225, 227; 226, identifier:_merge_cluster; 227, argument_list; 227, 228; 227, 233; 228, subscript; 228, 229; 228, 230; 229, identifier:loci; 230, subscript; 230, 231; 230, 232; 231, identifier:pairs; 232, integer:1; 233, identifier:new_c; 234, expression_statement; 234, 235; 235, list_comprehension; 235, 236; 235, 245; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:clus_seen; 239, identifier:update; 240, argument_list; 240, 241; 241, dictionary; 241, 242; 242, pair; 242, 243; 242, 244; 243, identifier:p; 244, identifier:n_cluster; 245, for_in_clause; 245, 246; 245, 247; 246, identifier:p; 247, identifier:pairs; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:internal_cluster; 252, identifier:n_cluster; 253, identifier:new_c; 254, if_statement; 254, 255; 254, 261; 255, comparison_operator:==; 255, 256; 255, 260; 256, call; 256, 257; 256, 258; 257, identifier:len; 258, argument_list; 258, 259; 259, identifier:p_seen; 260, integer:1; 261, block; 261, 262; 261, 270; 261, 286; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:idc_seen; 265, subscript; 265, 266; 265, 267; 266, identifier:clus_seen; 267, subscript; 267, 268; 267, 269; 268, identifier:p_seen; 269, integer:0; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 275; 272, subscript; 272, 273; 272, 274; 273, identifier:internal_cluster; 274, identifier:idc_seen; 275, call; 275, 276; 275, 277; 276, identifier:_merge_cluster; 277, argument_list; 277, 278; 277, 283; 278, subscript; 278, 279; 278, 280; 279, identifier:loci; 280, subscript; 280, 281; 280, 282; 281, identifier:p_unseen; 282, integer:0; 283, subscript; 283, 284; 283, 285; 284, identifier:internal_cluster; 285, identifier:idc_seen; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 293; 288, subscript; 288, 289; 288, 290; 289, identifier:clus_seen; 290, subscript; 290, 291; 290, 292; 291, identifier:p_unseen; 292, integer:0; 293, identifier:idc_seen; 294, else_clause; 294, 295; 295, block; 295, 296; 295, 305; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:logger; 300, identifier:debug; 301, argument_list; 301, 302; 302, binary_operator:%; 302, 303; 302, 304; 303, string:"_merge_similar: id %s %s are different"; 304, identifier:pairs; 305, continue_statement; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:internal_cluster; 310, identifier:update; 311, argument_list; 311, 312; 312, call; 312, 313; 312, 314; 313, identifier:_add_unseen; 314, argument_list; 314, 315; 314, 316; 314, 317; 315, identifier:loci; 316, identifier:clus_seen; 317, identifier:n_cluster; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:logger; 322, identifier:debug; 323, argument_list; 323, 324; 324, binary_operator:%; 324, 325; 324, 326; 325, string:"_merge_similar: total clus %s"; 326, call; 326, 327; 326, 328; 327, identifier:len; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:internal_cluster; 332, identifier:keys; 333, argument_list; 334, return_statement; 334, 335; 335, identifier:internal_cluster
def _merge_similar(loci, loci_similarity): n_cluster = 0 internal_cluster = {} clus_seen = {} loci_sorted = sorted(loci_similarity.iteritems(), key=operator.itemgetter(1), reverse=True) for pairs, sim in loci_sorted: common = sim > parameters.similar n_cluster += 1 logger.debug("_merge_similar:try new cluster %s" % n_cluster) new_c = cluster(n_cluster) p_seen, p_unseen = [], [] size = min(len(_get_seqs(loci[pairs[0]])), len(_get_seqs(loci[pairs[1]]))) if common: consistent = _is_consistent(pairs, common, clus_seen, loci_similarity) logger.debug("_merge_similar: clusters seen: %s" % clus_seen) logger.debug("_merge_similar: id %s common %s|%s total %s consistent %s" % (pairs, sim, common, size, consistent)) if not consistent: continue if pairs[0] in clus_seen: p_seen.append(pairs[0]) p_unseen.append(pairs[1]) if pairs[1] in clus_seen: p_seen.append(pairs[1]) p_unseen.append(pairs[0]) if len(p_seen) == 0: new_c = _merge_cluster(loci[pairs[0]], new_c) new_c = _merge_cluster(loci[pairs[1]], new_c) [clus_seen.update({p: n_cluster}) for p in pairs] internal_cluster[n_cluster] = new_c if len(p_seen) == 1: idc_seen = clus_seen[p_seen[0]] internal_cluster[idc_seen] = _merge_cluster(loci[p_unseen[0]], internal_cluster[idc_seen]) clus_seen[p_unseen[0]] = idc_seen else: logger.debug("_merge_similar: id %s %s are different" % pairs) continue internal_cluster.update(_add_unseen(loci, clus_seen, n_cluster)) logger.debug("_merge_similar: total clus %s" % len(internal_cluster.keys())) return internal_cluster
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_solve_loci_deprecated; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:c; 5, identifier:locilen_sorted; 6, identifier:seen_seqs; 7, identifier:filtered; 8, identifier:maxseq; 9, identifier:n_cluster; 10, block; 10, 11; 10, 15; 10, 21; 10, 25; 10, 34; 10, 41; 10, 195; 10, 201; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:first_run; 14, integer:0; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:seen_seqs; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 21, expression_statement; 21, 22; 22, augmented_assignment:+=; 22, 23; 22, 24; 23, identifier:n_cluster; 24, integer:1; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:logger; 29, identifier:debug; 30, argument_list; 30, 31; 31, binary_operator:%; 31, 32; 31, 33; 32, string:"_solve_loci:new cluster %s"; 33, identifier:n_cluster; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:new_c; 37, call; 37, 38; 37, 39; 38, identifier:cluster; 39, argument_list; 39, 40; 40, identifier:n_cluster; 41, for_statement; 41, 42; 41, 45; 41, 46; 42, pattern_list; 42, 43; 42, 44; 43, identifier:idl; 44, identifier:lenl; 45, identifier:locilen_sorted; 46, block; 46, 47; 46, 55; 46, 72; 46, 87; 46, 91; 46, 115; 46, 139; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:locus_seqs; 50, subscript; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:c; 53, identifier:loci2seq; 54, identifier:idl; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:first_run; 58, integer:0; 59, block; 59, 60; 59, 64; 59, 68; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:seen_seqs; 63, identifier:locus_seqs; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:first_run; 67, integer:1; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:first_idl; 71, identifier:idl; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:intersect; 75, call; 75, 76; 75, 77; 76, identifier:list; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 85; 79, attribute; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:set; 82, argument_list; 82, 83; 83, identifier:seen_seqs; 84, identifier:intersection; 85, argument_list; 85, 86; 86, identifier:locus_seqs; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:common; 90, integer:0; 91, if_statement; 91, 92; 91, 93; 92, identifier:intersect; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:common; 97, binary_operator:/; 97, 98; 97, 104; 98, binary_operator:*; 98, 99; 98, 103; 99, call; 99, 100; 99, 101; 100, identifier:len; 101, argument_list; 101, 102; 102, identifier:intersect; 103, float:1.0; 104, call; 104, 105; 104, 106; 105, identifier:min; 106, argument_list; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, identifier:seen_seqs; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, identifier:locus_seqs; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:logger; 119, identifier:debug; 120, argument_list; 120, 121; 121, binary_operator:%; 121, 122; 121, 123; 122, string:"_sole_loci:id %s idl %s len %s max %s seen %s inter %s common %s "; 123, tuple; 123, 124; 123, 127; 123, 128; 123, 129; 123, 130; 123, 134; 123, 138; 124, attribute; 124, 125; 124, 126; 125, identifier:c; 126, identifier:id; 127, identifier:idl; 128, identifier:lenl; 129, identifier:maxseq; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, identifier:seen_seqs; 134, call; 134, 135; 134, 136; 135, identifier:len; 136, argument_list; 136, 137; 137, identifier:intersect; 138, identifier:common; 139, if_statement; 139, 140; 139, 145; 139, 184; 140, comparison_operator:>=; 140, 141; 140, 144; 141, binary_operator:*; 141, 142; 141, 143; 142, identifier:common; 143, float:1.0; 144, float:0.6; 145, block; 145, 146; 146, if_statement; 146, 147; 146, 154; 146, 168; 147, comparison_operator:>=; 147, 148; 147, 151; 148, binary_operator:*; 148, 149; 148, 150; 149, identifier:lenl; 150, float:1.0; 151, binary_operator:*; 151, 152; 151, 153; 152, float:0.6; 153, identifier:maxseq; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 161; 157, pattern_list; 157, 158; 157, 159; 157, 160; 158, identifier:c; 159, identifier:new_c; 160, identifier:seen_seqs; 161, call; 161, 162; 161, 163; 162, identifier:_merge_loci_in_cluster; 163, argument_list; 163, 164; 163, 165; 163, 166; 163, 167; 164, identifier:c; 165, identifier:new_c; 166, identifier:idl; 167, identifier:seen_seqs; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 176; 172, pattern_list; 172, 173; 172, 174; 172, 175; 173, identifier:c; 174, identifier:new_c; 175, identifier:seen_seqs; 176, call; 176, 177; 176, 178; 177, identifier:_merge_with_first_loci; 178, argument_list; 178, 179; 178, 180; 178, 181; 178, 182; 178, 183; 179, identifier:c; 180, identifier:new_c; 181, identifier:first_idl; 182, identifier:idl; 183, identifier:seen_seqs; 184, else_clause; 184, 185; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:c; 189, call; 189, 190; 189, 191; 190, identifier:_remove_seqs_from_loci; 191, argument_list; 191, 192; 191, 193; 191, 194; 192, identifier:c; 193, identifier:idl; 194, identifier:seen_seqs; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:filtered; 199, identifier:n_cluster; 200, identifier:new_c; 201, return_statement; 201, 202; 202, expression_list; 202, 203; 202, 204; 202, 205; 202, 206; 203, identifier:c; 204, identifier:seen_seqs; 205, identifier:filtered; 206, identifier:n_cluster
def _solve_loci_deprecated(c, locilen_sorted, seen_seqs, filtered, maxseq, n_cluster): first_run = 0 seen_seqs = list() n_cluster += 1 logger.debug("_solve_loci:new cluster %s" % n_cluster) new_c = cluster(n_cluster) for idl, lenl in locilen_sorted: locus_seqs = c.loci2seq[idl] if first_run == 0: seen_seqs = locus_seqs first_run = 1 first_idl = idl intersect = list(set(seen_seqs).intersection(locus_seqs)) common = 0 if intersect: common = len(intersect)*1.0/min(len(seen_seqs), len(locus_seqs)) logger.debug("_sole_loci:id %s idl %s len %s max %s seen %s inter %s common %s " % (c.id, idl, lenl, maxseq, len(seen_seqs), len(intersect), common)) if common*1.0 >= 0.6: if lenl*1.0 >= 0.6*maxseq: c, new_c, seen_seqs = _merge_loci_in_cluster(c, new_c, idl, seen_seqs) else: c, new_c, seen_seqs = _merge_with_first_loci(c, new_c, first_idl, idl, seen_seqs) else: c = _remove_seqs_from_loci(c, idl, seen_seqs) filtered[n_cluster] = new_c return c, seen_seqs, filtered, n_cluster
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:hash_prefix_list_checksum; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:threat_list; 6, block; 6, 7; 6, 11; 6, 24; 6, 78; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:q; 10, string:'''SELECT value FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? ORDER BY value '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:params; 14, list:[threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type]; 14, 15; 14, 18; 14, 21; 15, attribute; 15, 16; 15, 17; 16, identifier:threat_list; 17, identifier:threat_type; 18, attribute; 18, 19; 18, 20; 19, identifier:threat_list; 20, identifier:platform_type; 21, attribute; 21, 22; 21, 23; 22, identifier:threat_list; 23, identifier:threat_entry_type; 24, with_statement; 24, 25; 24, 35; 25, with_clause; 25, 26; 26, with_item; 26, 27; 27, as_pattern; 27, 28; 27, 33; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:get_cursor; 32, argument_list; 33, as_pattern_target; 33, 34; 34, identifier:dbc; 35, block; 35, 36; 35, 44; 35, 65; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:dbc; 40, identifier:execute; 41, argument_list; 41, 42; 41, 43; 42, identifier:q; 43, identifier:params; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:all_hashes; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:b''; 50, identifier:join; 51, generator_expression; 51, 52; 51, 58; 52, call; 52, 53; 52, 54; 53, identifier:bytes; 54, argument_list; 54, 55; 55, subscript; 55, 56; 55, 57; 56, identifier:h; 57, integer:0; 58, for_in_clause; 58, 59; 58, 60; 59, identifier:h; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:dbc; 63, identifier:fetchall; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:checksum; 68, call; 68, 69; 68, 77; 69, attribute; 69, 70; 69, 76; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:hashlib; 73, identifier:sha256; 74, argument_list; 74, 75; 75, identifier:all_hashes; 76, identifier:digest; 77, argument_list; 78, return_statement; 78, 79; 79, identifier:checksum
def hash_prefix_list_checksum(self, threat_list): q = '''SELECT value FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? ORDER BY value ''' params = [threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type] with self.get_cursor() as dbc: dbc.execute(q, params) all_hashes = b''.join(bytes(h[0]) for h in dbc.fetchall()) checksum = hashlib.sha256(all_hashes).digest() return checksum
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:remove_hash_prefix_indices; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:threat_list; 6, identifier:indices; 7, block; 7, 8; 7, 12; 7, 16; 7, 26; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:batch_size; 11, integer:40; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:q; 15, string:'''DELETE FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? AND value IN ({}) '''; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:prefixes_to_remove; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:get_hash_prefix_values_to_remove; 23, argument_list; 23, 24; 23, 25; 24, identifier:threat_list; 25, identifier:indices; 26, with_statement; 26, 27; 26, 37; 27, with_clause; 27, 28; 28, with_item; 28, 29; 29, as_pattern; 29, 30; 29, 35; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:get_cursor; 34, argument_list; 35, as_pattern_target; 35, 36; 36, identifier:dbc; 37, block; 37, 38; 38, for_statement; 38, 39; 38, 40; 38, 49; 39, identifier:i; 40, call; 40, 41; 40, 42; 41, identifier:range; 42, argument_list; 42, 43; 42, 44; 42, 48; 43, integer:0; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:prefixes_to_remove; 48, identifier:batch_size; 49, block; 49, 50; 49, 62; 49, 86; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:remove_batch; 53, subscript; 53, 54; 53, 55; 54, identifier:prefixes_to_remove; 55, slice; 55, 56; 55, 57; 55, 58; 56, identifier:i; 57, colon; 58, parenthesized_expression; 58, 59; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:i; 61, identifier:batch_size; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:params; 65, binary_operator:+; 65, 66; 65, 76; 66, list:[ threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type ]; 66, 67; 66, 70; 66, 73; 67, attribute; 67, 68; 67, 69; 68, identifier:threat_list; 69, identifier:threat_type; 70, attribute; 70, 71; 70, 72; 71, identifier:threat_list; 72, identifier:platform_type; 73, attribute; 73, 74; 73, 75; 74, identifier:threat_list; 75, identifier:threat_entry_type; 76, list_comprehension; 76, 77; 76, 83; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:sqlite3; 80, identifier:Binary; 81, argument_list; 81, 82; 82, identifier:b; 83, for_in_clause; 83, 84; 83, 85; 84, identifier:b; 85, identifier:remove_batch; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:dbc; 90, identifier:execute; 91, argument_list; 91, 92; 91, 109; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:q; 95, identifier:format; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, string:','; 100, identifier:join; 101, argument_list; 101, 102; 102, binary_operator:*; 102, 103; 102, 105; 103, list:['?']; 103, 104; 104, string:'?'; 105, call; 105, 106; 105, 107; 106, identifier:len; 107, argument_list; 107, 108; 108, identifier:remove_batch; 109, identifier:params
def remove_hash_prefix_indices(self, threat_list, indices): batch_size = 40 q = '''DELETE FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? AND value IN ({}) ''' prefixes_to_remove = self.get_hash_prefix_values_to_remove(threat_list, indices) with self.get_cursor() as dbc: for i in range(0, len(prefixes_to_remove), batch_size): remove_batch = prefixes_to_remove[i:(i + batch_size)] params = [ threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type ] + [sqlite3.Binary(b) for b in remove_batch] dbc.execute(q.format(','.join(['?'] * len(remove_batch))), params)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:has_equal_value; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:state; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ordered; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ndigits; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:incorrect_msg; 13, None; 14, block; 14, 15; 14, 28; 14, 37; 14, 42; 14, 69; 14, 141; 15, if_statement; 15, 16; 15, 22; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:hasattr; 19, argument_list; 19, 20; 19, 21; 20, identifier:state; 21, string:"parent"; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, string:"You can only use has_equal_value() on the state resulting from check_column, check_row or check_result."; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:incorrect_msg; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:incorrect_msg; 36, string:"Column `{{col}}` seems to be incorrect.{{' Make sure you arranged the rows correctly.' if ordered else ''}}"; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:has_nrows; 40, argument_list; 40, 41; 41, identifier:state; 42, if_statement; 42, 43; 42, 45; 42, 55; 43, not_operator; 43, 44; 44, identifier:ordered; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:stu_res; 50, identifier:sol_res; 51, call; 51, 52; 51, 53; 52, identifier:sort_rows; 53, argument_list; 53, 54; 54, identifier:state; 55, else_clause; 55, 56; 56, block; 56, 57; 56, 63; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:stu_res; 60, attribute; 60, 61; 60, 62; 61, identifier:state; 62, identifier:student_result; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:sol_res; 66, attribute; 66, 67; 66, 68; 67, identifier:state; 68, identifier:solution_result; 69, for_statement; 69, 70; 69, 73; 69, 78; 70, pattern_list; 70, 71; 70, 72; 71, identifier:sol_col_name; 72, identifier:sol_col_vals; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:sol_res; 76, identifier:items; 77, argument_list; 78, block; 78, 79; 78, 85; 78, 111; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:stu_col_vals; 82, subscript; 82, 83; 82, 84; 83, identifier:stu_res; 84, identifier:sol_col_name; 85, if_statement; 85, 86; 85, 89; 86, comparison_operator:is; 86, 87; 86, 88; 87, identifier:ndigits; 88, None; 89, block; 89, 90; 90, try_statement; 90, 91; 90, 108; 91, block; 91, 92; 91, 100; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:sol_col_vals; 95, call; 95, 96; 95, 97; 96, identifier:round_seq; 97, argument_list; 97, 98; 97, 99; 98, identifier:sol_col_vals; 99, identifier:ndigits; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:stu_col_vals; 103, call; 103, 104; 103, 105; 104, identifier:round_seq; 105, argument_list; 105, 106; 105, 107; 106, identifier:stu_col_vals; 107, identifier:ndigits; 108, except_clause; 108, 109; 109, block; 109, 110; 110, pass_statement; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:!=; 112, 113; 112, 114; 113, identifier:sol_col_vals; 114, identifier:stu_col_vals; 115, block; 115, 116; 115, 134; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:_msg; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:state; 122, identifier:build_message; 123, argument_list; 123, 124; 123, 125; 124, identifier:incorrect_msg; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:fmt_kwargs; 127, dictionary; 127, 128; 127, 131; 128, pair; 128, 129; 128, 130; 129, string:"col"; 130, identifier:sol_col_name; 131, pair; 131, 132; 131, 133; 132, string:"ordered"; 133, identifier:ordered; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:state; 138, identifier:do_test; 139, argument_list; 139, 140; 140, identifier:_msg; 141, return_statement; 141, 142; 142, identifier:state
def has_equal_value(state, ordered=False, ndigits=None, incorrect_msg=None): if not hasattr(state, "parent"): raise ValueError( "You can only use has_equal_value() on the state resulting from check_column, check_row or check_result." ) if incorrect_msg is None: incorrect_msg = "Column `{{col}}` seems to be incorrect.{{' Make sure you arranged the rows correctly.' if ordered else ''}}" has_nrows(state) if not ordered: stu_res, sol_res = sort_rows(state) else: stu_res = state.student_result sol_res = state.solution_result for sol_col_name, sol_col_vals in sol_res.items(): stu_col_vals = stu_res[sol_col_name] if ndigits is not None: try: sol_col_vals = round_seq(sol_col_vals, ndigits) stu_col_vals = round_seq(stu_col_vals, ndigits) except: pass if sol_col_vals != stu_col_vals: _msg = state.build_message( incorrect_msg, fmt_kwargs={"col": sol_col_name, "ordered": ordered} ) state.do_test(_msg) return state
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_releases; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 23; 5, 32; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:releases; 9, list_comprehension; 9, 10; 9, 18; 10, tuple; 10, 11; 10, 17; 11, call; 11, 12; 11, 13; 12, identifier:parse_version; 13, argument_list; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:release; 16, identifier:version; 17, identifier:release; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:release; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:releases; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:releases; 27, identifier:sort; 28, argument_list; 28, 29; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:reverse; 31, True; 32, return_statement; 32, 33; 33, list_comprehension; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:release; 36, integer:1; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:release; 39, identifier:releases
def sorted_releases(self): releases = [(parse_version(release.version), release) for release in self.releases] releases.sort(reverse=True) return [release[1] for release in releases]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:image_position_stochastic; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:self; 5, identifier:source_x; 6, identifier:source_y; 7, identifier:kwargs_lens; 8, default_parameter; 8, 9; 8, 10; 9, identifier:search_window; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:precision_limit; 13, binary_operator:**; 13, 14; 13, 15; 14, integer:10; 15, parenthesized_expression; 15, 16; 16, unary_operator:-; 16, 17; 17, integer:10; 18, default_parameter; 18, 19; 18, 20; 19, identifier:arrival_time_sort; 20, True; 21, default_parameter; 21, 22; 21, 23; 22, identifier:x_center; 23, integer:0; 24, default_parameter; 24, 25; 24, 26; 25, identifier:y_center; 26, integer:0; 27, default_parameter; 27, 28; 27, 29; 28, identifier:num_random; 29, integer:1000; 30, default_parameter; 30, 31; 30, 32; 31, identifier:verbose; 32, False; 33, block; 33, 34; 33, 42; 33, 161; 33, 174; 33, 192; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:x_solve; 38, identifier:y_solve; 39, expression_list; 39, 40; 39, 41; 40, list:[]; 41, list:[]; 42, for_statement; 42, 43; 42, 44; 42, 48; 43, identifier:i; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 47, identifier:num_random; 48, block; 48, 49; 48, 68; 48, 87; 48, 98; 48, 122; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:x_init; 52, binary_operator:+; 52, 53; 52, 67; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:np; 57, identifier:random; 58, identifier:uniform; 59, argument_list; 59, 60; 59, 64; 60, binary_operator:/; 60, 61; 60, 63; 61, unary_operator:-; 61, 62; 62, identifier:search_window; 63, float:2.; 64, binary_operator:/; 64, 65; 64, 66; 65, identifier:search_window; 66, integer:2; 67, identifier:x_center; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:y_init; 71, binary_operator:+; 71, 72; 71, 86; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:np; 76, identifier:random; 77, identifier:uniform; 78, argument_list; 78, 79; 78, 83; 79, binary_operator:/; 79, 80; 79, 82; 80, unary_operator:-; 80, 81; 81, identifier:search_window; 82, float:2.; 83, binary_operator:/; 83, 84; 83, 85; 84, identifier:search_window; 85, integer:2; 86, identifier:y_center; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:xinitial; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:array; 94, argument_list; 94, 95; 95, list:[x_init, y_init]; 95, 96; 95, 97; 96, identifier:x_init; 97, identifier:y_init; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:result; 101, call; 101, 102; 101, 103; 102, identifier:minimize; 103, argument_list; 103, 104; 103, 107; 103, 108; 103, 114; 103, 119; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:_root; 107, identifier:xinitial; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:args; 110, tuple; 110, 111; 110, 112; 110, 113; 111, identifier:kwargs_lens; 112, identifier:source_x; 113, identifier:source_y; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:tol; 116, binary_operator:**; 116, 117; 116, 118; 117, identifier:precision_limit; 118, integer:2; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:method; 121, string:'Nelder-Mead'; 122, if_statement; 122, 123; 122, 138; 123, comparison_operator:<; 123, 124; 123, 135; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_root; 128, argument_list; 128, 129; 128, 132; 128, 133; 128, 134; 129, attribute; 129, 130; 129, 131; 130, identifier:result; 131, identifier:x; 132, identifier:kwargs_lens; 133, identifier:source_x; 134, identifier:source_y; 135, binary_operator:**; 135, 136; 135, 137; 136, identifier:precision_limit; 137, integer:2; 138, block; 138, 139; 138, 150; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:x_solve; 143, identifier:append; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:result; 148, identifier:x; 149, integer:0; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:y_solve; 154, identifier:append; 155, argument_list; 155, 156; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:result; 159, identifier:x; 160, integer:1; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, pattern_list; 163, 164; 163, 165; 164, identifier:x_mins; 165, identifier:y_mins; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:image_util; 169, identifier:findOverlap; 170, argument_list; 170, 171; 170, 172; 170, 173; 171, identifier:x_solve; 172, identifier:y_solve; 173, identifier:precision_limit; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:arrival_time_sort; 177, True; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, pattern_list; 181, 182; 181, 183; 182, identifier:x_mins; 183, identifier:y_mins; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:sort_arrival_times; 188, argument_list; 188, 189; 188, 190; 188, 191; 189, identifier:x_mins; 190, identifier:y_mins; 191, identifier:kwargs_lens; 192, return_statement; 192, 193; 193, expression_list; 193, 194; 193, 195; 194, identifier:x_mins; 195, identifier:y_mins
def image_position_stochastic(self, source_x, source_y, kwargs_lens, search_window=10, precision_limit=10**(-10), arrival_time_sort=True, x_center=0, y_center=0, num_random=1000, verbose=False): x_solve, y_solve = [], [] for i in range(num_random): x_init = np.random.uniform(-search_window / 2., search_window / 2) + x_center y_init = np.random.uniform(-search_window / 2., search_window / 2) + y_center xinitial = np.array([x_init, y_init]) result = minimize(self._root, xinitial, args=(kwargs_lens, source_x, source_y), tol=precision_limit ** 2, method='Nelder-Mead') if self._root(result.x, kwargs_lens, source_x, source_y) < precision_limit**2: x_solve.append(result.x[0]) y_solve.append(result.x[1]) x_mins, y_mins = image_util.findOverlap(x_solve, y_solve, precision_limit) if arrival_time_sort is True: x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) return x_mins, y_mins
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 42; 2, function_name:image_position_from_source; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 4, identifier:self; 5, identifier:sourcePos_x; 6, identifier:sourcePos_y; 7, identifier:kwargs_lens; 8, default_parameter; 8, 9; 8, 10; 9, identifier:min_distance; 10, float:0.1; 11, default_parameter; 11, 12; 11, 13; 12, identifier:search_window; 13, integer:10; 14, default_parameter; 14, 15; 14, 16; 15, identifier:precision_limit; 16, binary_operator:**; 16, 17; 16, 18; 17, integer:10; 18, parenthesized_expression; 18, 19; 19, unary_operator:-; 19, 20; 20, integer:10; 21, default_parameter; 21, 22; 21, 23; 22, identifier:num_iter_max; 23, integer:100; 24, default_parameter; 24, 25; 24, 26; 25, identifier:arrival_time_sort; 26, True; 27, default_parameter; 27, 28; 27, 29; 28, identifier:initial_guess_cut; 29, True; 30, default_parameter; 30, 31; 30, 32; 31, identifier:verbose; 32, False; 33, default_parameter; 33, 34; 33, 35; 34, identifier:x_center; 35, integer:0; 36, default_parameter; 36, 37; 36, 38; 37, identifier:y_center; 38, integer:0; 39, default_parameter; 39, 40; 39, 41; 40, identifier:num_random; 41, integer:0; 42, block; 42, 43; 42, 57; 42, 69; 42, 73; 42, 77; 42, 92; 42, 104; 42, 118; 42, 133; 42, 203; 42, 237; 42, 271; 42, 295; 42, 303; 42, 311; 42, 324; 42, 342; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:numPix; 46, call; 46, 47; 46, 48; 47, identifier:int; 48, argument_list; 48, 49; 49, binary_operator:+; 49, 50; 49, 56; 50, call; 50, 51; 50, 52; 51, identifier:round; 52, argument_list; 52, 53; 53, binary_operator:/; 53, 54; 53, 55; 54, identifier:search_window; 55, identifier:min_distance; 56, float:0.5; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, pattern_list; 59, 60; 59, 61; 60, identifier:x_grid; 61, identifier:y_grid; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:util; 65, identifier:make_grid; 66, argument_list; 66, 67; 66, 68; 67, identifier:numPix; 68, identifier:min_distance; 69, expression_statement; 69, 70; 70, augmented_assignment:+=; 70, 71; 70, 72; 71, identifier:x_grid; 72, identifier:x_center; 73, expression_statement; 73, 74; 74, augmented_assignment:+=; 74, 75; 74, 76; 75, identifier:y_grid; 76, identifier:y_center; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:x_mapped; 81, identifier:y_mapped; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:lensModel; 87, identifier:ray_shooting; 88, argument_list; 88, 89; 88, 90; 88, 91; 89, identifier:x_grid; 90, identifier:y_grid; 91, identifier:kwargs_lens; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:absmapped; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:util; 98, identifier:displaceAbs; 99, argument_list; 99, 100; 99, 101; 99, 102; 99, 103; 100, identifier:x_mapped; 101, identifier:y_mapped; 102, identifier:sourcePos_x; 103, identifier:sourcePos_y; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 110; 106, pattern_list; 106, 107; 106, 108; 106, 109; 107, identifier:x_mins; 108, identifier:y_mins; 109, identifier:delta_map; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:util; 113, identifier:neighborSelect; 114, argument_list; 114, 115; 114, 116; 114, 117; 115, identifier:absmapped; 116, identifier:x_grid; 117, identifier:y_grid; 118, if_statement; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:verbose; 121, True; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:print; 126, argument_list; 126, 127; 127, binary_operator:%; 127, 128; 127, 129; 128, string:"There are %s regions identified that could contain a solution of the lens equation"; 129, call; 129, 130; 129, 131; 130, identifier:len; 131, argument_list; 131, 132; 132, identifier:x_mins; 133, if_statement; 133, 134; 133, 137; 134, comparison_operator:is; 134, 135; 134, 136; 135, identifier:initial_guess_cut; 136, True; 137, block; 137, 138; 137, 156; 137, 164; 137, 176; 137, 188; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:mag; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:np; 144, identifier:abs; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:lensModel; 151, identifier:magnification; 152, argument_list; 152, 153; 152, 154; 152, 155; 153, identifier:x_mins; 154, identifier:y_mins; 155, identifier:kwargs_lens; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 160; 159, identifier:mag; 160, comparison_operator:<; 160, 161; 160, 162; 161, identifier:mag; 162, integer:1; 163, integer:1; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:x_mins; 167, subscript; 167, 168; 167, 169; 168, identifier:x_mins; 169, comparison_operator:<=; 169, 170; 169, 171; 170, identifier:delta_map; 171, binary_operator:*; 171, 172; 171, 175; 172, binary_operator:*; 172, 173; 172, 174; 173, identifier:min_distance; 174, identifier:mag; 175, integer:5; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:y_mins; 179, subscript; 179, 180; 179, 181; 180, identifier:y_mins; 181, comparison_operator:<=; 181, 182; 181, 183; 182, identifier:delta_map; 183, binary_operator:*; 183, 184; 183, 187; 184, binary_operator:*; 184, 185; 184, 186; 185, identifier:min_distance; 186, identifier:mag; 187, integer:5; 188, if_statement; 188, 189; 188, 192; 189, comparison_operator:is; 189, 190; 189, 191; 190, identifier:verbose; 191, True; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 196; 195, identifier:print; 196, argument_list; 196, 197; 197, binary_operator:%; 197, 198; 197, 199; 198, string:"The number of regions that meet the plausibility criteria are %s"; 199, call; 199, 200; 199, 201; 200, identifier:len; 201, argument_list; 201, 202; 202, identifier:x_mins; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:x_mins; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:np; 209, identifier:append; 210, argument_list; 210, 211; 210, 212; 211, identifier:x_mins; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:np; 216, identifier:random; 217, identifier:uniform; 218, argument_list; 218, 219; 218, 227; 218, 234; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:low; 221, binary_operator:+; 221, 222; 221, 226; 222, binary_operator:/; 222, 223; 222, 225; 223, unary_operator:-; 223, 224; 224, identifier:search_window; 225, integer:2; 226, identifier:x_center; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:high; 229, binary_operator:+; 229, 230; 229, 233; 230, binary_operator:/; 230, 231; 230, 232; 231, identifier:search_window; 232, integer:2; 233, identifier:x_center; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:size; 236, identifier:num_random; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:y_mins; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:np; 243, identifier:append; 244, argument_list; 244, 245; 244, 246; 245, identifier:y_mins; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:np; 250, identifier:random; 251, identifier:uniform; 252, argument_list; 252, 253; 252, 261; 252, 268; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:low; 255, binary_operator:+; 255, 256; 255, 260; 256, binary_operator:/; 256, 257; 256, 259; 257, unary_operator:-; 257, 258; 258, identifier:search_window; 259, integer:2; 260, identifier:y_center; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:high; 263, binary_operator:+; 263, 264; 263, 267; 264, binary_operator:/; 264, 265; 264, 266; 265, identifier:search_window; 266, integer:2; 267, identifier:y_center; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:size; 270, identifier:num_random; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 277; 273, pattern_list; 273, 274; 273, 275; 273, 276; 274, identifier:x_mins; 275, identifier:y_mins; 276, identifier:solver_precision; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:_findIterative; 281, argument_list; 281, 282; 281, 283; 281, 284; 281, 285; 281, 286; 281, 287; 281, 288; 281, 289; 281, 292; 282, identifier:x_mins; 283, identifier:y_mins; 284, identifier:sourcePos_x; 285, identifier:sourcePos_y; 286, identifier:kwargs_lens; 287, identifier:precision_limit; 288, identifier:num_iter_max; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:verbose; 291, identifier:verbose; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:min_distance; 294, identifier:min_distance; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:x_mins; 298, subscript; 298, 299; 298, 300; 299, identifier:x_mins; 300, comparison_operator:<=; 300, 301; 300, 302; 301, identifier:solver_precision; 302, identifier:precision_limit; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:y_mins; 306, subscript; 306, 307; 306, 308; 307, identifier:y_mins; 308, comparison_operator:<=; 308, 309; 308, 310; 309, identifier:solver_precision; 310, identifier:precision_limit; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 316; 313, pattern_list; 313, 314; 313, 315; 314, identifier:x_mins; 315, identifier:y_mins; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:image_util; 319, identifier:findOverlap; 320, argument_list; 320, 321; 320, 322; 320, 323; 321, identifier:x_mins; 322, identifier:y_mins; 323, identifier:min_distance; 324, if_statement; 324, 325; 324, 328; 325, comparison_operator:is; 325, 326; 325, 327; 326, identifier:arrival_time_sort; 327, True; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 334; 331, pattern_list; 331, 332; 331, 333; 332, identifier:x_mins; 333, identifier:y_mins; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:sort_arrival_times; 338, argument_list; 338, 339; 338, 340; 338, 341; 339, identifier:x_mins; 340, identifier:y_mins; 341, identifier:kwargs_lens; 342, return_statement; 342, 343; 343, expression_list; 343, 344; 343, 345; 344, identifier:x_mins; 345, identifier:y_mins
def image_position_from_source(self, sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, precision_limit=10**(-10), num_iter_max=100, arrival_time_sort=True, initial_guess_cut=True, verbose=False, x_center=0, y_center=0, num_random=0): numPix = int(round(search_window / min_distance) + 0.5) x_grid, y_grid = util.make_grid(numPix, min_distance) x_grid += x_center y_grid += y_center x_mapped, y_mapped = self.lensModel.ray_shooting(x_grid, y_grid, kwargs_lens) absmapped = util.displaceAbs(x_mapped, y_mapped, sourcePos_x, sourcePos_y) x_mins, y_mins, delta_map = util.neighborSelect(absmapped, x_grid, y_grid) if verbose is True: print("There are %s regions identified that could contain a solution of the lens equation" % len(x_mins)) if initial_guess_cut is True: mag = np.abs(self.lensModel.magnification(x_mins, y_mins, kwargs_lens)) mag[mag < 1] = 1 x_mins = x_mins[delta_map <= min_distance*mag*5] y_mins = y_mins[delta_map <= min_distance*mag*5] if verbose is True: print("The number of regions that meet the plausibility criteria are %s" % len(x_mins)) x_mins = np.append(x_mins, np.random.uniform(low=-search_window/2+x_center, high=search_window/2+x_center, size=num_random)) y_mins = np.append(y_mins, np.random.uniform(low=-search_window / 2 + y_center, high=search_window / 2 + y_center, size=num_random)) x_mins, y_mins, solver_precision = self._findIterative(x_mins, y_mins, sourcePos_x, sourcePos_y, kwargs_lens, precision_limit, num_iter_max, verbose=verbose, min_distance=min_distance) x_mins = x_mins[solver_precision <= precision_limit] y_mins = y_mins[solver_precision <= precision_limit] x_mins, y_mins = image_util.findOverlap(x_mins, y_mins, min_distance) if arrival_time_sort is True: x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) return x_mins, y_mins
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:count; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:event_collection; 5, default_parameter; 5, 6; 5, 7; 6, identifier:timeframe; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:timezone; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:interval; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:filters; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:group_by; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:order_by; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:max_age; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:limit; 28, None; 29, block; 29, 30; 29, 34; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:_initialize_client_from_environment; 33, argument_list; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:_client; 38, identifier:count; 39, argument_list; 39, 40; 39, 43; 39, 46; 39, 49; 39, 52; 39, 55; 39, 58; 39, 61; 39, 64; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:event_collection; 42, identifier:event_collection; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:timeframe; 45, identifier:timeframe; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:timezone; 48, identifier:timezone; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:interval; 51, identifier:interval; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:filters; 54, identifier:filters; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:group_by; 57, identifier:group_by; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:order_by; 60, identifier:order_by; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:max_age; 63, identifier:max_age; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:limit; 66, identifier:limit
def count(event_collection, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.count(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, max_age=max_age, limit=limit)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:sum; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:event_collection; 5, identifier:target_property; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timeframe; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:timezone; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:interval; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filters; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:group_by; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:order_by; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:max_age; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:limit; 29, None; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:_initialize_client_from_environment; 34, argument_list; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:_client; 39, identifier:sum; 40, argument_list; 40, 41; 40, 44; 40, 47; 40, 50; 40, 53; 40, 56; 40, 59; 40, 62; 40, 65; 40, 68; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:event_collection; 43, identifier:event_collection; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:timeframe; 46, identifier:timeframe; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:timezone; 49, identifier:timezone; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:interval; 52, identifier:interval; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:filters; 55, identifier:filters; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:group_by; 58, identifier:group_by; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:order_by; 61, identifier:order_by; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:target_property; 64, identifier:target_property; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:max_age; 67, identifier:max_age; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:limit; 70, identifier:limit
def sum(event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.sum(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, target_property=target_property, max_age=max_age, limit=limit)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:multi_analysis; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:event_collection; 5, identifier:analyses; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timeframe; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:interval; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:timezone; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filters; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:group_by; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:order_by; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:max_age; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:limit; 29, None; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:_initialize_client_from_environment; 34, argument_list; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:_client; 39, identifier:multi_analysis; 40, argument_list; 40, 41; 40, 44; 40, 47; 40, 50; 40, 53; 40, 56; 40, 59; 40, 62; 40, 65; 40, 68; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:event_collection; 43, identifier:event_collection; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:timeframe; 46, identifier:timeframe; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:interval; 49, identifier:interval; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:timezone; 52, identifier:timezone; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:filters; 55, identifier:filters; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:group_by; 58, identifier:group_by; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:order_by; 61, identifier:order_by; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:analyses; 64, identifier:analyses; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:max_age; 67, identifier:max_age; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:limit; 70, identifier:limit
def multi_analysis(event_collection, analyses, timeframe=None, interval=None, timezone=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.multi_analysis(event_collection=event_collection, timeframe=timeframe, interval=interval, timezone=timezone, filters=filters, group_by=group_by, order_by=order_by, analyses=analyses, max_age=max_age, limit=limit)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:select_unique; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 4, identifier:self; 5, identifier:event_collection; 6, identifier:target_property; 7, default_parameter; 7, 8; 7, 9; 8, identifier:timeframe; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:timezone; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:interval; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:filters; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:group_by; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:order_by; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:max_age; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:limit; 30, None; 31, block; 31, 32; 31, 70; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:params; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:get_params; 39, argument_list; 39, 40; 39, 43; 39, 46; 39, 49; 39, 52; 39, 55; 39, 58; 39, 61; 39, 64; 39, 67; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:event_collection; 42, identifier:event_collection; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:timeframe; 45, identifier:timeframe; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:timezone; 48, identifier:timezone; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:interval; 51, identifier:interval; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:filters; 54, identifier:filters; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:group_by; 57, identifier:group_by; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:order_by; 60, identifier:order_by; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:target_property; 63, identifier:target_property; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:max_age; 66, identifier:max_age; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:limit; 69, identifier:limit; 70, return_statement; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:api; 76, identifier:query; 77, argument_list; 77, 78; 77, 79; 78, string:"select_unique"; 79, identifier:params
def select_unique(self, event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): params = self.get_params(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, target_property=target_property, max_age=max_age, limit=limit) return self.api.query("select_unique", params)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:check_voltage; 3, parameters; 3, 4; 3, 5; 4, identifier:grid; 5, identifier:mode; 6, block; 6, 7; 6, 11; 6, 136; 6, 154; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:crit_nodes; 10, dictionary; 11, if_statement; 11, 12; 11, 15; 11, 129; 12, comparison_operator:==; 12, 13; 12, 14; 13, identifier:mode; 14, string:'MV'; 15, block; 15, 16; 15, 29; 15, 42; 15, 50; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:mv_max_v_level_lc_diff_normal; 19, call; 19, 20; 19, 21; 20, identifier:float; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:cfg_ding0; 25, identifier:get; 26, argument_list; 26, 27; 26, 28; 27, string:'mv_routing_tech_constraints'; 28, string:'mv_max_v_level_lc_diff_normal'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:mv_max_v_level_fc_diff_normal; 32, call; 32, 33; 32, 34; 33, identifier:float; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:cfg_ding0; 38, identifier:get; 39, argument_list; 39, 40; 39, 41; 40, string:'mv_routing_tech_constraints'; 41, string:'mv_max_v_level_fc_diff_normal'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:voltage_station; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:grid; 48, identifier:_station; 49, identifier:voltage_res; 50, for_statement; 50, 51; 50, 52; 50, 57; 51, identifier:node; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:grid; 55, identifier:graph_nodes_sorted; 56, argument_list; 57, block; 57, 58; 58, try_statement; 58, 59; 58, 126; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 93; 61, boolean_operator:or; 61, 62; 61, 77; 61, 78; 62, parenthesized_expression; 62, 63; 63, comparison_operator:>; 63, 64; 63, 76; 64, call; 64, 65; 64, 66; 65, identifier:abs; 66, argument_list; 66, 67; 67, binary_operator:-; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:voltage_station; 70, integer:0; 71, subscript; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:node; 74, identifier:voltage_res; 75, integer:0; 76, identifier:mv_max_v_level_lc_diff_normal; 77, line_continuation:\; 78, parenthesized_expression; 78, 79; 79, comparison_operator:>; 79, 80; 79, 92; 80, call; 80, 81; 80, 82; 81, identifier:abs; 82, argument_list; 82, 83; 83, binary_operator:-; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:voltage_station; 86, integer:1; 87, subscript; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:node; 90, identifier:voltage_res; 91, integer:1; 92, identifier:mv_max_v_level_fc_diff_normal; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:crit_nodes; 98, identifier:node; 99, dictionary; 99, 100; 99, 103; 100, pair; 100, 101; 100, 102; 101, string:'node'; 102, identifier:node; 103, pair; 103, 104; 103, 105; 104, string:'v_diff'; 105, call; 105, 106; 105, 107; 106, identifier:max; 107, argument_list; 107, 108; 108, list_comprehension; 108, 109; 108, 115; 109, call; 109, 110; 109, 111; 110, identifier:abs; 111, argument_list; 111, 112; 112, binary_operator:-; 112, 113; 112, 114; 113, identifier:v2; 114, identifier:v1; 115, for_in_clause; 115, 116; 115, 119; 116, pattern_list; 116, 117; 116, 118; 117, identifier:v1; 118, identifier:v2; 119, call; 119, 120; 119, 121; 120, identifier:zip; 121, argument_list; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:node; 124, identifier:voltage_res; 125, identifier:voltage_station; 126, except_clause; 126, 127; 127, block; 127, 128; 128, pass_statement; 129, elif_clause; 129, 130; 129, 133; 130, comparison_operator:==; 130, 131; 130, 132; 131, identifier:mode; 132, string:'LV'; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, identifier:NotImplementedError; 136, if_statement; 136, 137; 136, 138; 137, identifier:crit_nodes; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:logger; 143, identifier:info; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, string:'==> {} nodes have voltage issues.'; 148, identifier:format; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:crit_nodes; 154, return_statement; 154, 155; 155, list_comprehension; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:_; 158, string:'node'; 159, for_in_clause; 159, 160; 159, 161; 160, identifier:_; 161, call; 161, 162; 161, 163; 162, identifier:sorted; 163, argument_list; 163, 164; 163, 169; 163, 177; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:crit_nodes; 167, identifier:values; 168, argument_list; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:key; 171, lambda; 171, 172; 171, 174; 172, lambda_parameters; 172, 173; 173, identifier:_; 174, subscript; 174, 175; 174, 176; 175, identifier:_; 176, string:'v_diff'; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:reverse; 179, True
def check_voltage(grid, mode): crit_nodes = {} if mode == 'MV': mv_max_v_level_lc_diff_normal = float(cfg_ding0.get('mv_routing_tech_constraints', 'mv_max_v_level_lc_diff_normal')) mv_max_v_level_fc_diff_normal = float(cfg_ding0.get('mv_routing_tech_constraints', 'mv_max_v_level_fc_diff_normal')) voltage_station = grid._station.voltage_res for node in grid.graph_nodes_sorted(): try: if (abs(voltage_station[0] - node.voltage_res[0]) > mv_max_v_level_lc_diff_normal) or\ (abs(voltage_station[1] - node.voltage_res[1]) > mv_max_v_level_fc_diff_normal): crit_nodes[node] = {'node': node, 'v_diff': max([abs(v2-v1) for v1, v2 in zip(node.voltage_res, voltage_station)])} except: pass elif mode == 'LV': raise NotImplementedError if crit_nodes: logger.info('==> {} nodes have voltage issues.'.format(len(crit_nodes))) return [_['node'] for _ in sorted(crit_nodes.values(), key=lambda _: _['v_diff'], reverse=True)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compute_savings_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:graph; 6, block; 6, 7; 6, 11; 6, 100; 6, 125; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:savings_list; 10, dictionary; 11, for_statement; 11, 12; 11, 15; 11, 20; 12, pattern_list; 12, 13; 12, 14; 13, identifier:i; 14, identifier:j; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:graph; 18, identifier:edges; 19, argument_list; 20, block; 20, 21; 20, 46; 20, 64; 21, if_statement; 21, 22; 21, 31; 21, 38; 22, comparison_operator:<; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:repr; 25, argument_list; 25, 26; 26, identifier:i; 27, call; 27, 28; 27, 29; 28, identifier:repr; 29, argument_list; 29, 30; 30, identifier:j; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:t; 35, tuple; 35, 36; 35, 37; 36, identifier:i; 37, identifier:j; 38, else_clause; 38, 39; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:t; 43, tuple; 43, 44; 43, 45; 44, identifier:j; 45, identifier:i; 46, if_statement; 46, 47; 46, 62; 47, boolean_operator:or; 47, 48; 47, 55; 48, comparison_operator:==; 48, 49; 48, 50; 49, identifier:i; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:graph; 53, identifier:depot; 54, argument_list; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:j; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:graph; 60, identifier:depot; 61, argument_list; 62, block; 62, 63; 63, continue_statement; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:savings_list; 68, identifier:t; 69, binary_operator:-; 69, 70; 69, 93; 70, binary_operator:+; 70, 71; 70, 82; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:graph; 74, identifier:distance; 75, argument_list; 75, 76; 75, 81; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:graph; 79, identifier:depot; 80, argument_list; 81, identifier:i; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:graph; 85, identifier:distance; 86, argument_list; 86, 87; 86, 92; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:graph; 90, identifier:depot; 91, argument_list; 92, identifier:j; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:graph; 96, identifier:distance; 97, argument_list; 97, 98; 97, 99; 98, identifier:i; 99, identifier:j; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:sorted_savings_list; 103, call; 103, 104; 103, 105; 104, identifier:sorted; 105, argument_list; 105, 106; 105, 114; 105, 122; 106, call; 106, 107; 106, 108; 107, identifier:list; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:savings_list; 112, identifier:items; 113, argument_list; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:key; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:operator; 119, identifier:itemgetter; 120, argument_list; 120, 121; 121, integer:1; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:reverse; 124, True; 125, return_statement; 125, 126; 126, list_comprehension; 126, 127; 126, 128; 127, identifier:nodes; 128, for_in_clause; 128, 129; 128, 132; 129, pattern_list; 129, 130; 129, 131; 130, identifier:nodes; 131, identifier:saving; 132, identifier:sorted_savings_list
def compute_savings_list(self, graph): savings_list = {} for i, j in graph.edges(): if repr(i) < repr(j): t = (i, j) else: t = (j, i) if i == graph.depot() or j == graph.depot(): continue savings_list[t] = graph.distance(graph.depot(), i) + graph.distance(graph.depot(), j) - graph.distance(i, j) sorted_savings_list = sorted(list(savings_list.items()), key=operator.itemgetter(1), reverse=True) return [nodes for nodes, saving in sorted_savings_list]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 1, 28; 2, function_name:ask_choice; 3, parameters; 3, 4; 3, 9; 3, 17; 4, typed_parameter; 4, 5; 4, 7; 5, list_splat_pattern; 5, 6; 6, identifier:prompt; 7, type; 7, 8; 8, identifier:Token; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:choices; 11, type; 11, 12; 12, generic_type; 12, 13; 12, 14; 13, identifier:List; 14, type_parameter; 14, 15; 15, type; 15, 16; 16, identifier:Any; 17, typed_default_parameter; 17, 18; 17, 19; 17, 25; 18, identifier:func_desc; 19, type; 19, 20; 20, generic_type; 20, 21; 20, 22; 21, identifier:Optional; 22, type_parameter; 22, 23; 23, type; 23, 24; 24, identifier:FuncDesc; 25, None; 26, type; 26, 27; 27, identifier:Any; 28, block; 28, 29; 28, 44; 28, 51; 28, 57; 28, 66; 28, 96; 28, 100; 28, 104; 28, 173; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:func_desc; 32, None; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:func_desc; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:x; 40, call; 40, 41; 40, 42; 41, identifier:str; 42, argument_list; 42, 43; 43, identifier:x; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:tokens; 47, call; 47, 48; 47, 49; 48, identifier:get_ask_tokens; 49, argument_list; 49, 50; 50, identifier:prompt; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:info; 54, argument_list; 54, 55; 55, list_splat; 55, 56; 56, identifier:tokens; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:choices; 61, identifier:sort; 62, argument_list; 62, 63; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:key; 65, identifier:func_desc; 66, for_statement; 66, 67; 66, 70; 66, 77; 67, pattern_list; 67, 68; 67, 69; 68, identifier:i; 69, identifier:choice; 70, call; 70, 71; 70, 72; 71, identifier:enumerate; 72, argument_list; 72, 73; 72, 74; 73, identifier:choices; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:start; 76, integer:1; 77, block; 77, 78; 77, 85; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:choice_desc; 81, call; 81, 82; 81, 83; 82, identifier:func_desc; 83, argument_list; 83, 84; 84, identifier:choice; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:info; 88, argument_list; 88, 89; 88, 90; 88, 91; 88, 94; 88, 95; 89, string:" "; 90, identifier:blue; 91, binary_operator:%; 91, 92; 91, 93; 92, string:"%i"; 93, identifier:i; 94, identifier:reset; 95, identifier:choice_desc; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:keep_asking; 99, True; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:res; 103, None; 104, while_statement; 104, 105; 104, 106; 105, identifier:keep_asking; 106, block; 106, 107; 106, 113; 106, 119; 106, 137; 106, 161; 106, 169; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:answer; 110, call; 110, 111; 110, 112; 111, identifier:read_input; 112, argument_list; 113, if_statement; 113, 114; 113, 116; 114, not_operator; 114, 115; 115, identifier:answer; 116, block; 116, 117; 117, return_statement; 117, 118; 118, None; 119, try_statement; 119, 120; 119, 128; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:index; 124, call; 124, 125; 124, 126; 125, identifier:int; 126, argument_list; 126, 127; 127, identifier:answer; 128, except_clause; 128, 129; 128, 130; 129, identifier:ValueError; 130, block; 130, 131; 130, 136; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:info; 134, argument_list; 134, 135; 135, string:"Please enter a valid number"; 136, continue_statement; 137, if_statement; 137, 138; 137, 150; 138, comparison_operator:not; 138, 139; 138, 140; 139, identifier:index; 140, call; 140, 141; 140, 142; 141, identifier:range; 142, argument_list; 142, 143; 142, 144; 143, integer:1; 144, binary_operator:+; 144, 145; 144, 149; 145, call; 145, 146; 145, 147; 146, identifier:len; 147, argument_list; 147, 148; 148, identifier:choices; 149, integer:1; 150, block; 150, 151; 150, 160; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:info; 154, argument_list; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:str; 157, argument_list; 157, 158; 158, identifier:index; 159, string:"is out of range"; 160, continue_statement; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:res; 164, subscript; 164, 165; 164, 166; 165, identifier:choices; 166, binary_operator:-; 166, 167; 166, 168; 167, identifier:index; 168, integer:1; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:keep_asking; 172, False; 173, return_statement; 173, 174; 174, identifier:res
def ask_choice( *prompt: Token, choices: List[Any], func_desc: Optional[FuncDesc] = None ) -> Any: if func_desc is None: func_desc = lambda x: str(x) tokens = get_ask_tokens(prompt) info(*tokens) choices.sort(key=func_desc) for i, choice in enumerate(choices, start=1): choice_desc = func_desc(choice) info(" ", blue, "%i" % i, reset, choice_desc) keep_asking = True res = None while keep_asking: answer = read_input() if not answer: return None try: index = int(answer) except ValueError: info("Please enter a valid number") continue if index not in range(1, len(choices) + 1): info(str(index), "is out of range") continue res = choices[index - 1] keep_asking = False return res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:list; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 35; 5, 52; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:backups; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 22; 11, identifier:d; 12, call; 12, 13; 12, 14; 13, identifier:glob; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:join; 17, argument_list; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:backup_directory; 21, string:'*'; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:backups; 27, identifier:append; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:WorkspaceBackup; 32, identifier:from_path; 33, argument_list; 33, 34; 34, identifier:d; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:backups; 39, identifier:sort; 40, argument_list; 40, 41; 40, 49; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:key; 43, lambda; 43, 44; 43, 46; 44, lambda_parameters; 44, 45; 45, identifier:b; 46, attribute; 46, 47; 46, 48; 47, identifier:b; 48, identifier:lastmod; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:reverse; 51, True; 52, return_statement; 52, 53; 53, identifier:backups
def list(self): backups = [] for d in glob(join(self.backup_directory, '*')): backups.append(WorkspaceBackup.from_path(d)) backups.sort(key=lambda b: b.lastmod, reverse=True) return backups
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:retrieve; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:operation; 6, default_parameter; 6, 7; 6, 8; 7, identifier:field; 8, None; 9, block; 9, 10; 9, 20; 9, 40; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:obj; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_get; 17, argument_list; 17, 18; 17, 19; 18, identifier:operation; 19, identifier:field; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:obj; 23, None; 24, block; 24, 25; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:Mark; 28, argument_list; 28, 29; 28, 34; 28, 37; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:collection; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:collection; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:operation; 36, identifier:operation; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:field; 39, identifier:field; 40, return_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:Mark; 44, identifier:from_dict; 45, argument_list; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:collection; 49, identifier:obj
def retrieve(self, operation, field=None): obj = self._get(operation, field) if obj is None: return Mark(collection=self.collection, operation=operation, field=field) return Mark.from_dict(self.collection, obj)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:properties; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:criteria; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:distinct_key; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, block; 16, 17; 16, 43; 16, 52; 16, 69; 16, 87; 17, if_statement; 17, 18; 17, 21; 17, 33; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:properties; 20, None; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, pattern_list; 24, 25; 24, 26; 25, identifier:props; 26, identifier:prop_dict; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_parse_properties; 31, argument_list; 31, 32; 32, identifier:properties; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, pattern_list; 37, 38; 37, 39; 38, identifier:props; 39, identifier:prop_dict; 40, expression_list; 40, 41; 40, 42; 41, None; 42, None; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:crit; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_parse_criteria; 50, argument_list; 50, 51; 51, identifier:criteria; 52, if_statement; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:query_post; 56, block; 56, 57; 57, for_statement; 57, 58; 57, 59; 57, 62; 58, identifier:func; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:query_post; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:func; 66, argument_list; 66, 67; 66, 68; 67, identifier:crit; 68, identifier:props; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:cur; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:collection; 77, identifier:find; 78, argument_list; 78, 79; 78, 82; 78, 85; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:filter; 81, identifier:crit; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:projection; 84, identifier:props; 85, dictionary_splat; 85, 86; 86, identifier:kwargs; 87, if_statement; 87, 88; 87, 91; 87, 112; 88, comparison_operator:is; 88, 89; 88, 90; 89, identifier:distinct_key; 90, None; 91, block; 91, 92; 91, 101; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:cur; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:cur; 98, identifier:distinct; 99, argument_list; 99, 100; 100, identifier:distinct_key; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:QueryListResults; 104, argument_list; 104, 105; 104, 106; 104, 107; 105, identifier:prop_dict; 106, identifier:cur; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:postprocess; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:result_post; 112, else_clause; 112, 113; 113, block; 113, 114; 114, return_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:QueryResults; 117, argument_list; 117, 118; 117, 119; 117, 120; 118, identifier:prop_dict; 119, identifier:cur; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:postprocess; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:result_post
def query(self, properties=None, criteria=None, distinct_key=None, **kwargs): if properties is not None: props, prop_dict = self._parse_properties(properties) else: props, prop_dict = None, None crit = self._parse_criteria(criteria) if self.query_post: for func in self.query_post: func(crit, props) cur = self.collection.find(filter=crit, projection=props, **kwargs) if distinct_key is not None: cur = cur.distinct(distinct_key) return QueryListResults(prop_dict, cur, postprocess=self.result_post) else: return QueryResults(prop_dict, cur, postprocess=self.result_post)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_rows; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:rows; 6, identifier:section; 7, block; 7, 8; 7, 35; 8, if_statement; 8, 9; 8, 22; 8, 29; 9, comparison_operator:==; 9, 10; 9, 15; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:section; 13, identifier:lower; 14, argument_list; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:Differ; 19, identifier:CHANGED; 20, identifier:lower; 21, argument_list; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:sort_key; 26, attribute; 26, 27; 26, 28; 27, identifier:Differ; 28, identifier:CHANGED_DELTA; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:sort_key; 34, None; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:sort_key; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:rows; 44, identifier:sort; 45, argument_list; 45, 46; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, call; 48, 49; 48, 50; 49, identifier:itemgetter; 50, argument_list; 50, 51; 51, identifier:sort_key
def sort_rows(self, rows, section): if section.lower() == Differ.CHANGED.lower(): sort_key = Differ.CHANGED_DELTA else: sort_key = None if sort_key is not None: rows.sort(key=itemgetter(sort_key))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_free_crypto_domains; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:crypto_adapters; 7, None; 8, block; 8, 9; 8, 27; 8, 33; 8, 37; 8, 64; 8, 70; 8, 83; 8, 155; 8, 166; 8, 172; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:crypto_adapters; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:crypto_adapters; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:adapters; 22, identifier:findall; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:type; 26, string:'crypto'; 27, if_statement; 27, 28; 27, 30; 28, not_operator; 28, 29; 29, identifier:crypto_adapters; 30, block; 30, 31; 31, return_statement; 31, 32; 32, None; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:max_domains; 36, None; 37, for_statement; 37, 38; 37, 39; 37, 40; 38, identifier:ca; 39, identifier:crypto_adapters; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 45; 41, 52; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:max_domains; 44, None; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:max_domains; 49, attribute; 49, 50; 49, 51; 50, identifier:ca; 51, identifier:maximum_crypto_domains; 52, else_clause; 52, 53; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:max_domains; 57, call; 57, 58; 57, 59; 58, identifier:min; 59, argument_list; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ca; 62, identifier:maximum_crypto_domains; 63, identifier:max_domains; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:used_domains; 67, call; 67, 68; 67, 69; 68, identifier:set; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:partitions; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:partitions; 78, identifier:list; 79, argument_list; 79, 80; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:full_properties; 82, True; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:partition; 85, identifier:partitions; 86, block; 86, 87; 86, 96; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:crypto_config; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:partition; 93, identifier:get_property; 94, argument_list; 94, 95; 95, string:'crypto-configuration'; 96, if_statement; 96, 97; 96, 98; 97, identifier:crypto_config; 98, block; 98, 99; 98, 105; 98, 111; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:adapter_uris; 102, subscript; 102, 103; 102, 104; 103, identifier:crypto_config; 104, string:'crypto-adapter-uris'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:domain_configs; 108, subscript; 108, 109; 108, 110; 109, identifier:crypto_config; 110, string:'crypto-domain-configurations'; 111, for_statement; 111, 112; 111, 113; 111, 114; 112, identifier:ca; 113, identifier:crypto_adapters; 114, block; 114, 115; 115, if_statement; 115, 116; 115, 121; 116, comparison_operator:in; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:ca; 119, identifier:uri; 120, identifier:adapter_uris; 121, block; 121, 122; 121, 128; 121, 148; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:used_adapter_domains; 125, call; 125, 126; 125, 127; 126, identifier:list; 127, argument_list; 128, for_statement; 128, 129; 128, 130; 128, 131; 129, identifier:dc; 130, identifier:domain_configs; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 138; 133, comparison_operator:==; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:dc; 136, string:'access-mode'; 137, string:'control-usage'; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:used_adapter_domains; 143, identifier:append; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:dc; 147, string:'domain-index'; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:used_domains; 152, identifier:update; 153, argument_list; 153, 154; 154, identifier:used_adapter_domains; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:all_domains; 158, call; 158, 159; 158, 160; 159, identifier:set; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:range; 163, argument_list; 163, 164; 163, 165; 164, integer:0; 165, identifier:max_domains; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:free_domains; 169, binary_operator:-; 169, 170; 169, 171; 170, identifier:all_domains; 171, identifier:used_domains; 172, return_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:sorted; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:list; 178, argument_list; 178, 179; 179, identifier:free_domains
def get_free_crypto_domains(self, crypto_adapters=None): if crypto_adapters is None: crypto_adapters = self.adapters.findall(type='crypto') if not crypto_adapters: return None max_domains = None for ca in crypto_adapters: if max_domains is None: max_domains = ca.maximum_crypto_domains else: max_domains = min(ca.maximum_crypto_domains, max_domains) used_domains = set() partitions = self.partitions.list(full_properties=True) for partition in partitions: crypto_config = partition.get_property('crypto-configuration') if crypto_config: adapter_uris = crypto_config['crypto-adapter-uris'] domain_configs = crypto_config['crypto-domain-configurations'] for ca in crypto_adapters: if ca.uri in adapter_uris: used_adapter_domains = list() for dc in domain_configs: if dc['access-mode'] == 'control-usage': used_adapter_domains.append(dc['domain-index']) used_domains.update(used_adapter_domains) all_domains = set(range(0, max_domains)) free_domains = all_domains - used_domains return sorted(list(free_domains))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological; 3, parameters; 3, 4; 4, identifier:nodes; 5, block; 5, 6; 5, 21; 5, 93; 5, 105; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 12; 8, pattern_list; 8, 9; 8, 10; 8, 11; 9, identifier:order; 10, identifier:enter; 11, identifier:state; 12, expression_list; 12, 13; 12, 16; 12, 20; 13, call; 13, 14; 13, 15; 14, identifier:deque; 15, argument_list; 16, call; 16, 17; 16, 18; 17, identifier:set; 18, argument_list; 18, 19; 19, identifier:nodes; 20, dictionary; 21, function_definition; 21, 22; 21, 23; 21, 25; 22, function_name:dfs; 23, parameters; 23, 24; 24, identifier:node; 25, block; 25, 26; 25, 32; 25, 80; 25, 87; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:state; 30, identifier:node; 31, identifier:GRAY; 32, for_statement; 32, 33; 32, 34; 32, 41; 33, identifier:parent; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:nodes; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, identifier:node; 40, tuple; 41, block; 41, 42; 41, 52; 41, 62; 41, 68; 41, 75; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:color; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:state; 48, identifier:get; 49, argument_list; 49, 50; 49, 51; 50, identifier:parent; 51, None; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:==; 53, 54; 53, 55; 54, identifier:color; 55, identifier:GRAY; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:ValueError; 60, argument_list; 60, 61; 61, string:'cycle'; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:color; 65, identifier:BLACK; 66, block; 66, 67; 67, continue_statement; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:enter; 72, identifier:discard; 73, argument_list; 73, 74; 74, identifier:parent; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:dfs; 78, argument_list; 78, 79; 79, identifier:parent; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:order; 84, identifier:appendleft; 85, argument_list; 85, 86; 86, identifier:node; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:state; 91, identifier:node; 92, identifier:BLACK; 93, while_statement; 93, 94; 93, 95; 94, identifier:enter; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:dfs; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:enter; 103, identifier:pop; 104, argument_list; 105, return_statement; 105, 106; 106, identifier:order
def topological(nodes): order, enter, state = deque(), set(nodes), {} def dfs(node): state[node] = GRAY for parent in nodes.get(node, ()): color = state.get(parent, None) if color == GRAY: raise ValueError('cycle') if color == BLACK: continue enter.discard(parent) dfs(parent) order.appendleft(node) state[node] = BLACK while enter: dfs(enter.pop()) return order
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_teachers_sorted; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 31; 5, 65; 5, 92; 5, 110; 5, 120; 5, 142; 5, 148; 5, 175; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:teachers; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:get_teachers; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:teachers; 17, list_comprehension; 17, 18; 17, 28; 18, tuple; 18, 19; 18, 22; 18, 25; 19, attribute; 19, 20; 19, 21; 20, identifier:u; 21, identifier:last_name; 22, attribute; 22, 23; 22, 24; 23, identifier:u; 24, identifier:first_name; 25, attribute; 25, 26; 25, 27; 26, identifier:u; 27, identifier:id; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:u; 30, identifier:teachers; 31, for_statement; 31, 32; 31, 33; 31, 34; 32, identifier:t; 33, identifier:teachers; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 57; 36, boolean_operator:or; 36, 37; 36, 52; 37, boolean_operator:or; 37, 38; 37, 47; 38, boolean_operator:or; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:t; 41, None; 42, comparison_operator:is; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:t; 45, integer:0; 46, None; 47, comparison_operator:is; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:t; 50, integer:1; 51, None; 52, comparison_operator:is; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:t; 55, integer:2; 56, None; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:teachers; 62, identifier:remove; 63, argument_list; 63, 64; 64, identifier:t; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:t; 67, identifier:teachers; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 84; 70, boolean_operator:or; 70, 71; 70, 76; 71, comparison_operator:is; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:t; 74, integer:0; 75, None; 76, comparison_operator:<=; 76, 77; 76, 83; 77, call; 77, 78; 77, 79; 78, identifier:len; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:t; 82, integer:0; 83, integer:1; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:teachers; 89, identifier:remove; 90, argument_list; 90, 91; 91, identifier:t; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:teachers; 96, identifier:sort; 97, argument_list; 97, 98; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:key; 100, lambda; 100, 101; 100, 103; 101, lambda_parameters; 101, 102; 102, identifier:u; 103, tuple; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:u; 106, integer:0; 107, subscript; 107, 108; 107, 109; 108, identifier:u; 109, integer:1; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:id_list; 113, list_comprehension; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:t; 116, integer:2; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:t; 119, identifier:teachers; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:clauses; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, string:' '; 126, identifier:join; 127, argument_list; 127, 128; 128, list_comprehension; 128, 129; 128, 134; 129, binary_operator:%; 129, 130; 129, 131; 130, string:'WHEN id=%s THEN %s'; 131, tuple; 131, 132; 131, 133; 132, identifier:pk; 133, identifier:i; 134, for_in_clause; 134, 135; 134, 138; 135, pattern_list; 135, 136; 135, 137; 136, identifier:i; 137, identifier:pk; 138, call; 138, 139; 138, 140; 139, identifier:enumerate; 140, argument_list; 140, 141; 141, identifier:id_list; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:ordering; 145, binary_operator:%; 145, 146; 145, 147; 146, string:'CASE %s END'; 147, identifier:clauses; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:queryset; 151, call; 151, 152; 151, 164; 152, attribute; 152, 153; 152, 163; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:User; 157, identifier:objects; 158, identifier:filter; 159, argument_list; 159, 160; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:id__in; 162, identifier:id_list; 163, identifier:extra; 164, argument_list; 164, 165; 164, 171; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:select; 167, dictionary; 167, 168; 168, pair; 168, 169; 168, 170; 169, string:'ordering'; 170, identifier:ordering; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:order_by; 173, tuple; 173, 174; 174, string:'ordering'; 175, return_statement; 175, 176; 176, identifier:queryset
def get_teachers_sorted(self): teachers = self.get_teachers() teachers = [(u.last_name, u.first_name, u.id) for u in teachers] for t in teachers: if t is None or t[0] is None or t[1] is None or t[2] is None: teachers.remove(t) for t in teachers: if t[0] is None or len(t[0]) <= 1: teachers.remove(t) teachers.sort(key=lambda u: (u[0], u[1])) id_list = [t[2] for t in teachers] clauses = ' '.join(['WHEN id=%s THEN %s' % (pk, i) for i, pk in enumerate(id_list)]) ordering = 'CASE %s END' % clauses queryset = User.objects.filter(id__in=id_list).extra(select={'ordering': ordering}, order_by=('ordering',)) return queryset
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 17; 2, function_name:sorted_bits; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:List; 8, type_parameter; 8, 9; 9, type; 9, 10; 10, generic_type; 10, 11; 10, 12; 11, identifier:Tuple; 12, type_parameter; 12, 13; 12, 15; 13, type; 13, 14; 14, identifier:str; 15, type; 15, 16; 16, identifier:int; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:sorted; 21, argument_list; 21, 22; 21, 29; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:bit; 27, identifier:items; 28, argument_list; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:key; 31, lambda; 31, 32; 31, 34; 32, lambda_parameters; 32, 33; 33, identifier:x; 34, subscript; 34, 35; 34, 36; 35, identifier:x; 36, integer:1
def sorted_bits(self) -> List[Tuple[str, int]]: return sorted(self.bit.items(), key=lambda x: x[1])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 17; 2, function_name:sorted_enums; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:List; 8, type_parameter; 8, 9; 9, type; 9, 10; 10, generic_type; 10, 11; 10, 12; 11, identifier:Tuple; 12, type_parameter; 12, 13; 12, 15; 13, type; 13, 14; 14, identifier:str; 15, type; 15, 16; 16, identifier:int; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:sorted; 21, argument_list; 21, 22; 21, 29; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:enum; 27, identifier:items; 28, argument_list; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:key; 31, lambda; 31, 32; 31, 34; 32, lambda_parameters; 32, 33; 33, identifier:x; 34, subscript; 34, 35; 34, 36; 35, identifier:x; 36, integer:1
def sorted_enums(self) -> List[Tuple[str, int]]: return sorted(self.enum.items(), key=lambda x: x[1])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:collate; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:iterables; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 22; 8, 32; 8, 39; 8, 52; 8, 56; 8, 60; 8, 99; 8, 114; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:key; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:kwargs; 15, identifier:pop; 16, argument_list; 16, 17; 16, 18; 17, string:'key'; 18, lambda; 18, 19; 18, 21; 19, lambda_parameters; 19, 20; 20, identifier:a; 21, identifier:a; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:reverse; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:kwargs; 28, identifier:pop; 29, argument_list; 29, 30; 29, 31; 30, string:'reverse'; 31, False; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:min_or_max; 35, conditional_expression:if; 35, 36; 35, 37; 35, 38; 36, identifier:max; 37, identifier:reverse; 38, identifier:min; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:rows; 42, list_comprehension; 42, 43; 42, 47; 42, 50; 43, call; 43, 44; 43, 45; 44, identifier:iter; 45, argument_list; 45, 46; 46, identifier:iterable; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:iterable; 49, identifier:iterables; 50, if_clause; 50, 51; 51, identifier:iterable; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:next_values; 55, dictionary; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:by_key; 59, list:[]; 60, function_definition; 60, 61; 60, 62; 60, 65; 61, function_name:gather_next_value; 62, parameters; 62, 63; 62, 64; 63, identifier:row; 64, identifier:index; 65, block; 65, 66; 66, try_statement; 66, 67; 66, 75; 66, 79; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:next_value; 71, call; 71, 72; 71, 73; 72, identifier:next; 73, argument_list; 73, 74; 74, identifier:row; 75, except_clause; 75, 76; 75, 77; 76, identifier:StopIteration; 77, block; 77, 78; 78, pass_statement; 79, else_clause; 79, 80; 80, block; 80, 81; 80, 87; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:next_values; 85, identifier:index; 86, identifier:next_value; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:by_key; 91, identifier:append; 92, argument_list; 92, 93; 93, tuple; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:key; 96, argument_list; 96, 97; 97, identifier:next_value; 98, identifier:index; 99, for_statement; 99, 100; 99, 103; 99, 107; 100, pattern_list; 100, 101; 100, 102; 101, identifier:index; 102, identifier:row; 103, call; 103, 104; 103, 105; 104, identifier:enumerate; 105, argument_list; 105, 106; 106, identifier:rows; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:gather_next_value; 111, argument_list; 111, 112; 111, 113; 112, identifier:row; 113, identifier:index; 114, while_statement; 114, 115; 114, 116; 115, identifier:by_key; 116, block; 116, 117; 116, 126; 116, 135; 116, 144; 116, 147; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, pattern_list; 119, 120; 119, 121; 120, identifier:key_value; 121, identifier:index; 122, call; 122, 123; 122, 124; 123, identifier:min_or_max; 124, argument_list; 124, 125; 125, identifier:by_key; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:by_key; 130, identifier:remove; 131, argument_list; 131, 132; 132, tuple; 132, 133; 132, 134; 133, identifier:key_value; 134, identifier:index; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:next_value; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:next_values; 141, identifier:pop; 142, argument_list; 142, 143; 143, identifier:index; 144, expression_statement; 144, 145; 145, yield; 145, 146; 146, identifier:next_value; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:gather_next_value; 150, argument_list; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:rows; 153, identifier:index; 154, identifier:index
def collate(*iterables, **kwargs): key = kwargs.pop('key', lambda a: a) reverse = kwargs.pop('reverse', False) min_or_max = max if reverse else min rows = [iter(iterable) for iterable in iterables if iterable] next_values = {} by_key = [] def gather_next_value(row, index): try: next_value = next(row) except StopIteration: pass else: next_values[index] = next_value by_key.append((key(next_value), index)) for index, row in enumerate(rows): gather_next_value(row, index) while by_key: key_value, index = min_or_max(by_key) by_key.remove((key_value, index)) next_value = next_values.pop(index) yield next_value gather_next_value(rows[index], index)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:order_key_defs; 3, parameters; 3, 4; 4, identifier:key_def; 5, block; 5, 6; 5, 10; 5, 60; 5, 72; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:_int; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:kd; 12, identifier:key_def; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 23; 14, 51; 15, comparison_operator:>; 15, 16; 15, 22; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, subscript; 19, 20; 19, 21; 20, identifier:kd; 21, string:'use'; 22, integer:1; 23, block; 23, 24; 24, for_statement; 24, 25; 24, 26; 24, 29; 25, identifier:_use; 26, subscript; 26, 27; 26, 28; 27, identifier:kd; 28, string:'use'; 29, block; 29, 30; 29, 38; 29, 44; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:_kd; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:kd; 36, identifier:copy; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:_kd; 42, string:'use'; 43, identifier:_use; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:_int; 48, identifier:append; 49, argument_list; 49, 50; 50, identifier:_kd; 51, else_clause; 51, 52; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:_int; 57, identifier:append; 58, argument_list; 58, 59; 59, identifier:kd; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:_int; 64, identifier:sort; 65, argument_list; 65, 66; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:key; 68, call; 68, 69; 68, 70; 69, identifier:cmp_to_key; 70, argument_list; 70, 71; 71, identifier:sort_func; 72, return_statement; 72, 73; 73, identifier:_int
def order_key_defs(key_def): _int = [] for kd in key_def: if len(kd['use']) > 1: for _use in kd['use']: _kd = kd.copy() _kd['use'] = _use _int.append(_kd) else: _int.append(kd) _int.sort(key=cmp_to_key(sort_func)) return _int
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:wait; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:condition_or_value; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timeout; 8, None; 9, block; 9, 10; 9, 32; 9, 50; 9, 62; 9, 68; 9, 81; 9, 145; 9, 155; 9, 166; 10, if_statement; 10, 11; 10, 26; 11, parenthesized_expression; 11, 12; 12, boolean_operator:and; 12, 13; 12, 20; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:condition_or_value; 17, attribute; 17, 18; 17, 19; 18, identifier:collections; 19, identifier:Sequence; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:condition_or_value; 25, identifier:basestring; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:NotImplementedError; 30, argument_list; 30, 31; 31, string:'Currently only single conditions are supported'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:condition_test; 35, parenthesized_expression; 35, 36; 36, conditional_expression:if; 36, 37; 36, 38; 36, 42; 37, identifier:condition_or_value; 38, call; 38, 39; 38, 40; 39, identifier:callable; 40, argument_list; 40, 41; 41, identifier:condition_or_value; 42, lambda; 42, 43; 42, 45; 43, lambda_parameters; 43, 44; 44, identifier:s; 45, comparison_operator:==; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:s; 48, identifier:value; 49, identifier:condition_or_value; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:ioloop; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:tornado; 58, identifier:ioloop; 59, identifier:IOLoop; 60, identifier:current; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:f; 65, call; 65, 66; 65, 67; 66, identifier:Future; 67, argument_list; 68, if_statement; 68, 69; 68, 75; 69, comparison_operator:==; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:sampling_strategy; 73, tuple; 73, 74; 74, string:'none'; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:KATCPSensorError; 79, argument_list; 79, 80; 80, string:'Cannot wait on a sensor that does not have a strategy set'; 81, function_definition; 81, 82; 81, 83; 81, 86; 82, function_name:handle_update; 83, parameters; 83, 84; 83, 85; 84, identifier:sensor; 85, identifier:reading; 86, block; 86, 87; 87, try_statement; 87, 88; 87, 124; 88, block; 88, 89; 88, 93; 89, assert_statement; 89, 90; 90, comparison_operator:is; 90, 91; 90, 92; 91, identifier:sensor; 92, identifier:self; 93, if_statement; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:condition_test; 96, argument_list; 96, 97; 97, identifier:reading; 98, block; 98, 99; 98, 106; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:unregister_listener; 104, argument_list; 104, 105; 105, identifier:handle_update; 106, if_statement; 106, 107; 106, 113; 107, not_operator; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:f; 111, identifier:done; 112, argument_list; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:ioloop; 118, identifier:add_callback; 119, argument_list; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:f; 122, identifier:set_result; 123, True; 124, except_clause; 124, 125; 124, 126; 125, identifier:Exception; 126, block; 126, 127; 126, 138; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:f; 131, identifier:set_exc_info; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:sys; 136, identifier:exc_info; 137, argument_list; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:unregister_listener; 143, argument_list; 143, 144; 144, identifier:handle_update; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:register_listener; 150, argument_list; 150, 151; 150, 152; 151, identifier:handle_update; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:reading; 154, True; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:ioloop; 159, identifier:add_callback; 160, argument_list; 160, 161; 160, 162; 160, 163; 161, identifier:handle_update; 162, identifier:self; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:_reading; 166, if_statement; 166, 167; 166, 168; 166, 204; 167, identifier:timeout; 168, block; 168, 169; 168, 179; 168, 187; 168, 202; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:to; 172, binary_operator:+; 172, 173; 172, 178; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:ioloop; 176, identifier:time; 177, argument_list; 178, identifier:timeout; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:timeout_f; 182, call; 182, 183; 182, 184; 183, identifier:with_timeout; 184, argument_list; 184, 185; 184, 186; 185, identifier:to; 186, identifier:f; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:timeout_f; 191, identifier:add_done_callback; 192, argument_list; 192, 193; 193, lambda; 193, 194; 193, 196; 194, lambda_parameters; 194, 195; 195, identifier:f; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:unregister_listener; 200, argument_list; 200, 201; 201, identifier:handle_update; 202, return_statement; 202, 203; 203, identifier:timeout_f; 204, else_clause; 204, 205; 205, block; 205, 206; 206, return_statement; 206, 207; 207, identifier:f
def wait(self, condition_or_value, timeout=None): if (isinstance(condition_or_value, collections.Sequence) and not isinstance(condition_or_value, basestring)): raise NotImplementedError( 'Currently only single conditions are supported') condition_test = (condition_or_value if callable(condition_or_value) else lambda s: s.value == condition_or_value) ioloop = tornado.ioloop.IOLoop.current() f = Future() if self.sampling_strategy == ('none', ): raise KATCPSensorError( 'Cannot wait on a sensor that does not have a strategy set') def handle_update(sensor, reading): try: assert sensor is self if condition_test(reading): self.unregister_listener(handle_update) if not f.done(): ioloop.add_callback(f.set_result, True) except Exception: f.set_exc_info(sys.exc_info()) self.unregister_listener(handle_update) self.register_listener(handle_update, reading=True) ioloop.add_callback(handle_update, self, self._reading) if timeout: to = ioloop.time() + timeout timeout_f = with_timeout(to, f) timeout_f.add_done_callback( lambda f: self.unregister_listener(handle_update)) return timeout_f else: return f
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_find_nearest_conn_objects; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:network; 5, identifier:node; 6, identifier:branches; 7, block; 7, 8; 7, 18; 7, 22; 7, 35; 7, 243; 7, 262; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:conn_diff_tolerance; 11, subscript; 11, 12; 11, 17; 12, subscript; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:network; 15, identifier:config; 16, string:'grid_connection'; 17, string:'conn_diff_tolerance'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:conn_objects_min_stack; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:node_shp; 25, call; 25, 26; 25, 27; 26, identifier:transform; 27, argument_list; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:proj2equidistant; 30, argument_list; 30, 31; 31, identifier:network; 32, attribute; 32, 33; 32, 34; 33, identifier:node; 34, identifier:geom; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:branch; 37, identifier:branches; 38, block; 38, 39; 38, 45; 38, 60; 38, 75; 38, 84; 38, 147; 38, 187; 38, 217; 38, 236; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:stations; 42, subscript; 42, 43; 42, 44; 43, identifier:branch; 44, string:'adj_nodes'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:station1_shp; 48, call; 48, 49; 48, 50; 49, identifier:transform; 50, argument_list; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:proj2equidistant; 53, argument_list; 53, 54; 54, identifier:network; 55, attribute; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:stations; 58, integer:0; 59, identifier:geom; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:station2_shp; 63, call; 63, 64; 63, 65; 64, identifier:transform; 65, argument_list; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:proj2equidistant; 68, argument_list; 68, 69; 69, identifier:network; 70, attribute; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:stations; 73, integer:1; 74, identifier:geom; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:line_shp; 78, call; 78, 79; 78, 80; 79, identifier:LineString; 80, argument_list; 80, 81; 81, list:[station1_shp, station2_shp]; 81, 82; 81, 83; 82, identifier:station1_shp; 83, identifier:station2_shp; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:conn_objects; 87, dictionary; 87, 88; 87, 109; 87, 130; 88, pair; 88, 89; 88, 90; 89, string:'s1'; 90, dictionary; 90, 91; 90, 96; 90, 99; 91, pair; 91, 92; 91, 93; 92, string:'obj'; 93, subscript; 93, 94; 93, 95; 94, identifier:stations; 95, integer:0; 96, pair; 96, 97; 96, 98; 97, string:'shp'; 98, identifier:station1_shp; 99, pair; 99, 100; 99, 101; 100, string:'dist'; 101, binary_operator:*; 101, 102; 101, 108; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:node_shp; 105, identifier:distance; 106, argument_list; 106, 107; 107, identifier:station1_shp; 108, float:0.999; 109, pair; 109, 110; 109, 111; 110, string:'s2'; 111, dictionary; 111, 112; 111, 117; 111, 120; 112, pair; 112, 113; 112, 114; 113, string:'obj'; 114, subscript; 114, 115; 114, 116; 115, identifier:stations; 116, integer:1; 117, pair; 117, 118; 117, 119; 118, string:'shp'; 119, identifier:station2_shp; 120, pair; 120, 121; 120, 122; 121, string:'dist'; 122, binary_operator:*; 122, 123; 122, 129; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:node_shp; 126, identifier:distance; 127, argument_list; 127, 128; 128, identifier:station2_shp; 129, float:0.999; 130, pair; 130, 131; 130, 132; 131, string:'b'; 132, dictionary; 132, 133; 132, 136; 132, 139; 133, pair; 133, 134; 133, 135; 134, string:'obj'; 135, identifier:branch; 136, pair; 136, 137; 136, 138; 137, string:'shp'; 138, identifier:line_shp; 139, pair; 139, 140; 139, 141; 140, string:'dist'; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:node_shp; 144, identifier:distance; 145, argument_list; 145, 146; 146, identifier:line_shp; 147, if_statement; 147, 148; 147, 182; 148, parenthesized_expression; 148, 149; 149, boolean_operator:or; 149, 150; 149, 166; 150, comparison_operator:<; 150, 151; 150, 165; 151, call; 151, 152; 151, 153; 152, identifier:abs; 153, argument_list; 153, 154; 154, binary_operator:-; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:conn_objects; 158, string:'s1'; 159, string:'dist'; 160, subscript; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:conn_objects; 163, string:'b'; 164, string:'dist'; 165, identifier:conn_diff_tolerance; 166, comparison_operator:<; 166, 167; 166, 181; 167, call; 167, 168; 167, 169; 168, identifier:abs; 169, argument_list; 169, 170; 170, binary_operator:-; 170, 171; 170, 176; 171, subscript; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:conn_objects; 174, string:'s2'; 175, string:'dist'; 176, subscript; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:conn_objects; 179, string:'b'; 180, string:'dist'; 181, identifier:conn_diff_tolerance; 182, block; 182, 183; 183, delete_statement; 183, 184; 184, subscript; 184, 185; 184, 186; 185, identifier:conn_objects; 186, string:'b'; 187, if_statement; 187, 188; 187, 197; 187, 202; 188, call; 188, 189; 188, 190; 189, identifier:isinstance; 190, argument_list; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:conn_objects; 194, string:'s1'; 195, string:'obj'; 196, identifier:MVStation; 197, block; 197, 198; 198, delete_statement; 198, 199; 199, subscript; 199, 200; 199, 201; 200, identifier:conn_objects; 201, string:'s1'; 202, elif_clause; 202, 203; 202, 212; 203, call; 203, 204; 203, 205; 204, identifier:isinstance; 205, argument_list; 205, 206; 205, 211; 206, subscript; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:conn_objects; 209, string:'s2'; 210, string:'obj'; 211, identifier:MVStation; 212, block; 212, 213; 213, delete_statement; 213, 214; 214, subscript; 214, 215; 214, 216; 215, identifier:conn_objects; 216, string:'s2'; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:conn_objects_min; 220, call; 220, 221; 220, 222; 221, identifier:min; 222, argument_list; 222, 223; 222, 228; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:conn_objects; 226, identifier:values; 227, argument_list; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:key; 230, lambda; 230, 231; 230, 233; 231, lambda_parameters; 231, 232; 232, identifier:v; 233, subscript; 233, 234; 233, 235; 234, identifier:v; 235, string:'dist'; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:conn_objects_min_stack; 240, identifier:append; 241, argument_list; 241, 242; 242, identifier:conn_objects_min; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:conn_objects_min_stack; 246, list_comprehension; 246, 247; 246, 248; 247, identifier:_; 248, for_in_clause; 248, 249; 248, 250; 249, identifier:_; 250, call; 250, 251; 250, 252; 251, identifier:sorted; 252, argument_list; 252, 253; 252, 254; 253, identifier:conn_objects_min_stack; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:key; 256, lambda; 256, 257; 256, 259; 257, lambda_parameters; 257, 258; 258, identifier:x; 259, subscript; 259, 260; 259, 261; 260, identifier:x; 261, string:'dist'; 262, return_statement; 262, 263; 263, identifier:conn_objects_min_stack
def _find_nearest_conn_objects(network, node, branches): conn_diff_tolerance = network.config['grid_connection'][ 'conn_diff_tolerance'] conn_objects_min_stack = [] node_shp = transform(proj2equidistant(network), node.geom) for branch in branches: stations = branch['adj_nodes'] station1_shp = transform(proj2equidistant(network), stations[0].geom) station2_shp = transform(proj2equidistant(network), stations[1].geom) line_shp = LineString([station1_shp, station2_shp]) conn_objects = {'s1': {'obj': stations[0], 'shp': station1_shp, 'dist': node_shp.distance(station1_shp) * 0.999}, 's2': {'obj': stations[1], 'shp': station2_shp, 'dist': node_shp.distance(station2_shp) * 0.999}, 'b': {'obj': branch, 'shp': line_shp, 'dist': node_shp.distance(line_shp)}} if ( abs(conn_objects['s1']['dist'] - conn_objects['b']['dist']) < conn_diff_tolerance or abs(conn_objects['s2']['dist'] - conn_objects['b']['dist']) < conn_diff_tolerance ): del conn_objects['b'] if isinstance(conn_objects['s1']['obj'], MVStation): del conn_objects['s1'] elif isinstance(conn_objects['s2']['obj'], MVStation): del conn_objects['s2'] conn_objects_min = min(conn_objects.values(), key=lambda v: v['dist']) conn_objects_min_stack.append(conn_objects_min) conn_objects_min_stack = [_ for _ in sorted(conn_objects_min_stack, key=lambda x: x['dist'])] return conn_objects_min_stack
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:mv_voltage_deviation; 3, parameters; 3, 4; 3, 5; 4, identifier:network; 5, default_parameter; 5, 6; 5, 7; 6, identifier:voltage_levels; 7, string:'mv_lv'; 8, block; 8, 9; 8, 13; 8, 17; 8, 23; 8, 29; 8, 39; 8, 49; 8, 147; 8, 173; 8, 199; 8, 211; 8, 224; 8, 278; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:crit_nodes; 12, dictionary; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:v_dev_allowed_per_case; 16, dictionary; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:v_dev_allowed_per_case; 21, string:'feedin_case_lower'; 22, float:0.9; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:v_dev_allowed_per_case; 27, string:'load_case_upper'; 28, float:1.1; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:offset; 32, subscript; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:network; 36, identifier:config; 37, string:'grid_expansion_allowed_voltage_deviations'; 38, string:'hv_mv_trafo_offset'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:control_deviation; 42, subscript; 42, 43; 42, 48; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:network; 46, identifier:config; 47, string:'grid_expansion_allowed_voltage_deviations'; 48, string:'hv_mv_trafo_control_deviation'; 49, if_statement; 49, 50; 49, 53; 49, 92; 49, 135; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:voltage_levels; 52, string:'mv_lv'; 53, block; 53, 54; 53, 73; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 55, 60; 56, subscript; 56, 57; 56, 58; 57, identifier:v_dev_allowed_per_case; 58, string:'feedin_case_upper'; 59, line_continuation:\; 60, binary_operator:+; 60, 61; 60, 66; 61, binary_operator:+; 61, 62; 61, 65; 62, binary_operator:+; 62, 63; 62, 64; 63, integer:1; 64, identifier:offset; 65, identifier:control_deviation; 66, subscript; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:network; 70, identifier:config; 71, string:'grid_expansion_allowed_voltage_deviations'; 72, string:'mv_lv_feedin_case_max_v_deviation'; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 74, 79; 75, subscript; 75, 76; 75, 77; 76, identifier:v_dev_allowed_per_case; 77, string:'load_case_lower'; 78, line_continuation:\; 79, binary_operator:-; 79, 80; 79, 85; 80, binary_operator:-; 80, 81; 80, 84; 81, binary_operator:+; 81, 82; 81, 83; 82, integer:1; 83, identifier:offset; 84, identifier:control_deviation; 85, subscript; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:network; 89, identifier:config; 90, string:'grid_expansion_allowed_voltage_deviations'; 91, string:'mv_lv_load_case_max_v_deviation'; 92, elif_clause; 92, 93; 92, 96; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:voltage_levels; 95, string:'mv'; 96, block; 96, 97; 96, 116; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 98, 103; 99, subscript; 99, 100; 99, 101; 100, identifier:v_dev_allowed_per_case; 101, string:'feedin_case_upper'; 102, line_continuation:\; 103, binary_operator:+; 103, 104; 103, 109; 104, binary_operator:+; 104, 105; 104, 108; 105, binary_operator:+; 105, 106; 105, 107; 106, integer:1; 107, identifier:offset; 108, identifier:control_deviation; 109, subscript; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:network; 113, identifier:config; 114, string:'grid_expansion_allowed_voltage_deviations'; 115, string:'mv_feedin_case_max_v_deviation'; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 117, 122; 118, subscript; 118, 119; 118, 120; 119, identifier:v_dev_allowed_per_case; 120, string:'load_case_lower'; 121, line_continuation:\; 122, binary_operator:-; 122, 123; 122, 128; 123, binary_operator:-; 123, 124; 123, 127; 124, binary_operator:+; 124, 125; 124, 126; 125, integer:1; 126, identifier:offset; 127, identifier:control_deviation; 128, subscript; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:network; 132, identifier:config; 133, string:'grid_expansion_allowed_voltage_deviations'; 134, string:'mv_load_case_max_v_deviation'; 135, else_clause; 135, 136; 136, block; 136, 137; 137, raise_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:ValueError; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:'Specified mode {} is not a valid option.'; 144, identifier:format; 145, argument_list; 145, 146; 146, identifier:voltage_levels; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 148, 151; 149, identifier:v_dev_allowed_upper; 150, line_continuation:\; 151, call; 151, 152; 151, 161; 152, attribute; 152, 153; 152, 160; 153, attribute; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:network; 157, identifier:timeseries; 158, identifier:timesteps_load_feedin_case; 159, identifier:case; 160, identifier:apply; 161, argument_list; 161, 162; 162, lambda; 162, 163; 162, 165; 163, lambda_parameters; 163, 164; 164, identifier:_; 165, subscript; 165, 166; 165, 167; 166, identifier:v_dev_allowed_per_case; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'{}_upper'; 170, identifier:format; 171, argument_list; 171, 172; 172, identifier:_; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 174, 177; 175, identifier:v_dev_allowed_lower; 176, line_continuation:\; 177, call; 177, 178; 177, 187; 178, attribute; 178, 179; 178, 186; 179, attribute; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:network; 183, identifier:timeseries; 184, identifier:timesteps_load_feedin_case; 185, identifier:case; 186, identifier:apply; 187, argument_list; 187, 188; 188, lambda; 188, 189; 188, 191; 189, lambda_parameters; 189, 190; 190, identifier:_; 191, subscript; 191, 192; 191, 193; 192, identifier:v_dev_allowed_per_case; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, string:'{}_lower'; 196, identifier:format; 197, argument_list; 197, 198; 198, identifier:_; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:nodes; 202, call; 202, 203; 202, 210; 203, attribute; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:network; 207, identifier:mv_grid; 208, identifier:graph; 209, identifier:nodes; 210, argument_list; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:crit_nodes_grid; 214, call; 214, 215; 214, 216; 215, identifier:_voltage_deviation; 216, argument_list; 216, 217; 216, 218; 216, 219; 216, 220; 216, 221; 217, identifier:network; 218, identifier:nodes; 219, identifier:v_dev_allowed_upper; 220, identifier:v_dev_allowed_lower; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:voltage_level; 223, string:'mv'; 224, if_statement; 224, 225; 224, 229; 224, 269; 225, not_operator; 225, 226; 226, attribute; 226, 227; 226, 228; 227, identifier:crit_nodes_grid; 228, identifier:empty; 229, block; 229, 230; 229, 249; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 234; 233, identifier:crit_nodes; 234, attribute; 234, 235; 234, 236; 235, identifier:network; 236, identifier:mv_grid; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:crit_nodes_grid; 240, identifier:sort_values; 241, argument_list; 241, 242; 241, 246; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:by; 244, list:['v_mag_pu']; 244, 245; 245, string:'v_mag_pu'; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:ascending; 248, False; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:logger; 253, identifier:debug; 254, argument_list; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, string:'==> {} node(s) in MV grid has/have voltage issues.'; 258, identifier:format; 259, argument_list; 259, 260; 260, subscript; 260, 261; 260, 268; 261, attribute; 261, 262; 261, 267; 262, subscript; 262, 263; 262, 264; 263, identifier:crit_nodes; 264, attribute; 264, 265; 264, 266; 265, identifier:network; 266, identifier:mv_grid; 267, identifier:shape; 268, integer:0; 269, else_clause; 269, 270; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:logger; 275, identifier:debug; 276, argument_list; 276, 277; 277, string:'==> No voltage issues in MV grid.'; 278, return_statement; 278, 279; 279, identifier:crit_nodes
def mv_voltage_deviation(network, voltage_levels='mv_lv'): crit_nodes = {} v_dev_allowed_per_case = {} v_dev_allowed_per_case['feedin_case_lower'] = 0.9 v_dev_allowed_per_case['load_case_upper'] = 1.1 offset = network.config[ 'grid_expansion_allowed_voltage_deviations']['hv_mv_trafo_offset'] control_deviation = network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'hv_mv_trafo_control_deviation'] if voltage_levels == 'mv_lv': v_dev_allowed_per_case['feedin_case_upper'] = \ 1 + offset + control_deviation + network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_lv_feedin_case_max_v_deviation'] v_dev_allowed_per_case['load_case_lower'] = \ 1 + offset - control_deviation - network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_lv_load_case_max_v_deviation'] elif voltage_levels == 'mv': v_dev_allowed_per_case['feedin_case_upper'] = \ 1 + offset + control_deviation + network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_feedin_case_max_v_deviation'] v_dev_allowed_per_case['load_case_lower'] = \ 1 + offset - control_deviation - network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_load_case_max_v_deviation'] else: raise ValueError( 'Specified mode {} is not a valid option.'.format(voltage_levels)) v_dev_allowed_upper = \ network.timeseries.timesteps_load_feedin_case.case.apply( lambda _: v_dev_allowed_per_case['{}_upper'.format(_)]) v_dev_allowed_lower = \ network.timeseries.timesteps_load_feedin_case.case.apply( lambda _: v_dev_allowed_per_case['{}_lower'.format(_)]) nodes = network.mv_grid.graph.nodes() crit_nodes_grid = _voltage_deviation( network, nodes, v_dev_allowed_upper, v_dev_allowed_lower, voltage_level='mv') if not crit_nodes_grid.empty: crit_nodes[network.mv_grid] = crit_nodes_grid.sort_values( by=['v_mag_pu'], ascending=False) logger.debug( '==> {} node(s) in MV grid has/have voltage issues.'.format( crit_nodes[network.mv_grid].shape[0])) else: logger.debug('==> No voltage issues in MV grid.') return crit_nodes
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:calc_geo_lines_in_buffer; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:network; 5, identifier:node; 6, identifier:grid; 7, identifier:radius; 8, identifier:radius_inc; 9, block; 9, 10; 9, 14; 9, 99; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:lines; 13, list:[]; 14, while_statement; 14, 15; 14, 17; 15, not_operator; 15, 16; 16, identifier:lines; 17, block; 17, 18; 17, 31; 17, 40; 17, 95; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:node_shp; 21, call; 21, 22; 21, 23; 22, identifier:transform; 23, argument_list; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:proj2equidistant; 26, argument_list; 26, 27; 27, identifier:network; 28, attribute; 28, 29; 28, 30; 29, identifier:node; 30, identifier:geom; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:buffer_zone_shp; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:node_shp; 37, identifier:buffer; 38, argument_list; 38, 39; 39, identifier:radius; 40, for_statement; 40, 41; 40, 42; 40, 49; 41, identifier:line; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:grid; 46, identifier:graph; 47, identifier:lines; 48, argument_list; 49, block; 49, 50; 49, 56; 49, 80; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:nodes; 53, subscript; 53, 54; 53, 55; 54, identifier:line; 55, string:'adj_nodes'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:branch_shp; 59, call; 59, 60; 59, 61; 60, identifier:transform; 61, argument_list; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:proj2equidistant; 64, argument_list; 64, 65; 65, identifier:network; 66, call; 66, 67; 66, 68; 67, identifier:LineString; 68, argument_list; 68, 69; 69, list:[nodes[0].geom, nodes[1].geom]; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:nodes; 73, integer:0; 74, identifier:geom; 75, attribute; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:nodes; 78, integer:1; 79, identifier:geom; 80, if_statement; 80, 81; 80, 87; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:buffer_zone_shp; 84, identifier:intersects; 85, argument_list; 85, 86; 86, identifier:branch_shp; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:lines; 92, identifier:append; 93, argument_list; 93, 94; 94, identifier:line; 95, expression_statement; 95, 96; 96, augmented_assignment:+=; 96, 97; 96, 98; 97, identifier:radius; 98, identifier:radius_inc; 99, return_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:sorted; 102, argument_list; 102, 103; 102, 104; 103, identifier:lines; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:key; 106, lambda; 106, 107; 106, 109; 107, lambda_parameters; 107, 108; 108, identifier:_; 109, call; 109, 110; 109, 111; 110, identifier:repr; 111, argument_list; 111, 112; 112, identifier:_
def calc_geo_lines_in_buffer(network, node, grid, radius, radius_inc): lines = [] while not lines: node_shp = transform(proj2equidistant(network), node.geom) buffer_zone_shp = node_shp.buffer(radius) for line in grid.graph.lines(): nodes = line['adj_nodes'] branch_shp = transform(proj2equidistant(network), LineString([nodes[0].geom, nodes[1].geom])) if buffer_zone_shp.intersects(branch_shp): lines.append(line) radius += radius_inc return sorted(lines, key=lambda _: repr(_))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_group_by_size_greedy; 3, parameters; 3, 4; 3, 5; 4, identifier:obj_list; 5, identifier:tot_groups; 6, block; 6, 7; 6, 25; 6, 36; 6, 63; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sorted_list; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 12, 14; 12, 22; 13, identifier:obj_list; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:key; 16, lambda; 16, 17; 16, 19; 17, lambda_parameters; 17, 18; 18, identifier:x; 19, subscript; 19, 20; 19, 21; 20, identifier:x; 21, string:'size'; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:reverse; 24, True; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:groups; 28, list_comprehension; 28, 29; 28, 30; 29, list:[]; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:_; 32, call; 32, 33; 32, 34; 33, identifier:range; 34, argument_list; 34, 35; 35, identifier:tot_groups; 36, for_statement; 36, 37; 36, 40; 36, 44; 37, pattern_list; 37, 38; 37, 39; 38, identifier:index; 39, identifier:obj; 40, call; 40, 41; 40, 42; 41, identifier:enumerate; 42, argument_list; 42, 43; 43, identifier:sorted_list; 44, block; 44, 45; 44, 56; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:current_group; 48, subscript; 48, 49; 48, 50; 49, identifier:groups; 50, binary_operator:%; 50, 51; 50, 52; 51, identifier:index; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:groups; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:current_group; 60, identifier:append; 61, argument_list; 61, 62; 62, identifier:obj; 63, return_statement; 63, 64; 64, identifier:groups
def _group_by_size_greedy(obj_list, tot_groups): sorted_list = sorted(obj_list, key=lambda x: x['size'], reverse=True) groups = [[] for _ in range(tot_groups)] for index, obj in enumerate(sorted_list): current_group = groups[index % len(groups)] current_group.append(obj) return groups
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:dimensions_from_subgroups; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 10; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:letters; 9, string:'XYABCDEFGHIJKLMNOPQRSTUVWZ'; 10, return_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:' '; 14, identifier:join; 15, argument_list; 15, 16; 16, list_comprehension; 16, 17; 16, 26; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, string:'dim{0}={1}'; 20, identifier:format; 21, argument_list; 21, 22; 21, 23; 22, identifier:dim; 23, attribute; 23, 24; 23, 25; 24, identifier:sg; 25, identifier:name; 26, for_in_clause; 26, 27; 26, 30; 27, pattern_list; 27, 28; 27, 29; 28, identifier:dim; 29, identifier:sg; 30, call; 30, 31; 30, 32; 31, identifier:zip; 32, argument_list; 32, 33; 32, 34; 33, identifier:letters; 34, identifier:s
def dimensions_from_subgroups(s): letters = 'XYABCDEFGHIJKLMNOPQRSTUVWZ' return ' '.join(['dim{0}={1}'.format(dim, sg.name) for dim, sg in zip(letters, s)])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:filter_composite_from_subgroups; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 10; 5, 36; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:dims; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 23; 11, pattern_list; 11, 12; 11, 13; 12, identifier:letter; 13, identifier:sg; 14, call; 14, 15; 14, 16; 15, identifier:zip; 16, argument_list; 16, 17; 16, 18; 17, string:'ABCDEFGHIJKLMNOPQRSTUVWZ'; 18, subscript; 18, 19; 18, 20; 19, identifier:s; 20, slice; 20, 21; 20, 22; 21, integer:2; 22, colon; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:dims; 28, identifier:append; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:'dim{0}'; 33, identifier:format; 34, argument_list; 34, 35; 35, identifier:letter; 36, if_statement; 36, 37; 36, 38; 37, identifier:dims; 38, block; 38, 39; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:' '; 43, identifier:join; 44, argument_list; 44, 45; 45, identifier:dims
def filter_composite_from_subgroups(s): dims = [] for letter, sg in zip('ABCDEFGHIJKLMNOPQRSTUVWZ', s[2:]): dims.append('dim{0}'.format(letter)) if dims: return ' '.join(dims)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:_get_videos_for_filter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 13; 4, identifier:video_filter; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_field; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, attribute; 10, 11; 10, 12; 11, identifier:SortDirection; 12, identifier:asc; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pagination_conf; 15, None; 16, block; 16, 17; 16, 29; 16, 33; 16, 63; 16, 116; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:videos; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:Video; 24, identifier:objects; 25, identifier:filter; 26, argument_list; 26, 27; 27, dictionary_splat; 27, 28; 28, identifier:video_filter; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:paginator_context; 32, dictionary; 33, if_statement; 33, 34; 33, 35; 34, identifier:sort_field; 35, block; 35, 36; 35, 48; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:videos; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:videos; 42, identifier:order_by; 43, argument_list; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:sort_field; 46, identifier:value; 47, string:"edx_video_id"; 48, if_statement; 48, 49; 48, 54; 49, comparison_operator:==; 49, 50; 49, 51; 50, identifier:sort_dir; 51, attribute; 51, 52; 51, 53; 52, identifier:SortDirection; 53, identifier:desc; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:videos; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:videos; 61, identifier:reverse; 62, argument_list; 63, if_statement; 63, 64; 63, 65; 64, identifier:pagination_conf; 65, block; 65, 66; 65, 75; 65, 83; 65, 97; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:videos_per_page; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:pagination_conf; 72, identifier:get; 73, argument_list; 73, 74; 74, string:'videos_per_page'; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:paginator; 78, call; 78, 79; 78, 80; 79, identifier:Paginator; 80, argument_list; 80, 81; 80, 82; 81, identifier:videos; 82, identifier:videos_per_page; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:videos; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:paginator; 89, identifier:page; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:pagination_conf; 94, identifier:get; 95, argument_list; 95, 96; 96, string:'page_number'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:paginator_context; 100, dictionary; 100, 101; 100, 106; 100, 113; 101, pair; 101, 102; 101, 103; 102, string:'current_page'; 103, attribute; 103, 104; 103, 105; 104, identifier:videos; 105, identifier:number; 106, pair; 106, 107; 106, 108; 107, string:'total_pages'; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:videos; 111, identifier:paginator; 112, identifier:num_pages; 113, pair; 113, 114; 113, 115; 114, string:'items_on_one_page'; 115, identifier:videos_per_page; 116, return_statement; 116, 117; 117, expression_list; 117, 118; 117, 128; 118, generator_expression; 118, 119; 118, 125; 119, attribute; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:VideoSerializer; 122, argument_list; 122, 123; 123, identifier:video; 124, identifier:data; 125, for_in_clause; 125, 126; 125, 127; 126, identifier:video; 127, identifier:videos; 128, identifier:paginator_context
def _get_videos_for_filter(video_filter, sort_field=None, sort_dir=SortDirection.asc, pagination_conf=None): videos = Video.objects.filter(**video_filter) paginator_context = {} if sort_field: videos = videos.order_by(sort_field.value, "edx_video_id") if sort_dir == SortDirection.desc: videos = videos.reverse() if pagination_conf: videos_per_page = pagination_conf.get('videos_per_page') paginator = Paginator(videos, videos_per_page) videos = paginator.page(pagination_conf.get('page_number')) paginator_context = { 'current_page': videos.number, 'total_pages': videos.paginator.num_pages, 'items_on_one_page':videos_per_page } return (VideoSerializer(video).data for video in videos), paginator_context
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:get_videos_for_course; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 13; 4, identifier:course_id; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_field; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, attribute; 10, 11; 10, 12; 11, identifier:SortDirection; 12, identifier:asc; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pagination_conf; 15, None; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:_get_videos_for_filter; 20, argument_list; 20, 21; 20, 33; 20, 34; 20, 35; 21, dictionary; 21, 22; 21, 30; 22, pair; 22, 23; 22, 24; 23, string:'courses__course_id'; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:six; 27, identifier:text_type; 28, argument_list; 28, 29; 29, identifier:course_id; 30, pair; 30, 31; 30, 32; 31, string:'courses__is_hidden'; 32, False; 33, identifier:sort_field; 34, identifier:sort_dir; 35, identifier:pagination_conf
def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc, pagination_conf=None): return _get_videos_for_filter( {'courses__course_id': six.text_type(course_id), 'courses__is_hidden': False}, sort_field, sort_dir, pagination_conf, )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:get_videos_for_ids; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:edx_video_ids; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_field; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, attribute; 10, 11; 10, 12; 11, identifier:SortDirection; 12, identifier:asc; 13, block; 13, 14; 13, 28; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:videos; 18, identifier:__; 19, call; 19, 20; 19, 21; 20, identifier:_get_videos_for_filter; 21, argument_list; 21, 22; 21, 26; 21, 27; 22, dictionary; 22, 23; 23, pair; 23, 24; 23, 25; 24, string:"edx_video_id__in"; 25, identifier:edx_video_ids; 26, identifier:sort_field; 27, identifier:sort_dir; 28, return_statement; 28, 29; 29, identifier:videos
def get_videos_for_ids( edx_video_ids, sort_field=None, sort_dir=SortDirection.asc ): videos, __ = _get_videos_for_filter( {"edx_video_id__in":edx_video_ids}, sort_field, sort_dir, ) return videos
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:put; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:block_id; 6, identifier:priority; 7, default_parameter; 7, 8; 7, 9; 8, identifier:pb_type; 9, string:'offline'; 10, block; 10, 11; 10, 23; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:not; 12, 13; 12, 14; 13, identifier:pb_type; 14, tuple; 14, 15; 14, 16; 15, string:'offline'; 16, string:'realtime'; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ValueError; 21, argument_list; 21, 22; 22, string:'Invalid PB type.'; 23, with_statement; 23, 24; 23, 29; 24, with_clause; 24, 25; 25, with_item; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_mutex; 29, block; 29, 30; 29, 44; 29, 59; 29, 65; 29, 89; 29, 97; 29, 105; 29, 114; 29, 122; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:added_time; 33, call; 33, 34; 33, 43; 34, attribute; 34, 35; 34, 42; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:datetime; 39, identifier:datetime; 40, identifier:utcnow; 41, argument_list; 42, identifier:isoformat; 43, argument_list; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:entry; 47, tuple; 47, 48; 47, 49; 47, 56; 47, 57; 47, 58; 48, identifier:priority; 49, binary_operator:-; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:sys; 52, identifier:maxsize; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_index; 56, identifier:block_id; 57, identifier:pb_type; 58, identifier:added_time; 59, expression_statement; 59, 60; 60, augmented_assignment:+=; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_index; 64, integer:1; 65, if_statement; 65, 66; 65, 76; 66, comparison_operator:is; 66, 67; 66, 75; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_block_map; 72, identifier:get; 73, argument_list; 73, 74; 74, identifier:block_id; 75, None; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:KeyError; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, concatenated_string; 83, 84; 83, 85; 84, string:'ERROR: Block id "{}" already exists in '; 85, string:'PC PB queue!'; 86, identifier:format; 87, argument_list; 87, 88; 88, identifier:block_id; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_block_map; 95, identifier:block_id; 96, identifier:entry; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:LOG; 101, identifier:debug; 102, argument_list; 102, 103; 102, 104; 103, string:"Adding PB %s to queue"; 104, identifier:block_id; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_queue; 111, identifier:append; 112, argument_list; 112, 113; 113, identifier:entry; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_queue; 120, identifier:sort; 121, argument_list; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_queue; 128, identifier:reverse; 129, argument_list
def put(self, block_id, priority, pb_type='offline'): if pb_type not in ('offline', 'realtime'): raise ValueError('Invalid PB type.') with self._mutex: added_time = datetime.datetime.utcnow().isoformat() entry = (priority, sys.maxsize-self._index, block_id, pb_type, added_time) self._index += 1 if self._block_map.get(block_id) is not None: raise KeyError('ERROR: Block id "{}" already exists in ' 'PC PB queue!'. format(block_id)) self._block_map[block_id] = entry LOG.debug("Adding PB %s to queue", block_id) self._queue.append(entry) self._queue.sort() self._queue.reverse()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_device; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 18; 5, 22; 5, 107; 5, 114; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 13; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:devices; 12, identifier:sort; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:idx; 17, list:[]; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:names; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:dev; 24, identifier:order; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 30; 26, 79; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:dev; 29, identifier:all_models; 30, block; 30, 31; 30, 47; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:all_dev; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:sorted; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:all_models; 44, identifier:dev; 45, identifier:keys; 46, argument_list; 47, for_statement; 47, 48; 47, 49; 47, 50; 48, identifier:item; 49, identifier:all_dev; 50, block; 50, 51; 51, if_statement; 51, 52; 51, 57; 52, comparison_operator:in; 52, 53; 52, 54; 53, identifier:item; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:devices; 57, block; 57, 58; 57, 72; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:idx; 62, identifier:append; 63, argument_list; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:devices; 69, identifier:index; 70, argument_list; 70, 71; 71, identifier:item; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:names; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:item; 79, elif_clause; 79, 80; 79, 85; 80, comparison_operator:in; 80, 81; 80, 82; 81, identifier:dev; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:devices; 85, block; 85, 86; 85, 100; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:idx; 90, identifier:append; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:devices; 97, identifier:index; 98, argument_list; 98, 99; 99, identifier:dev; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:names; 104, identifier:append; 105, argument_list; 105, 106; 106, identifier:dev; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:idx; 110, call; 110, 111; 110, 112; 111, identifier:sorted; 112, argument_list; 112, 113; 113, identifier:idx; 114, for_statement; 114, 115; 114, 118; 114, 123; 115, pattern_list; 115, 116; 115, 117; 116, identifier:id; 117, identifier:name; 118, call; 118, 119; 118, 120; 119, identifier:zip; 120, argument_list; 120, 121; 120, 122; 121, identifier:idx; 122, identifier:names; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:devices; 130, identifier:id; 131, identifier:name
def sort_device(self): self.devices.sort() idx = [] names = [] for dev in order: if dev in all_models: all_dev = list(sorted(all_models[dev].keys())) for item in all_dev: if item in self.devices: idx.append(self.devices.index(item)) names.append(item) elif dev in self.devices: idx.append(self.devices.index(dev)) names.append(dev) idx = sorted(idx) for id, name in zip(idx, names): self.devices[id] = name
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:export_csv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:idx; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:header; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:formatted; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sort_idx; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:fmt; 20, string:'%.18e'; 21, block; 21, 22; 21, 32; 21, 48; 21, 59; 21, 68; 22, if_statement; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:idx; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:idx; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_idx; 32, if_statement; 32, 33; 32, 35; 33, not_operator; 33, 34; 34, identifier:header; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:header; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:get_header; 43, argument_list; 43, 44; 43, 45; 44, identifier:idx; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:formatted; 47, identifier:formatted; 48, assert_statement; 48, 49; 48, 58; 49, comparison_operator:==; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:idx; 54, call; 54, 55; 54, 56; 55, identifier:len; 56, argument_list; 56, 57; 57, identifier:header; 58, string:"Idx length does not match header length"; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:body; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:get_values; 66, argument_list; 66, 67; 67, identifier:idx; 68, with_statement; 68, 69; 68, 79; 69, with_clause; 69, 70; 70, with_item; 70, 71; 71, as_pattern; 71, 72; 71, 77; 72, call; 72, 73; 72, 74; 73, identifier:open; 74, argument_list; 74, 75; 74, 76; 75, identifier:path; 76, string:'w'; 77, as_pattern_target; 77, 78; 78, identifier:fd; 79, block; 79, 80; 79, 94; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:fd; 84, identifier:write; 85, argument_list; 85, 86; 86, binary_operator:+; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:','; 90, identifier:join; 91, argument_list; 91, 92; 92, identifier:header; 93, string:'\n'; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:np; 98, identifier:savetxt; 99, argument_list; 99, 100; 99, 101; 99, 102; 99, 105; 100, identifier:fd; 101, identifier:body; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:fmt; 104, identifier:fmt; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:delimiter; 107, string:','
def export_csv(self, path, idx=None, header=None, formatted=False, sort_idx=True, fmt='%.18e'): if not idx: idx = self._idx if not header: header = self.get_header(idx, formatted=formatted) assert len(idx) == len(header), \ "Idx length does not match header length" body = self.get_values(idx) with open(path, 'w') as fd: fd.write(','.join(header) + '\n') np.savetxt(fd, body, fmt=fmt, delimiter=',')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_event_times; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 23; 5, 48; 5, 64; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:times; 9, list:[]; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:times; 14, identifier:extend; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:Breaker; 21, identifier:get_times; 22, argument_list; 23, for_statement; 23, 24; 23, 25; 23, 32; 24, identifier:model; 25, attribute; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:__dict__; 30, string:'Event'; 31, identifier:all_models; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:times; 37, identifier:extend; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:__dict__; 45, identifier:model; 46, identifier:get_times; 47, argument_list; 48, if_statement; 48, 49; 48, 50; 49, identifier:times; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:times; 54, call; 54, 55; 54, 56; 55, identifier:sorted; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:list; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:set; 62, argument_list; 62, 63; 63, identifier:times; 64, return_statement; 64, 65; 65, identifier:times
def get_event_times(self): times = [] times.extend(self.Breaker.get_times()) for model in self.__dict__['Event'].all_models: times.extend(self.__dict__[model].get_times()) if times: times = sorted(list(set(times))) return times
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_sort_field; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 5, 17; 5, 34; 5, 43; 5, 57; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sort_direction; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:request; 13, identifier:GET; 14, identifier:get; 15, argument_list; 15, 16; 16, string:"dir"; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:field_name; 20, conditional_expression:if; 20, 21; 20, 32; 20, 33; 21, parenthesized_expression; 21, 22; 22, boolean_operator:or; 22, 23; 22, 31; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:request; 27, identifier:GET; 28, identifier:get; 29, argument_list; 29, 30; 30, string:"sort"; 31, string:""; 32, identifier:sort_direction; 33, string:""; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:sort_sign; 37, conditional_expression:if; 37, 38; 37, 39; 37, 42; 38, string:"-"; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:sort_direction; 41, string:"desc"; 42, string:""; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:result_field; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:"{sign}{field}"; 49, identifier:format; 50, argument_list; 50, 51; 50, 54; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:sign; 53, identifier:sort_sign; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:field; 56, identifier:field_name; 57, return_statement; 57, 58; 58, identifier:result_field
def get_sort_field(request): sort_direction = request.GET.get("dir") field_name = (request.GET.get("sort") or "") if sort_direction else "" sort_sign = "-" if sort_direction == "desc" else "" result_field = "{sign}{field}".format(sign=sort_sign, field=field_name) return result_field
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:linkage_group_ordering; 3, parameters; 3, 4; 4, identifier:linkage_records; 5, block; 5, 6; 5, 12; 5, 77; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:new_records; 9, call; 9, 10; 9, 11; 10, identifier:dict; 11, argument_list; 12, for_statement; 12, 13; 12, 16; 12, 28; 13, pattern_list; 13, 14; 13, 15; 14, identifier:lg_name; 15, identifier:linkage_group; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:itertools; 19, identifier:groupby; 20, argument_list; 20, 21; 20, 22; 21, identifier:linkage_records; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:operator; 25, identifier:itemgetter; 26, argument_list; 26, 27; 27, integer:0; 28, block; 28, 29; 28, 35; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:new_records; 33, identifier:lg_name; 34, list:[]; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:record; 37, identifier:linkage_group; 38, block; 38, 39; 38, 46; 38, 52; 38, 58; 38, 68; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:init_contig; 42, subscript; 42, 43; 42, 44; 43, identifier:record; 44, unary_operator:-; 44, 45; 45, integer:1; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:start; 49, subscript; 49, 50; 49, 51; 50, identifier:record; 51, integer:1; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:end; 55, subscript; 55, 56; 55, 57; 56, identifier:record; 57, integer:2; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:new_record; 61, list:[init_contig, -3, start, end, 1]; 61, 62; 61, 63; 61, 65; 61, 66; 61, 67; 62, identifier:init_contig; 63, unary_operator:-; 63, 64; 64, integer:3; 65, identifier:start; 66, identifier:end; 67, integer:1; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:new_records; 73, identifier:lg_name; 74, identifier:append; 75, argument_list; 75, 76; 76, identifier:new_record; 77, return_statement; 77, 78; 78, identifier:new_records
def linkage_group_ordering(linkage_records): new_records = dict() for lg_name, linkage_group in itertools.groupby( linkage_records, operator.itemgetter(0) ): new_records[lg_name] = [] for record in linkage_group: init_contig = record[-1] start = record[1] end = record[2] new_record = [init_contig, -3, start, end, 1] new_records[lg_name].append(new_record) return new_records
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 2, function_name:get_issues; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 4, default_parameter; 4, 5; 4, 6; 5, identifier:repo_name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:profile; 9, string:'github'; 10, default_parameter; 10, 11; 10, 12; 11, identifier:milestone; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:state; 15, string:'open'; 16, default_parameter; 16, 17; 16, 18; 17, identifier:assignee; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:creator; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:mentioned; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:labels; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:sort; 30, string:'created'; 31, default_parameter; 31, 32; 31, 33; 32, identifier:direction; 33, string:'desc'; 34, default_parameter; 34, 35; 34, 36; 35, identifier:since; 36, None; 37, default_parameter; 37, 38; 37, 39; 38, identifier:output; 39, string:'min'; 40, default_parameter; 40, 41; 40, 42; 41, identifier:per_page; 42, None; 43, block; 43, 44; 43, 46; 43, 54; 43, 67; 43, 79; 43, 83; 43, 92; 43, 101; 43, 110; 43, 119; 43, 128; 43, 137; 43, 146; 43, 159; 43, 172; 43, 185; 43, 189; 43, 205; 43, 249; 44, expression_statement; 44, 45; 45, string:''' Returns information for all issues in a given repository, based on the search options. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. milestone The number of a GitHub milestone, or a string of either ``*`` or ``none``. If a number is passed, it should refer to a milestone by its number field. Use the ``github.get_milestone`` function to obtain a milestone's number. If the string ``*`` is passed, issues with any milestone are accepted. If the string ``none`` is passed, issues without milestones are returned. state Indicates the state of the issues to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. assignee Can be the name of a user. Pass in ``none`` (as a string) for issues with no assigned user or ``*`` for issues assigned to any user. creator The user that created the issue. mentioned A user that's mentioned in the issue. labels A string of comma separated label names. For example, ``bug,ui,@high``. sort What to sort results by. Can be either ``created``, ``updated``, or ``comments``. Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. since Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_issues my-github-repo '''; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:org_name; 49, call; 49, 50; 49, 51; 50, identifier:_get_config_value; 51, argument_list; 51, 52; 51, 53; 52, identifier:profile; 53, string:'org_name'; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:is; 55, 56; 55, 57; 56, identifier:repo_name; 57, None; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:repo_name; 62, call; 62, 63; 62, 64; 63, identifier:_get_config_value; 64, argument_list; 64, 65; 64, 66; 65, identifier:profile; 66, string:'repo_name'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:action; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:'/'; 73, identifier:join; 74, argument_list; 74, 75; 75, list:['repos', org_name, repo_name]; 75, 76; 75, 77; 75, 78; 76, string:'repos'; 77, identifier:org_name; 78, identifier:repo_name; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:args; 82, dictionary; 83, if_statement; 83, 84; 83, 85; 84, identifier:milestone; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:args; 90, string:'milestone'; 91, identifier:milestone; 92, if_statement; 92, 93; 92, 94; 93, identifier:assignee; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:args; 99, string:'assignee'; 100, identifier:assignee; 101, if_statement; 101, 102; 101, 103; 102, identifier:creator; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:args; 108, string:'creator'; 109, identifier:creator; 110, if_statement; 110, 111; 110, 112; 111, identifier:mentioned; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:args; 117, string:'mentioned'; 118, identifier:mentioned; 119, if_statement; 119, 120; 119, 121; 120, identifier:labels; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:args; 126, string:'labels'; 127, identifier:labels; 128, if_statement; 128, 129; 128, 130; 129, identifier:since; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:args; 135, string:'since'; 136, identifier:since; 137, if_statement; 137, 138; 137, 139; 138, identifier:per_page; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:args; 144, string:'per_page'; 145, identifier:per_page; 146, if_statement; 146, 147; 146, 152; 147, boolean_operator:and; 147, 148; 147, 149; 148, identifier:state; 149, comparison_operator:!=; 149, 150; 149, 151; 150, identifier:state; 151, string:'open'; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:args; 157, string:'state'; 158, identifier:state; 159, if_statement; 159, 160; 159, 165; 160, boolean_operator:and; 160, 161; 160, 162; 161, identifier:sort; 162, comparison_operator:!=; 162, 163; 162, 164; 163, identifier:sort; 164, string:'created'; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:args; 170, string:'sort'; 171, identifier:sort; 172, if_statement; 172, 173; 172, 178; 173, boolean_operator:and; 173, 174; 173, 175; 174, identifier:direction; 175, comparison_operator:!=; 175, 176; 175, 177; 176, identifier:direction; 177, string:'desc'; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:args; 183, string:'direction'; 184, identifier:direction; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:ret; 188, dictionary; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:issues; 192, call; 192, 193; 192, 194; 193, identifier:_query; 194, argument_list; 194, 195; 194, 196; 194, 199; 194, 202; 195, identifier:profile; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:action; 198, identifier:action; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:command; 201, string:'issues'; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:args; 204, identifier:args; 205, for_statement; 205, 206; 205, 207; 205, 208; 206, identifier:issue; 207, identifier:issues; 208, block; 208, 209; 208, 218; 208, 227; 209, if_statement; 209, 210; 209, 216; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:issue; 213, identifier:get; 214, argument_list; 214, 215; 215, string:'pull_request'; 216, block; 216, 217; 217, continue_statement; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:issue_id; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:issue; 224, identifier:get; 225, argument_list; 225, 226; 226, string:'id'; 227, if_statement; 227, 228; 227, 231; 227, 238; 228, comparison_operator:==; 228, 229; 228, 230; 229, identifier:output; 230, string:'full'; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:ret; 236, identifier:issue_id; 237, identifier:issue; 238, else_clause; 238, 239; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:ret; 244, identifier:issue_id; 245, call; 245, 246; 245, 247; 246, identifier:_format_issue; 247, argument_list; 247, 248; 248, identifier:issue; 249, return_statement; 249, 250; 250, identifier:ret
def get_issues(repo_name=None, profile='github', milestone=None, state='open', assignee=None, creator=None, mentioned=None, labels=None, sort='created', direction='desc', since=None, output='min', per_page=None): ''' Returns information for all issues in a given repository, based on the search options. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. milestone The number of a GitHub milestone, or a string of either ``*`` or ``none``. If a number is passed, it should refer to a milestone by its number field. Use the ``github.get_milestone`` function to obtain a milestone's number. If the string ``*`` is passed, issues with any milestone are accepted. If the string ``none`` is passed, issues without milestones are returned. state Indicates the state of the issues to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. assignee Can be the name of a user. Pass in ``none`` (as a string) for issues with no assigned user or ``*`` for issues assigned to any user. creator The user that created the issue. mentioned A user that's mentioned in the issue. labels A string of comma separated label names. For example, ``bug,ui,@high``. sort What to sort results by. Can be either ``created``, ``updated``, or ``comments``. Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. since Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_issues my-github-repo ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if milestone: args['milestone'] = milestone if assignee: args['assignee'] = assignee if creator: args['creator'] = creator if mentioned: args['mentioned'] = mentioned if labels: args['labels'] = labels if since: args['since'] = since if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'created': args['sort'] = sort if direction and direction != 'desc': args['direction'] = direction ret = {} issues = _query(profile, action=action, command='issues', args=args) for issue in issues: if issue.get('pull_request'): continue issue_id = issue.get('id') if output == 'full': ret[issue_id] = issue else: ret[issue_id] = _format_issue(issue) return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:get_milestones; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 4, default_parameter; 4, 5; 4, 6; 5, identifier:repo_name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:profile; 9, string:'github'; 10, default_parameter; 10, 11; 10, 12; 11, identifier:state; 12, string:'open'; 13, default_parameter; 13, 14; 13, 15; 14, identifier:sort; 15, string:'due_on'; 16, default_parameter; 16, 17; 16, 18; 17, identifier:direction; 18, string:'asc'; 19, default_parameter; 19, 20; 19, 21; 20, identifier:output; 21, string:'min'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:per_page; 24, None; 25, block; 25, 26; 25, 28; 25, 36; 25, 49; 25, 61; 25, 65; 25, 74; 25, 87; 25, 100; 25, 113; 25, 117; 25, 133; 25, 186; 26, expression_statement; 26, 27; 27, string:''' Return information about milestones for a given repository. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state The state of the milestone. Either ``open``, ``closed``, or ``all``. Default is ``open``. sort What to sort results by. Either ``due_on`` or ``completeness``. Default is ``due_on``. direction The direction of the sort. Either ``asc`` or ``desc``. Default is ``asc``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. CLI Example: .. code-block:: bash salt myminion github.get_milestones '''; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:org_name; 31, call; 31, 32; 31, 33; 32, identifier:_get_config_value; 33, argument_list; 33, 34; 33, 35; 34, identifier:profile; 35, string:'org_name'; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:repo_name; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:repo_name; 44, call; 44, 45; 44, 46; 45, identifier:_get_config_value; 46, argument_list; 46, 47; 46, 48; 47, identifier:profile; 48, string:'repo_name'; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:action; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, string:'/'; 55, identifier:join; 56, argument_list; 56, 57; 57, list:['repos', org_name, repo_name]; 57, 58; 57, 59; 57, 60; 58, string:'repos'; 59, identifier:org_name; 60, identifier:repo_name; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:args; 64, dictionary; 65, if_statement; 65, 66; 65, 67; 66, identifier:per_page; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:args; 72, string:'per_page'; 73, identifier:per_page; 74, if_statement; 74, 75; 74, 80; 75, boolean_operator:and; 75, 76; 75, 77; 76, identifier:state; 77, comparison_operator:!=; 77, 78; 77, 79; 78, identifier:state; 79, string:'open'; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:args; 85, string:'state'; 86, identifier:state; 87, if_statement; 87, 88; 87, 93; 88, boolean_operator:and; 88, 89; 88, 90; 89, identifier:sort; 90, comparison_operator:!=; 90, 91; 90, 92; 91, identifier:sort; 92, string:'due_on'; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:args; 98, string:'sort'; 99, identifier:sort; 100, if_statement; 100, 101; 100, 106; 101, boolean_operator:and; 101, 102; 101, 103; 102, identifier:direction; 103, comparison_operator:!=; 103, 104; 103, 105; 104, identifier:direction; 105, string:'asc'; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:args; 111, string:'direction'; 112, identifier:direction; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:ret; 116, dictionary; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:milestones; 120, call; 120, 121; 120, 122; 121, identifier:_query; 122, argument_list; 122, 123; 122, 124; 122, 127; 122, 130; 123, identifier:profile; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:action; 126, identifier:action; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:command; 129, string:'milestones'; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:args; 132, identifier:args; 133, for_statement; 133, 134; 133, 135; 133, 136; 134, identifier:milestone; 135, identifier:milestones; 136, block; 136, 137; 136, 146; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:milestone_id; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:milestone; 143, identifier:get; 144, argument_list; 144, 145; 145, string:'id'; 146, if_statement; 146, 147; 146, 150; 146, 157; 147, comparison_operator:==; 147, 148; 147, 149; 148, identifier:output; 149, string:'full'; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:ret; 155, identifier:milestone_id; 156, identifier:milestone; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 166; 158, 173; 158, 180; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:milestone; 163, identifier:pop; 164, argument_list; 164, 165; 165, string:'creator'; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:milestone; 170, identifier:pop; 171, argument_list; 171, 172; 172, string:'html_url'; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:milestone; 177, identifier:pop; 178, argument_list; 178, 179; 179, string:'labels_url'; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:ret; 184, identifier:milestone_id; 185, identifier:milestone; 186, return_statement; 186, 187; 187, identifier:ret
def get_milestones(repo_name=None, profile='github', state='open', sort='due_on', direction='asc', output='min', per_page=None): ''' Return information about milestones for a given repository. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state The state of the milestone. Either ``open``, ``closed``, or ``all``. Default is ``open``. sort What to sort results by. Either ``due_on`` or ``completeness``. Default is ``due_on``. direction The direction of the sort. Either ``asc`` or ``desc``. Default is ``asc``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. CLI Example: .. code-block:: bash salt myminion github.get_milestones ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'due_on': args['sort'] = sort if direction and direction != 'asc': args['direction'] = direction ret = {} milestones = _query(profile, action=action, command='milestones', args=args) for milestone in milestones: milestone_id = milestone.get('id') if output == 'full': ret[milestone_id] = milestone else: milestone.pop('creator') milestone.pop('html_url') milestone.pop('labels_url') ret[milestone_id] = milestone return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:get_prs; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 4, default_parameter; 4, 5; 4, 6; 5, identifier:repo_name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:profile; 9, string:'github'; 10, default_parameter; 10, 11; 10, 12; 11, identifier:state; 12, string:'open'; 13, default_parameter; 13, 14; 13, 15; 14, identifier:head; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:base; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:sort; 21, string:'created'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:direction; 24, string:'desc'; 25, default_parameter; 25, 26; 25, 27; 26, identifier:output; 27, string:'min'; 28, default_parameter; 28, 29; 28, 30; 29, identifier:per_page; 30, None; 31, block; 31, 32; 31, 34; 31, 42; 31, 55; 31, 67; 31, 71; 31, 80; 31, 89; 31, 98; 31, 111; 31, 124; 31, 137; 31, 141; 31, 157; 31, 192; 32, expression_statement; 32, 33; 33, string:''' Returns information for all pull requests in a given repository, based on the search options provided. .. versionadded:: 2017.7.0 repo_name The name of the repository for which to list pull requests. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the ``repo_name`` defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state Indicates the state of the pull requests to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. head Filter pull requests by head user and branch name in the format of ``user:ref-name``. Example: ``'github:new-script-format'``. Default is ``None``. base Filter pulls by base branch name. Example: ``gh-pages``. Default is ``None``. sort What to sort results by. Can be either ``created``, ``updated``, ``popularity`` (comment count), or ``long-running`` (age, filtering by pull requests updated within the last month). Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. output The amount of data returned by each pull request. Defaults to ``min``. Change to ``full`` to see all pull request output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of pull requests gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_prs salt myminion github.get_prs base=2016.11 '''; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:org_name; 37, call; 37, 38; 37, 39; 38, identifier:_get_config_value; 39, argument_list; 39, 40; 39, 41; 40, identifier:profile; 41, string:'org_name'; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:repo_name; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:repo_name; 50, call; 50, 51; 50, 52; 51, identifier:_get_config_value; 52, argument_list; 52, 53; 52, 54; 53, identifier:profile; 54, string:'repo_name'; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:action; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:'/'; 61, identifier:join; 62, argument_list; 62, 63; 63, list:['repos', org_name, repo_name]; 63, 64; 63, 65; 63, 66; 64, string:'repos'; 65, identifier:org_name; 66, identifier:repo_name; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:args; 70, dictionary; 71, if_statement; 71, 72; 71, 73; 72, identifier:head; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:args; 78, string:'head'; 79, identifier:head; 80, if_statement; 80, 81; 80, 82; 81, identifier:base; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:args; 87, string:'base'; 88, identifier:base; 89, if_statement; 89, 90; 89, 91; 90, identifier:per_page; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:args; 96, string:'per_page'; 97, identifier:per_page; 98, if_statement; 98, 99; 98, 104; 99, boolean_operator:and; 99, 100; 99, 101; 100, identifier:state; 101, comparison_operator:!=; 101, 102; 101, 103; 102, identifier:state; 103, string:'open'; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:args; 109, string:'state'; 110, identifier:state; 111, if_statement; 111, 112; 111, 117; 112, boolean_operator:and; 112, 113; 112, 114; 113, identifier:sort; 114, comparison_operator:!=; 114, 115; 114, 116; 115, identifier:sort; 116, string:'created'; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:args; 122, string:'sort'; 123, identifier:sort; 124, if_statement; 124, 125; 124, 130; 125, boolean_operator:and; 125, 126; 125, 127; 126, identifier:direction; 127, comparison_operator:!=; 127, 128; 127, 129; 128, identifier:direction; 129, string:'desc'; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:args; 135, string:'direction'; 136, identifier:direction; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:ret; 140, dictionary; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:prs; 144, call; 144, 145; 144, 146; 145, identifier:_query; 146, argument_list; 146, 147; 146, 148; 146, 151; 146, 154; 147, identifier:profile; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:action; 150, identifier:action; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:command; 153, string:'pulls'; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:args; 156, identifier:args; 157, for_statement; 157, 158; 157, 159; 157, 160; 158, identifier:pr_; 159, identifier:prs; 160, block; 160, 161; 160, 170; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:pr_id; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:pr_; 167, identifier:get; 168, argument_list; 168, 169; 169, string:'id'; 170, if_statement; 170, 171; 170, 174; 170, 181; 171, comparison_operator:==; 171, 172; 171, 173; 172, identifier:output; 173, string:'full'; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:ret; 179, identifier:pr_id; 180, identifier:pr_; 181, else_clause; 181, 182; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:ret; 187, identifier:pr_id; 188, call; 188, 189; 188, 190; 189, identifier:_format_pr; 190, argument_list; 190, 191; 191, identifier:pr_; 192, return_statement; 192, 193; 193, identifier:ret
def get_prs(repo_name=None, profile='github', state='open', head=None, base=None, sort='created', direction='desc', output='min', per_page=None): ''' Returns information for all pull requests in a given repository, based on the search options provided. .. versionadded:: 2017.7.0 repo_name The name of the repository for which to list pull requests. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the ``repo_name`` defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state Indicates the state of the pull requests to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. head Filter pull requests by head user and branch name in the format of ``user:ref-name``. Example: ``'github:new-script-format'``. Default is ``None``. base Filter pulls by base branch name. Example: ``gh-pages``. Default is ``None``. sort What to sort results by. Can be either ``created``, ``updated``, ``popularity`` (comment count), or ``long-running`` (age, filtering by pull requests updated within the last month). Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. output The amount of data returned by each pull request. Defaults to ``min``. Change to ``full`` to see all pull request output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of pull requests gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_prs salt myminion github.get_prs base=2016.11 ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if head: args['head'] = head if base: args['base'] = base if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'created': args['sort'] = sort if direction and direction != 'desc': args['direction'] = direction ret = {} prs = _query(profile, action=action, command='pulls', args=args) for pr_ in prs: pr_id = pr_.get('id') if output == 'full': ret[pr_id] = pr_ else: ret[pr_id] = _format_pr(pr_) return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_diff_lists; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:old; 5, identifier:new; 6, identifier:comparator; 7, block; 7, 8; 7, 10; 7, 48; 7, 64; 7, 73; 7, 151; 7, 157; 8, expression_statement; 8, 9; 9, string:''' Compare lists to extract the changes :param old: old list :param new: new list :return: a dictionary with ``unchanged``, ``new``, ``deleted`` and ``sorted`` keys The sorted list is the union of unchanged and new lists, but keeping the original order from the new list. '''; 10, function_definition; 10, 11; 10, 12; 10, 14; 11, function_name:_remove_indent; 12, parameters; 12, 13; 13, identifier:node; 14, block; 14, 15; 14, 17; 14, 26; 14, 32; 14, 46; 15, expression_statement; 15, 16; 16, string:''' Remove the XML indentation to compare XML trees more easily '''; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:node_copy; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:copy; 23, identifier:deepcopy; 24, argument_list; 24, 25; 25, identifier:node; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:node_copy; 30, identifier:text; 31, None; 32, for_statement; 32, 33; 32, 34; 32, 39; 33, identifier:item; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:node_copy; 37, identifier:iter; 38, argument_list; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:item; 44, identifier:tail; 45, None; 46, return_statement; 46, 47; 47, identifier:node_copy; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:diff; 51, dictionary; 51, 52; 51, 55; 51, 58; 51, 61; 52, pair; 52, 53; 52, 54; 53, string:'unchanged'; 54, list:[]; 55, pair; 55, 56; 55, 57; 56, string:'new'; 57, list:[]; 58, pair; 58, 59; 58, 60; 59, string:'deleted'; 60, list:[]; 61, pair; 61, 62; 61, 63; 62, string:'sorted'; 63, list:[]; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:old_devices; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:copy; 70, identifier:deepcopy; 71, argument_list; 71, 72; 72, identifier:old; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:new_item; 75, identifier:new; 76, block; 76, 77; 76, 97; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:found; 80, list_comprehension; 80, 81; 80, 82; 80, 85; 81, identifier:item; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:item; 84, identifier:old_devices; 85, if_clause; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:comparator; 88, argument_list; 88, 89; 88, 93; 89, call; 89, 90; 89, 91; 90, identifier:_remove_indent; 91, argument_list; 91, 92; 92, identifier:item; 93, call; 93, 94; 93, 95; 94, identifier:_remove_indent; 95, argument_list; 95, 96; 96, identifier:new_item; 97, if_statement; 97, 98; 97, 99; 97, 131; 98, identifier:found; 99, block; 99, 100; 99, 109; 99, 120; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:old_devices; 104, identifier:remove; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:found; 108, integer:0; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:diff; 114, string:'unchanged'; 115, identifier:append; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:found; 119, integer:0; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:diff; 125, string:'sorted'; 126, identifier:append; 127, argument_list; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:found; 130, integer:0; 131, else_clause; 131, 132; 132, block; 132, 133; 132, 142; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:diff; 138, string:'new'; 139, identifier:append; 140, argument_list; 140, 141; 141, identifier:new_item; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:diff; 147, string:'sorted'; 148, identifier:append; 149, argument_list; 149, 150; 150, identifier:new_item; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:diff; 155, string:'deleted'; 156, identifier:old_devices; 157, return_statement; 157, 158; 158, identifier:diff
def _diff_lists(old, new, comparator): ''' Compare lists to extract the changes :param old: old list :param new: new list :return: a dictionary with ``unchanged``, ``new``, ``deleted`` and ``sorted`` keys The sorted list is the union of unchanged and new lists, but keeping the original order from the new list. ''' def _remove_indent(node): ''' Remove the XML indentation to compare XML trees more easily ''' node_copy = copy.deepcopy(node) node_copy.text = None for item in node_copy.iter(): item.tail = None return node_copy diff = {'unchanged': [], 'new': [], 'deleted': [], 'sorted': []} old_devices = copy.deepcopy(old) for new_item in new: found = [item for item in old_devices if comparator(_remove_indent(item), _remove_indent(new_item))] if found: old_devices.remove(found[0]) diff['unchanged'].append(found[0]) diff['sorted'].append(found[0]) else: diff['new'].append(new_item) diff['sorted'].append(new_item) diff['deleted'] = old_devices return diff
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_job_sorting_key; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:job; 6, block; 6, 7; 6, 16; 6, 20; 6, 31; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:is; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_base_graph; 12, None; 13, block; 13, 14; 14, return_statement; 14, 15; 15, integer:0; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:MAX_JOBS; 19, integer:1000000; 20, if_statement; 20, 21; 20, 28; 21, comparison_operator:not; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:job; 24, identifier:addr; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_node_addr_visiting_order; 28, block; 28, 29; 29, return_statement; 29, 30; 30, identifier:MAX_JOBS; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_node_addr_visiting_order; 37, identifier:index; 38, argument_list; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:job; 41, identifier:addr
def _job_sorting_key(self, job): if self._base_graph is None: return 0 MAX_JOBS = 1000000 if job.addr not in self._node_addr_visiting_order: return MAX_JOBS return self._node_addr_visiting_order.index(job.addr)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:instruction_addresses; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:addrs; 9, list:[ ]; 10, for_statement; 10, 11; 10, 12; 10, 26; 11, identifier:b; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:blocks; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, lambda; 20, 21; 20, 23; 21, lambda_parameters; 21, 22; 22, identifier:x; 23, attribute; 23, 24; 23, 25; 24, identifier:x; 25, identifier:addr; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:addrs; 31, identifier:extend; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:b; 36, identifier:instruction_addresses; 37, argument_list; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:sorted; 41, argument_list; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:set; 44, argument_list; 44, 45; 45, identifier:addrs; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, lambda; 48, 49; 48, 51; 49, lambda_parameters; 49, 50; 50, identifier:x; 51, subscript; 51, 52; 51, 53; 52, identifier:x; 53, integer:0
def instruction_addresses(self): addrs = [ ] for b in sorted(self.blocks, key=lambda x: x.addr): addrs.extend(b.instruction_addresses()) return sorted(set(addrs), key=lambda x: x[0])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:desymbolize; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 29; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:sort; 11, string:'unknown'; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:content; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:binary; 20, identifier:fast_memory_load; 21, argument_list; 21, 22; 21, 25; 21, 28; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:addr; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:size; 28, identifier:bytes; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:content; 34, list:[ content ]; 34, 35; 35, identifier:content
def desymbolize(self): self.sort = 'unknown' content = self.binary.fast_memory_load(self.addr, self.size, bytes) self.content = [ content ]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:append_data; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:name; 6, identifier:initial_content; 7, identifier:size; 8, default_parameter; 8, 9; 8, 10; 9, identifier:readonly; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, string:"unknown"; 14, block; 14, 15; 14, 28; 14, 37; 14, 47; 14, 72; 15, if_statement; 15, 16; 15, 17; 15, 22; 16, identifier:readonly; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:section_name; 21, string:".rodata"; 22, else_clause; 22, 23; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:section_name; 27, string:'.data'; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:initial_content; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:initial_content; 36, string:b""; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:initial_content; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:initial_content; 43, identifier:ljust; 44, argument_list; 44, 45; 44, 46; 45, identifier:size; 46, string:b"\x00"; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:data; 50, call; 50, 51; 50, 52; 51, identifier:Data; 52, argument_list; 52, 53; 52, 54; 52, 57; 52, 60; 52, 63; 52, 66; 52, 69; 53, identifier:self; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:memory_data; 56, None; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:section_name; 59, identifier:section_name; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:name; 62, identifier:name; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:initial_content; 65, identifier:initial_content; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:size; 68, identifier:size; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:sort; 71, identifier:sort; 72, if_statement; 72, 73; 72, 76; 72, 86; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:section_name; 75, string:'.rodata'; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:extra_rodata; 83, identifier:append; 84, argument_list; 84, 85; 85, identifier:data; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:extra_data; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:data
def append_data(self, name, initial_content, size, readonly=False, sort="unknown"): if readonly: section_name = ".rodata" else: section_name = '.data' if initial_content is None: initial_content = b"" initial_content = initial_content.ljust(size, b"\x00") data = Data(self, memory_data=None, section_name=section_name, name=name, initial_content=initial_content, size=size, sort=sort ) if section_name == '.rodata': self.extra_rodata.append(data) else: self.extra_data.append(data)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:pop_job; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:returning; 7, True; 8, block; 8, 9; 8, 15; 8, 38; 8, 66; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:self; 12, block; 12, 13; 13, return_statement; 13, 14; 14, None; 15, if_statement; 15, 16; 15, 18; 16, not_operator; 16, 17; 17, identifier:returning; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_pop_job; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:next; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:reversed; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_jobs; 36, identifier:keys; 37, argument_list; 38, for_statement; 38, 39; 38, 40; 38, 50; 39, identifier:func_addr; 40, call; 40, 41; 40, 42; 41, identifier:reversed; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_jobs; 48, identifier:keys; 49, argument_list; 50, block; 50, 51; 50, 59; 51, if_statement; 51, 52; 51, 57; 52, comparison_operator:not; 52, 53; 52, 54; 53, identifier:func_addr; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_returning_functions; 57, block; 57, 58; 58, continue_statement; 59, return_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_pop_job; 64, argument_list; 64, 65; 65, identifier:func_addr; 66, return_statement; 66, 67; 67, None
def pop_job(self, returning=True): if not self: return None if not returning: return self._pop_job(next(reversed(self._jobs.keys()))) for func_addr in reversed(self._jobs.keys()): if func_addr not in self._returning_functions: continue return self._pop_job(func_addr) return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_min_addr; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 32; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_regions; 11, block; 11, 12; 11, 30; 12, if_statement; 12, 13; 12, 22; 13, comparison_operator:!=; 13, 14; 13, 21; 14, attribute; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:project; 19, identifier:arch; 20, identifier:name; 21, string:"Soot"; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:l; 27, identifier:error; 28, argument_list; 28, 29; 29, string:"self._regions is empty or not properly set."; 30, return_statement; 30, 31; 31, None; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:next; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_regions; 41, identifier:irange; 42, argument_list
def _get_min_addr(self): if not self._regions: if self.project.arch.name != "Soot": l.error("self._regions is empty or not properly set.") return None return next(self._regions.irange())
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_job_sorting_key; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:job; 6, block; 6, 7; 6, 11; 6, 37; 6, 63; 6, 102; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:MAX_BLOCKS_PER_FUNCTION; 10, integer:1000000; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:task_functions; 14, call; 14, 15; 14, 16; 15, identifier:list; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:reversed; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:list; 22, generator_expression; 22, 23; 22, 26; 22, 31; 23, attribute; 23, 24; 23, 25; 24, identifier:task; 25, identifier:function_address; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:task; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_task_stack; 31, if_clause; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:task; 36, identifier:FunctionAnalysis; 37, try_statement; 37, 38; 37, 50; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:function_pos; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:task_functions; 45, identifier:index; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:job; 49, identifier:func_addr; 50, except_clause; 50, 51; 50, 52; 50, 62; 51, identifier:ValueError; 52, ERROR; 52, 53; 52, 56; 52, 58; 52, 61; 53, attribute; 53, 54; 53, 55; 54, identifier:l; 55, identifier:warning; 56, ERROR; 56, 57; 57, identifier:Function; 58, binary_operator:%; 58, 59; 58, 60; 59, identifier:address; 60, identifier:return; 61, integer:0; 62, block:; 63, try_statement; 63, 64; 63, 83; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:block_in_function_pos; 68, call; 68, 69; 68, 79; 69, attribute; 69, 70; 69, 78; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_ordered_node_addrs; 74, argument_list; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:job; 77, identifier:func_addr; 78, identifier:index; 79, argument_list; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:job; 82, identifier:addr; 83, except_clause; 83, 84; 83, 85; 84, identifier:ValueError; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:block_in_function_pos; 89, call; 89, 90; 89, 91; 90, identifier:min; 91, argument_list; 91, 92; 91, 99; 92, binary_operator:-; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:job; 95, identifier:addr; 96, attribute; 96, 97; 96, 98; 97, identifier:job; 98, identifier:func_addr; 99, binary_operator:-; 99, 100; 99, 101; 100, identifier:MAX_BLOCKS_PER_FUNCTION; 101, integer:1; 102, return_statement; 102, 103; 103, binary_operator:+; 103, 104; 103, 105; 104, identifier:block_in_function_pos; 105, binary_operator:*; 105, 106; 105, 107; 106, identifier:MAX_BLOCKS_PER_FUNCTION; 107, identifier:function_pos
def _job_sorting_key(self, job): MAX_BLOCKS_PER_FUNCTION = 1000000 task_functions = list(reversed( list(task.function_address for task in self._task_stack if isinstance(task, FunctionAnalysis)) )) try: function_pos = task_functions.index(job.func_addr) except ValueError: l.warning('Function address % return 0 try: block_in_function_pos = self._ordered_node_addrs(job.func_addr).index(job.addr) except ValueError: block_in_function_pos = min(job.addr - job.func_addr, MAX_BLOCKS_PER_FUNCTION - 1) return block_in_function_pos + MAX_BLOCKS_PER_FUNCTION * function_pos
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_merge_points; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:function_address; 6, block; 6, 7; 6, 24; 6, 54; 7, try_statement; 7, 8; 7, 19; 8, block; 8, 9; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:new_function; 12, subscript; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:kb; 17, identifier:functions; 18, identifier:function_address; 19, except_clause; 19, 20; 19, 21; 20, identifier:KeyError; 21, block; 21, 22; 22, return_statement; 22, 23; 23, list:[ ]; 24, if_statement; 24, 25; 24, 30; 25, comparison_operator:not; 25, 26; 25, 27; 26, identifier:function_address; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_function_merge_points; 30, block; 30, 31; 30, 46; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:ordered_merge_points; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:CFGUtils; 37, identifier:find_merge_points; 38, argument_list; 38, 39; 38, 40; 38, 43; 39, identifier:function_address; 40, attribute; 40, 41; 40, 42; 41, identifier:new_function; 42, identifier:endpoints; 43, attribute; 43, 44; 43, 45; 44, identifier:new_function; 45, identifier:graph; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_function_merge_points; 52, identifier:function_address; 53, identifier:ordered_merge_points; 54, return_statement; 54, 55; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_function_merge_points; 59, identifier:function_address
def _merge_points(self, function_address): try: new_function = self.kb.functions[function_address] except KeyError: return [ ] if function_address not in self._function_merge_points: ordered_merge_points = CFGUtils.find_merge_points(function_address, new_function.endpoints, new_function.graph) self._function_merge_points[function_address] = ordered_merge_points return self._function_merge_points[function_address]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_widening_points; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:function_address; 6, block; 6, 7; 6, 24; 6, 66; 7, try_statement; 7, 8; 7, 19; 8, block; 8, 9; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:new_function; 12, subscript; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:kb; 17, identifier:functions; 18, identifier:function_address; 19, except_clause; 19, 20; 19, 21; 20, identifier:KeyError; 21, block; 21, 22; 22, return_statement; 22, 23; 23, list:[ ]; 24, if_statement; 24, 25; 24, 30; 25, comparison_operator:not; 25, 26; 25, 27; 26, identifier:function_address; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_function_widening_points; 30, block; 30, 31; 30, 43; 30, 58; 31, if_statement; 31, 32; 31, 36; 32, not_operator; 32, 33; 33, attribute; 33, 34; 33, 35; 34, identifier:new_function; 35, identifier:normalized; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:new_function; 41, identifier:normalize; 42, argument_list; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:widening_points; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:CFGUtils; 49, identifier:find_widening_points; 50, argument_list; 50, 51; 50, 52; 50, 55; 51, identifier:function_address; 52, attribute; 52, 53; 52, 54; 53, identifier:new_function; 54, identifier:endpoints; 55, attribute; 55, 56; 55, 57; 56, identifier:new_function; 57, identifier:graph; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 65; 60, subscript; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_function_widening_points; 64, identifier:function_address; 65, identifier:widening_points; 66, return_statement; 66, 67; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_function_widening_points; 71, identifier:function_address
def _widening_points(self, function_address): try: new_function = self.kb.functions[function_address] except KeyError: return [ ] if function_address not in self._function_widening_points: if not new_function.normalized: new_function.normalize() widening_points = CFGUtils.find_widening_points(function_address, new_function.endpoints, new_function.graph) self._function_widening_points[function_address] = widening_points return self._function_widening_points[function_address]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_variables; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:collapse_same_ident; 10, False; 11, block; 11, 12; 11, 16; 11, 23; 11, 62; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:variables; 15, list:[ ]; 16, if_statement; 16, 17; 16, 18; 17, identifier:collapse_same_ident; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:NotImplementedError; 22, argument_list; 23, for_statement; 23, 24; 23, 25; 23, 28; 24, identifier:var; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_variables; 28, block; 28, 29; 28, 42; 28, 55; 29, if_statement; 29, 30; 29, 40; 30, boolean_operator:and; 30, 31; 30, 34; 31, comparison_operator:==; 31, 32; 31, 33; 32, identifier:sort; 33, string:'stack'; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:var; 39, identifier:SimStackVariable; 40, block; 40, 41; 41, continue_statement; 42, if_statement; 42, 43; 42, 53; 43, boolean_operator:and; 43, 44; 43, 47; 44, comparison_operator:==; 44, 45; 44, 46; 45, identifier:sort; 46, string:'reg'; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:var; 52, identifier:SimRegisterVariable; 53, block; 53, 54; 54, continue_statement; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:variables; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:var; 62, return_statement; 62, 63; 63, identifier:variables
def get_variables(self, sort=None, collapse_same_ident=False): variables = [ ] if collapse_same_ident: raise NotImplementedError() for var in self._variables: if sort == 'stack' and not isinstance(var, SimStackVariable): continue if sort == 'reg' and not isinstance(var, SimRegisterVariable): continue variables.append(var) return variables
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:find_merge_points; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:function_addr; 5, identifier:function_endpoints; 6, identifier:graph; 7, block; 7, 8; 7, 14; 7, 39; 7, 49; 7, 59; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:merge_points; 11, call; 11, 12; 11, 13; 12, identifier:set; 13, argument_list; 14, for_statement; 14, 15; 14, 16; 14, 21; 15, identifier:node; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:graph; 19, identifier:nodes; 20, argument_list; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 31; 23, comparison_operator:>; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:graph; 27, identifier:in_degree; 28, argument_list; 28, 29; 29, identifier:node; 30, integer:1; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:merge_points; 36, identifier:add; 37, argument_list; 37, 38; 38, identifier:node; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:ordered_merge_points; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:CFGUtils; 45, identifier:quasi_topological_sort_nodes; 46, argument_list; 46, 47; 46, 48; 47, identifier:graph; 48, identifier:merge_points; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:addrs; 52, list_comprehension; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:n; 55, identifier:addr; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:n; 58, identifier:ordered_merge_points; 59, return_statement; 59, 60; 60, identifier:addrs
def find_merge_points(function_addr, function_endpoints, graph): merge_points = set() for node in graph.nodes(): if graph.in_degree(node) > 1: merge_points.add(node) ordered_merge_points = CFGUtils.quasi_topological_sort_nodes(graph, merge_points) addrs = [n.addr for n in ordered_merge_points] return addrs
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:reverse_post_order_sort_nodes; 3, parameters; 3, 4; 3, 5; 4, identifier:graph; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nodes; 7, None; 8, block; 8, 9; 8, 18; 8, 31; 8, 35; 8, 52; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:post_order; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:networkx; 15, identifier:dfs_postorder_nodes; 16, argument_list; 16, 17; 17, identifier:graph; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:nodes; 21, None; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:reversed; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:list; 29, argument_list; 29, 30; 30, identifier:post_order; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:addrs_to_index; 34, dictionary; 35, for_statement; 35, 36; 35, 39; 35, 43; 36, pattern_list; 36, 37; 36, 38; 37, identifier:i; 38, identifier:n; 39, call; 39, 40; 39, 41; 40, identifier:enumerate; 41, argument_list; 41, 42; 42, identifier:post_order; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 48; 47, identifier:addrs_to_index; 48, attribute; 48, 49; 48, 50; 49, identifier:n; 50, identifier:addr; 51, identifier:i; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:sorted; 55, argument_list; 55, 56; 55, 57; 55, 67; 56, identifier:nodes; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:key; 59, lambda; 59, 60; 59, 62; 60, lambda_parameters; 60, 61; 61, identifier:n; 62, subscript; 62, 63; 62, 64; 63, identifier:addrs_to_index; 64, attribute; 64, 65; 64, 66; 65, identifier:n; 66, identifier:addr; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:reverse; 69, True
def reverse_post_order_sort_nodes(graph, nodes=None): post_order = networkx.dfs_postorder_nodes(graph) if nodes is None: return reversed(list(post_order)) addrs_to_index = {} for i, n in enumerate(post_order): addrs_to_index[n.addr] = i return sorted(nodes, key=lambda n: addrs_to_index[n.addr], reverse=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:split; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stash_splitter; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:stash_ranker; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:state_ranker; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:limit; 16, integer:8; 17, default_parameter; 17, 18; 17, 19; 18, identifier:from_stash; 19, string:'active'; 20, default_parameter; 20, 21; 20, 22; 21, identifier:to_stash; 22, string:'stashed'; 23, block; 23, 24; 23, 35; 23, 126; 23, 138; 23, 145; 23, 153; 23, 161; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:states; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_fetch_states; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:stash; 34, identifier:from_stash; 35, if_statement; 35, 36; 35, 39; 35, 49; 35, 77; 35, 108; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:stash_splitter; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, pattern_list; 42, 43; 42, 44; 43, identifier:keep; 44, identifier:split; 45, call; 45, 46; 45, 47; 46, identifier:stash_splitter; 47, argument_list; 47, 48; 48, identifier:states; 49, elif_clause; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:stash_ranker; 52, None; 53, block; 53, 54; 53, 61; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:ranked_paths; 57, call; 57, 58; 57, 59; 58, identifier:stash_ranker; 59, argument_list; 59, 60; 60, identifier:states; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:keep; 65, identifier:split; 66, expression_list; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 69; 68, identifier:ranked_paths; 69, slice; 69, 70; 69, 71; 70, colon; 71, identifier:limit; 72, subscript; 72, 73; 72, 74; 73, identifier:ranked_paths; 74, slice; 74, 75; 74, 76; 75, identifier:limit; 76, colon; 77, elif_clause; 77, 78; 77, 81; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:state_ranker; 80, None; 81, block; 81, 82; 81, 92; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:ranked_paths; 85, call; 85, 86; 85, 87; 86, identifier:sorted; 87, argument_list; 87, 88; 87, 89; 88, identifier:states; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:key; 91, identifier:state_ranker; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, pattern_list; 94, 95; 94, 96; 95, identifier:keep; 96, identifier:split; 97, expression_list; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 100; 99, identifier:ranked_paths; 100, slice; 100, 101; 100, 102; 101, colon; 102, identifier:limit; 103, subscript; 103, 104; 103, 105; 104, identifier:ranked_paths; 105, slice; 105, 106; 105, 107; 106, identifier:limit; 107, colon; 108, else_clause; 108, 109; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, pattern_list; 112, 113; 112, 114; 113, identifier:keep; 114, identifier:split; 115, expression_list; 115, 116; 115, 121; 116, subscript; 116, 117; 116, 118; 117, identifier:states; 118, slice; 118, 119; 118, 120; 119, colon; 120, identifier:limit; 121, subscript; 121, 122; 121, 123; 122, identifier:states; 123, slice; 123, 124; 123, 125; 124, identifier:limit; 125, colon; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, pattern_list; 128, 129; 128, 130; 129, identifier:keep; 130, identifier:split; 131, call; 131, 132; 131, 133; 132, identifier:map; 133, argument_list; 133, 134; 133, 135; 134, identifier:list; 135, tuple; 135, 136; 135, 137; 136, identifier:keep; 137, identifier:split; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_clear_states; 143, argument_list; 143, 144; 144, identifier:from_stash; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:_store_states; 150, argument_list; 150, 151; 150, 152; 151, identifier:from_stash; 152, identifier:keep; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:_store_states; 158, argument_list; 158, 159; 158, 160; 159, identifier:to_stash; 160, identifier:split; 161, return_statement; 161, 162; 162, identifier:self
def split(self, stash_splitter=None, stash_ranker=None, state_ranker=None, limit=8, from_stash='active', to_stash='stashed'): states = self._fetch_states(stash=from_stash) if stash_splitter is not None: keep, split = stash_splitter(states) elif stash_ranker is not None: ranked_paths = stash_ranker(states) keep, split = ranked_paths[:limit], ranked_paths[limit:] elif state_ranker is not None: ranked_paths = sorted(states, key=state_ranker) keep, split = ranked_paths[:limit], ranked_paths[limit:] else: keep, split = states[:limit], states[limit:] keep, split = map(list, (keep, split)) self._clear_states(from_stash) self._store_states(from_stash, keep) self._store_states(to_stash, split) return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_executable_memory_regions; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:objects; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:force_segment; 10, False; 11, block; 11, 12; 11, 33; 11, 37; 11, 260; 11, 291; 11, 306; 12, if_statement; 12, 13; 12, 16; 12, 27; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:objects; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:binaries; 20, attribute; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:project; 25, identifier:loader; 26, identifier:all_objects; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:binaries; 32, identifier:objects; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:memory_regions; 36, list:[ ]; 37, for_statement; 37, 38; 37, 39; 37, 40; 38, identifier:b; 39, identifier:binaries; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 47; 41, 114; 41, 149; 41, 195; 41, 219; 41, 229; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:b; 46, identifier:ELF; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 55; 48, 84; 49, boolean_operator:and; 49, 50; 49, 52; 50, not_operator; 50, 51; 51, identifier:force_segment; 52, attribute; 52, 53; 52, 54; 53, identifier:b; 54, identifier:sections; 55, block; 55, 56; 56, for_statement; 56, 57; 56, 58; 56, 61; 57, identifier:section; 58, attribute; 58, 59; 58, 60; 59, identifier:b; 60, identifier:sections; 61, block; 61, 62; 62, if_statement; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:section; 65, identifier:is_executable; 66, block; 66, 67; 66, 77; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:tpl; 70, tuple; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:section; 73, identifier:min_addr; 74, attribute; 74, 75; 74, 76; 75, identifier:section; 76, identifier:max_addr; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:memory_regions; 81, identifier:append; 82, argument_list; 82, 83; 83, identifier:tpl; 84, else_clause; 84, 85; 85, block; 85, 86; 86, for_statement; 86, 87; 86, 88; 86, 91; 87, identifier:segment; 88, attribute; 88, 89; 88, 90; 89, identifier:b; 90, identifier:segments; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:segment; 95, identifier:is_executable; 96, block; 96, 97; 96, 107; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:tpl; 100, tuple; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:segment; 103, identifier:min_addr; 104, attribute; 104, 105; 104, 106; 105, identifier:segment; 106, identifier:max_addr; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:memory_regions; 111, identifier:append; 112, argument_list; 112, 113; 113, identifier:tpl; 114, elif_clause; 114, 115; 114, 120; 115, call; 115, 116; 115, 117; 116, identifier:isinstance; 117, argument_list; 117, 118; 117, 119; 118, identifier:b; 119, identifier:PE; 120, block; 120, 121; 121, for_statement; 121, 122; 121, 123; 121, 126; 122, identifier:section; 123, attribute; 123, 124; 123, 125; 124, identifier:b; 125, identifier:sections; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:section; 130, identifier:is_executable; 131, block; 131, 132; 131, 142; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:tpl; 135, tuple; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:section; 138, identifier:min_addr; 139, attribute; 139, 140; 139, 141; 140, identifier:section; 141, identifier:max_addr; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:memory_regions; 146, identifier:append; 147, argument_list; 147, 148; 148, identifier:tpl; 149, elif_clause; 149, 150; 149, 155; 150, call; 150, 151; 150, 152; 151, identifier:isinstance; 152, argument_list; 152, 153; 152, 154; 153, identifier:b; 154, identifier:MachO; 155, block; 155, 156; 156, if_statement; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:b; 159, identifier:segments; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 166; 162, identifier:seg; 163, attribute; 163, 164; 163, 165; 164, identifier:b; 165, identifier:segments; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:seg; 170, identifier:is_executable; 171, block; 171, 172; 172, for_statement; 172, 173; 172, 174; 172, 177; 173, identifier:section; 174, attribute; 174, 175; 174, 176; 175, identifier:seg; 176, identifier:sections; 177, block; 177, 178; 177, 188; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:tpl; 181, tuple; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:section; 184, identifier:min_addr; 185, attribute; 185, 186; 185, 187; 186, identifier:section; 187, identifier:max_addr; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:memory_regions; 192, identifier:append; 193, argument_list; 193, 194; 194, identifier:tpl; 195, elif_clause; 195, 196; 195, 201; 196, call; 196, 197; 196, 198; 197, identifier:isinstance; 198, argument_list; 198, 199; 198, 200; 199, identifier:b; 200, identifier:Blob; 201, block; 201, 202; 201, 212; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:tpl; 205, tuple; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:b; 208, identifier:min_addr; 209, attribute; 209, 210; 209, 211; 210, identifier:b; 211, identifier:max_addr; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:memory_regions; 216, identifier:append; 217, argument_list; 217, 218; 218, identifier:tpl; 219, elif_clause; 219, 220; 219, 227; 220, call; 220, 221; 220, 222; 221, identifier:isinstance; 222, argument_list; 222, 223; 222, 224; 223, identifier:b; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:_cle_pseudo_objects; 227, block; 227, 228; 228, pass_statement; 229, else_clause; 229, 230; 230, block; 230, 231; 230, 243; 230, 253; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:l; 235, identifier:warning; 236, argument_list; 236, 237; 236, 238; 237, string:'Unsupported object format "%s". Treat it as an executable.'; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:b; 241, identifier:__class__; 242, identifier:__name__; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:tpl; 246, tuple; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:b; 249, identifier:min_addr; 250, attribute; 250, 251; 250, 252; 251, identifier:b; 252, identifier:max_addr; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:memory_regions; 257, identifier:append; 258, argument_list; 258, 259; 259, identifier:tpl; 260, if_statement; 260, 261; 260, 263; 261, not_operator; 261, 262; 262, identifier:memory_regions; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:memory_regions; 267, list_comprehension; 267, 268; 267, 276; 268, tuple; 268, 269; 268, 270; 269, identifier:start; 270, binary_operator:+; 270, 271; 270, 272; 271, identifier:start; 272, call; 272, 273; 272, 274; 273, identifier:len; 274, argument_list; 274, 275; 275, identifier:backer; 276, for_in_clause; 276, 277; 276, 280; 277, pattern_list; 277, 278; 277, 279; 278, identifier:start; 279, identifier:backer; 280, call; 280, 281; 280, 290; 281, attribute; 281, 282; 281, 289; 282, attribute; 282, 283; 282, 288; 283, attribute; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:self; 286, identifier:project; 287, identifier:loader; 288, identifier:memory; 289, identifier:backers; 290, argument_list; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:memory_regions; 294, call; 294, 295; 294, 296; 295, identifier:sorted; 296, argument_list; 296, 297; 296, 298; 297, identifier:memory_regions; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:key; 300, lambda; 300, 301; 300, 303; 301, lambda_parameters; 301, 302; 302, identifier:x; 303, subscript; 303, 304; 303, 305; 304, identifier:x; 305, integer:0; 306, return_statement; 306, 307; 307, identifier:memory_regions
def _executable_memory_regions(self, objects=None, force_segment=False): if objects is None: binaries = self.project.loader.all_objects else: binaries = objects memory_regions = [ ] for b in binaries: if isinstance(b, ELF): if not force_segment and b.sections: for section in b.sections: if section.is_executable: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) else: for segment in b.segments: if segment.is_executable: tpl = (segment.min_addr, segment.max_addr) memory_regions.append(tpl) elif isinstance(b, PE): for section in b.sections: if section.is_executable: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) elif isinstance(b, MachO): if b.segments: for seg in b.segments: if seg.is_executable: for section in seg.sections: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) elif isinstance(b, Blob): tpl = (b.min_addr, b.max_addr) memory_regions.append(tpl) elif isinstance(b, self._cle_pseudo_objects): pass else: l.warning('Unsupported object format "%s". Treat it as an executable.', b.__class__.__name__) tpl = (b.min_addr, b.max_addr) memory_regions.append(tpl) if not memory_regions: memory_regions = [(start, start + len(backer)) for start, backer in self.project.loader.memory.backers()] memory_regions = sorted(memory_regions, key=lambda x: x[0]) return memory_regions
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_debug_check; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:old_end; 9, integer:0; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:old_sort; 13, string:""; 14, for_statement; 14, 15; 14, 16; 14, 19; 15, identifier:segment; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_list; 19, block; 19, 20; 19, 38; 19, 44; 20, if_statement; 20, 21; 20, 32; 21, boolean_operator:and; 21, 22; 21, 27; 22, comparison_operator:<=; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:segment; 25, identifier:start; 26, identifier:old_end; 27, comparison_operator:==; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:segment; 30, identifier:sort; 31, identifier:old_sort; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:AngrCFGError; 36, argument_list; 36, 37; 37, string:"Error in SegmentList: blocks are not merged"; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:old_end; 41, attribute; 41, 42; 41, 43; 42, identifier:segment; 43, identifier:end; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:old_sort; 47, attribute; 47, 48; 47, 49; 48, identifier:segment; 49, identifier:sort
def _debug_check(self): old_end = 0 old_sort = "" for segment in self._list: if segment.start <= old_end and segment.sort == old_sort: raise AngrCFGError("Error in SegmentList: blocks are not merged") old_end = segment.end old_sort = segment.sort
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:next_pos_with_sort_not_in; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:address; 6, identifier:sorts; 7, default_parameter; 7, 8; 7, 9; 8, identifier:max_distance; 9, None; 10, block; 10, 11; 10, 20; 10, 29; 10, 131; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:list_length; 14, call; 14, 15; 14, 16; 15, identifier:len; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:idx; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_search; 27, argument_list; 27, 28; 28, identifier:address; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:<; 30, 31; 30, 32; 31, identifier:idx; 32, identifier:list_length; 33, block; 33, 34; 33, 42; 33, 57; 33, 80; 33, 84; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:block; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_list; 41, identifier:idx; 42, if_statement; 42, 43; 42, 54; 43, boolean_operator:and; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:max_distance; 46, None; 47, comparison_operator:<; 47, 48; 47, 51; 48, binary_operator:+; 48, 49; 48, 50; 49, identifier:address; 50, identifier:max_distance; 51, attribute; 51, 52; 51, 53; 52, identifier:block; 53, identifier:start; 54, block; 54, 55; 55, return_statement; 55, 56; 56, None; 57, if_statement; 57, 58; 57, 66; 58, comparison_operator:<=; 58, 59; 58, 62; 58, 63; 59, attribute; 59, 60; 59, 61; 60, identifier:block; 61, identifier:start; 62, identifier:address; 63, attribute; 63, 64; 63, 65; 64, identifier:block; 65, identifier:end; 66, block; 66, 67; 66, 76; 67, if_statement; 67, 68; 67, 73; 68, comparison_operator:not; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:block; 71, identifier:sort; 72, identifier:sorts; 73, block; 73, 74; 74, return_statement; 74, 75; 75, identifier:address; 76, expression_statement; 76, 77; 77, augmented_assignment:+=; 77, 78; 77, 79; 78, identifier:idx; 79, integer:1; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:i; 83, identifier:idx; 84, while_statement; 84, 85; 84, 88; 85, comparison_operator:<; 85, 86; 85, 87; 86, identifier:i; 87, identifier:list_length; 88, block; 88, 89; 88, 108; 88, 127; 89, if_statement; 89, 90; 89, 105; 90, boolean_operator:and; 90, 91; 90, 94; 91, comparison_operator:is; 91, 92; 91, 93; 92, identifier:max_distance; 93, None; 94, comparison_operator:<; 94, 95; 94, 98; 95, binary_operator:+; 95, 96; 95, 97; 96, identifier:address; 97, identifier:max_distance; 98, attribute; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_list; 103, identifier:i; 104, identifier:start; 105, block; 105, 106; 106, return_statement; 106, 107; 107, None; 108, if_statement; 108, 109; 108, 118; 109, comparison_operator:not; 109, 110; 109, 117; 110, attribute; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_list; 115, identifier:i; 116, identifier:sort; 117, identifier:sorts; 118, block; 118, 119; 119, return_statement; 119, 120; 120, attribute; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_list; 125, identifier:i; 126, identifier:start; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 130; 129, identifier:i; 130, integer:1; 131, return_statement; 131, 132; 132, None
def next_pos_with_sort_not_in(self, address, sorts, max_distance=None): list_length = len(self._list) idx = self._search(address) if idx < list_length: block = self._list[idx] if max_distance is not None and address + max_distance < block.start: return None if block.start <= address < block.end: if block.sort not in sorts: return address idx += 1 i = idx while i < list_length: if max_distance is not None and address + max_distance < self._list[i].start: return None if self._list[i].sort not in sorts: return self._list[i].start i += 1 return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:occupied_by_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:address; 6, block; 6, 7; 6, 16; 6, 28; 6, 54; 6, 81; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:idx; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_search; 14, argument_list; 14, 15; 15, identifier:address; 16, if_statement; 16, 17; 16, 25; 17, comparison_operator:<=; 17, 18; 17, 24; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_list; 24, identifier:idx; 25, block; 25, 26; 26, return_statement; 26, 27; 27, None; 28, if_statement; 28, 29; 28, 45; 29, comparison_operator:<=; 29, 30; 29, 37; 29, 38; 30, attribute; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_list; 35, identifier:idx; 36, identifier:start; 37, identifier:address; 38, attribute; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_list; 43, identifier:idx; 44, identifier:end; 45, block; 45, 46; 46, return_statement; 46, 47; 47, attribute; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_list; 52, identifier:idx; 53, identifier:sort; 54, if_statement; 54, 55; 54, 70; 55, boolean_operator:and; 55, 56; 55, 59; 56, comparison_operator:>; 56, 57; 56, 58; 57, identifier:idx; 58, integer:0; 59, comparison_operator:<; 59, 60; 59, 61; 60, identifier:address; 61, attribute; 61, 62; 61, 69; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_list; 66, binary_operator:-; 66, 67; 66, 68; 67, identifier:idx; 68, integer:1; 69, identifier:end; 70, block; 70, 71; 71, return_statement; 71, 72; 72, attribute; 72, 73; 72, 80; 73, subscript; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_list; 77, binary_operator:-; 77, 78; 77, 79; 78, identifier:idx; 79, integer:1; 80, identifier:sort; 81, return_statement; 81, 82; 82, None
def occupied_by_sort(self, address): idx = self._search(address) if len(self._list) <= idx: return None if self._list[idx].start <= address < self._list[idx].end: return self._list[idx].sort if idx > 0 and address < self._list[idx - 1].end: return self._list[idx - 1].sort return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_binary_insert; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:lst; 5, identifier:elem; 6, identifier:key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:lo; 9, integer:0; 10, default_parameter; 10, 11; 10, 12; 11, identifier:hi; 12, None; 13, block; 13, 14; 13, 24; 13, 36; 13, 75; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:<; 15, 16; 15, 17; 16, identifier:lo; 17, integer:0; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:ValueError; 22, argument_list; 22, 23; 23, string:"lo must be a non-negative number"; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:hi; 27, None; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:hi; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, identifier:lst; 36, while_statement; 36, 37; 36, 40; 37, comparison_operator:<; 37, 38; 37, 39; 38, identifier:lo; 39, identifier:hi; 40, block; 40, 41; 40, 50; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:mid; 44, binary_operator://; 44, 45; 44, 49; 45, parenthesized_expression; 45, 46; 46, binary_operator:+; 46, 47; 46, 48; 47, identifier:lo; 48, identifier:hi; 49, integer:2; 50, if_statement; 50, 51; 50, 62; 50, 69; 51, comparison_operator:<; 51, 52; 51, 58; 52, call; 52, 53; 52, 54; 53, identifier:key; 54, argument_list; 54, 55; 55, subscript; 55, 56; 55, 57; 56, identifier:lst; 57, identifier:mid; 58, call; 58, 59; 58, 60; 59, identifier:key; 60, argument_list; 60, 61; 61, identifier:elem; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:lo; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:mid; 68, integer:1; 69, else_clause; 69, 70; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:hi; 74, identifier:mid; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:lst; 79, identifier:insert; 80, argument_list; 80, 81; 80, 82; 81, identifier:lo; 82, identifier:elem
def _binary_insert(lst, elem, key, lo=0, hi=None): if lo < 0: raise ValueError("lo must be a non-negative number") if hi is None: hi = len(lst) while lo < hi: mid = (lo + hi) // 2 if key(lst[mid]) < key(elem): lo = mid + 1 else: hi = mid lst.insert(lo, elem)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_sort_io_counters; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:process; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sortedby; 7, string:'io_counters'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sortedby_secondary; 10, string:'memory_percent'; 11, block; 11, 12; 12, return_statement; 12, 13; 13, binary_operator:-; 13, 14; 13, 31; 14, binary_operator:+; 14, 15; 14, 26; 15, binary_operator:-; 15, 16; 15, 21; 16, subscript; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:process; 19, identifier:sortedby; 20, integer:0; 21, subscript; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:process; 24, identifier:sortedby; 25, integer:2; 26, subscript; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:process; 29, identifier:sortedby; 30, integer:1; 31, subscript; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:process; 34, identifier:sortedby; 35, integer:3
def _sort_io_counters(process, sortedby='io_counters', sortedby_secondary='memory_percent'): return process[sortedby][0] - process[sortedby][2] + process[sortedby][1] - process[sortedby][3]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_sort_lambda; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:sortedby; 6, string:'cpu_percent'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sortedby_secondary; 9, string:'memory_percent'; 10, block; 10, 11; 10, 15; 10, 33; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:ret; 14, None; 15, if_statement; 15, 16; 15, 19; 15, 24; 16, comparison_operator:==; 16, 17; 16, 18; 17, identifier:sortedby; 18, string:'io_counters'; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ret; 23, identifier:_sort_io_counters; 24, elif_clause; 24, 25; 24, 28; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:sortedby; 27, string:'cpu_times'; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:ret; 32, identifier:_sort_cpu_times; 33, return_statement; 33, 34; 34, identifier:ret
def _sort_lambda(sortedby='cpu_percent', sortedby_secondary='memory_percent'): ret = None if sortedby == 'io_counters': ret = _sort_io_counters elif sortedby == 'cpu_times': ret = _sort_cpu_times return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:loop_position; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 26; 6, for_statement; 6, 7; 6, 10; 6, 16; 7, pattern_list; 7, 8; 7, 9; 8, identifier:i; 9, identifier:v; 10, call; 10, 11; 10, 12; 11, identifier:enumerate; 12, argument_list; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_sort_loop; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:v; 20, attribute; 20, 21; 20, 22; 21, identifier:glances_processes; 22, identifier:sort_key; 23, block; 23, 24; 24, return_statement; 24, 25; 25, identifier:i; 26, return_statement; 26, 27; 27, integer:0
def loop_position(self): for i, v in enumerate(self._sort_loop): if v == glances_processes.sort_key: return i return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_event_sort_key; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:event_type; 6, block; 6, 7; 6, 37; 7, if_statement; 7, 8; 7, 14; 7, 19; 7, 31; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:event_type; 11, identifier:startswith; 12, argument_list; 12, 13; 13, string:"MEM"; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:ret; 18, string:'memory_percent'; 19, elif_clause; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:event_type; 23, identifier:startswith; 24, argument_list; 24, 25; 25, string:"CPU_IOWAIT"; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:ret; 30, string:'io_counters'; 31, else_clause; 31, 32; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:ret; 36, string:'cpu_percent'; 37, return_statement; 37, 38; 38, identifier:ret
def get_event_sort_key(self, event_type): if event_type.startswith("MEM"): ret = 'memory_percent' elif event_type.startswith("CPU_IOWAIT"): ret = 'io_counters' else: ret = 'cpu_percent' return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:set_process_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:event_type; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:glances_processes; 10, identifier:auto_sort; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:glances_processes; 16, identifier:sort_key; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:get_event_sort_key; 21, argument_list; 21, 22; 22, identifier:event_type
def set_process_sort(self, event_type): if glances_processes.auto_sort: glances_processes.sort_key = self.get_event_sort_key(event_type)