| | |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "encoding/csv" |
| | | "fmt" |
| | | "os" |
| | | "ruleModelEngine/cache" |
| | | "ruleModelEngine/config" |
| | | "ruleModelEngine/data" |
| | | "ruleModelEngine/db" |
| | | "ruleModelEngine/task" |
| | | "strconv" |
| | | "time" |
| | | ) |
| | | |
| | | // |
| | |
| | | // } |
| | | // return true |
| | | //} |
| | | |
| | | func writeCSV(filename string, data []db.CaptureInfo) error { |
| | | file, err := os.Create(filename) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | defer file.Close() |
| | | |
| | | writer := csv.NewWriter(file) |
| | | defer writer.Flush() |
| | | |
| | | // Write header |
| | | header := []string{"档案编号", "抓拍天数", "过夜天数", "分类", "常用地址"} |
| | | if err := writer.Write(header); err != nil { |
| | | return err |
| | | } |
| | | |
| | | // Write data |
| | | for _, info := range data { |
| | | record := []string{ |
| | | info.DocumentNumber, |
| | | strconv.Itoa(info.CaptureDays), |
| | | strconv.Itoa(info.OvernightStays), |
| | | info.Status, |
| | | info.FrequentAddress, |
| | | } |
| | | if err := writer.Write(record); err != nil { |
| | | return err |
| | | } |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func executeEnteringButNotLeaving(communityId string) { |
| | | //进出异常布控任务,暂时归类到标签计算部分 |
| | |
| | | |
| | | cameraIds := make([]string, 0) |
| | | for _, deviceInfo := range cache.Device { |
| | | if deviceInfo.AreaID == communityId && deviceInfo.BuildingType == db.BuildingTypeMixedUse { |
| | | if deviceInfo.CommunityID == communityId && deviceInfo.BuildingType == db.BuildingTypeMixedUse { |
| | | cameraIds = append(cameraIds, deviceInfo.DeviceCode) |
| | | } |
| | | } |
| | | |
| | | if len(cameraIds) == 0 { |
| | | logger.Info("不存在商住楼设备:", cameraIds) |
| | | return |
| | |
| | | logger.Error("GetAllData Error", err) |
| | | } |
| | | fmt.Println("ruleInfo: ", ruleInfo) |
| | | statusNo := make(map[string]int) |
| | | statusNo["stranger"] = db.StatusStranger |
| | | statusNo["visitor"] = db.StatusVisitor |
| | | statusNo["resident"] = db.StatusResident |
| | | communityIDs, err := db.GetCommunityIDs() |
| | | //fmt.Println("communityIDs:", communityIDs) |
| | | fmt.Println("communityIDs:", communityIDs) |
| | | if err != nil { |
| | | logger.Error("GetCommunityIDs Error", err) |
| | | } |
| | | labeManage, err := db.GetLabelManageIdentity(2) |
| | | labeManage, err := db.GeIdentityLabels() |
| | | if err != nil { |
| | | logger.Error("GetDBPersonStatusData Error", err) |
| | | } |
| | | //fmt.Println(labeManage) |
| | | for _, communityID := range communityIDs { |
| | | executeEnteringButNotLeaving(communityID) |
| | | |
| | | //万全社区 |
| | | //if communityID != "50010101010000001001" { |
| | | // continue |
| | | //} |
| | | fmt.Println("communityID: ", communityID) |
| | | //continue |
| | | now := time.Now() |
| | | timeThresholdDay := now.AddDate(0, 0, -config.Api.TimeThreshold) |
| | | timeThresholdDayZeroTime := time.Date(timeThresholdDay.Year(), timeThresholdDay.Month(), timeThresholdDay.Day(), 0, 0, 0, 0, timeThresholdDay.Location()).Unix() |
| | | fmt.Println("比对时间戳:", timeThresholdDayZeroTime) |
| | | //查询社区内人员档案,方便数据更新 |
| | | personStatusList, err := db.QueryPersonStatusWithPagination(communityID, 30) |
| | | personStatusList, err := db.QueryPersonStatusWithPagination(communityID, timeThresholdDayZeroTime) |
| | | if err != nil { |
| | | logger.Error("QueryPersonStatusWithPagination err: ", err) |
| | | } |
| | | // |
| | | |
| | | documentNumberIDS := make([]string, 0) |
| | | for _, personStatus := range personStatusList { |
| | |
| | | documentNumberIDS = append(documentNumberIDS, personStatus.DocumentNumber) |
| | | //业务逻辑 |
| | | } |
| | | //fmt.Println("len(documentNumberIDS)", len(documentNumberIDS)) |
| | | fmt.Println("社区档案总条数:", len(documentNumberIDS)) |
| | | |
| | | captureInfos := make([]db.CaptureInfo, 0) |
| | | batchSize := config.Elastic.BatchSize |
| | | //fmt.Println(batchSize) |
| | |
| | | } |
| | | batch := documentNumberIDS[i:end] |
| | | //fmt.Println("batch: ", batch) |
| | | batchCaptureInfos, err := db.Query1MDataByCommunityId(communityID, batch, 30) |
| | | batchCaptureInfos, err := db.QueryByTimeThresholdDataByCommunityId(communityID, batch, config.Api.TimeThreshold) |
| | | if err != nil { |
| | | logger.Error("Query1MDataByCommunityId Error", err) |
| | | } |
| | |
| | | fmt.Println("共计有档案数据条数为:", len(captureInfos)) |
| | | //补全分析所需数据 |
| | | for i := range captureInfos { |
| | | |
| | | captureDays, overnightCount := data.CalculateCaptureDays(captureInfos[i].CaptureDetail) |
| | | captureInfos[i].CaptureDays = captureDays |
| | | captureInfos[i].OvernightStays = overnightCount |
| | |
| | | } |
| | | captureInfos[i].Age = age |
| | | captureInfos[i].FrequentAddress = data.GetFrequentAddress(captureInfos[i].CaptureDetail) |
| | | |
| | | //fmt.Println("CaptureDetail: ", captureInfos[i].DocumentNumber, captureInfos[i].CaptureDays, captureInfos[i].CaptureDetail) |
| | | } |
| | | //err1 := writeCSV("report.csv", captureInfos) |
| | | //if err != nil { |
| | | // fmt.Println(err1) |
| | | //} |
| | | //continue |
| | | //fmt.Println("residentCount: ", residentCount) |
| | | //fmt.Println("captureInfosQ: ", captureInfos) |
| | | |
| | | for _, identity := range labeManage { |
| | | switch identity.Name { |
| | | case "服务人员": |
| | | identity, attribute := CreateLinearModel(captureInfos, communityID, 2.68, identity.ValidDays, identity.Id) |
| | | identity, attribute := CreateLinearModel(captureInfos, communityID, 2.68, identity.ValidDays, identity.ID) |
| | | |
| | | errIdentity := db.UpdateDBPersonLabel(identity) |
| | | if errIdentity != nil { |
| | | logger.Error("UpdateDBPersonLabel Error", errIdentity) |
| | | } |
| | | |
| | | captureInfos = attribute |
| | | |
| | | } |
| | | } |
| | | |
| | | identity := CreateProcessModel(captureInfos, 30, communityID, labeManage) |
| | | errIdentity := db.UpdateDBPersonLabel(identity) |
| | | if errIdentity != nil { |
| | | logger.Error("UpdateDBPersonLabel Error", errIdentity) |
| | | } |
| | | |
| | | //continue |
| | | |
| | | postCaptureInfos := data.ProcessData(captureInfos, personStatusList, ruleInfo, communityID) |
| | | /*for _, inf := range postCaptureInfos { |
| | | fmt.Println("inf: ", inf.DocumentNumber, inf.Status, inf.FrequentAddress, inf.LastAppearanceStatusTime) |
| | | }*/ |
| | | //fmt.Println("共更新档案数:", len(postCaptureInfos)) |
| | | postCaptureInfos := data.ProcessData(captureInfos, personStatusList, ruleInfo, statusNo, communityID) |
| | | for _, inf := range postCaptureInfos { |
| | | fmt.Println("---->pause prepare: capture ", inf.DocumentNumber, inf.Status, inf.FrequentAddress) |
| | | //return |
| | | //time.Sleep(time.Second * 10) |
| | | |
| | | //fmt.Println("inf: ", inf.DocumentNumber, inf.Status, inf.FrequentAddress, inf.LastAppearanceStatusTime) |
| | | } |
| | | fmt.Println("共更新档案数:", len(postCaptureInfos)) |
| | | //fmt.Println("----->captureInfos: ", len(captureInfos)) |
| | | //continue |
| | | UpdatePersonInfoErr := db.UpdatePersonInfo(postCaptureInfos, communityID) |