当前位置: 首页>>代码示例>>Python>>正文


Python Node.create方法代码示例

本文整理汇总了Python中models.Node.create方法的典型用法代码示例。如果您正苦于以下问题:Python Node.create方法的具体用法?Python Node.create怎么用?Python Node.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Node的用法示例。


在下文中一共展示了Node.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calculate_connected_component

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import create [as 别名]
def calculate_connected_component(index, graph, top_artists, talky=False):
    """
	Takes the given graph and computes the following measures:
		- size (number of nodes)
		[- diameter]
		- density
		- degree
		- closeness_centrality
		[- betweenness_centrality]
		[- eccentricity]

	The first three measures are computed for each connected component.
	The remaining ones are computed for each node.

	The result is written to a database (see tricorder.models).
	"""
    is_real_graph = graph.number_of_edges() > 0
    num_artists = 0
    num_top_artists = 0

    # calculate measures (only if we have edges!)
    density = nx.density(graph) if is_real_graph else 0
    # print "diameter..."
    # diameter = nx.diameter(graph) if is_real_graph else 0
    degree = sc.degree_centrality(graph) if is_real_graph else {}
    closeness = sc.closeness_centrality(graph) if is_real_graph else {}
    # betweenness = sc.betweenness_centrality(graph) if is_real_graph else {}
    # print "eccentricity..."
    # eccentricity = sc.eccentricity(graph) if is_real_graph else {}

    # create Node DB entries
    for id, attrs in graph.node.items():
        if attrs["type"] == "artist":
            num_artists += 1
            if attrs["name"] in top_artists:
                num_top_artists += 1
                # ecc = 1/eccentricity[id] if id in eccentricity else 0 # need an extra variable here since division by zero is evil
        Node.create(
            nid=int(id),
            pid=graph.graph["pid"],
            node_type=attrs["type"],
            name=attrs["name"],
            degree=degree.get(id, 0),
            closeness=closeness.get(id, 0),
        )
        # eccentricity=ecc)#, betweenness=betweenness.get(id, 0))

        # create Partition DB entry
    Partition.create(
        pid=graph.graph["pid"],  # diameter=diameter,
        num_nodes=graph.number_of_nodes(),
        num_edges=graph.number_of_edges(),
        num_artists=num_artists,
        num_top_artists=num_top_artists,
        density=density,
    )

    if talky and index % 500 == 0:
        print index
开发者ID:Wolff09,项目名称:nap,代码行数:61,代码来源:calculator.py

示例2: seed_node

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import create [as 别名]
	def seed_node(site_id = None, alias = None, latitude = None, longitude = None):
		if site_id:
			site = Site.query.filter_by(id = site_id).first()
		else:
			site = Site.create(name = 'Techrice site {}'.format(uuid4().hex))
		
		if not alias: 
			alias = 'Techrice node {}'.format(uuid4().hex)
		node = Node.create(name = alias, site = site, latitude = latitude, longitude = longitude)
		

		solar = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'solar voltage').first(), name = 'vsol')
		battery = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'battery voltage').first(), name = 'vbat')
		temperature = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'DHT11 temperature').first(), name = 'temperature')
		humidity = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'DHT11 humidity').first(), name = 'humidity')
		sonar = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'sonar HC SR-04').first(), name = 'sonar')

		header = Header.get_header(node_id = node.id)
		print header

		return {
			'node': 'name: {}, id: {}, longitude: {}, latitude: {}'.format(node.name, node.id, node.longitude, node.latitude),
			'sensors': map(lambda s: 'name: {}, id: {}'.format(s.name, s.id), node.sensors),
			'header' : header
			}
开发者ID:Hackerfarm,项目名称:techrice,代码行数:27,代码来源:seed.py

示例3: seed_site

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import create [as 别名]
def seed_site(sensors = 1, days = 7, interval_seconds = 3600):
	site = Site.create(name = 'seeded_site')
	node = Node.create(name = 'seeded_node', site = site, latitude = 35.146623 + random() / 100.0, longitude = 139.9835682 + random() / 100.0)
	sensortype = SensorType.create(name = 'HC SR-04', unit = 'cm')
	for i in range(sensors):
		sensor = Sensor.create(sensortype = sensortype, node = node, name = 'water distance %s'%i)
		timestamp = datetime.utcnow() - timedelta(days = 7)
		data = loggeobrowngen()
		n_readings = 0
		while timestamp < datetime.utcnow():
			Reading.create(sensor = sensor, value = data.next(), timestamp = timestamp)
			timestamp += timedelta(seconds = interval_seconds)
			n_readings += 1
		data.close()
	return {'site': site, 'node': node}
开发者ID:Hackerfarm,项目名称:techrice,代码行数:17,代码来源:seed.py

示例4: post

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import create [as 别名]
	def post(self):
		parser = reqparse.RequestParser(bundle_errors = True)
		parser.add_argument('site_id', type=int, location='form', required=True, help='<int> site_id required')
		parser.add_argument('name', type=str, location='form', required=True, help='<str> name required')
		parser.add_argument('longitude', type=float, location='form', required=True, help='<float> longitude required')
		parser.add_argument('latitude', type=float, location='form', required=True, help='<float> latitude required')
		args = parser.parse_args()
		
		site = Site.query.filter_by(id = args['site_id']).first()
		if not site:
			return jsonify(ApiError('site {} not found'.format(args['site_id'])))

		node = Node.create(site = site, name = args['name'], longitude = args['longitude'], latitude = args['latitude'])
		if node:
			return jsonify(ApiObjects(node.json()))
		else:
			return jsonify(ApiObjects())
开发者ID:Hackerfarm,项目名称:techrice,代码行数:19,代码来源:resources.py


注:本文中的models.Node.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。