def find_next_by_node(features, collection_edges, alist=[], id=None): if isinstance(id, str): id = add_mongo_id(id) l = _.deep_pluck(list(collection_edges.find({'properties.start':id})),'properties.end') for i in l: obj = _.find(features, {'_id': i}) if obj and obj.has_key('properties'): if obj['properties'].has_key('devices'): alist.append(obj['_id']) else: alist = find_next_by_node(features, collection_edges, alist, obj['_id']) return alist
def find_next_by_node(features, collection_edges, alist=[], id=None): if isinstance(id, str): id = add_mongo_id(id) l = _.deep_pluck(list(collection_edges.find({'properties.start': id})), 'properties.end') for i in l: obj = _.find(features, {'_id': i}) if obj and obj.has_key('properties'): if obj['properties'].has_key('devices'): alist.append(obj['_id']) else: alist = find_next_by_node(features, collection_edges, alist, obj['_id']) return alist
def test_jfykx(): #酒房丫口线 piny = get_pinyin_data() client = MongoClient('localhost', 27017) db = client['kmgd_pe'] collection_fea = db['features'] collection_network = db['network'] collection_edges = db['edges'] one = collection_network.find_one( {'_id': add_mongo_id('570ce0c1ca49c80858320619')}) # print(len(one['properties']['nodes'])) branches = [] l = list(collection_fea.find({'properties.py': { '$regex': '^.*dhpzzx.*$' }})) # 大河平掌支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大河平掌支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线大河平掌支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*bszzx.*$' }})) # 控制半山寨支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'控制半山寨支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线控制半山寨支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*mchzx.*$' }})) # 控制马草河支线支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'控制马草河支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线控制马草河支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*dpzzx.*$' }})) # 大平掌支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大平掌支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线大平掌支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*bjzx.*$' }})) # 碧鸡支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'碧鸡支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线碧鸡支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^jfykxN.*$'}})) ids = _.pluck(l, '_id') main_ids = _.difference(ids, branches) print('len(main_ids)=%d' % len(main_ids)) l = list(collection_fea.find({'_id': {'$in': main_ids}})) # 酒房丫口线 l = sortlist(collection_edges, l) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'酒房丫口线%d, [%s]' % (len(l), s)) name = u'酒房丫口线主线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } collection_network.insert(o)
def test_pzzx(): #坪掌寨线 piny = get_pinyin_data() client = MongoClient('localhost', 27017) db = client['kmgd_pe'] collection_fea = db['features'] collection_network = db['network'] collection_edges = db['edges'] one = collection_network.find_one( {'_id': add_mongo_id('570ce0c1ca49c8085832061a')}) branches = [] print(len(one['properties']['nodes'])) l = list(collection_fea.find({'properties.py': { '$regex': '^.*sslzx.*$' }})) #松山林支线 # print(len(l)) l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'松山林支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线松山林支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*mdszx.*$' }})) # 忙肚山支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'忙肚山支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线忙肚山支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*mdszx.*$' }})) # 大河边支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大河边支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线大河边支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': { '$regex': '^.*xdtzx.*$' }})) #下大田支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'下大田支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线下大田支线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^pzzxN.*$'}})) ids = _.pluck(l, '_id') main_ids = _.difference(ids, branches) print('len(main_ids)=%d' % len(main_ids)) l = list(collection_fea.find({'_id': {'$in': main_ids}})) # 坪掌寨线 l = sortlist(collection_edges, l) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'坪掌寨线%d, [%s]' % (len(l), s)) name = u'坪掌寨线主线' o = { 'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace( 'I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') } } collection_network.insert(o)
def test_jfykx():#酒房丫口线 piny = get_pinyin_data() client = MongoClient('localhost', 27017) db = client['kmgd_pe'] collection_fea = db['features'] collection_network = db['network'] collection_edges = db['edges'] one = collection_network.find_one({'_id': add_mongo_id('570ce0c1ca49c80858320619')}) # print(len(one['properties']['nodes'])) branches = [] l = list(collection_fea.find({'properties.py': {'$regex': '^.*dhpzzx.*$'}})) # 大河平掌支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大河平掌支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线大河平掌支线' o = {'properties':{ 'name':name, 'py':piny.hanzi2pinyin_first_letter(name.replace('#','').replace('II',u'二').replace('I',u'一').replace(u'Ⅱ',u'二').replace(u'Ⅰ',u'一')), 'voltage':'12', 'webgis_type':'polyline_dn', 'nodes':_.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*bszzx.*$'}})) # 控制半山寨支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'控制半山寨支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线控制半山寨支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*mchzx.*$'}})) # 控制马草河支线支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'控制马草河支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线控制马草河支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*dpzzx.*$'}})) # 大平掌支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大平掌支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线大平掌支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*bjzx.*$'}})) # 碧鸡支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'碧鸡支线%d, [%s]' % (len(l), s)) name = u'酒房丫口线碧鸡支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^jfykxN.*$'}})) ids = _.pluck(l, '_id') main_ids = _.difference(ids, branches) print('len(main_ids)=%d' % len(main_ids)) l = list(collection_fea.find({'_id': {'$in': main_ids}})) # 酒房丫口线 l = sortlist(collection_edges, l) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'酒房丫口线%d, [%s]' % (len(l), s)) name = u'酒房丫口线主线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} collection_network.insert(o)
def test_pzzx():#坪掌寨线 piny = get_pinyin_data() client = MongoClient('localhost', 27017) db = client['kmgd_pe'] collection_fea = db['features'] collection_network = db['network'] collection_edges = db['edges'] one = collection_network.find_one({'_id':add_mongo_id('570ce0c1ca49c8085832061a')}) branches = [] print(len(one['properties']['nodes'])) l = list(collection_fea.find({'properties.py': {'$regex': '^.*sslzx.*$'}})) #松山林支线 # print(len(l)) l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'松山林支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线松山林支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*mdszx.*$'}})) # 忙肚山支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'忙肚山支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线忙肚山支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*mdszx.*$'}})) # 大河边支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'大河边支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线大河边支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^.*xdtzx.*$'}})) #下大田支线 l = sortlist(collection_edges, l) branches.extend(_.pluck(l, '_id')) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'下大田支线%d, [%s]' % (len(l), s)) name = u'坪掌寨线下大田支线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} # print(o) collection_network.insert(o) l = list(collection_fea.find({'properties.py': {'$regex': '^pzzxN.*$'}})) ids = _.pluck(l, '_id') main_ids = _.difference(ids, branches) print('len(main_ids)=%d' % len(main_ids)) l = list(collection_fea.find({'_id': {'$in': main_ids}})) # 坪掌寨线 l = sortlist(collection_edges, l) s = ','.join(_.deep_pluck(l, 'properties.name')) print(u'坪掌寨线%d, [%s]' % (len(l), s)) name = u'坪掌寨线主线' o = {'properties': { 'name': name, 'py': piny.hanzi2pinyin_first_letter( name.replace('#', '').replace('II', u'二').replace('I', u'一').replace(u'Ⅱ', u'二').replace(u'Ⅰ', u'一')), 'voltage': '12', 'webgis_type': 'polyline_dn', 'nodes': _.pluck(l, '_id') }} collection_network.insert(o)