def exportClusterPoints(): """ 根据网点文件id导出网点和聚类信息 """ res = ResMsg() try: aiBusModel = AiBusModel() userInfo = session.get("userInfo") data = request.get_json() fileId = data["fileId"] # print(fileId) #sitefileList=aiBusModel.searchSiteListByFileId(fileId) # 聚类文件导出 #1)先查询聚类参数 clusterParams = aiBusModel.selectClusterParams((fileId)) if not clusterParams: clusterParams = aiBusModel.selectClusterParamsBySiteFileId( (fileId)) if not clusterParams: res.update(code=ResponseCode.Success, data={"clusterResult": []}) return res.data fileId = clusterParams["id"] clusterInfo = aiBusModel.searchClusterResult(fileId) if None == clusterInfo: clusterInfo = [] res.update(code=ResponseCode.Success, data={"clusterResult": clusterInfo}) return res.data except Exception as e: res.update(code=ResponseCode.Fail) return res.data
def exportClusterResult(): res = ResMsg() try: aiBusModel = AiBusModel() fileId = request.args.get("fileId") clusterPoints = [] sitePoints = [] #1)先查询聚类参数 siteParams = aiBusModel.selectClusterParams( (fileId)) ##根据网点文件fileId的查询网点文件 if not siteParams: siteResut = aiBusModel.exportCustomSiteInfo(fileId) siteItems = [ "区域", "经度", "纬度", "公交站", "公交站属性", "客户姓名", "客户属性", "年龄", "客户地址", "乘车人数", "年级" ] for item in siteResut: if item["siteProperty"] == 1: item["siteProperty"] = "固定" elif item["siteProperty"] == 0: item["siteProperty"] = "临时" else: item["siteProperty"] = "自定义" row = [ item["region"], item["longitude"], item["latitude"], item["siteName"], item["siteProperty"], item["clientName"], item["clientProperty"], item["age"], item["clientAddress"], item["number"], item["grade"] ] sitePoints.append(row) file_path = writeExcel(fileId, siteItems, sitePoints, "网点文件") clusterParams = aiBusModel.selectClusterParamsBySiteFileId( (fileId)) ##根据网点文件fileId查询聚类文件 if clusterParams: clusterId = clusterParams["id"] #2)查询聚类结果 clusterResut = aiBusModel.exportClusterResult((1, clusterId)) clusterItems = ["区域", "经度", "纬度", "公交站", "公交站属性", "乘车人数"] for item in clusterResut: if item["relativeProperty"] == 1: item["relativeProperty"] = "固定" elif item["relativeProperty"] == 0: item["relativeProperty"] = "临时" else: item["relativeProperty"] = "自定义" clusterrow = [ item["region"], item["longitude"], item["latitude"], item["clusterName"], item["relativeProperty"], item["number"] ] clusterPoints.append(clusterrow) file_path = writeExcel(fileId, clusterItems, clusterPoints, "聚类文件", removeLabel=False) if file_path is None: return to_json({'success': 0, 'message': '请输入参数'}) else: if file_path == '': return to_json({'success': 0, 'message': '请输入正确路径'}) else: if not os.path.isfile(file_path): return to_json({'success': 0, 'message': '文件路径不存在'}) else: filename = os.path.basename( file_path) #filename=routeplan_student.xls utf_filename = quote(filename.encode('utf-8')) # print(utf_filename) response = Response(file_iterator(file_path)) # response.headers['Content-Type'] = 'application/octet-stream' # response.headers["Content-Disposition"] = 'attachment;filename="{}"'.format(filename) response.headers[ "Content-Disposition"] = "attachment;filename*=UTF-8''{}".format( utf_filename) response.headers[ 'Content-Type'] = "application/octet-stream; charset=UTF-8" #print(response) return response except Exception as e: res.update(code=ResponseCode.Fail, msg="导出报错!") return res.data
def queryClusterResult(): res = ResMsg() try: logger.info("begin queryClusterResult!") aiBusModel = AiBusModel() userInfo = session.get("userInfo") data = request.get_json() fileId = data["fileId"] clusterOutPoints = [] clusterCorePoints = [] clusterAroundPoints = [] #1)先查询聚类参数 clusterParams = aiBusModel.selectClusterParams((fileId)) if not clusterParams: clusterParams = aiBusModel.selectClusterParamsBySiteFileId( (fileId)) if not clusterParams: res.update(code=ResponseCode.Success) return res.data fileId = clusterParams["id"] #2)查询聚类结果 clusterResut = aiBusModel.selectClusterResult((1, fileId)) for item in clusterResut: if item["relativeProperty"] == 1: siteProperty = "固定" elif item["relativeProperty"] == 0: siteProperty = "临时" else: siteProperty = "自定义" #根据site id查询网点信息 clientNames = [] users = [] if item["siteSet"] != '': users = item["siteSet"].split(",") siteInfo = aiBusModel.selectClientNameByIds(users) for site in siteInfo: clientNames.append(site["clientName"]) row={"id":item["id"],"siteName":item["clusterName"],"siteProperty":siteProperty,\ "longitude":item["longitude"],"latitude":item["latitude"],"number":item["number"],\ "users":users,"userNames":clientNames} if item["clusterProperty"] == 1: clusterCorePoints.append(row) elif item["clusterProperty"] == 2: clusterAroundPoints.append(row) else: clusterOutPoints.append(row) res.update(code=ResponseCode.Success, data={ "epsRadius": clusterParams["clusterRadius"], "minSamples": clusterParams["clusterMinSamples"], "clusterCorePoints": clusterCorePoints, "clusterAroundPoints": clusterAroundPoints, "clusterOutPoints": clusterOutPoints }) return res.data except Exception as e: logger.error("generateClusterPoints exception:{}".format(str(e))) res.update(code=ResponseCode.Fail, msg="查询聚类结果报错!") return res.data