idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
18,300
def starting_at ( self , datetime_or_str ) : if isinstance ( datetime_or_str , str ) : self . _starting_at = parse ( datetime_or_str ) elif isinstance ( datetime_or_str , datetime . datetime ) : self . _starting_at = datetime_or_str else : raise ValueError ( '.starting_at() method can only take strings or datetime obje...
Set the starting time for the cron job . If not specified the starting time will always be the beginning of the interval that is current when the cron is started .
18,301
def run ( self , func , * func_args , ** func__kwargs ) : self . _func = func self . _func_args = func_args self . _func_kwargs = func__kwargs return self
Specify the function to run at the scheduled times
18,302
def _get_target ( self ) : if None in [ self . _func , self . _func_kwargs , self . _func_kwargs , self . _every_kwargs ] : raise ValueError ( 'You must call the .every() and .run() methods on every tab.' ) return self . _loop
returns a callable with no arguments designed to be the target of a Subprocess
18,303
def wrapped_target ( target , q_stdout , q_stderr , q_error , robust , name , * args , ** kwargs ) : import sys sys . stdout = IOQueue ( q_stdout ) sys . stderr = IOQueue ( q_stderr ) try : target ( * args , ** kwargs ) except : if not robust : s = 'Error in tab\n' + traceback . format_exc ( ) logger = daiquiri . getLo...
Wraps a target with queues replacing stdout and stderr
18,304
def loop ( self , max_seconds = None ) : loop_started = datetime . datetime . now ( ) self . _is_running = True while self . _is_running : self . process_error_queue ( self . q_error ) if max_seconds is not None : if ( datetime . datetime . now ( ) - loop_started ) . total_seconds ( ) > max_seconds : break for subproce...
Main loop for the process . This will run continuously until maxiter
18,305
def escape ( string , escape_pattern ) : try : return string . translate ( escape_pattern ) except AttributeError : warnings . warn ( "Non-string-like data passed. " "Attempting to convert to 'str'." ) return str ( string ) . translate ( tag_escape )
Assistant function for string escaping
18,306
def _make_serializer ( meas , schema , rm_none , extra_tags , placeholder ) : _validate_schema ( schema , placeholder ) tags = [ ] fields = [ ] ts = None meas = meas for k , t in schema . items ( ) : if t is MEASUREMENT : meas = f"{{i.{k}}}" elif t is TIMEINT : ts = f"{{i.{k}}}" elif t is TIMESTR : if pd : ts = f"{{pd....
Factory of line protocol parsers
18,307
def lineprotocol ( cls = None , * , schema : Optional [ Mapping [ str , type ] ] = None , rm_none : bool = False , extra_tags : Optional [ Mapping [ str , str ] ] = None , placeholder : bool = False ) : def _lineprotocol ( cls ) : _schema = schema or getattr ( cls , '__annotations__' , { } ) f = _make_serializer ( cls ...
Adds to_lineprotocol method to arbitrary user - defined classes
18,308
def _serialize_fields ( point ) : output = [ ] for k , v in point [ 'fields' ] . items ( ) : k = escape ( k , key_escape ) if isinstance ( v , bool ) : output . append ( f'{k}={v}' ) elif isinstance ( v , int ) : output . append ( f'{k}={v}i' ) elif isinstance ( v , str ) : output . append ( f'{k}="{v.translate(str_esc...
Field values can be floats integers strings or Booleans .
18,309
def serialize ( data , measurement = None , tag_columns = None , ** extra_tags ) : if isinstance ( data , bytes ) : return data elif isinstance ( data , str ) : return data . encode ( 'utf-8' ) elif hasattr ( data , 'to_lineprotocol' ) : return data . to_lineprotocol ( ) elif pd is not None and isinstance ( data , pd ....
Converts input data into line protocol format
18,310
def iterpoints ( resp : dict , parser : Optional [ Callable ] = None ) -> Iterator [ Any ] : for statement in resp [ 'results' ] : if 'series' not in statement : continue for series in statement [ 'series' ] : if parser is None : return ( x for x in series [ 'values' ] ) elif 'meta' in inspect . signature ( parser ) . ...
Iterates a response JSON yielding data point by point .
18,311
def parse ( resp ) -> DataFrameType : statements = [ ] for statement in resp [ 'results' ] : series = { } for s in statement . get ( 'series' , [ ] ) : series [ _get_name ( s ) ] = _drop_zero_index ( _serializer ( s ) ) statements . append ( series ) if len ( statements ) == 1 : series : dict = statements [ 0 ] if len ...
Makes a dictionary of DataFrames from a response object
18,312
def _itertuples ( df ) : cols = [ df . iloc [ : , k ] for k in range ( len ( df . columns ) ) ] return zip ( df . index , * cols )
Custom implementation of DataFrame . itertuples that returns plain tuples instead of namedtuples . About 50% faster .
18,313
def serialize ( df , measurement , tag_columns = None , ** extra_tags ) -> bytes : if measurement is None : raise ValueError ( "Missing 'measurement'" ) if not isinstance ( df . index , pd . DatetimeIndex ) : raise ValueError ( 'DataFrame index is not DatetimeIndex' ) tag_columns = set ( tag_columns or [ ] ) isnull = d...
Converts a Pandas DataFrame into line protocol format
18,314
def runner ( coro ) : @ wraps ( coro ) def inner ( self , * args , ** kwargs ) : if self . mode == 'async' : return coro ( self , * args , ** kwargs ) return self . _loop . run_until_complete ( coro ( self , * args , ** kwargs ) ) return inner
Function execution decorator .
18,315
def _check_error ( response ) : if 'error' in response : raise InfluxDBError ( response [ 'error' ] ) elif 'results' in response : for statement in response [ 'results' ] : if 'error' in statement : msg = '{d[error]} (statement {d[statement_id]})' raise InfluxDBError ( msg . format ( d = statement ) )
Checks for JSON error messages and raises Python exception
18,316
def create_magic_packet ( macaddress ) : if len ( macaddress ) == 12 : pass elif len ( macaddress ) == 17 : sep = macaddress [ 2 ] macaddress = macaddress . replace ( sep , '' ) else : raise ValueError ( 'Incorrect MAC address format' ) data = b'FFFFFFFFFFFF' + ( macaddress * 16 ) . encode ( ) send_data = b'' for i in ...
Create a magic packet .
18,317
def send_magic_packet ( * macs , ** kwargs ) : packets = [ ] ip = kwargs . pop ( 'ip_address' , BROADCAST_IP ) port = kwargs . pop ( 'port' , DEFAULT_PORT ) for k in kwargs : raise TypeError ( 'send_magic_packet() got an unexpected keyword ' 'argument {!r}' . format ( k ) ) for mac in macs : packet = create_magic_packe...
Wake up computers having any of the given mac addresses .
18,318
def main ( argv = None ) : parser = argparse . ArgumentParser ( description = 'Wake one or more computers using the wake on lan' ' protocol.' ) parser . add_argument ( 'macs' , metavar = 'mac address' , nargs = '+' , help = 'The mac addresses or of the computers you are trying to wake.' ) parser . add_argument ( '-i' ,...
Run wake on lan as a CLI application .
18,319
def mjml ( parser , token ) : nodelist = parser . parse ( ( 'endmjml' , ) ) parser . delete_first_token ( ) tokens = token . split_contents ( ) if len ( tokens ) != 1 : raise template . TemplateSyntaxError ( "'%r' tag doesn't receive any arguments." % tokens [ 0 ] ) return MJMLRenderNode ( nodelist )
Compile MJML template after render django template .
18,320
def parse_header_line ( self , line ) : self . header = line [ 1 : ] . rstrip ( ) . split ( '\t' ) if len ( self . header ) < 9 : self . header = line [ 1 : ] . rstrip ( ) . split ( ) self . individuals = self . header [ 9 : ]
docstring for parse_header_line
18,321
def print_header ( self ) : lines_to_print = [ ] lines_to_print . append ( '##fileformat=' + self . fileformat ) if self . filedate : lines_to_print . append ( '##fileformat=' + self . fileformat ) for filt in self . filter_dict : lines_to_print . append ( self . filter_dict [ filt ] ) for form in self . format_dict : ...
Returns a list with the header lines if proper format
18,322
def add_variant ( self , chrom , pos , rs_id , ref , alt , qual , filt , info , form = None , genotypes = [ ] ) : variant_info = [ chrom , pos , rs_id , ref , alt , qual , filt , info ] if form : variant_info . append ( form ) for individual in genotypes : variant_info . append ( individual ) variant_line = '\t' . join...
Add a variant to the parser . This function is for building a vcf . It takes the relevant parameters and make a vcf variant in the proper format .
18,323
def content_get ( self , cid , nid = None ) : r = self . request ( method = "content.get" , data = { "cid" : cid } , nid = nid ) return self . _handle_error ( r , "Could not get post {}." . format ( cid ) )
Get data from post cid in network nid
18,324
def content_create ( self , params ) : r = self . request ( method = "content.create" , data = params ) return self . _handle_error ( r , "Could not create object {}." . format ( repr ( params ) ) )
Create a post or followup .
18,325
def add_students ( self , student_emails , nid = None ) : r = self . request ( method = "network.update" , data = { "from" : "ClassSettingsPage" , "add_students" : student_emails } , nid = nid , nid_key = "id" ) return self . _handle_error ( r , "Could not add users." )
Enroll students in a network nid .
18,326
def get_all_users ( self , nid = None ) : r = self . request ( method = "network.get_all_users" , nid = nid ) return self . _handle_error ( r , "Could not get users." )
Get a listing of data for each user in a network nid
18,327
def get_users ( self , user_ids , nid = None ) : r = self . request ( method = "network.get_users" , data = { "ids" : user_ids } , nid = nid ) return self . _handle_error ( r , "Could not get users." )
Get a listing of data for specific users user_ids in a network nid
18,328
def remove_users ( self , user_ids , nid = None ) : r = self . request ( method = "network.update" , data = { "remove_users" : user_ids } , nid = nid , nid_key = "id" ) return self . _handle_error ( r , "Could not remove users." )
Remove users from a network nid
18,329
def get_my_feed ( self , limit = 150 , offset = 20 , sort = "updated" , nid = None ) : r = self . request ( method = "network.get_my_feed" , nid = nid , data = dict ( limit = limit , offset = offset , sort = sort ) ) return self . _handle_error ( r , "Could not retrieve your feed." )
Get my feed
18,330
def filter_feed ( self , updated = False , following = False , folder = False , filter_folder = "" , sort = "updated" , nid = None ) : assert sum ( [ updated , following , folder ] ) == 1 if folder : assert filter_folder if updated : filter_type = dict ( updated = 1 ) elif following : filter_type = dict ( following = 1...
Get filtered feed
18,331
def search ( self , query , nid = None ) : r = self . request ( method = "network.search" , nid = nid , data = dict ( query = query ) ) return self . _handle_error ( r , "Search with query '{}' failed." . format ( query ) )
Search for posts with query
18,332
def get_stats ( self , nid = None ) : r = self . request ( api_type = "main" , method = "network.get_stats" , nid = nid , ) return self . _handle_error ( r , "Could not retrieve stats for class." )
Get statistics for class
18,333
def request ( self , method , data = None , nid = None , nid_key = 'nid' , api_type = "logic" , return_response = False ) : self . _check_authenticated ( ) nid = nid if nid else self . _nid if data is None : data = { } headers = { } if "session_id" in self . session . cookies : headers [ "CSRF-Token" ] = self . session...
Get data from arbitrary Piazza API endpoint method in network nid
18,334
def _handle_error ( self , result , err_msg ) : if result . get ( u'error' ) : raise RequestError ( "{}\nResponse: {}" . format ( err_msg , json . dumps ( result , indent = 2 ) ) ) else : return result . get ( u'result' )
Check result for error
18,335
def get_user_classes ( self ) : status = self . get_user_status ( ) uid = status [ 'id' ] raw_classes = status . get ( 'networks' , [ ] ) classes = [ ] for rawc in raw_classes : c = { k : rawc [ k ] for k in [ 'name' , 'term' ] } c [ 'num' ] = rawc . get ( 'course_number' , '' ) c [ 'nid' ] = rawc [ 'id' ] c [ 'is_ta' ...
Get list of the current user s classes . This is a subset of the information returned by the call to get_user_status .
18,336
def nonce ( ) : nonce_part1 = _int2base ( int ( _time ( ) * 1000 ) , 36 ) nonce_part2 = _int2base ( round ( _random ( ) * 1679616 ) , 36 ) return "{}{}" . format ( nonce_part1 , nonce_part2 )
Returns a new nonce to be used with the Piazza API .
18,337
def iter_all_posts ( self , limit = None ) : feed = self . get_feed ( limit = 999999 , offset = 0 ) cids = [ post [ 'id' ] for post in feed [ "feed" ] ] if limit is not None : cids = cids [ : limit ] for cid in cids : yield self . get_post ( cid )
Get all posts visible to the current user
18,338
def create_post ( self , post_type , post_folders , post_subject , post_content , is_announcement = 0 , bypass_email = 0 , anonymous = False ) : params = { "anonymous" : "yes" if anonymous else "no" , "subject" : post_subject , "content" : post_content , "folders" : post_folders , "type" : post_type , "config" : { "byp...
Create a post
18,339
def create_followup ( self , post , content , anonymous = False ) : try : cid = post [ "id" ] except KeyError : cid = post params = { "cid" : cid , "type" : "followup" , "subject" : content , "content" : "" , "anonymous" : "yes" if anonymous else "no" , } return self . _rpc . content_create ( params )
Create a follow - up on a post post .
18,340
def create_instructor_answer ( self , post , content , revision , anonymous = False ) : try : cid = post [ "id" ] except KeyError : cid = post params = { "cid" : cid , "type" : "i_answer" , "content" : content , "revision" : revision , "anonymous" : "yes" if anonymous else "no" , } return self . _rpc . content_instruct...
Create an instructor s answer to a post post .
18,341
def mark_as_duplicate ( self , duplicated_cid , master_cid , msg = '' ) : content_id_from = self . get_post ( duplicated_cid ) [ "id" ] content_id_to = self . get_post ( master_cid ) [ "id" ] params = { "cid_dupe" : content_id_from , "cid_to" : content_id_to , "msg" : msg } return self . _rpc . content_mark_duplicate (...
Mark the post at duplicated_cid as a duplicate of master_cid
18,342
def resolve_post ( self , post ) : try : cid = post [ "id" ] except KeyError : cid = post params = { "cid" : cid , "resolved" : "true" } return self . _rpc . content_mark_resolved ( params )
Mark post as resolved
18,343
def delete_post ( self , post ) : try : cid = post [ 'id' ] except KeyError : cid = post except TypeError : post = self . get_post ( post ) cid = post [ 'id' ] params = { "cid" : cid , } return self . _rpc . content_delete ( params )
Deletes post by cid
18,344
def get_feed ( self , limit = 100 , offset = 0 ) : return self . _rpc . get_my_feed ( limit = limit , offset = offset )
Get your feed for this network
18,345
def get_filtered_feed ( self , feed_filter ) : assert isinstance ( feed_filter , ( UnreadFilter , FollowingFilter , FolderFilter ) ) return self . _rpc . filter_feed ( ** feed_filter . to_kwargs ( ) )
Get your feed containing only posts filtered by feed_filter
18,346
def get_dataset ( self , dataset ) : success = True dataset_path = self . base_dataset_path + dataset if not isdir ( dataset_path ) : was_error = False for iteration in range ( 5 ) : if iteration == 0 or was_error is True : zip_path = dataset_path + ".zip" if not isfile ( zip_path ) : try : with DLProgress ( unit = 'B'...
Checks to see if the dataset is present . If not it downloads and unzips it .
18,347
def first_plugin_context ( self ) : first_spf_reg = next ( iter ( self . registrations ) ) return self . get_context_from_spf ( first_spf_reg )
Returns the context is associated with the first app this plugin was registered on
18,348
async def route_wrapper ( self , route , request , context , request_args , request_kw , * decorator_args , with_context = None , ** decorator_kw ) : if with_context : resp = route ( request , context , * request_args , ** request_kw ) else : resp = route ( request , * request_args , ** request_kw ) if isawaitable ( re...
This is the function that is called when a route is decorated with your plugin decorator . Context will normally be None but the user can pass use_context = True so the route will get the plugin context
18,349
def check_credentials ( client ) : pid , uid , gid = get_peercred ( client ) euid = os . geteuid ( ) client_name = "PID:%s UID:%s GID:%s" % ( pid , uid , gid ) if uid not in ( 0 , euid ) : raise SuspiciousClient ( "Can't accept client with %s. It doesn't match the current EUID:%s or ROOT." % ( client_name , euid ) ) _L...
Checks credentials for given socket .
18,350
def handle_connection_exec ( client ) : class ExitExecLoop ( Exception ) : pass def exit ( ) : raise ExitExecLoop ( ) client . settimeout ( None ) fh = os . fdopen ( client . detach ( ) if hasattr ( client , 'detach' ) else client . fileno ( ) ) with closing ( client ) : with closing ( fh ) : try : payload = fh . readl...
Alternate connection handler . No output redirection .
18,351
def handle_connection_repl ( client ) : client . settimeout ( None ) backup = [ ] old_interval = getinterval ( ) patches = [ ( 'r' , ( 'stdin' , '__stdin__' ) ) , ( 'w' , ( 'stdout' , '__stdout__' ) ) ] if _MANHOLE . redirect_stderr : patches . append ( ( 'w' , ( 'stderr' , '__stderr__' ) ) ) try : client_fd = client ....
Handles connection .
18,352
def install ( verbose = True , verbose_destination = sys . __stderr__ . fileno ( ) if hasattr ( sys . __stderr__ , 'fileno' ) else sys . __stderr__ , strict = True , ** kwargs ) : global _MANHOLE with _LOCK : if _MANHOLE is None : _MANHOLE = Manhole ( ) else : if strict : raise AlreadyInstalled ( "Manhole already insta...
Installs the manhole .
18,353
def dump_stacktraces ( ) : lines = [ ] for thread_id , stack in sys . _current_frames ( ) . items ( ) : lines . append ( "\n######### ProcessID=%s, ThreadID=%s #########" % ( os . getpid ( ) , thread_id ) ) for filename , lineno , name , line in traceback . extract_stack ( stack ) : lines . append ( 'File: "%s", line %...
Dumps thread ids and tracebacks to stdout .
18,354
def clone ( self , ** kwargs ) : return ManholeThread ( self . get_socket , self . sigmask , self . start_timeout , connection_handler = self . connection_handler , daemon_connection = self . daemon_connection , ** kwargs )
Make a fresh thread with the same options . This is usually used on dead threads .
18,355
def reinstall ( self ) : with _LOCK : if not ( self . thread . is_alive ( ) and self . thread in _ORIGINAL__ACTIVE ) : self . thread = self . thread . clone ( bind_delay = self . reinstall_delay ) if self . should_restart : self . thread . start ( )
Reinstalls the manhole . Checks if the thread is running . If not it starts it again .
18,356
def patched_forkpty ( self ) : pid , master_fd = self . original_os_forkpty ( ) if not pid : _LOG ( 'Fork detected. Reinstalling Manhole.' ) self . reinstall ( ) return pid , master_fd
Fork a new process with a new pseudo - terminal as controlling tty .
18,357
def update ( self , alert_condition_nrql_id , policy_id , name = None , threshold_type = None , query = None , since_value = None , terms = None , expected_groups = None , value_function = None , runbook_url = None , ignore_overlap = None , enabled = True ) : conditions_nrql_dict = self . list ( policy_id ) target_cond...
Updates any of the optional parameters of the alert condition nrql
18,358
def create ( self , policy_id , name , threshold_type , query , since_value , terms , expected_groups = None , value_function = None , runbook_url = None , ignore_overlap = None , enabled = True ) : data = { 'nrql_condition' : { 'type' : threshold_type , 'name' : name , 'enabled' : enabled , 'terms' : terms , 'nrql' : ...
Creates an alert condition nrql
18,359
def delete ( self , alert_condition_nrql_id ) : return self . _delete ( url = '{0}alerts_nrql_conditions/{1}.json' . format ( self . URL , alert_condition_nrql_id ) , headers = self . headers )
This API endpoint allows you to delete an alert condition nrql
18,360
def list ( self , filter_name = None , filter_ids = None , filter_labels = None , page = None ) : label_param = '' if filter_labels : label_param = ';' . join ( [ '{}:{}' . format ( label , value ) for label , value in filter_labels . items ( ) ] ) filters = [ 'filter[name]={0}' . format ( filter_name ) if filter_name ...
This API endpoint returns a paginated list of the Servers associated with your New Relic account . Servers can be filtered by their name or by a list of server IDs .
18,361
def update ( self , id , name = None ) : nr_data = self . show ( id ) [ 'server' ] data = { 'server' : { 'name' : name or nr_data [ 'name' ] , } } return self . _put ( url = '{0}servers/{1}.json' . format ( self . URL , id ) , headers = self . headers , data = data )
Updates any of the optional parameters of the server
18,362
def create ( self , name , incident_preference ) : data = { "policy" : { "name" : name , "incident_preference" : incident_preference } } return self . _post ( url = '{0}alerts_policies.json' . format ( self . URL ) , headers = self . headers , data = data )
This API endpoint allows you to create an alert policy
18,363
def update ( self , id , name , incident_preference ) : data = { "policy" : { "name" : name , "incident_preference" : incident_preference } } return self . _put ( url = '{0}alerts_policies/{1}.json' . format ( self . URL , id ) , headers = self . headers , data = data )
This API endpoint allows you to update an alert policy
18,364
def delete ( self , id ) : return self . _delete ( url = '{0}alerts_policies/{1}.json' . format ( self . URL , id ) , headers = self . headers )
This API endpoint allows you to delete an alert policy
18,365
def associate_with_notification_channel ( self , id , channel_id ) : return self . _put ( url = '{0}alerts_policy_channels.json?policy_id={1}&channel_ids={2}' . format ( self . URL , id , channel_id ) , headers = self . headers )
This API endpoint allows you to associate an alert policy with an notification channel
18,366
def dissociate_from_notification_channel ( self , id , channel_id ) : return self . _delete ( url = '{0}alerts_policy_channels.json?policy_id={1}&channel_id={2}' . format ( self . URL , id , channel_id ) , headers = self . headers )
This API endpoint allows you to dissociate an alert policy from an notification channel
18,367
def list ( self , policy_id , page = None ) : filters = [ 'policy_id={0}' . format ( policy_id ) , 'page={0}' . format ( page ) if page else None ] return self . _get ( url = '{0}alerts_conditions.json' . format ( self . URL ) , headers = self . headers , params = self . build_param_string ( filters ) )
This API endpoint returns a paginated list of alert conditions associated with the given policy_id .
18,368
def update ( self , alert_condition_id , policy_id , type = None , condition_scope = None , name = None , entities = None , metric = None , runbook_url = None , terms = None , user_defined = None , enabled = None ) : conditions_dict = self . list ( policy_id ) target_condition = None for condition in conditions_dict [ ...
Updates any of the optional parameters of the alert condition
18,369
def create ( self , policy_id , type , condition_scope , name , entities , metric , terms , runbook_url = None , user_defined = None , enabled = True ) : data = { 'condition' : { 'type' : type , 'name' : name , 'enabled' : enabled , 'entities' : entities , 'condition_scope' : condition_scope , 'terms' : terms , 'metric...
Creates an alert condition
18,370
def delete ( self , alert_condition_id ) : return self . _delete ( url = '{0}alerts_conditions/{1}.json' . format ( self . URL , alert_condition_id ) , headers = self . headers )
This API endpoint allows you to delete an alert condition
18,371
def list ( self , policy_id , limit = None , offset = None ) : filters = [ 'policy_id={0}' . format ( policy_id ) , 'limit={0}' . format ( limit ) if limit else '50' , 'offset={0}' . format ( offset ) if offset else '0' ] return self . _get ( url = '{0}alerts/conditions' . format ( self . URL ) , headers = self . heade...
This API endpoint returns a paginated list of alert conditions for infrastucture metrics associated with the given policy_id .
18,372
def show ( self , alert_condition_infra_id ) : return self . _get ( url = '{0}alerts/conditions/{1}' . format ( self . URL , alert_condition_infra_id ) , headers = self . headers , )
This API endpoint returns an alert condition for infrastucture identified by its ID .
18,373
def create ( self , policy_id , name , condition_type , alert_condition_configuration , enabled = True ) : data = { "data" : alert_condition_configuration } data [ 'data' ] [ 'type' ] = condition_type data [ 'data' ] [ 'policy_id' ] = policy_id data [ 'data' ] [ 'name' ] = name data [ 'data' ] [ 'enabled' ] = enabled r...
This API endpoint allows you to create an alert condition for infrastucture
18,374
def update ( self , alert_condition_infra_id , policy_id , name , condition_type , alert_condition_configuration , enabled = True ) : data = { "data" : alert_condition_configuration } data [ 'data' ] [ 'type' ] = condition_type data [ 'data' ] [ 'policy_id' ] = policy_id data [ 'data' ] [ 'name' ] = name data [ 'data' ...
This API endpoint allows you to update an alert condition for infrastucture
18,375
def delete ( self , alert_condition_infra_id ) : return self . _delete ( url = '{0}alerts/conditions/{1}' . format ( self . URL , alert_condition_infra_id ) , headers = self . headers )
This API endpoint allows you to delete an alert condition for infrastucture
18,376
def create ( self , name , category , applications = None , servers = None ) : data = { "label" : { "category" : category , "name" : name , "links" : { "applications" : applications or [ ] , "servers" : servers or [ ] } } } return self . _put ( url = '{0}labels.json' . format ( self . URL ) , headers = self . headers ,...
This API endpoint will create a new label with the provided name and category
18,377
def delete ( self , key ) : return self . _delete ( url = '{url}labels/labels/{key}.json' . format ( url = self . URL , key = key ) , headers = self . headers , )
When applications are provided this endpoint will remove those applications from the label .
18,378
def list ( self , filter_guid = None , filter_ids = None , detailed = None , page = None ) : filters = [ 'filter[guid]={0}' . format ( filter_guid ) if filter_guid else None , 'filter[ids]={0}' . format ( ',' . join ( [ str ( app_id ) for app_id in filter_ids ] ) ) if filter_ids else None , 'detailed={0}' . format ( de...
This API endpoint returns a paginated list of the plugins associated with your New Relic account .
18,379
def list ( self , application_id , filter_hostname = None , filter_ids = None , page = None ) : filters = [ 'filter[hostname]={0}' . format ( filter_hostname ) if filter_hostname else None , 'filter[ids]={0}' . format ( ',' . join ( [ str ( app_id ) for app_id in filter_ids ] ) ) if filter_ids else None , 'page={0}' . ...
This API endpoint returns a paginated list of instances associated with the given application .
18,380
def show ( self , application_id , host_id ) : return self . _get ( url = '{root}applications/{application_id}/hosts/{host_id}.json' . format ( root = self . URL , application_id = application_id , host_id = host_id ) , headers = self . headers , )
This API endpoint returns a single application host identified by its ID .
18,381
def metric_data ( self , id , names , values = None , from_dt = None , to_dt = None , summarize = False ) : params = [ 'from={0}' . format ( from_dt ) if from_dt else None , 'to={0}' . format ( to_dt ) if to_dt else None , 'summarize=true' if summarize else None ] params += [ 'names[]={0}' . format ( name ) for name in...
This API endpoint returns a list of values for each of the requested metrics . The list of available metrics can be returned using the Metric Name API endpoint .
18,382
def create ( self , dashboard_data ) : return self . _post ( url = '{0}dashboards.json' . format ( self . URL ) , headers = self . headers , data = dashboard_data , )
This API endpoint creates a dashboard and all defined widgets .
18,383
def update ( self , id , dashboard_data ) : return self . _put ( url = '{0}dashboards/{1}.json' . format ( self . URL , id ) , headers = self . headers , data = dashboard_data , )
This API endpoint updates a dashboard and all defined widgets .
18,384
def operatorPrecedence ( base , operators ) : expression = Forward ( ) last = base | Suppress ( '(' ) + expression + Suppress ( ')' ) def parse_operator ( expr , arity , association , action = None , extra = None ) : return expr , arity , association , action , extra for op in operators : expr , arity , association , a...
This re - implements pyparsing s operatorPrecedence function .
18,385
def set_parse_attributes ( self , string , location , tokens ) : "Fluent API for setting parsed location" self . string = string self . location = location self . tokens = tokens return self
Fluent API for setting parsed location
18,386
def evaluate_object ( obj , cls = None , cache = False , ** kwargs ) : old_obj = obj if isinstance ( obj , Element ) : if cache : obj = obj . evaluate_cached ( ** kwargs ) else : obj = obj . evaluate ( cache = cache , ** kwargs ) if cls is not None and type ( obj ) != cls : obj = cls ( obj ) for attr in ( 'string' , 'l...
Evaluates elements and coerces objects to a class if needed
18,387
def readGraph ( edgeList , nodeList = None , directed = False , idKey = 'ID' , eSource = 'From' , eDest = 'To' ) : progArgs = ( 0 , "Starting to reading graphs" ) if metaknowledge . VERBOSE_MODE : progKwargs = { 'dummy' : False } else : progKwargs = { 'dummy' : True } with _ProgressBar ( * progArgs , ** progKwargs ) as...
Reads the files given by _edgeList_ and _nodeList_ and creates a networkx graph for the files .
18,388
def writeGraph ( grph , name , edgeInfo = True , typing = False , suffix = 'csv' , overwrite = True , allSameAttribute = False ) : progArgs = ( 0 , "Writing the graph to files starting with: {}" . format ( name ) ) if metaknowledge . VERBOSE_MODE : progKwargs = { 'dummy' : False } else : progKwargs = { 'dummy' : True }...
Writes both the edge list and the node attribute list of _grph_ to files starting with _name_ .
18,389
def getNodeDegrees ( grph , weightString = "weight" , strictMode = False , returnType = int , edgeType = 'bi' ) : ndsDict = { } for nd in grph . nodes ( ) : ndsDict [ nd ] = returnType ( 0 ) for e in grph . edges ( data = True ) : if weightString : try : edgVal = returnType ( e [ 2 ] [ weightString ] ) except KeyError ...
Retunrs a dictionary of nodes to their degrees the degree is determined by adding the weight of edge with the weight being the string weightString that gives the name of the attribute of each edge containng thier weight . The Weights are then converted to the type returnType . If weightString is give as False instead e...
18,390
def mergeGraphs ( targetGraph , addedGraph , incrementedNodeVal = 'count' , incrementedEdgeVal = 'weight' ) : for addedNode , attribs in addedGraph . nodes ( data = True ) : if incrementedNodeVal : try : targetGraph . node [ addedNode ] [ incrementedNodeVal ] += attribs [ incrementedNodeVal ] except KeyError : targetGr...
A quick way of merging graphs this is meant to be quick and is only intended for graphs generated by metaknowledge . This does not check anything and as such may cause unexpected results if the source and target were not generated by the same method .
18,391
def AD ( val ) : retDict = { } for v in val : split = v . split ( ' : ' ) retDict [ split [ 0 ] ] = [ s for s in ' : ' . join ( split [ 1 : ] ) . replace ( '\n' , '' ) . split ( ';' ) if s != '' ] return retDict
Affiliation Undoing what the parser does then splitting at the semicolons and dropping newlines extra fitlering is required beacuse some AD s end with a semicolon
18,392
def AUID ( val ) : retDict = { } for v in val : split = v . split ( ' : ' ) retDict [ split [ 0 ] ] = ' : ' . join ( split [ 1 : ] ) return retDict
AuthorIdentifier one line only just need to undo the parser s effects
18,393
def isInteractive ( ) : if sys . stdout . isatty ( ) and os . name != 'nt' : try : import threading except ImportError : return False else : return True else : return False
A basic check of if the program is running in interactive mode
18,394
def getInstitutions ( self , tags = None , seperator = ";" , _getTag = False ) : if tags is None : tags = [ ] elif isinstance ( tags , str ) : tags = [ tags ] for k in self . keys ( ) : if 'institution' in k . lower ( ) and k not in tags : tags . append ( k ) return super ( ) . getInvestigators ( tags = tags , seperato...
Returns a list with the names of the institution . The optional arguments are ignored
18,395
def writeRecord ( self , f ) : if self . bad : raise BadPubmedRecord ( "This record cannot be converted to a file as the input was malformed.\nThe original line number (if any) is: {} and the original file is: '{}'" . format ( self . _sourceLine , self . _sourceFile ) ) else : authTags = { } for tag in authorBasedTags ...
This is nearly identical to the original the FAU tag is the only tag not writen in the same place doing so would require changing the parser and lots of extra logic .
18,396
def quickVisual ( G , showLabel = False ) : colours = "brcmykwg" f = plt . figure ( 1 ) ax = f . add_subplot ( 1 , 1 , 1 ) ndTypes = [ ] ndColours = [ ] layout = nx . spring_layout ( G , k = 4 / math . sqrt ( len ( G . nodes ( ) ) ) ) for nd in G . nodes ( data = True ) : if 'type' in nd [ 1 ] : if nd [ 1 ] [ 'type' ] ...
Just makes a simple _matplotlib_ figure and displays it with each node coloured by its type . You can add labels with _showLabel_ . This looks a bit nicer than the one provided my _networkx_ s defaults .
18,397
def graphDensityContourPlot ( G , iters = 50 , layout = None , layoutScaleFactor = 1 , overlay = False , nodeSize = 10 , axisSamples = 100 , blurringFactor = .1 , contours = 15 , graphType = 'coloured' ) : from mpl_toolkits . mplot3d import Axes3D if not isinstance ( G , nx . classes . digraph . DiGraph ) and not isins...
Creates a 3D plot giving the density of nodes on a 2D plane as a surface in 3D .
18,398
def makeBiDirectional ( d ) : dTmp = d . copy ( ) for k in d : dTmp [ d [ k ] ] = k return dTmp
Helper for generating tagNameConverter Makes dict that maps from key to value and back
18,399
def reverseDict ( d ) : retD = { } for k in d : retD [ d [ k ] ] = k return retD
Helper for generating fullToTag Makes dict of value to key