def GetMore(request): graph = Neo4j_Object() label = request.POST.get('label', '') property = request.POST.get('property', '') content = request.POST.get('content', '') res = graph.GetMore(property, content, label) return HttpResponse(json.dumps(res))
def GetCoordinate(request): graph = Neo4j_Object() choosed_layer = request.POST.get('layer', '') if (choosed_layer != ''): try: layer_data = layer.objects.get(layer_name=choosed_layer) except Exception as e: print(e) return HttpResponse(0) else: label = layer_data.layer_label longitude = layer_data.layer_longitude latitude = layer_data.layer_latitude property = layer_data.layer_property else: label = request.POST.get('label', '') longitude = request.POST.get('longitude', '') latitude = request.POST.get('latitude', '') property = request.POST.get('property', '') res = graph.GetCoordinate(label, property, longitude, latitude) Coordinate = [] for i in res: temp = {} temp["title"] = i["title"] temp["type"] = i["type"][0] #暂不考虑两个标签的情况 temp["point"] = str(i["longitude"]) + "|" + str(i["latitude"]) temp["isOpen"] = 1 temp["property"] = property Coordinate.append(temp) return HttpResponse(json.dumps(Coordinate))
def index(request): #登录验证 username = request.user.username title = "数据概览" if not username: return redirect('/user/login.html') else: graph = Neo4j_Object() nodesCounts = graph.GetNodesCounts() labels = graph.GetLabels() labels_json = json.dumps(labels) #print(labels_json) lablesCount = len(labels) if (labels != 0) else 0 relaCounts = graph.GetRelaCounts() relaType = graph.GetRela() relaTypeCounts = len(relaType) if (relaType != 0) else 0 keyslist = serializers.serialize("json", labels_key.objects.all()) degrees = graph.GetDegrees() averageClusteringCoefficient = graph.GetAverageClusteringCoefficient() # louvain = graph.GetLouvai() return render(request, 'index.html', locals())
def map(request): title = "地图视图" username = request.user.username if not username: return redirect('/user/login.html') else: graph = Neo4j_Object() labels = graph.GetLabels() layers = layer.objects.all().values('layer_name') return render(request, 'map.html', locals())
def relationship(request): title = "关系发现" username = request.user.username if not username: return redirect('/user/login.html') else: graph = Neo4j_Object() labels = graph.GetLabels() keyslist = list(labels_key.objects.all().values()) return render(request, 'relationship.html', locals())
def network(request): #登录验证 title = "节点查询" username = request.user.username if not username: return redirect('/user/login.html') else: graph = Neo4j_Object() labels = graph.GetLabels() keyslist = list(labels_key.objects.all().values()) return render(request, 'network.html', locals())
def analysis(request): title = "实例分析" username = request.user.username if not username: return redirect('/user/login.html') else: graph = Neo4j_Object() labels = graph.GetLabels() project_id = request.GET.get('id') project_list = project_module.objects.get(id=project_id) algo_mark = get_mark(project_list.project_algo.algo_content) json_algo_mark = json.dumps(algo_mark) keyslist = list(labels_key.objects.all().values()) return render(request, 'analysis.html', locals())
def GetPoint(request): graph = Neo4j_Object() label = request.POST.get('label', '') longitude = request.POST.get('longitude', '') latitude = request.POST.get('latitude', '') property = request.POST.get('property', '') query = request.POST.get('query', '') res = graph.GetPoint(label, property, longitude, latitude, query) Coordinate = [] for i in res: temp = {} temp["title"] = i["title"] temp["type"] = i["type"][0] # 暂不考虑两个标签的情况 temp["point"] = str(i["longitude"]) + "|" + str(i["latitude"]) temp["isOpen"] = 1 temp["property"] = property Coordinate.append(temp) return HttpResponse(json.dumps(Coordinate))
def pro_manage(request, project_manage): if (project_manage == 'project_add'): name = request.POST.get('project-name', '') content = request.POST.get('project-content', '') algo = request.POST.get('project-algo', '') layout = request.POST.get('project-vis', '') # data = request.FILES.get('project-data','') # data.save() if (algo): algo_name = algo_module.objects.get(algo_name=algo) else: algo_name = '' if (name and algo_name): try: project_module.objects.create(project_name=name, project_algo=algo_name, project_layout=layout, project_text=content) except Exception as e: print(e) error = "创建失败" else: error = "创建失败" return redirect('/project') if (project_manage == 'project_del'): project_id = request.POST.get('id', '') try: project_module.objects.filter(id=project_id).delete() except Exception as e: error = "操作失败:" + e return HttpResponse(error) else: return HttpResponse('成功删除') if (project_manage == 'project_start'): mark = request.POST.dict() project_list = project_module.objects.get(id=mark['id']) algo = project_list.project_algo.algo_content for key in mark: if (key != 'id'): algo = algo.replace(key, mark[key]) graph = Neo4j_Object() res = graph.ProjectRunCql(algo, mark['id']) #获取运行结果 graph = getJson(res) #数据格式处理 return HttpResponse(json.dumps(graph))
def GetRegion(request): graph = Neo4j_Object() label = request.POST.get('label', '') longitude = request.POST.get('longitude', '') latitude = request.POST.get('latitude', '') key = request.POST.get('property', '') if_ = request.POST.get('if_', '') content = request.POST.get('filter', '') res = graph.GetRegion(label, key, longitude, latitude, key, if_, content) Coordinate = [] for i in res: temp = {} temp["title"] = i["title"] temp["type"] = i["type"][0] #暂不考虑两个标签的情况 temp["point"] = str(i["longitude"]) + "|" + str(i["latitude"]) temp["isOpen"] = 1 temp["property"] = key Coordinate.append(temp) return HttpResponse(json.dumps(Coordinate))
def for_compare(request, ajax): graph = Neo4j_Object() label = request.POST.get('label', '') rela = request.POST.get('rela', '') key1 = request.POST.get('key1', '') if1 = request.POST.get('if1', '') content1 = request.POST.get('content1', '') if (ajax == 'pagerank'): res = graph.GetPageRankWithCypher(label, rela, key1, if1, content1) res_ = [] for i in res: temp = {} node = i['node'] label = str(node.labels) label = label[1:] property = get_property(label) if (property != '未知节点'): temp['node'] = node[property] else: temp['node'] = property temp['label'] = label temp['score'] = round(i['score'], 3) res_.append(temp) # print(res_) return HttpResponse(json.dumps(res_)) if (ajax == 'count'): res = graph.GetCompareGraph(label, rela, key1, if1, content1) all_nodes = graph.GetNodesCounts() all_labels = graph.GetLabels() all_relas = graph.GetRelaCounts() result = {} result['nodenum'] = res[0]['nodenum'] result['allnode'] = all_nodes result['labelnum'] = res[0]['labelnum'] result['alllabel'] = len(all_labels) result['relanum'] = res[1]['relanum'] result['allrelas'] = all_relas result['avgdegree'] = round(res[2]['degree'] / res[0]['nodenum'], 2) result['avgCC'] = round(res[3]['averageClusteringCoefficient'], 3) return HttpResponse(json.dumps(result))
def getData(request, ajax): #接受ajax传来的数据进行查询和处理操作 graph = Neo4j_Object() if (ajax == 'query'): #索引查询 index = graph.GetIndexlist() return HttpResponse(json.dumps(index)) if (ajax == 'search'): #网络视图查看深度为3的节点关系 index = request.GET.get("index") index = index.split(',') content = request.GET.get("content") #暂不考虑两个标签导致内容多于两个出现逗号的情况 label = request.GET.get("label") if (index and content and label): node_key = graph.GetMore(index[0], content, label) node_links = graph.GetGraph(index[0], content, label) input = [] for i in node_links: for j in i['r']: if j not in input: input.append(j) GraphJson = getJson(input) GraphJson.append(node_key) keysList = list(labels_key.objects.all().values()) GraphJson.append(keysList) # print(json.dumps(GraphJson)) return HttpResponse(json.dumps(GraphJson)) if (ajax == 'keys'): #获取所有标签列表 keys_list = [] label = request.GET.get("label") keys = graph.GetKeys(label) for i in keys: for j in i['keys']: if j not in keys_list: keys_list.append(j) return HttpResponse(json.dumps(keys_list)) if (ajax == 'shortpath'): #最短路径查询 start_label = request.POST.get('start_label', '') start_key = request.POST.get('start_key', '') start_content = request.POST.get('start_content', '') end_label = request.POST.get('end_label', '') end_key = request.POST.get('end_key', '') end_content = request.POST.get('end_content', '') weight = request.POST.get('weight', '') #print(start_label,start_key,start_content) rela_input = graph.GetShortTestPath(start_label, start_key, start_content, end_label, end_key, end_content, weight) GraphJson = getJson(rela_input) return HttpResponse(json.dumps(GraphJson)) if (ajax == 'ksp'): start_label = request.POST.get('start_label', '') start_key = request.POST.get('start_key', '') start_content = request.POST.get('start_content', '') end_label = request.POST.get('end_label', '') end_key = request.POST.get('end_key', '') end_content = request.POST.get('end_content', '') k = request.POST.get('k', '') weight = request.POST.get('weight', '') rela_input = graph.GetKSP(start_label, start_key, start_content, end_label, end_key, end_content, k, weight) GraphJson = getJson(rela_input) return HttpResponse(json.dumps(GraphJson)) if (ajax == 'find'): label = request.POST.get('label', '') query = request.POST.get('query', '') deepth = request.POST.get('deepth', '') key = request.POST.get('key', '') if (query and (key == '' or label == '选择对象标签')): #索引搜索 result = graph.GetSearch(query) else: print("here") result = graph.GetSearchAll(query, label, key) #全局搜索 for i in result: t_label = i['labels'] key = [] index = [] for j in t_label: #有的节点两个标签,所以用循环 try: res = labels_key.objects.get(labels=j) except: print('映射表无记录!') else: if (res.main_key): x = res.main_key index.append(x) key.append(i['node'][x]) # key.append(res.main_key) elif (res.second_key): x = res.second_key index.append(x) key.append(i['node'][x]) # key.append(res.second_key) if not key: key.append('未知节点') i['key'] = key i['index'] = index # print(result) return HttpResponse(json.dumps(result)) if (ajax == 'pagerank'): label = request.POST.get('label', '') res = graph.GetPageRank(label=label) return HttpResponse(json.dumps(res)) if (ajax == 'findrela'): start_label = request.POST.get('start_label', '') start_key = request.POST.get('start_key', '') start_content = request.POST.get('start_content', '') end_label = request.POST.get('end_label', '') end_key = request.POST.get('end_key', '') end_content = request.POST.get('end_content', '') deepth = request.POST.get('deepth', '') rela_input = graph.FindRela(start_label, start_key, start_content, end_label, end_key, end_content, deepth) input = [] for i in rela_input: for j in i['r']: if j not in input: input.append(j) GraphJson = getJson(input) return HttpResponse(json.dumps(GraphJson)) if (ajax == 'getLouvai'): louvain = graph.GetLouvai() return HttpResponse(louvain) if (ajax == 'getIndex'): index = graph.GetIndex() return HttpResponse(json.dumps(index)) if (ajax == 'getMainIndex'): filename = "sys.conf" # 相对路径,文件在.py文件所在的目录中 try: fobj = open(filename, 'r') except IOError as e: print(e) return HttpResponse(0) else: res = fobj.read() pattern = re.compile(r"(?<=index=)[a-zA-Z0-9].*") main_index = re.findall(pattern, res, flags=0)[0] print(main_index) if (main_index): return HttpResponse(json.dumps(main_index)) else: return HttpResponse(0) if (ajax == 'setMainindex'): main_index = request.POST.get('main_index', '') filename = "sys.conf" try: fobj = open(filename, 'r') except IOError as e: print(e) return HttpResponse(0) else: res = fobj.read() fobj.close() res = (re.sub(re.compile(r"(?<=index=)[a-zA-Z0-9].*"), main_index, res)) with open("sys.conf", "w") as f2: f2.write(res) return HttpResponse(1)