|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"math/rand"
|
5
|
5
|
"miads/adslib/redis_data"
|
6
|
6
|
"miads/adslib/utils"
|
|
7
|
+ "strings"
|
7
|
8
|
)
|
8
|
9
|
|
9
|
10
|
func CombineOrderBy(adData *AdData, dsp *utils.DspParam) {
|
|
@@ -32,7 +33,7 @@ func CombineOrderBy(adData *AdData, dsp *utils.DspParam) {
|
32
|
33
|
|
33
|
34
|
|
34
|
35
|
// 获取一个广告
|
35
|
|
-func GetOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdOrderInfo, error){
|
|
36
|
+func getOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdOrderInfo, error){
|
36
|
37
|
// 取出广告
|
37
|
38
|
orders, err := redis_data.GetOrderInfos(dsp, fixFlag)
|
38
|
39
|
if err != nil {
|
|
@@ -80,25 +81,65 @@ func GetOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdO
|
80
|
81
|
return nil, nil
|
81
|
82
|
}
|
82
|
83
|
|
|
84
|
+func getSubTimeValue(adData *redis_data.AdOrderInfo, a) {
|
|
85
|
+ b_min = int(ads_item['begin_time'])
|
|
86
|
+ b_min = datetime.fromtimestamp(b_min)
|
|
87
|
+
|
|
88
|
+ // 获取当前分钟值
|
|
89
|
+ now_minute = b_min.minute + (b_min.hour * 60)
|
|
90
|
+
|
|
91
|
+ // 不足一天
|
|
92
|
+ all_count = 1587820.0
|
|
93
|
+ e_time = int(ads_item['end_time'])
|
|
94
|
+
|
|
95
|
+ // 获取起点分钟
|
|
96
|
+ be_minute = now_minute + 2
|
|
97
|
+ // 获取分钟数到24点还能跑多少值
|
|
98
|
+ key = "time_all_count_" + str(be_minute)
|
|
99
|
+ if int(ads_item['line_type']) == 1:
|
|
100
|
+ // 定制曲线
|
|
101
|
+ key = "time_all_count_{0}_{1}".format(ads_item['order_id'], str(be_minute))
|
|
102
|
+ // 起始剩余值
|
|
103
|
+ all_count = redis_tools.get_key_int_value(key)
|
|
104
|
+
|
|
105
|
+ // 计算最后分钟
|
|
106
|
+ e_d = datetime.fromtimestamp(e_time)
|
|
107
|
+ e_d_min = e_d.minute + (e_d.hour * 60)
|
|
108
|
+ if e_d_min > 1439:
|
|
109
|
+ e_d_min = e_d_min - 1440 + 2
|
|
110
|
+ key = "time_all_count_" + str(e_d_min)
|
|
111
|
+ if int(ads_item['line_type']) == 1:
|
|
112
|
+ // 定制曲线
|
|
113
|
+ key = "time_all_count_{0}_{1}".format(ads_item['order_id'], str(e_d_min))
|
|
114
|
+ // 结束的剩余值 - 起始剩余值 = 获取区间能跑的值
|
|
115
|
+ all_count = all_count - redis_tools.get_key_int_value(key)
|
|
116
|
+ return all_count
|
|
117
|
+}
|
|
118
|
+
|
83
|
119
|
func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag int, xiaomiHasFlag int) {
|
84
|
120
|
ua = dsp.ua_client
|
85
|
121
|
req_source = dsp.req_source
|
86
|
122
|
|
87
|
|
- ads_item = getOneAds(dsp, order_type, fix_flag)
|
88
|
|
- if ads_item is
|
89
|
|
-None:
|
90
|
|
- raise
|
91
|
|
- gen.Return((None, None))
|
92
|
|
- r = random.randint(0, 100)
|
93
|
|
- if xiaomi_has_flag == 1:
|
94
|
|
- if ads_item['title'].find("_ios") > 0:
|
95
|
|
- raise
|
96
|
|
- gen.Return((None, None)) else:
|
97
|
|
- r = random.randint(50, 100)
|
|
123
|
+ order, err := getOneAds(dsp, order_type, fix_flag)
|
|
124
|
+ if err != nil {
|
|
125
|
+ return err
|
|
126
|
+ }
|
|
127
|
+ if order == nil {
|
|
128
|
+ return nil
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ r = rand.Intn( 100)
|
|
132
|
+ if xiaomiHasFlag == 1 {
|
|
133
|
+ if strings.Index(order.Title, "_ios") > 0 {
|
|
134
|
+ return nil
|
|
135
|
+ } else {
|
|
136
|
+ r = rand.Intn(50)
|
|
137
|
+ }
|
|
138
|
+ }
|
98
|
139
|
|
99
|
140
|
a = datetime.now()
|
100
|
141
|
|
101
|
|
- #获取剩余时间内的值
|
|
142
|
+ // 获取剩余时间内的值
|
102
|
143
|
all_count = get_sub_time_value(ads_item, a)
|
103
|
144
|
all_count = all_count * 1.0
|
104
|
145
|
|