idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
45,900 | def list_resources ( self , lang ) : return registry . registry . http_handler . get ( '/api/2/project/%s/resources/' % ( self . get_project_slug ( lang ) , ) ) | Return a sequence of resources for a given lang . |
45,901 | def resources ( self , lang , slug ) : resource = resources . Resource . get ( project_slug = self . get_project_slug ( lang ) , slug = slug , ) return resource | Generate a list of Resources in the Project . |
45,902 | def resource_exists ( self , slug , locale , project_slug = None ) : try : resource = resources . Resource . get ( project_slug = project_slug or self . get_project_slug ( locale ) , slug = slug , ) return resource except NotFoundError : pass return None | Return True if a Resource with the given slug exists in locale . |
45,903 | def get_event_list ( config ) : eventinstances = session_request ( config . session . post , device_event_url . format ( proto = config . web_proto , host = config . host , port = config . port ) , auth = config . session . auth , headers = headers , data = request_xml ) raw_event_list = _prepare_event ( eventinstances... | Get a dict of supported events from device . |
45,904 | def _prepare_event ( eventinstances ) : import xml . etree . ElementTree as ET def parse_event ( events ) : def clean_attrib ( attrib = { } ) : attributes = { } for key , value in attrib . items ( ) : attributes [ key . split ( '}' ) [ - 1 ] ] = value return attributes description = { } for child in events : child_tag ... | Converts event instances to a relevant dictionary . |
45,905 | def url ( self ) : return URL . format ( http = self . web_proto , host = self . host , port = self . port ) | Represent device base url . |
45,906 | def process_raw ( self , raw : dict ) -> None : raw_ports = { } for param in raw : port_index = REGEX_PORT_INDEX . search ( param ) . group ( 0 ) if port_index not in raw_ports : raw_ports [ port_index ] = { } name = param . replace ( IOPORT + '.I' + port_index + '.' , '' ) raw_ports [ port_index ] [ name ] = raw [ par... | Pre - process raw dict . |
45,907 | def name ( self ) -> str : if self . direction == DIRECTION_IN : return self . raw . get ( 'Input.Name' , '' ) return self . raw . get ( 'Output.Name' , '' ) | Return name relevant to direction . |
45,908 | def action ( self , action ) : r if not self . direction == DIRECTION_OUT : return port_action = quote ( '{port}:{action}' . format ( port = int ( self . id ) + 1 , action = action ) , safe = '' ) url = URL + ACTION . format ( action = port_action ) self . _request ( 'get' , url ) | r Activate or deactivate an output . |
45,909 | def initialize_params ( self , preload_data = True ) -> None : params = '' if preload_data : params = self . request ( 'get' , param_url ) self . params = Params ( params , self . request ) | Load device parameters and initialize parameter management . |
45,910 | def initialize_ports ( self ) -> None : if not self . params : self . initialize_params ( preload_data = False ) self . params . update_ports ( ) self . ports = Ports ( self . params , self . request ) | Load IO port parameters for device . |
45,911 | def initialize_users ( self ) -> None : users = self . request ( 'get' , pwdgrp_url ) self . users = Users ( users , self . request ) | Load device user data and initialize user management . |
45,912 | def new_event ( self , event_data : str ) -> None : event = self . parse_event_xml ( event_data ) if EVENT_OPERATION in event : self . manage_event ( event ) | New event to process . |
45,913 | def parse_event_xml ( self , event_data ) -> dict : event = { } event_xml = event_data . decode ( ) message = MESSAGE . search ( event_xml ) if not message : return { } event [ EVENT_OPERATION ] = message . group ( EVENT_OPERATION ) topic = TOPIC . search ( event_xml ) if topic : event [ EVENT_TOPIC ] = topic . group (... | Parse metadata xml . |
45,914 | def manage_event ( self , event ) -> None : name = EVENT_NAME . format ( topic = event [ EVENT_TOPIC ] , source = event . get ( EVENT_SOURCE_IDX ) ) if event [ EVENT_OPERATION ] == 'Initialized' and name not in self . events : for event_class in EVENT_CLASSES : if event_class . TOPIC in event [ EVENT_TOPIC ] : self . e... | Received new metadata . |
45,915 | def state ( self , state : str ) -> None : self . _state = state for callback in self . _callbacks : callback ( ) | Update state of event . |
45,916 | def remove_callback ( self , callback ) -> None : if callback in self . _callbacks : self . _callbacks . remove ( callback ) | Remove callback . |
45,917 | def enable_events ( self , event_callback = None ) -> None : self . event = EventManager ( event_callback ) self . stream . event = self . event | Enable events for stream . |
45,918 | def update_brand ( self ) -> None : self . update ( path = URL_GET + GROUP . format ( group = BRAND ) ) | Update brand group of parameters . |
45,919 | def update_ports ( self ) -> None : self . update ( path = URL_GET + GROUP . format ( group = INPUT ) ) self . update ( path = URL_GET + GROUP . format ( group = IOPORT ) ) self . update ( path = URL_GET + GROUP . format ( group = OUTPUT ) ) | Update port groups of parameters . |
45,920 | def ports ( self ) -> dict : return { param : self [ param ] . raw for param in self if param . startswith ( IOPORT ) } | Create a smaller dictionary containing all ports . |
45,921 | def update_properties ( self ) -> None : self . update ( path = URL_GET + GROUP . format ( group = PROPERTIES ) ) | Update properties group of parameters . |
45,922 | def delete ( self , user : str ) -> None : data = { 'action' : 'remove' , 'user' : user } self . _request ( 'post' , URL , data = data ) | Remove user . |
45,923 | def start ( self ) : conn = self . loop . create_connection ( lambda : self , self . session . host , self . session . port ) task = self . loop . create_task ( conn ) task . add_done_callback ( self . init_done ) | Start session . |
45,924 | def stop ( self ) : if self . transport : self . transport . write ( self . method . TEARDOWN ( ) . encode ( ) ) self . transport . close ( ) self . rtp . stop ( ) | Stop session . |
45,925 | def connection_made ( self , transport ) : self . transport = transport self . transport . write ( self . method . message . encode ( ) ) self . time_out_handle = self . loop . call_later ( TIME_OUT_LIMIT , self . time_out ) | Connect to device is successful . |
45,926 | def data_received ( self , data ) : self . time_out_handle . cancel ( ) self . session . update ( data . decode ( ) ) if self . session . state == STATE_STARTING : self . transport . write ( self . method . message . encode ( ) ) self . time_out_handle = self . loop . call_later ( TIME_OUT_LIMIT , self . time_out ) eli... | Got response on RTSP session . |
45,927 | def time_out ( self ) : _LOGGER . warning ( 'Response timed out %s' , self . session . host ) self . stop ( ) self . callback ( SIGNAL_FAILED ) | If we don t get a response within time the RTSP request time out . |
45,928 | def message ( self ) : message = self . message_methods [ self . session . method ] ( ) _LOGGER . debug ( message ) return message | Return RTSP method based on sequence number from session . |
45,929 | def OPTIONS ( self , authenticate = True ) : message = "OPTIONS " + self . session . url + " RTSP/1.0\r\n" message += self . sequence message += self . authentication if authenticate else '' message += self . user_agent message += self . session_id message += '\r\n' return message | Request options device supports . |
45,930 | def DESCRIBE ( self ) : message = "DESCRIBE " + self . session . url + " RTSP/1.0\r\n" message += self . sequence message += self . authentication message += self . user_agent message += "Accept: application/sdp\r\n" message += '\r\n' return message | Request description of what services RTSP server make available . |
45,931 | def SETUP ( self ) : message = "SETUP " + self . session . control_url + " RTSP/1.0\r\n" message += self . sequence message += self . authentication message += self . user_agent message += self . transport message += '\r\n' return message | Set up stream transport . |
45,932 | def PLAY ( self ) : message = "PLAY " + self . session . url + " RTSP/1.0\r\n" message += self . sequence message += self . authentication message += self . user_agent message += self . session_id message += '\r\n' return message | RTSP session is ready to send data . |
45,933 | def authentication ( self ) : if self . session . digest : authentication = self . session . generate_digest ( ) elif self . session . basic : authentication = self . session . generate_basic ( ) else : return '' return "Authorization: " + authentication + '\r\n' | Generate authentication string . |
45,934 | def transport ( self ) : transport = "Transport: RTP/AVP;unicast;client_port={}-{}\r\n" return transport . format ( str ( self . session . rtp_port ) , str ( self . session . rtcp_port ) ) | Generate transport string . |
45,935 | def state ( self ) : if self . method in [ 'OPTIONS' , 'DESCRIBE' , 'SETUP' , 'PLAY' ] : state = STATE_STARTING elif self . method in [ 'KEEP-ALIVE' ] : state = STATE_PLAYING else : state = STATE_STOPPED _LOGGER . debug ( 'RTSP session (%s) state %s' , self . host , state ) return state | Which state the session is in . |
45,936 | def stream_url ( self ) : rtsp_url = RTSP_URL . format ( host = self . config . host , video = self . video_query , audio = self . audio_query , event = self . event_query ) _LOGGER . debug ( rtsp_url ) return rtsp_url | Build url for stream . |
45,937 | def session_callback ( self , signal ) : if signal == SIGNAL_DATA : self . event . new_event ( self . data ) elif signal == SIGNAL_FAILED : self . retry ( ) if signal in [ SIGNAL_PLAYING , SIGNAL_FAILED ] and self . connection_status_callback : self . connection_status_callback ( signal ) | Signalling from stream session . |
45,938 | def start ( self ) : if not self . stream or self . stream . session . state == STATE_STOPPED : self . stream = RTSPClient ( self . config . loop , self . stream_url , self . config . host , self . config . username , self . config . password , self . session_callback ) self . stream . start ( ) | Start stream . |
45,939 | def stop ( self ) : if self . stream and self . stream . session . state != STATE_STOPPED : self . stream . stop ( ) | Stop stream . |
45,940 | def retry ( self ) : self . stream = None self . config . loop . call_later ( RETRY_TIMER , self . start ) _LOGGER . debug ( 'Reconnecting to %s' , self . config . host ) | No connection to device retry connection after 15 seconds . |
45,941 | def check_perm ( user_id , permission_code ) : try : perm = db . DBSession . query ( Perm ) . filter ( Perm . code == permission_code ) . one ( ) except NoResultFound : raise PermissionError ( "Nonexistent permission type: %s" % ( permission_code ) ) try : res = db . DBSession . query ( User ) . join ( RoleUser , RoleU... | Checks whether a user has permission to perform an action . The permission_code parameter should be a permission contained in tPerm . |
45,942 | def required_perms ( * req_perms ) : def dec_wrapper ( wfunc ) : @ wraps ( wfunc ) def wrapped ( * args , ** kwargs ) : user_id = kwargs . get ( "user_id" ) for perm in req_perms : check_perm ( user_id , perm ) return wfunc ( * args , ** kwargs ) return wrapped return dec_wrapper | Decorator applied to functions requiring caller to possess permission Takes args tuple of required perms and raises PermissionsError via check_perm if these are not a subset of user perms |
45,943 | def required_role ( req_role ) : def dec_wrapper ( wfunc ) : @ wraps ( wfunc ) def wrapped ( * args , ** kwargs ) : user_id = kwargs . get ( "user_id" ) try : res = db . DBSession . query ( RoleUser ) . filter ( RoleUser . user_id == user_id ) . join ( Role , Role . code == req_role ) . one ( ) except NoResultFound : r... | Decorator applied to functions requiring caller to possess the specified role |
45,944 | def get_time_period ( period_name ) : time_abbreviation = time_map . get ( period_name . lower ( ) ) if time_abbreviation is None : raise Exception ( "Symbol %s not recognised as a time period" % period_name ) return time_abbreviation | Given a time period name fetch the hydra - compatible time abbreviation . |
45,945 | def get_datetime ( timestamp ) : timestamp_is_float = False try : float ( timestamp ) timestamp_is_float = True except ( ValueError , TypeError ) : pass if timestamp_is_float == True : raise ValueError ( "Timestamp %s is a float" % ( timestamp , ) ) try : parsed_dt = parse ( timestamp , dayfirst = False ) if parsed_dt ... | Turn a string timestamp into a date time . First tries to use dateutil . Failing that it tries to guess the time format and converts it manually using stfptime . |
45,946 | def timestamp_to_ordinal ( timestamp ) : if timestamp is None : return None ts_time = get_datetime ( timestamp ) ordinal_ts_time = Decimal ( ts_time . toordinal ( ) ) total_seconds = ( ts_time - datetime ( ts_time . year , ts_time . month , ts_time . day , 0 , 0 , 0 ) ) . total_seconds ( ) fraction = ( Decimal ( repr (... | Convert a timestamp as defined in the soap interface to the time format stored in the database . |
45,947 | def guess_timefmt ( datestr ) : if isinstance ( datestr , float ) or isinstance ( datestr , int ) : return None seasonal_key = str ( config . get ( 'DEFAULT' , 'seasonal_key' , '9999' ) ) if datestr . find ( 'T' ) > 0 : dt_delim = 'T' else : dt_delim = ' ' delimiters = [ '-' , '.' , ' ' , '/' ] formatstrings = [ [ '%Y'... | Try to guess the format a date is written in . |
45,948 | def reindex_timeseries ( ts_string , new_timestamps ) : if not isinstance ( new_timestamps , list ) : new_timestamps = [ new_timestamps ] new_timestamps_converted = [ ] for t in new_timestamps : new_timestamps_converted . append ( get_datetime ( t ) ) new_timestamps = new_timestamps_converted seasonal_year = config . g... | get data for timesamp |
45,949 | def parse_time_step ( time_step , target = 's' , units_ref = None ) : log . info ( "Parsing time step %s" , time_step ) value = re . findall ( r'\d+' , time_step ) [ 0 ] valuelen = len ( value ) try : value = float ( value ) except : HydraPluginError ( "Unable to extract number of time steps (%s) from time step %s" % (... | Read in the time step and convert it to seconds . |
45,950 | def get_time_axis ( start_time , end_time , time_step , time_axis = None ) : from . . lib import units if time_axis is not None : actual_dates_axis = [ ] for t in time_axis : t = t . replace ( ',' , '' ) . strip ( ) if t == '' : continue actual_dates_axis . append ( get_datetime ( t ) ) return actual_dates_axis else : ... | Create a list of datetimes based on an start time end time and time step . If such a list is already passed in then this is not necessary . |
45,951 | def _get_all_attributes ( network ) : attrs = network . attributes for n in network . nodes : attrs . extend ( n . attributes ) for l in network . links : attrs . extend ( l . attributes ) for g in network . resourcegroups : attrs . extend ( g . attributes ) return attrs | Get all the complex mode attributes in the network so that they can be used for mapping to resource scenarios later . |
45,952 | def _get_all_group_items ( network_id ) : base_qry = db . DBSession . query ( ResourceGroupItem ) item_qry = base_qry . join ( Scenario ) . filter ( Scenario . network_id == network_id ) x = time . time ( ) logging . info ( "Getting all items" ) all_items = db . DBSession . execute ( item_qry . statement ) . fetchall (... | Get all the resource group items in the network across all scenarios returns a dictionary of dict objects keyed on scenario_id |
45,953 | def _get_all_resourcescenarios ( network_id , user_id ) : rs_qry = db . DBSession . query ( Dataset . type , Dataset . unit_id , Dataset . name , Dataset . hash , Dataset . cr_date , Dataset . created_by , Dataset . hidden , Dataset . value , ResourceScenario . dataset_id , ResourceScenario . scenario_id , ResourceScen... | Get all the resource scenarios in a network across all scenarios returns a dictionary of dict objects keyed on scenario_id |
45,954 | def _get_metadata ( network_id , user_id ) : log . info ( "Getting Metadata" ) dataset_qry = db . DBSession . query ( Dataset ) . outerjoin ( DatasetOwner , and_ ( DatasetOwner . dataset_id == Dataset . id , DatasetOwner . user_id == user_id ) ) . filter ( or_ ( Dataset . hidden == 'N' , DatasetOwner . user_id != None ... | Get all the metadata in a network across all scenarios returns a dictionary of dict objects keyed on dataset ID |
45,955 | def _get_links ( network_id , template_id = None ) : extras = { 'types' : [ ] , 'attributes' : [ ] } link_qry = db . DBSession . query ( Link ) . filter ( Link . network_id == network_id , Link . status == 'A' ) . options ( noload ( 'network' ) ) if template_id is not None : link_qry = link_qry . filter ( ResourceType ... | Get all the links in a network |
45,956 | def _get_groups ( network_id , template_id = None ) : extras = { 'types' : [ ] , 'attributes' : [ ] } group_qry = db . DBSession . query ( ResourceGroup ) . filter ( ResourceGroup . network_id == network_id , ResourceGroup . status == 'A' ) . options ( noload ( 'network' ) ) if template_id is not None : group_qry = gro... | Get all the resource groups in a network |
45,957 | def _get_scenarios ( network_id , include_data , user_id , scenario_ids = None ) : scen_qry = db . DBSession . query ( Scenario ) . filter ( Scenario . network_id == network_id ) . options ( noload ( 'network' ) ) . filter ( Scenario . status == 'A' ) if scenario_ids : logging . info ( "Filtering by scenario_ids %s" , ... | Get all the scenarios in a network |
45,958 | def set_network_status ( network_id , status , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) net_i . check_write_permission ( user_id ) net_i . status = status except NoResultFound : raise ResourceNotFoundError ( "Ne... | Activates a network by setting its status attribute to A . |
45,959 | def get_network_extents ( network_id , ** kwargs ) : rs = db . DBSession . query ( Node . x , Node . y ) . filter ( Node . network_id == network_id ) . all ( ) if len ( rs ) == 0 : return dict ( network_id = network_id , min_x = None , max_x = None , min_y = None , max_y = None , ) x = [ r . x for r in rs if r . x is n... | Given a network return its maximum extents . This would be the minimum x value of all nodes the minimum y value of all nodes the maximum x value of all nodes and maximum y value of all nodes . |
45,960 | def add_nodes ( network_id , nodes , ** kwargs ) : start_time = datetime . datetime . now ( ) names = [ ] for n_i in nodes : if n_i . name in names : raise HydraError ( "Duplicate Node Name: %s" % ( n_i . name ) ) names . append ( n_i . name ) user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( ... | Add nodes to network |
45,961 | def add_links ( network_id , links , ** kwargs ) : start_time = datetime . datetime . now ( ) user_id = kwargs . get ( 'user_id' ) names = [ ] for l_i in links : if l_i . name in names : raise HydraError ( "Duplicate Link Name: %s" % ( l_i . name ) ) names . append ( l_i . name ) try : net_i = db . DBSession . query ( ... | add links to network |
45,962 | def update_node ( node , flush = True , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : node_i = db . DBSession . query ( Node ) . filter ( Node . id == node . id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Node %s not found" % ( node . id ) ) node_i . network . check_write_permission ( u... | Update a node . If new attributes are present they will be added to the node . The non - presence of attributes does not remove them . |
45,963 | def update_nodes ( nodes , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) updated_nodes = [ ] for n in nodes : updated_node_i = update_node ( n , flush = False , user_id = user_id ) updated_nodes . append ( updated_node_i ) db . DBSession . flush ( ) return updated_nodes | Update multiple nodes . If new attributes are present they will be added to the node . The non - presence of attributes does not remove them . |
45,964 | def set_node_status ( node_id , status , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : node_i = db . DBSession . query ( Node ) . filter ( Node . id == node_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Node %s not found" % ( node_id ) ) node_i . network . check_write_permission ( user... | Set the status of a node to X |
45,965 | def purge_network ( network_id , purge_data , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Network %s not found" % ( network_id ) ) log . info ( "Deleting networ... | Remove a network from DB completely Use purge_data to try to delete the data associated with only this network . If no other resources link to this data it will be deleted . |
45,966 | def _purge_datasets_unique_to_resource ( ref_key , ref_id ) : count_qry = db . DBSession . query ( ResourceScenario . dataset_id , func . count ( ResourceScenario . dataset_id ) ) . group_by ( ResourceScenario . dataset_id ) . filter ( ResourceScenario . resource_attr_id == ResourceAttr . id ) if ref_key == 'NODE' : co... | Find the number of times a a resource and dataset combination occurs . If this equals the number of times the dataset appears then we can say this dataset is unique to this resource therefore it can be deleted |
45,967 | def delete_node ( node_id , purge_data , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : node_i = db . DBSession . query ( Node ) . filter ( Node . id == node_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Node %s not found" % ( node_id ) ) group_items = db . DBSession . query ( ResourceG... | Remove node from DB completely If there are attributes on the node use purge_data to try to delete the data . If no other resources link to this data it will be deleted . |
45,968 | def add_link ( network_id , link , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) net_i . check_write_permission ( user_id ) except NoResultFound : raise ResourceNotFoundError ( "Network %s not found" % ( network_id )... | Add a link to a network |
45,969 | def update_link ( link , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : link_i = db . DBSession . query ( Link ) . filter ( Link . id == link . id ) . one ( ) link_i . network . check_write_permission ( user_id ) except NoResultFound : raise ResourceNotFoundError ( "Link %s not found" % ( link . id ) ) if lin... | Update a link . |
45,970 | def set_link_status ( link_id , status , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : link_i = db . DBSession . query ( Link ) . filter ( Link . id == link_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Link %s not found" % ( link_id ) ) link_i . network . check_write_permission ( user... | Set the status of a link |
45,971 | def delete_link ( link_id , purge_data , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : link_i = db . DBSession . query ( Link ) . filter ( Link . id == link_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Link %s not found" % ( link_id ) ) group_items = db . DBSession . query ( ResourceG... | Remove link from DB completely If there are attributes on the link use purge_data to try to delete the data . If no other resources link to this data it will be deleted . |
45,972 | def add_group ( network_id , group , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) net_i . check_write_permission ( user_id = user_id ) except NoResultFound : raise ResourceNotFoundError ( "Network %s not found" % ( ... | Add a resourcegroup to a network |
45,973 | def update_group ( group , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : group_i = db . DBSession . query ( ResourceGroup ) . filter ( ResourceGroup . id == group . id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "group %s not found" % ( group . id ) ) group_i . network . check_write_perm... | Update a group . If new attributes are present they will be added to the group . The non - presence of attributes does not remove them . |
45,974 | def set_group_status ( group_id , status , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : group_i = db . DBSession . query ( ResourceGroup ) . filter ( ResourceGroup . id == group_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "ResourceGroup %s not found" % ( group_id ) ) group_i . networ... | Set the status of a group to X |
45,975 | def delete_group ( group_id , purge_data , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : group_i = db . DBSession . query ( ResourceGroup ) . filter ( ResourceGroup . id == group_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Group %s not found" % ( group_id ) ) group_items = db . DBSes... | Remove group from DB completely If there are attributes on the group use purge_data to try to delete the data . If no other resources group to this data it will be deleted . |
45,976 | def get_scenarios ( network_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) net_i . check_read_permission ( user_id = user_id ) except NoResultFound : raise ResourceNotFoundError ( "Network %s not found" % ( netwo... | Get all the scenarios in a given network . |
45,977 | def validate_network_topology ( network_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) net_i . check_write_permission ( user_id = user_id ) except NoResultFound : raise ResourceNotFoundError ( "Network %s not fou... | Check for the presence of orphan nodes in a network . |
45,978 | def get_resources_of_type ( network_id , type_id , ** kwargs ) : nodes_with_type = db . DBSession . query ( Node ) . join ( ResourceType ) . filter ( Node . network_id == network_id , ResourceType . type_id == type_id ) . all ( ) links_with_type = db . DBSession . query ( Link ) . join ( ResourceType ) . filter ( Link ... | Return the Nodes Links and ResourceGroups which have the type specified . |
45,979 | def clean_up_network ( network_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : log . debug ( "Querying Network %s" , network_id ) net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . options ( noload ( 'scenarios' ) ) . options ( noload ( 'nodes' ) ) . options ( noload ( 'l... | Purge any deleted nodes links resourcegroups and scenarios in a given network |
45,980 | def get_all_resource_attributes_in_network ( attr_id , network_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : a = db . DBSession . query ( Attr ) . filter ( Attr . id == attr_id ) . one ( ) except NoResultFound : raise HydraError ( "Attribute %s not found" % ( attr_id , ) ) ra_qry = db . DBSession . quer... | Find every resource attribute in the network matching the supplied attr_id |
45,981 | def copy_data_from_scenario ( resource_attrs , source_scenario_id , target_scenario_id , ** kwargs ) : target_resourcescenarios = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . scenario_id == target_scenario_id , ResourceScenario . resource_attr_id . in_ ( resource_attrs ) ) . all ( ) target_... | For a given list of resource attribute IDS copy the dataset_ids from the resource scenarios in the source scenario to those in the target scenario . |
45,982 | def get_scenario ( scenario_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) scen_i = _get_scenario ( scenario_id , user_id ) scen_j = JSONObject ( scen_i ) rscen_rs = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . scenario_id == scenario_id ) . options ( joinedload_all ( 'dataset.meta... | Get the specified scenario |
45,983 | def add_scenario ( network_id , scenario , ** kwargs ) : user_id = int ( kwargs . get ( 'user_id' ) ) log . info ( "Adding scenarios to network" ) _check_network_ownership ( network_id , user_id ) existing_scen = db . DBSession . query ( Scenario ) . filter ( Scenario . name == scenario . name , Scenario . network_id =... | Add a scenario to a specified network . |
45,984 | def update_scenario ( scenario , update_data = True , update_groups = True , flush = True , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) scen = _get_scenario ( scenario . id , user_id ) if scen . locked == 'Y' : raise PermissionError ( 'Scenario is locked. Unlock before editing.' ) start_time = None if isinstance... | Update a single scenario as all resources already exist there is no need to worry about negative IDS |
45,985 | def _get_as_obj ( obj_dict , name ) : if obj_dict . get ( '_sa_instance_state' ) : del obj_dict [ '_sa_instance_state' ] obj = namedtuple ( name , tuple ( obj_dict . keys ( ) ) ) for k , v in obj_dict . items ( ) : setattr ( obj , k , v ) log . info ( "%s = %s" , k , getattr ( obj , k ) ) return obj | Turn a dictionary into a named tuple so it can be passed into the constructor of a complex model generator . |
45,986 | def get_resource_scenario ( resource_attr_id , scenario_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) _get_scenario ( scenario_id , user_id ) try : rs = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . resource_attr_id == resource_attr_id , ResourceScenario . scenario_id == scenario_i... | Get the resource scenario object for a given resource atttribute and scenario . This is done when you know the attribute resource and scenario and want to get the value associated with it . |
45,987 | def bulk_update_resourcedata ( scenario_ids , resource_scenarios , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) res = None res = { } net_ids = db . DBSession . query ( Scenario . network_id ) . filter ( Scenario . id . in_ ( scenario_ids ) ) . all ( ) if len ( set ( net_ids ) ) != 1 : raise HydraError ( "Scenario... | Update the data associated with a list of scenarios . |
45,988 | def update_resourcedata ( scenario_id , resource_scenarios , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) res = None _check_can_edit_scenario ( scenario_id , kwargs [ 'user_id' ] ) scen_i = _get_scenario ( scenario_id , user_id ) res = [ ] for rs in resource_scenarios : if rs . dataset is not None : updated_rs = ... | Update the data associated with a scenario . Data missing from the resource scenario will not be removed from the scenario . Use the remove_resourcedata for this task . |
45,989 | def delete_resource_scenario ( scenario_id , resource_attr_id , quiet = False , ** kwargs ) : _check_can_edit_scenario ( scenario_id , kwargs [ 'user_id' ] ) _delete_resourcescenario ( scenario_id , resource_attr_id , suppress_error = quiet ) | Remove the data associated with a resource in a scenario . |
45,990 | def delete_resourcedata ( scenario_id , resource_scenario , quiet = False , ** kwargs ) : _check_can_edit_scenario ( scenario_id , kwargs [ 'user_id' ] ) _delete_resourcescenario ( scenario_id , resource_scenario . resource_attr_id , suppress_error = quiet ) | Remove the data associated with a resource in a scenario . The quiet parameter indicates whether an non - existent RS should throw an error . |
45,991 | def _update_resourcescenario ( scenario , resource_scenario , dataset = None , new = False , user_id = None , source = None ) : if scenario is None : scenario = db . DBSession . query ( Scenario ) . filter ( Scenario . id == 1 ) . one ( ) ra_id = resource_scenario . resource_attr_id log . debug ( "Assigning resource at... | Insert or Update the value of a resource s attribute by first getting the resource then parsing the input data then assigning the value . |
45,992 | def assign_value ( rs , data_type , val , unit_id , name , metadata = { } , data_hash = None , user_id = None , source = None ) : log . debug ( "Assigning value %s to rs %s in scenario %s" , name , rs . resource_attr_id , rs . scenario_id ) if rs . scenario . locked == 'Y' : raise PermissionError ( "Cannot assign value... | Insert or update a piece of data in a scenario . If the dataset is being shared by other resource scenarios a new dataset is inserted . If the dataset is ONLY being used by the resource scenario in question the dataset is updated to avoid unnecessary duplication . |
45,993 | def add_data_to_attribute ( scenario_id , resource_attr_id , dataset , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) _check_can_edit_scenario ( scenario_id , user_id ) scenario_i = _get_scenario ( scenario_id , user_id ) try : r_scen_i = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . sce... | Add data to a resource scenario outside of a network update |
45,994 | def get_scenario_data ( scenario_id , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) scenario_data = db . DBSession . query ( Dataset ) . filter ( Dataset . id == ResourceScenario . dataset_id , ResourceScenario . scenario_id == scenario_id ) . options ( joinedload_all ( 'metadata' ) ) . distinct ( ) . all ( ) for ... | Get all the datasets from the group with the specified name |
45,995 | def get_attribute_data ( attr_ids , node_ids , ** kwargs ) : node_attrs = db . DBSession . query ( ResourceAttr ) . options ( joinedload_all ( 'attr' ) ) . filter ( ResourceAttr . node_id . in_ ( node_ids ) , ResourceAttr . attr_id . in_ ( attr_ids ) ) . all ( ) ra_ids = [ ] for ra in node_attrs : ra_ids . append ( ra ... | For a given attribute or set of attributes return all the resources and resource scenarios in the network |
45,996 | def get_resource_data ( ref_key , ref_id , scenario_id , type_id = None , expunge_session = True , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) resource_data_qry = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . dataset_id == Dataset . id , ResourceAttr . id == ResourceScenario . resourc... | Get all the resource scenarios for a given resource in a given scenario . If type_id is specified only return the resource scenarios for the attributes within the type . |
45,997 | def get_resourcegroupitems ( group_id , scenario_id , ** kwargs ) : rgi_qry = db . DBSession . query ( ResourceGroupItem ) . filter ( ResourceGroupItem . scenario_id == scenario_id ) if group_id is not None : rgi_qry = rgi_qry . filter ( ResourceGroupItem . group_id == group_id ) rgi = rgi_qry . all ( ) return rgi | Get all the items in a group in a scenario . If group_id is None return all items across all groups in the scenario . |
45,998 | def delete_resourcegroupitems ( scenario_id , item_ids , ** kwargs ) : user_id = int ( kwargs . get ( 'user_id' ) ) _get_scenario ( scenario_id , user_id ) for item_id in item_ids : rgi = db . DBSession . query ( ResourceGroupItem ) . filter ( ResourceGroupItem . id == item_id ) . one ( ) db . DBSession . delete ( rgi ... | Delete specified items in a group in a scenario . |
45,999 | def empty_group ( group_id , scenario_id , ** kwargs ) : user_id = int ( kwargs . get ( 'user_id' ) ) _get_scenario ( scenario_id , user_id ) rgi = db . DBSession . query ( ResourceGroupItem ) . filter ( ResourceGroupItem . group_id == group_id ) . filter ( ResourceGroupItem . scenario_id == scenario_id ) . all ( ) rgi... | Delete all itemas in a group in a scenario . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.