code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
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"%(network_id)) node_qry = db.DBSession.query(...
def get_nodes(network_id, template_id=None, **kwargs)
Get all the nodes in a network. args: network_id (int): The network in which to search template_id (int): Only return nodes whose type is in this template.
3.212379
3.350611
0.958744
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"%(network_id)) link_qry = db.DBSession.query(...
def get_links(network_id, template_id=None, **kwargs)
Get all the links in a network. args: network_id (int): The network in which to search template_id (int): Only return links whose type is in this template.
3.25173
3.393167
0.958317
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"%(network_id)) group_qry = db.DBSession.query...
def get_groups(network_id, template_id=None, **kwargs)
Get all the resource groups in a network. args: network_id (int): The network in which to search template_id (int): Only return resource groups whose type is in this template.
3.214288
3.253936
0.987816
try: res = db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one() net = get_network(res.id, 'Y', None, **kwargs) return net except NoResultFound: raise ResourceNotFoundError("Network with name %s no...
def get_network_by_name(project_id, network_name,**kwargs)
Return a whole network as a complex model.
3.855671
3.819497
1.009471
try: db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one() return 'Y' except NoResultFound: return 'N'
def network_exists(project_id, network_name,**kwargs)
Return a whole network as a complex model.
3.200499
3.295598
0.971144
user_id = kwargs.get('user_id') #check_perm(user_id, 'delete_network') 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("Netwo...
def set_network_status(network_id,status,**kwargs)
Activates a network by setting its status attribute to 'A'.
3.260409
3.38825
0.962269
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, ) # Compute min/max extent of the network...
def get_network_extents(network_id,**kwargs)
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. @returns NetworkExtents object
1.925848
2.024361
0.951336
start_time = datetime.datetime.now() names=[] # used to check uniqueness of node name 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 = d...
def add_nodes(network_id, nodes,**kwargs)
Add nodes to network
3.436851
3.412694
1.007078
''' add links to network ''' start_time = datetime.datetime.now() user_id = kwargs.get('user_id') names=[] # used to check uniqueness of link name before saving links to database for l_i in links: if l_i.name in names: raise HydraError("Duplicate Link Name: %s"%(l_...
def add_links(network_id, links,**kwargs)
add links to network
3.499091
3.535953
0.989575
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_id) node_i.name = node.name if node.name is not N...
def update_node(node, flush=True, **kwargs)
Update a node. If new attributes are present, they will be added to the node. The non-presence of attributes does not remove them. The flush argument indicates whether dbsession.flush should be called. THis is set to False when update_node is called from another function which does the flush.
2.372617
2.411223
0.983989
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
def update_nodes(nodes,**kwargs)
Update multiple nodes. If new attributes are present, they will be added to the node. The non-presence of attributes does not remove them. %TODO:merge this with the 'update_nodes' functionality in the 'update_netework' function, so we're not duplicating functionality. D.R.Y! returns: a list of upd...
3.258153
3.887781
0.838049
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_id) node_i.status = status for link in node_...
def set_node_status(node_id, status, **kwargs)
Set the status of a node to 'X'
2.904688
2.935182
0.989611
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 network %s, id=%s", net_i.name, network_id) net_i.check_wri...
def purge_network(network_id, purge_data,**kwargs)
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.
3.030495
3.253535
0.931447
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...
def _purge_datasets_unique_to_resource(ref_key, ref_id)
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
2.165136
2.135538
1.01386
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(ResourceGroupItem).filter( ...
def delete_node(node_id, purge_data,**kwargs)
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.
3.384103
3.624124
0.933771
user_id = kwargs.get('user_id') #check_perm(user_id, 'edit_topology') 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))...
def add_link(network_id, link,**kwargs)
Add a link to a network
2.598669
2.610577
0.995439
user_id = kwargs.get('user_id') #check_perm(user_id, 'edit_topology') 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)) ...
def update_link(link,**kwargs)
Update a link.
2.756181
2.776119
0.992818
user_id = kwargs.get('user_id') #check_perm(user_id, 'edit_topology') 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_id) lin...
def set_link_status(link_id, status, **kwargs)
Set the status of a link
3.758451
3.831027
0.981056
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(ResourceGroupItem).filter( ...
def delete_link(link_id, purge_data,**kwargs)
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.
3.459474
3.69532
0.936177
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"%(network_id)) res_grp_i = net_i.add_group(...
def add_group(network_id, group,**kwargs)
Add a resourcegroup to a network
2.75651
2.766815
0.996276
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_permission(user_id) group_i.name = group.n...
def update_group(group,**kwargs)
Update a group. If new attributes are present, they will be added to the group. The non-presence of attributes does not remove them.
3.005635
3.294806
0.912234
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.network.check_write_permission(user_id) group_i.status...
def set_group_status(group_id, status, **kwargs)
Set the status of a group to 'X'
3.768156
3.9142
0.962689
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.DBSession.query(ResourceGroupItem).filter( ...
def delete_group(group_id, purge_data,**kwargs)
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.
3.309246
3.541339
0.934462
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"%(network_id)) return net_i.scenarios
def get_scenarios(network_id,**kwargs)
Get all the scenarios in a given network.
3.531481
3.584873
0.985106
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"%(network_id)) nodes = [] for node_i in...
def validate_network_topology(network_id,**kwargs)
Check for the presence of orphan nodes in a network.
2.189685
2.267757
0.965573
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.network_id==network_id, ResourceType.type_id==type_id).all() groups_with_type = db.DBSession....
def get_resources_of_type(network_id, type_id, **kwargs)
Return the Nodes, Links and ResourceGroups which have the type specified.
1.736369
1.603255
1.083027
user_id = kwargs.get('user_id') #check_perm(user_id, 'delete_network') 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('links')).options(...
def clean_up_network(network_id, **kwargs)
Purge any deleted nodes, links, resourcegroups and scenarios in a given network
2.506032
2.343626
1.069297
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.query(ResourceAttr).filter( ResourceAttr.attr_id==attr_id, ...
def get_all_resource_attributes_in_network(attr_id, network_id, **kwargs)
Find every resource attribute in the network matching the supplied attr_id
2.387754
2.429304
0.982896
rs_qry = db.DBSession.query( ResourceAttr.attr_id, Attr.name.label('attr_name'), ResourceAttr.id.label('resource_attr_id'), ResourceAttr.ref_key, ResourceAttr.network_id, ResourceAttr.node_id, ResourceAttr...
def get_all_resource_data(scenario_id, include_metadata='N', page_start=None, page_end=None, **kwargs)
A function which returns the data for all resources in a network. -
2.298501
2.34918
0.978427
user_id = kwargs['user_id'] ex_net = db.DBSession.query(Network).filter(Network.id==network_id).one() ex_net.check_read_permission(user_id) if project_id is None and new_project == True: log.info("Creating a new project for cloned network") ex_proj = db.DBSession.query(Project...
def clone_network(network_id, recipient_user_id=None, new_network_name=None, project_id=None, project_name=None, new_project=True, **kwargs)
Create an exact clone of the specified network for the specified user. If project_id is specified, put the new network in there. Otherwise create a new project with the specified name and put it in there.
2.072159
2.113652
0.980369
#Get all the resource scenarios we wish to update target_resourcescenarios = db.DBSession.query(ResourceScenario).filter( ResourceScenario.scenario_id==target_scenario_id, ResourceScenario.resource_attr_id.in_(resource_attrs)).all() target_rs_dict = {} for target_rs in tar...
def copy_data_from_scenario(resource_attrs, source_scenario_id, target_scenario_id, **kwargs)
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.
2.315069
2.188469
1.057849
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.metadata')).all() #lazy load resource attributes and att...
def get_scenario(scenario_id,**kwargs)
Get the specified scenario
4.222311
4.307153
0.980302
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==network_id).first() if existing_scen is not None: raise Hyd...
def add_scenario(network_id, scenario,**kwargs)
Add a scenario to a specified network.
2.536362
2.543171
0.997322
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(scenario.start_time, float): start_time = six.text_type(scenario.start_time) ...
def update_scenario(scenario,update_data=True,update_groups=True,flush=True,**kwargs)
Update a single scenario as all resources already exist, there is no need to worry about negative IDS flush = True flushes to the DB at the end of the function. flush = False does not flush, assuming that it will happen as part of another process, like update_network.
3.151383
3.229136
0.975922
user_id = kwargs.get('user_id') _check_can_edit_scenario(scenario_id, kwargs['user_id']) scenario_i = _get_scenario(scenario_id, user_id) scenario_i.status = status db.DBSession.flush() return 'OK'
def set_scenario_status(scenario_id, status, **kwargs)
Set the status of a scenario.
4.421358
4.472619
0.988539
_check_can_edit_scenario(scenario_id, kwargs['user_id']) user_id = kwargs.get('user_id') scenario_i = _get_scenario(scenario_id, user_id) db.DBSession.delete(scenario_i) db.DBSession.flush() return 'OK'
def purge_scenario(scenario_id, **kwargs)
Set the status of a scenario.
4.220993
4.138379
1.019963
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
def _get_as_obj(obj_dict, name)
Turn a dictionary into a named tuple so it can be passed into the constructor of a complex model generator.
2.74715
2.579518
1.064986
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_id).options(joinedload_all('data...
def get_resource_scenario(resource_attr_id, scenario_id, **kwargs)
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.
3.317034
3.678893
0.901639
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 IDS are not in the same network") for scenario_id in scenario_ids: _che...
def bulk_update_resourcedata(scenario_ids, resource_scenarios,**kwargs)
Update the data associated with a list of scenarios.
3.648849
3.689998
0.988849
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_resourcescenario(scen_i, rs, user_id...
def update_resourcedata(scenario_id, resource_scenarios,**kwargs)
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. If the resource scenario does not exist, it will be created. If the value of the resource scenario is specified as being ...
4.043568
4.460361
0.906556
_check_can_edit_scenario(scenario_id, kwargs['user_id']) _delete_resourcescenario(scenario_id, resource_attr_id, suppress_error=quiet)
def delete_resource_scenario(scenario_id, resource_attr_id, quiet=False, **kwargs)
Remove the data associated with a resource in a scenario.
6.414961
6.712012
0.955743
_check_can_edit_scenario(scenario_id, kwargs['user_id']) _delete_resourcescenario(scenario_id, resource_scenario.resource_attr_id, suppress_error=quiet)
def delete_resourcedata(scenario_id, resource_scenario, quiet = False, **kwargs)
Remove the data associated with a resource in a scenario. The 'quiet' parameter indicates whether an non-existent RS should throw an error.
7.552283
8.029266
0.940594
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 attribute: %s",ra_id) try: r_scen_i = db.DBSession.query(ResourceScenario).filter( ResourceSce...
def _update_resourcescenario(scenario, resource_scenario, dataset=None, new=False, user_id=None, source=None)
Insert or Update the value of a resource's attribute by first getting the resource, then parsing the input data, then assigning the value. returns a ResourceScenario object.
2.852491
2.815521
1.013131
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. Scenario %s is locked" %(rs.scenario_id)) #Check if this RS is the only RS i...
def assign_value(rs, data_type, val, unit_id, name, metadata={}, data_hash=None, user_id=None, source=None)
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.
4.101197
3.963394
1.034769
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.scenario_id==scenario_id, ...
def add_data_to_attribute(scenario_id, resource_attr_id, dataset,**kwargs)
Add data to a resource scenario outside of a network update
2.998528
2.996689
1.000614
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 sd in scenario_data: if sd.hidden == 'Y': try: ...
def get_scenario_data(scenario_id,**kwargs)
Get all the datasets from the group with the specified name @returns a list of dictionaries
5.022406
5.653937
0.888302
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 ...
def get_attribute_data(attr_ids, node_ids, **kwargs)
For a given attribute or set of attributes, return all the resources and resource scenarios in the network
3.97793
3.875549
1.026417
user_id = kwargs.get('user_id') resource_data_qry = db.DBSession.query(ResourceScenario).filter( ResourceScenario.dataset_id == Dataset.id, ResourceAttr.id == ResourceScenario.resource_attr_id, ResourceScenario.scenario_id == scenario_id, ResourceAttr.ref_key == ref_key,...
def get_resource_data(ref_key, ref_id, scenario_id, type_id=None, expunge_session=True, **kwargs)
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.
3.272708
3.239513
1.010247
user_id = kwargs.get('user_id') scenario_i = _get_scenario(scenario_id, user_id) try: a = db.DBSession.query(Attr).filter(Attr.id == attr_id).one() except NoResultFound: raise HydraError("Attribute %s not found"%(attr_id,)) rs_qry = db.DBSession.query(ResourceScenario).filte...
def get_attribute_datasets(attr_id, scenario_id, **kwargs)
Retrieve all the datasets in a scenario for a given attribute. Also return the resource attributes so there is a reference to the node/link
2.460796
2.440371
1.00837
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
def get_resourcegroupitems(group_id, scenario_id, **kwargs)
Get all the items in a group, in a scenario. If group_id is None, return all items across all groups in the scenario.
2.574701
2.819014
0.913334
user_id = int(kwargs.get('user_id')) #check the scenario exists _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) db.DBSession.flush()
def delete_resourcegroupitems(scenario_id, item_ids, **kwargs)
Delete specified items in a group, in a scenario.
3.041619
3.164894
0.961049
user_id = int(kwargs.get('user_id')) #check the scenario exists _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()
def empty_group(group_id, scenario_id, **kwargs)
Delete all itemas in a group, in a scenario.
4.423923
4.138548
1.068955
user_id = int(kwargs.get('user_id')) if scenario is None: scenario = _get_scenario(scenario_id, user_id) _check_network_ownership(scenario.network_id, user_id) newitems = [] for group_item in items: group_item_i = _add_resourcegroupitem(group_item, scenario.id) newit...
def add_resourcegroupitems(scenario_id, items, scenario=None, **kwargs)
Get all the items in a group, in a scenario.
3.194701
3.259282
0.980186
if group_item.id and group_item.id > 0: try: group_item_i = db.DBSession.query(ResourceGroupItem).filter(ResourceGroupItem.id == group_item.id).one() except NoResultFound: raise ResourceNotFoundError("ResourceGroupItem %s not found" % (group_item.id)) else: ...
def _add_resourcegroupitem(group_item, scenario_id)
Add a single resource group item (no DB flush, as it's an internal function)
1.890369
1.846163
1.023945
user_id = int(kwargs.get('user_id')) rm = aliased(ResourceAttrMap, name='rm') #Check the mapping exists. mapping = db.DBSession.query(rm).filter( or_( and_( rm.resource_attr_id_a == source_resource_attr_id, rm.resource_attr_id_b == target_resourc...
def update_value_from_mapping(source_resource_attr_id, target_resource_attr_id, source_scenario_id, target_scenario_id, **kwargs)
Using a resource attribute mapping, take the value from the source and apply it to the target. Both source and target scenarios must be specified (and therefor must exist).
2.522819
2.542364
0.992312
plugins = [] plugin_paths = [] #Look in directory or set of directories for #plugins base_plugin_dir = config.get('plugin', 'default_directory') plugin_xsd_path = config.get('plugin', 'plugin_xsd_path') base_plugin_dir_contents = os.listdir(base_plugin_dir) for direc...
def get_plugins(**kwargs)
Get all available plugins
3.838218
3.837761
1.000119
args = [sys.executable] #Get plugin executable home = os.path.expanduser('~') path_to_plugin = os.path.join(home, 'svn/HYDRA/HydraPlugins', plugin.location) args.append(path_to_plugin) #Parse plugin arguments into a string plugin_params = " " for p in plugin.params: ...
def run_plugin(plugin,**kwargs)
Run a plugin
4.204846
4.230332
0.993976
global localfiles global localfile global repofile global repofiles global userfile global userfiles global sysfile global sysfiles global CONFIG logging.basicConfig(level='INFO') config = ConfigParser.ConfigParser(allow_no_value=True) modulepath = os.path.dirname(...
def load_config()
Load a config file. This function looks for a config (*.ini) file in the following order:: (1) ./*.ini (2) ~/.config/hydra/ (3) /etc/hydra (4) /path/to/hydra_base/*.ini (1) will override (2) will override (3) will override (4). Parameters not defined in (1) will be taken fr...
2.141891
2.126869
1.007063
#Remove trailing whitespace and forwardslashes db_url = db_url.strip().strip('/') #Check this is a mysql URL if db_url.find('mysql') >= 0: #Get the DB name from config and check if it's in the URL db_name = config.get('mysqld', 'db_name', 'hydradb') if db_url.find(db_na...
def create_mysql_db(db_url)
To simplify deployment, create the mysql DB if it's not there. Accepts a URL with or without a DB name stated, and returns a db url containing the db name for use in the main sqlalchemy engine. THe formats can take the following form: mysql+driver://username:password@hostname m...
3.701706
3.477943
1.064338
user_id = kwargs.get('user_id') existing_proj = get_project_by_name(project.name,user_id=user_id) if len(existing_proj) > 0: raise HydraError("A Project with the name \"%s\" already exists"%(project.name,)) #check_perm(user_id, 'add_project') proj_i = Project() proj_i.name = proj...
def add_project(project,**kwargs)
Add a new project returns a project complexmodel
3.500985
3.582083
0.97736
user_id = kwargs.get('user_id') #check_perm(user_id, 'update_project') proj_i = _get_project(project.id) proj_i.check_write_permission(user_id) proj_i.name = project.name proj_i.description = project.description attr_map = hdb.add_resource_attributes(proj_i, project.attribute...
def update_project(project,**kwargs)
Update a project returns a project complexmodel
4.160518
4.333534
0.960075
user_id = kwargs.get('user_id') proj_i = _get_project(project_id) #lazy load owners proj_i.owners proj_i.check_read_permission(user_id) proj_j = JSONObject(proj_i) proj_j.networks = [] for net_i in proj_i.networks: #lazy load owners net_i.owners net_i.sce...
def get_project(project_id, include_deleted_networks=False, **kwargs)
get a project complexmodel
3.452194
3.321124
1.039465
user_id = kwargs.get('user_id') projects_i = db.DBSession.query(Project).join(ProjectOwner).join(Network, Project.id==Network.project_id).filter( Network.id==network_id, ProjectOwner.user_id==user_id).o...
def get_project_by_network_id(network_id,**kwargs)
get a project complexmodel by a network_id
3.133598
3.180572
0.985231
user_id = kwargs.get('user_id') projects_i = db.DBSession.query(Project).join(ProjectOwner).filter( Project.name==project_name, ProjectOwner.user_id==user_id).order_by('name').all() ret_projects = ...
def get_project_by_name(project_name,**kwargs)
get a project complexmodel
3.075414
3.154186
0.975026
if visited_children is None: visited_children = [] if back_relationships is None: back_relationships = [] serialized_data = {c.key: getattr(obj, c.key) for c in obj.__table__.columns} #Any other non-column data to include in the keyed tuple for k, v in extras.items(): ...
def to_named_tuple(obj, visited_children=None, back_relationships=None, levels=None, ignore=[], extras={})
Altered from an example found on stackoverflow http://stackoverflow.com/questions/23554119/convert-sqlalchemy-orm-result-to-dict
2.669417
2.674839
0.997973
req_user_id = kwargs.get('user_id') ##Don't load the project's networks. Load them separately, as the networks #must be checked individually for ownership projects_qry = db.DBSession.query(Project) log.info("Getting projects for %s", uid) if include_shared_projects is True: proje...
def get_projects(uid, include_shared_projects=True, projects_ids_list_filter=None, **kwargs)
Get all the projects owned by the specified user. These include projects created by the user, but also ones shared with the user. For shared projects, only include networks in those projects which are accessible to the user. the include_shared_projects flag indicates whether to include projects...
2.994448
3.020673
0.991318
user_id = kwargs.get('user_id') #check_perm(user_id, 'delete_project') project = _get_project(project_id) project.check_write_permission(user_id) project.status = status db.DBSession.flush()
def set_project_status(project_id, status, **kwargs)
Set the status of a project to 'X'
3.968164
4.205828
0.943492
user_id = kwargs.get('user_id') #check_perm(user_id, 'delete_project') project = _get_project(project_id) project.check_write_permission(user_id) db.DBSession.delete(project) db.DBSession.flush() return 'OK'
def delete_project(project_id,**kwargs)
Set the status of a project to 'X'
3.45151
3.648074
0.946118
log.info("Getting networks for project %s", project_id) user_id = kwargs.get('user_id') project = _get_project(project_id) project.check_read_permission(user_id) rs = db.DBSession.query(Network.id, Network.status).filter(Network.project_id==project_id).all() networks=[] for r in rs: ...
def get_networks(project_id, include_data='N', **kwargs)
Get all networks in a project Returns an array of network objects.
3.267132
3.331552
0.980664
net_proj = db.DBSession.query(Project).join(Network, and_(Project.id==Network.id, Network.id==network_id)).first() if net_proj is None: raise HydraError("Network %s not found"% network_id) return net_proj
def get_network_project(network_id, **kwargs)
get the project that a network is in
3.954944
3.970926
0.995975
if types is None: return [] existing_type_ids = [] if resource_i.types: for t in resource_i.types: existing_type_ids.append(t.type_id) new_type_ids = [] for templatetype in types: if templatetype.id in existing_type_ids: continue rt_i ...
def add_resource_types(resource_i, types)
Save a reference to the types used for this resource. @returns a list of type_ids representing the type ids on the resource.
2.102115
2.086172
1.007642
default_units_file_location = os.path.realpath(\ os.path.join(os.path.dirname(os.path.realpath(__file__)), '../', 'static', 'default_units_and_dimensions.json')) d=None with open(default_units_file_location) as json_data: ...
def create_default_units_and_dimensions()
Adds the units and the dimensions reading a json file. It adds only dimensions and units that are not inside the db It is possible adding new dimensions and units to the DB just modifiyin the json file
2.451653
2.393091
1.024471
try: dimension = db.DBSession.query(Dimension).filter(Dimension.name==dimension_name).one() return JSONObject(dimension) except NoResultFound: raise ResourceNotFoundError("Dimension %s not found"%(dimension_name))
def get_dimension_from_db_by_name(dimension_name)
Gets a dimension from the DB table.
3.868662
3.695141
1.046959
rules = db.DBSession.query(Rule).filter(Rule.scenario_id==scenario_id, Rule.status=='A').all() return rules
def get_rules(scenario_id, **kwargs)
Get all the rules for a given scenario.
4.711286
5.019915
0.938519
try: attr_i = db.DBSession.query(Attr).filter(Attr.id==attr_id).one() return attr_i except NoResultFound: return None
def get_attribute_by_id(attr_id, **kwargs)
Get a specific attribute by its ID.
4.158716
4.281137
0.971404
try: attrs_i = db.DBSession.query(Attr).filter(TemplateType.template_id==template_id).filter(TypeAttr.type_id==TemplateType.id).filter(Attr.id==TypeAttr.id).all() log.debug(attrs_i) return attrs_i except NoResultFound: return None
def get_template_attributes(template_id, **kwargs)
Get a specific attribute by its ID.
4.500971
4.588054
0.98102
try: attr_i = db.DBSession.query(Attr).filter(and_(Attr.name==name, Attr.dimension_id==dimension_id)).one() log.debug("Attribute retrieved") return attr_i except NoResultFound: return None
def get_attribute_by_name_and_dimension(name, dimension_id=None,**kwargs)
Get a specific attribute by its name. dimension_id can be None, because in attribute the dimension_id is not anymore mandatory
3.632797
3.889516
0.933997
log.debug("Adding attribute: %s", attr.name) try: attr_i = db.DBSession.query(Attr).filter(Attr.name == attr.name, Attr.dimension_id == attr.dimension_id).one() log.info("Attr already exists") except NoResultFound: attr_i = Attr(...
def add_attribute(attr,**kwargs)
Add a generic attribute, which can then be used in creating a resource attribute, and put into a type. .. code-block:: python (Attr){ id = 1020 name = "Test Attr" dimension_id = 123 }
2.783683
2.834768
0.981979
log.debug("Updating attribute: %s", attr.name) attr_i = _get_attr(attr.id) attr_i.name = attr.name attr_i.dimension_id = attr.dimension_id attr_i.description = attr.description #Make sure an update hasn't caused an inconsistency. #check_sion(attr_i.id) db.DBSession.flush() re...
def update_attribute(attr,**kwargs)
Add a generic attribute, which can then be used in creating a resource attribute, and put into a type. .. code-block:: python (Attr){ id = 1020 name = "Test Attr" dimension_id = 123 }
5.772922
5.552185
1.039757
#Check to see if any of the attributs being added are already there. #If they are there already, don't add a new one. If an attribute #with the same name is there already but with a different dimension, #add a new attribute. # All existing attributes all_attrs = db.DBSession.query(Attr).a...
def add_attributes(attrs,**kwargs)
Add a list of generic attributes, which can then be used in creating a resource attribute, and put into a type. .. code-block:: python (Attr){ id = 1020 name = "Test Attr" dimen = "very big" }
2.881642
2.844961
1.012893
attrs = db.DBSession.query(Attr).order_by(Attr.name).all() return attrs
def get_attributes(**kwargs)
Get all attributes
9.26194
7.945946
1.165618
user_id = kwargs.get('user_id') try: ra = db.DBSession.query(ResourceAttr).filter(ResourceAttr.id == resource_attr_id).one() except NoResultFound: raise ResourceNotFoundError("Resource Attribute %s not found"%(resource_attr_id)) ra.check_write_permission(user_id) ra.is_var = i...
def update_resource_attribute(resource_attr_id, is_var, **kwargs)
Deletes a resource attribute and all associated data.
3.386849
3.477873
0.973828
user_id = kwargs.get('user_id') try: ra = db.DBSession.query(ResourceAttr).filter(ResourceAttr.id == resource_attr_id).one() except NoResultFound: raise ResourceNotFoundError("Resource Attribute %s not found"%(resource_attr_id)) ra.check_write_permission(user_id) db.DBSession.d...
def delete_resource_attribute(resource_attr_id, **kwargs)
Deletes a resource attribute and all associated data.
2.818593
2.993674
0.941516
attr = db.DBSession.query(Attr).filter(Attr.id==attr_id).first() if attr is None: raise ResourceNotFoundError("Attribute with ID %s does not exist."%attr_id) resource_i = _get_resource(resource_type, resource_id) resourceattr_qry = db.DBSession.query(ResourceAttr).filter(ResourceAttr.re...
def add_resource_attribute(resource_type, resource_id, attr_id, is_var, error_on_duplicate=True, **kwargs)
Add a resource attribute attribute to a resource. attr_is_var indicates whether the attribute is a variable or not -- this is used in simulation to indicate that this value is expected to be filled in by the simulator.
2.155062
2.168653
0.993733
type_i = _get_templatetype(type_id) resource_i = _get_resource(resource_type, resource_id) resourceattr_qry = db.DBSession.query(ResourceAttr).filter(ResourceAttr.ref_key==resource_type) if resource_type == 'NETWORK': resourceattr_qry.filter(ResourceAttr.network_id==resource_id) elif...
def add_resource_attrs_from_type(type_id, resource_type, resource_id,**kwargs)
adds all the attributes defined by a type to a node.
2.213986
2.232675
0.99163
user_id = kwargs.get('user_id') resource_attr_qry = db.DBSession.query(ResourceAttr).\ outerjoin(Node, Node.id==ResourceAttr.node_id).\ outerjoin(Link, Link.id==ResourceAttr.link_id).\ outerjoin(ResourceGroup, ResourceGroup.id==ResourceAttr.group_id).filter( Re...
def get_all_resource_attributes(ref_key, network_id, template_id=None, **kwargs)
Get all the resource attributes for a given resource type in the network. That includes all the resource attributes for a given type within the network. For example, if the ref_key is 'NODE', then it will return all the attirbutes of all nodes in the network. This function allows a front end to ...
2.146085
2.174877
0.986761
user_id = kwargs.get('user_id') resource_attr_qry = db.DBSession.query(ResourceAttr).filter( ResourceAttr.ref_key == ref_key, or_( ResourceAttr.network_id==ref_id, ResourceAttr.node_id==ref_id, ResourceAttr.link_id==ref_id, ResourceAttr.grou...
def get_resource_attributes(ref_key, ref_id, type_id=None, **kwargs)
Get all the resource attributes for a given resource. If type_id is specified, only return the resource attributes within the type.
2.257676
2.315138
0.97518
attr_i = _get_attr(attr_id) datasets = db.DBSession.query(Dataset).filter(Dataset.id == ResourceScenario.dataset_id, ResourceScenario.resource_attr_id == ResourceAttr.id, ResourceAttr.attr_id == attr_id).all() bad_datasets = [] for d in datasets: ...
def check_attr_dimension(attr_id, **kwargs)
Check that the dimension of the resource attribute data is consistent with the definition of the attribute. If the attribute says 'volume', make sure every dataset connected with this attribute via a resource attribute also has a dimension of 'volume'.
3.900821
3.766487
1.035665
resource_attr_qry = db.DBSession.query(ResourceAttr).filter( ResourceAttr.id == resource_attr_id, ) resource_attr = resource_attr_qry.first() if resource_attr is None: raise ResourceNotFoundError("Resource attribute %s does not exist", resource_attr_id) return resource_a...
def get_resource_attribute(resource_attr_id, **kwargs)
Get a specific resource attribte, by ID If type_id is Gspecified, only return the resource attributes within the type.
2.998224
3.119343
0.961172
user_id = kwargs.get('user_id') ra_1 = get_resource_attribute(resource_attr_a) ra_2 = get_resource_attribute(resource_attr_b) mapping = ResourceAttrMap(resource_attr_id_a = resource_attr_a, resource_attr_id_b = resource_attr_b, network_a_i...
def set_attribute_mapping(resource_attr_a, resource_attr_b, **kwargs)
Define one resource attribute from one network as being the same as that from another network.
3.100355
3.089263
1.003591
user_id = kwargs.get('user_id') rm = aliased(ResourceAttrMap, name='rm') log.info("Trying to delete attribute map. %s -> %s", resource_attr_a, resource_attr_b) mapping = db.DBSession.query(rm).filter( rm.resource_attr_id_a == resource_attr_a, ...
def delete_attribute_mapping(resource_attr_a, resource_attr_b, **kwargs)
Define one resource attribute from one network as being the same as that from another network.
2.657022
2.802127
0.948216
qry = db.DBSession.query(ResourceAttrMap).filter(or_(ResourceAttrMap.network_a_id == network_id, ResourceAttrMap.network_b_id == network_id)) if network_2_id is not None: qry = qry.filter(or_(ResourceAttrMap.network_a_id==network_2_id, ResourceAttrMap.network_b_id==network_2_id)) mappings = q...
def delete_mappings_in_network(network_id, network_2_id=None, **kwargs)
Delete all the resource attribute mappings in a network. If another network is specified, only delete the mappings between the two networks.
2.253873
2.119238
1.06353
qry = db.DBSession.query(ResourceAttrMap).filter(or_(ResourceAttrMap.network_a_id == network_id, ResourceAttrMap.network_b_id == network_id)) if network_2_id is not None: qry = qry.filter(or_(ResourceAttrMap.network_a_id==network_2_id, ResourceAttrMap.network_b_id==network_2_id)) return qry.a...
def get_mappings_in_network(network_id, network_2_id=None, **kwargs)
Get all the resource attribute mappings in a network. If another network is specified, only return the mappings between the two networks.
2.277215
2.180151
1.044522
qry = db.DBSession.query(ResourceAttrMap).filter( or_( and_( ResourceAttrMap.resource_attr_id_a == ResourceAttr.id, ResourceAttr.node_id == node_id), and_( ResourceAttrMap.resource_attr_id_b == ResourceAttr.id, Reso...
def get_node_mappings(node_id, node_2_id=None, **kwargs)
Get all the resource attribute mappings in a network. If another network is specified, only return the mappings between the two networks.
1.937383
1.908302
1.015239
qry = db.DBSession.query(ResourceAttrMap).filter( or_( and_( ResourceAttrMap.resource_attr_id_a == ResourceAttr.id, ResourceAttr.link_id == link_id), and_( ResourceAttrMap.resource_attr_id_b == ResourceAttr.id, Reso...
def get_link_mappings(link_id, link_2_id=None, **kwargs)
Get all the resource attribute mappings in a network. If another network is specified, only return the mappings between the two networks.
1.939275
1.931637
1.003954
qry = db.DBSession.query(ResourceAttrMap).filter( or_( and_( ResourceAttrMap.resource_attr_id_a == ResourceAttr.id, ResourceAttr.network_id == network_id), and_( ResourceAttrMap.resource_attr_id_b == ResourceAttr.id, ...
def get_network_mappings(network_id, network_2_id=None, **kwargs)
Get all the mappings of network resource attributes, NOT ALL THE MAPPINGS WITHIN A NETWORK. For that, ``use get_mappings_in_network``. If another network is specified, only return the mappings between the two networks.
1.980126
1.935478
1.023068
qry = db.DBSession.query(ResourceAttrMap).filter( ResourceAttrMap.resource_attr_id_a == resource_attr_id_source, ResourceAttrMap.resource_attr_id_b == resource_attr_id_target).all() if len(qry) > 0: return 'Y' else: return 'N'
def check_attribute_mapping_exists(resource_attr_id_source, resource_attr_id_target, **kwargs)
Check whether an attribute mapping exists between a source and target resource attribute. returns 'Y' if a mapping exists. Returns 'N' in all other cases.
2.791106
2.48994
1.120953
user_id=kwargs.get('user_id') try: group_i = db.DBSession.query(AttrGroup).filter( AttrGroup.id==group_id).one() group_i.project.check_read_permission(user_id) except NoResultFound: raise HydraError("Group %s not found" % (group_id,)...
def get_attribute_group(group_id, **kwargs)
Get a specific attribute group
4.972746
4.910357
1.012706
log.info("attributegroup.project_id %s",attributegroup.project_id) # It is None while it should be valued user_id=kwargs.get('user_id') project_i = db.DBSession.query(Project).filter(Project.id==attributegroup.project_id).one() project_i.check_write_permission(user_id) try: group_i = d...
def add_attribute_group(attributegroup, **kwargs)
Add a new attribute group. An attribute group is a container for attributes which need to be grouped in some logical way. For example, if the 'attr_is_var' flag isn't expressive enough to delineate different groupings. an attribute group looks like: { 'proje...
2.650333
2.46731
1.074179
user_id=kwargs.get('user_id') if attributegroup.id is None: raise HydraError("cannot update attribute group. no ID specified") try: group_i = db.DBSession.query(AttrGroup).filter(AttrGroup.id==attributegroup.id).one() group_i.project.check_write_permission(user_id) g...
def update_attribute_group(attributegroup, **kwargs)
Add a new attribute group. An attribute group is a container for attributes which need to be grouped in some logical way. For example, if the 'attr_is_var' flag isn't expressive enough to delineate different groupings. an attribute group looks like: { 'proje...
3.382776
3.115817
1.085679