Beispiel #1
0
def addNewClusterPoint():
    res = ResMsg()
    try:
        logger.info("begin addNewClusterPoint!")
        aiBusModel = AiBusModel()
        userInfo = session.get("userInfo")
        data = request.get_json()
        fileId = data["fileId"]
        siteName = data["siteName"]
        longitude = data["longitude"]
        latitude = data["latitude"]
        number = data["number"]
        siteProperty = data["siteProperty"]
        if siteProperty == "固定":
            relativeProperty = 1
        elif siteProperty == "临时":
            relativeProperty = 0
        else:
            relativeProperty = 2

        row = aiBusModel.selectClusterPointId(
            (fileId, siteName, float(longitude), float(latitude)))
        if row:
            res.update(code=ResponseCode.Success, data={"id":row["id"],"siteName":siteName,\
                "longitude":longitude,"latitude":latitude,"number":number,"siteProperty":siteProperty,"users":[]})
            return res.data
        #插入
        aiBusModel.insertClusterPoint(
            (fileId, ' ', relativeProperty, siteName, 1, 2, float(longitude),
             float(latitude), number, ' ', userInfo["userName"],
             userInfo["userName"]))
        #查找id
        row = aiBusModel.selectClusterPointId(
            (fileId, siteName, float(longitude), float(latitude)))
        res.update(code=ResponseCode.Success, data={"id":row["id"],"siteName":siteName,\
            "longitude":longitude,"latitude":latitude,"number":number,"siteProperty":siteProperty,"users":[]})
        return res.data
    except Exception as e:
        logger.error("addNewClusterPoint exception:{}".format(str(e)))
        res.update(code=ResponseCode.Fail, msg="新增聚类点报错!")
        return res.data
Beispiel #2
0
def saveClusterResult():
    """
    保存聚类接口
    """
    res = ResMsg()
    try:
        logger.info("begin saveClusterResult!")
        aiBusModel = AiBusModel()
        userInfo = session.get("userInfo")
        data = request.get_json()
        fileId = data["fileId"]
        epsRadius = data["epsRadius"]
        minSamples = data["minSamples"]
        clusterAroundPoints = data["clusterAroundPoints"]
        clusterCorePoints = data["clusterCorePoints"]
        clusterOutPoints = data["clusterOutPoints"]
        #1)先判断该文件是网点文件还是聚类结果文件,再更新文件表;
        fileProperty = aiBusModel.selectSiteFileStatus(fileId)
        if fileProperty["clusterStatus"] == 1:
            aiBusModel.updateClusterParams(
                (epsRadius, minSamples, userInfo["userName"], fileId))
        else:
            #先判断是否存在聚类文件
            row = aiBusModel.selectClusterFileId(
                (fileProperty["fileName"] + "_聚类", 1, fileId))
            if not row:
                #插入新的聚类文件
                #fileName,fileProperty,fileStatus,siteFileId,clusterStatus,clusterRadius,clusterMinSamples,destination,mapType,longitude,latitude,userCitycode,createUser,updateUser
                aiBusModel.insertClusterFile((fileProperty["fileName"]+"_聚类",1,1,fileId,\
                    1,epsRadius,minSamples,fileProperty["destination"],fileProperty["mapType"],
                    fileProperty["longitude"],fileProperty["latitude"],userInfo["citycode"],userInfo["userName"],userInfo["userName"]))
                #查询对应聚类文件id
                clusterFile = aiBusModel.selectClusterFileId(
                    (fileProperty["fileName"] + "_聚类", 1, fileId))
                fileId = clusterFile["id"]
            else:
                aiBusModel.updateClusterParams(
                    (epsRadius, minSamples, userInfo["userName"], row["id"]))
                fileId = row["id"]
        #对文件的之前的聚类结果进行失效
        aiBusModel.updateClusterResultByFileId(
            (0, userInfo["userName"], fileId), [1, 2])

        #2)插入边界点
        for point in clusterAroundPoints:
            if point["siteProperty"] == "固定":
                relativeProperty = 1
            elif point["siteProperty"] == "临时":
                relativeProperty = 0
            else:
                relativeProperty = 2
            siteSet = ",".join(point["users"]).strip(",")

            if point["id"] != "":
                #clusterName=%s,fileId=%s,clusterProperty=%s,clusterStatus=%s,relativeProperty=%s,longitude=%s,latitude=%s, number=%s,siteSet=%s,updateUser=%s
                aiBusModel.updateClusterPointById(
                    (point["siteName"], fileId, 2, 1, relativeProperty,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     point["id"]))
            else:
                aiBusModel.insertClusterPoint(
                    (fileId, "", relativeProperty, point["siteName"], 2, 1,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     userInfo["userName"]))

        #3)插入聚类点
        for point in clusterCorePoints:
            if point["siteProperty"] == "固定":
                relativeProperty = 1
            elif point["siteProperty"] == "临时":
                relativeProperty = 0
            else:
                relativeProperty = 2
            siteSet = ",".join(point["users"]).strip(",")

            if point["id"] != "":
                #clusterName=%s,fileId=%s,clusterProperty=%s,clusterStatus=%s,relativeProperty=%s,longitude=%s,latitude=%s, number=%s,siteSet=%s,updateUser=%s
                aiBusModel.updateClusterPointById(
                    (point["siteName"], fileId, 1, 1, relativeProperty,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     point["id"]))
            else:
                aiBusModel.insertClusterPoint(
                    (fileId, "", relativeProperty, point["siteName"], 1, 1,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     userInfo["userName"]))

        #4)插入异常点
        for point in clusterOutPoints:
            if point["siteProperty"] == "固定":
                relativeProperty = 1
            elif point["siteProperty"] == "临时":
                relativeProperty = 0
            else:
                relativeProperty = 2
            siteSet = ",".join(point["users"]).strip(",")

            if point["id"] != "":
                #clusterName=%s,fileId=%s,clusterProperty=%s,clusterStatus=%s,relativeProperty=%s,longitude=%s,latitude=%s, number=%s,siteSet=%s,updateUser=%s
                aiBusModel.updateClusterPointById(
                    (point["siteName"], fileId, 0, 1, relativeProperty,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     point["id"]))
            else:
                aiBusModel.insertClusterPoint(
                    (fileId, "", relativeProperty, point["siteName"], 0, 1,
                     float(point["longitude"]), float(point["latitude"]),
                     point["number"], siteSet, userInfo["userName"],
                     userInfo["userName"]))

        res.update(code=ResponseCode.Success, msg="成功保存聚类结果!")
        return res.data
    except Exception as e:
        logger.error("generateClusterPoints exception:{}".format(str(e)))
        res.update(code=ResponseCode.Fail, msg="保存聚类点保存!")
        return res.data