def modify_config_js(): path = os.path.join(module_path(), '..', 'data', 'www', 'js', 'config.js') l = [] with open(path) as f: for i in f.readlines(): if len(i.strip())>14 and i.strip()[:14] == 'var g_app_root': root = os.path.join(module_path(), '..','data', 'www') root = root.replace('\\','/') g_app_root = 'var g_app_root = "file:///' + root + '";\r\n' l.append(g_app_root) elif len(i.strip())>20 and i.strip()[:20] == 'var g_local_tile_url': g_local_tile_path = 'var g_local_tile_url = "%s";\r\n' % gConfig['map_local_tiles_url'] l.append(g_local_tile_path) elif "var g_default_basemap" in i: if len(gConfig['map_local_tiles_url'])>0: l.append("var g_default_basemap = 'basemap_esrilocal';\r\n") else: l.append("var g_default_basemap = 'basemap_googlesat';\r\n") elif "'basemap_esrilocal':'本地地图'," in i: if len(gConfig['map_local_tiles_url'])>0: l.append("\t'basemap_esrilocal':'本地地图',\r\n") else: l.append("\t//'basemap_esrilocal':'本地地图',\r\n") else: l.append(i) s = '' for i in l: s += dec(i) #print(s) with open(path, 'w') as f: f.write(enc(s))
def test_isolutor_count(): client = MongoClient('localhost', 27017, slave_okay=True, replicaset='kmgdrs', read_preference=ReadPreference.PRIMARY) db = client['ztgd'] features = db['features'] mapfunc = Code("function() {" " var idx = this.properties.name.indexOf('#');" " var line_name = this.properties.name.slice(0, idx);" " if(this.properties.metals){" " var count = 0;" " this.properties.metals.forEach(function(metal) {" " if(metal.type == '绝缘子串'){" #" if(metal.type == '防振锤'){" " emit(line_name, {count:1});" " }" " });" " }" "}") reducefunc = Code("function(key,values){" " var result = {count:0};" " for (var i = 0; i < values.length; i++) {" " result.count += values[i].count;" " }" " return result;" "}") results = features.map_reduce(mapfunc, reducefunc, "isolutor_count") for i in results.find(): print('%s=%d' % (enc(i['_id']), i['value']['count']))
def test_isolutor_count(): client = MongoClient('localhost', 27017, slave_okay=True, replicaset='kmgdrs', read_preference = ReadPreference.PRIMARY) db = client['ztgd'] features = db['features'] mapfunc = Code("function() {" " var idx = this.properties.name.indexOf('#');" " var line_name = this.properties.name.slice(0, idx);" " if(this.properties.metals){" " var count = 0;" " this.properties.metals.forEach(function(metal) {" " if(metal.type == '绝缘子串'){" #" if(metal.type == '防振锤'){" " emit(line_name, {count:1});" " }" " });" " }" "}" ) reducefunc = Code("function(key,values){" " var result = {count:0};" " for (var i = 0; i < values.length; i++) {" " result.count += values[i].count;" " }" " return result;" "}" ) results = features.map_reduce(mapfunc,reducefunc,"isolutor_count") for i in results.find(): print('%s=%d' % (enc(i['_id']), i['value']['count']))
#log(u'连接服务器出错:%s' % devicecabledata['error']) #sys.exit(0) gTunnelList, start, geojson = init_tunnel_list(tdata) device_geojson = init_device_list(devicetunneldata) s = json.dumps(gTunnelList, indent=4, ensure_ascii=False) s_start = json.dumps(start, indent=4, ensure_ascii=False) s_geojson = json.dumps(geojson, indent=4, ensure_ascii=False) s_device_geojson = json.dumps(device_geojson, indent=4, ensure_ascii=False) path = os.path.join(module_path(), LEVEL_DIR, 'tunnels.json') path_start = os.path.join(module_path(), LEVEL_DIR, 'tunnels_start.json') path_geojson = os.path.join(module_path(), JSONROOT, 'tunnels_geojson.json') path_device_geojson = os.path.join(module_path(), JSONROOT, 'device_geojson.json') with open(path, 'w+') as f: f.write(enc(s)) with open(path_geojson, 'w+') as f: f.write(enc(s_geojson)) with open(path_device_geojson, 'w+') as f: f.write(enc(s_device_geojson)) if not os.path.exists(path_start): with open(path_start, 'w+') as f: f.write(enc(s_start)) log('tunnel list initialized') #print(s) #print(s_start) gCableList = init_cable_list(cdata) s = json.dumps(gCableList, indent=4, ensure_ascii=False) path = os.path.join(module_path(), LEVEL_DIR, 'cables.json')