// 保存投放轨迹到电信redis func (this *ZjPut) saveTraceToDianxin() { var ( db = lib.GetConfVal("zhejiang::dx_redis_db") pwd = lib.GetConfVal("zhejiang::dx_redis_pwd") adcount = 0 ) rdb, err := lib.GetZJDxRedisObj() if err != nil { log.Error("redis连接失败", err) return } rdb.Auth(pwd) rdb.SelectDb(db) rdb.FlushDb() // ua默认md5加密 go func() { for { rdb.Receive() } }() this.kf.AdUaIdsSet(func(ad string, ua string, ids map[string]int8) { var key = ad + "|" + strings.ToUpper(ua) rdb.Set(key, "1") adcount++ }) rdb.Flush() rdb.Close() // 广告数量统计数据 dx_stats , Zj_1461016800, 11111 lib.StatisticsData("dx_stats", fmt.Sprintf("zj_%s", this.Timestamp), convert.ToString(adcount), "") }
// 域名找回信息获取 func (this *ZjPut) VisitorData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 zhejiang_put , other_1461016800, 11111 lib.StatisticsData("dsource_stats", "zj_"+this.Timestamp+"_visitor", convert.ToString(datacount), "") }() m, err := lib.GetMongoObj() if err != nil { log.Error(err) in <- 1 return } defer m.Close() qconf := mongodb.MongodbQueryConf{} qconf.Db = "data_source" qconf.Table = "zhejiang_visitor" qconf.Query = mongodb.MM{} m.Query(qconf, func(info map[string]interface{}) { ad := convert.ToString(info["ad"]) ua := encrypt.DefaultMd5.Encode(encrypt.DefaultBase64.Decode(convert.ToString(info["ua"]))) aids := convert.ToString(info["aids"]) datacount++ out <- fmt.Sprintf("%s\t%s\t%s", ad, ua, aids) }) log.Info("访客ok") in <- 1 }
// 保存投放轨迹到投放系统 func (this *ZjPut) saveTraceToPutSys() { rdb, err := lib.GetPutRedisObj("put_redis_proxy_url") if err != nil { log.Error("redis连接失败", err) return } go func() { for { rdb.Receive() } }() //rdb.SelectDb("1") adcount := 0 this.kf.AdUaIdsSet(func(ad string, ua string, aids map[string]int8) { key := ad if ua != "ua" { key = encrypt.DefaultMd5.Encode(ad + "_" + ua) } for aid, _ := range aids { rdb.HSet(key, "advert:"+aid, aid) } rdb.Expire(key, 5400) adcount++ }) rdb.Flush() rdb.Close() // 广告数量统计数据 put_stats , Zj_1461016800, 11111 lib.StatisticsData("put_stats", fmt.Sprintf("zj_%s", this.Timestamp), convert.ToString(adcount), "") }
// 保存投放轨迹到电信ftp func (this *JsPut) saveTraceToDianxin() { var ( ftp = lib.GetConfVal("jiangsu::ftp_path") ppath = lib.GetConfVal("jiangsu::put_path") rk = "account.10046.sha1." + time.Now().Add(-time.Hour).Format("200601021504") fname = ppath + "/" + rk adcount = 0 ) f, err := os.Create(fname) if err != nil { log.Error("创建文件失败", err) return } defer f.Close() this.kf.AdSet(func(ad string) { if v, ok := this.areamap[ad]; ok { f.WriteString(ad + "," + v + "\n") adcount++ } }) cmd := exec.Command(ftp, rk) str, err := cmd.Output() log.Info(string(str), err) // 广告数量统计数据 dx_stats , js_1461016800, 11111 lib.StatisticsData("dx_stats", fmt.Sprintf("js_%s", timestamp.GetHourTimestamp(-1)), convert.ToString(adcount), "") }
// 标签数据统计 func (this *ZjPut) tagDataStats() { fname := convert.ToString(time.Now().UnixNano()) + "_" this.kf.IDAdUaSet(fname, func(info map[string]int) { for k, v := range info { tagid := strings.TrimPrefix(k, fname) tagids := strings.Split(tagid, "_") // 标签统计数据 tags_stats , url_1461016800, 11111 lib.StatisticsData("tags_stats", fmt.Sprintf("zj_%s_%s_%s", this.Timestamp, tagids[0], tagids[1]), convert.ToString(v), "incr") } }, true) }
// 保存广告对应的ad,ua func (this *ZjPut) saveAdvertSet() { tname := "advert_tj_zj_" + this.Timestamp + "_" fname := lib.GetConfVal("zhejiang::data_path") + tname this.kf.IDAdUaSet(fname, func(info map[string]int) { tm := this.Timestamp for k, v := range info { aid := strings.TrimPrefix(k, tname) // 广告数量统计数据 advert_stats , zj_1461016800_1111, 11111 lib.StatisticsData("advert_stats", fmt.Sprintf("zj_%s_%s", tm, aid), convert.ToString(v), "") } }, false) }
// 其他杂项数据获取 func (this *JsPut) otherData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 jiangsu_put , other_1461016800, 11111 lib.StatisticsData("dsource_stats", "js_"+timestamp.GetHourTimestamp(-1)+"_other", convert.ToString(datacount), "") }() fname := "jiangsu_other_" + timestamp.GetHourTimestamp(-1) if err := lib.GetFdbData(fname, func(val string) { if v := lib.AddPrefix(val, "mg_"); v != "" { datacount++ out <- v } }); err != nil { in <- 1 return } in <- 1 }
// 域名数据获取 func (this *ShPut) domainData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 jiangsu_put , url_1461016800, 11111 lib.StatisticsData("dsource_stats", "sh_"+this.Timestamp+"_url", convert.ToString(datacount), "") }() fname := "shanghai_url_" + this.Timestamp if err := lib.GetFdbData(fname, func(val string) { if v := lib.AddPrefix(val, "url_"); v != "" { datacount++ out <- v } }); err != nil { in <- 1 return } log.Info("域名ok") in <- 1 }
// 其他杂项数据获取 func (this *ZjPut) otherData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 zhejiang_put , other_1461016800, 11111 lib.StatisticsData("dsource_stats", "zj_"+this.Timestamp+"_other", convert.ToString(datacount), "") }() fname := "zhejiang_other_" + this.Timestamp if err := lib.GetFdbData(fname, func(val string) { if v := lib.AddPrefix(val, "mg_"); v != "" { datacount++ out <- v } }); err != nil { in <- 1 return } log.Info("其他ok") in <- 1 }
// 无限数据获取 func (this *CookiePut) coikieData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 jiangsu_put , url_1461016800, 11111 lib.StatisticsData("dsource_stats", "zj_"+this.Timestamp+"_cookie", convert.ToString(datacount), "") }() fname := "zhejiang_cookie_" + this.Timestamp if err := lib.GetFdbData(fname, func(val string) { if v := lib.AddPrefix2(val, "cookie_"); v != "" { datacount++ out <- v } }); err != nil { in <- 1 return } log.Info("cookieok") in <- 1 }
// 店铺信息获取 func (this *ZjPut) ShopData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 zhejiang_put , other_1461016800, 11111 lib.StatisticsData("dsource_stats", "zj_"+this.Timestamp+"_shop", convert.ToString(datacount), "") }() es, err := lib.GetESObj() if err != nil { log.Error(err) in <- 1 return } this.shopAdverts = this.GetPutShopInfo() for shopid, shopinfo := range this.shopAdverts { for _, adids := range shopinfo.ShopAdverts { date := timestamp.GetDayTimestamp(adids.Date * -1) var scrollid = "" var query = elastic.NewBoolQuery() query.Must(elastic.NewRangeQuery("timestamp").Gte(date)) query.Must(elastic.NewTermQuery("shop", shopid)) sr, err := es.Scroll().Index("zhejiang_tb_shop_trace").Type("shop"). Query(query).Do() if err != nil { log.Error(err) continue } scrollid = sr.ScrollId for { sres, err := es.Scroll().Index("zhejiang_tb_shop_trace").Type("shop"). Query(query).ScrollId(scrollid).Size(1000).Do() if err == elastic.EOS { break } if err != nil { log.Error(err) out <- 1 return } for _, hit := range sres.Hits.Hits { item := make(map[string]interface{}) err := json.Unmarshal(*hit.Source, &item) if err != nil { continue } ad := convert.ToString(item["ad"]) ua := encrypt.DefaultMd5.Encode(convert.ToString(item["ua"])) datacount++ out <- fmt.Sprintf("%s\t%s\t%s", ad, ua, adids.AdvertId) } scrollid = sres.ScrollId } } } log.Info("店铺ok") in <- 1 }
// 电商数据获取 func (this *ZjPut) BusinessData(out chan interface{}, in chan int8) { var datacount = 0 defer func() { // 统计数据 zhejiang_put , other_1461016800, 11111 lib.StatisticsData("dsource_stats", "zj_"+this.Timestamp+"_business", convert.ToString(datacount), "") }() es, err := lib.GetESObj() if err != nil { out <- 1 return } var bt = timestamp.GetHourTimestamp(-1) var et = timestamp.GetHourTimestamp(-73) var query = elastic.NewRangeQuery("timestamp").Gte(et).Lte(bt) var sid = "" res, err := es.Scroll().Index("zhejiang_tb_ad_trace").Type("ad").Query(query).Size(1000).Do() if err != nil { log.Error(err) out <- 1 return } sid = res.ScrollId for { sres, err := es.Scroll().Index("zhejiang_tb_ad_trace").Type("ad"). Query(query).ScrollId(sid).Size(1000).Do() if err == elastic.EOS { break } if err != nil { log.Error(err) out <- 1 return } for _, hit := range sres.Hits.Hits { item := make(map[string]interface{}) err := json.Unmarshal(*hit.Source, &item) if err != nil { continue } ad := convert.ToString(item["ad"]) ua := encrypt.DefaultMd5.Encode(convert.ToString(item["ua"])) cids := item["cids"].([]interface{}) ncids := make(map[string]int) ncidsary := make([]string, 0, len(cids)) for _, v := range cids { if vv, ok := lib.TcatBig[convert.ToString(v)]; ok { ncids[vv] = 1 } } for k, _ := range ncids { ncidsary = append(ncidsary, "tb_"+k) } if len(ncidsary) == 0 { continue } datacount++ out <- fmt.Sprintf("%s\t%s\t%s", ad, ua, strings.Join(ncidsary, ",")) } sid = sres.ScrollId } log.Info("电商ok") in <- 1 }