|
@@ -84,43 +84,65 @@ class type_spec_chs(object):
|
|
|
return 1
|
|
|
pass
|
|
|
|
|
|
- def adjust_combine(names, count, cost):
|
|
|
- rate = count / (cost + 0.0000001)
|
|
|
- for chname in names:
|
|
|
+ def costor(ch_costes):
|
|
|
+ total = 0
|
|
|
+ for chname,maxspeed in ch_costes:
|
|
|
+ total += maxspeed
|
|
|
+ return total
|
|
|
+
|
|
|
+ def arrange(ch_costes,cost):
|
|
|
+ if len(ch_costes) == 0:
|
|
|
+ return 0
|
|
|
+
|
|
|
+ all = costor(ch_costes)
|
|
|
+ all = len(ch_costes) if all == 0 else all
|
|
|
+ cost = 0 if cost < 0 else cost
|
|
|
+ rate = cost / all
|
|
|
+
|
|
|
+ for chname,maxspeed in ch_costes:
|
|
|
+ speed = round(maxspeed * rate)
|
|
|
ch_item = self._chs[chname]
|
|
|
- speed = ch_item.reckon_speed()
|
|
|
- append = round(speed * rate)
|
|
|
- ch_item.add_reckon_speed(append)
|
|
|
- pass
|
|
|
+ ch_item.add_reckon_speed(speed)
|
|
|
+ return cost
|
|
|
|
|
|
- total = self.cur_speed()
|
|
|
+ total = self.normal_speed()
|
|
|
rate = split_order(total)
|
|
|
|
|
|
- feed_count = round(total * (1 - rate))
|
|
|
- combine_count = total - feed_count
|
|
|
-
|
|
|
logger.debug(f'{self._spec}-{self._card_type} total={total}')
|
|
|
feeds, chpos, combination = self._looper()
|
|
|
feeds.extend(self._no_price)
|
|
|
if len(combination) > 0:
|
|
|
item = self._op_maxsuccs(combination, chpos, rate)
|
|
|
- cost, combines, _feeds = self._distribute(chpos, item, total, rate)
|
|
|
+ _feeds, increase, decrease = self._distribute(chpos, item, total, rate)
|
|
|
feeds.extend(_feeds)
|
|
|
else:
|
|
|
- cost = 0
|
|
|
- combines = []
|
|
|
+ increase = []
|
|
|
+ decrease = []
|
|
|
|
|
|
- if cost < combine_count and len(combines) > 0:
|
|
|
- adjust_combine(combines, combine_count - cost, cost)
|
|
|
- left = total - combine_count
|
|
|
- cost = combine_count
|
|
|
+ if len(feeds) > 0:
|
|
|
+ feed_count = round(total * (1 - rate))
|
|
|
+ else:
|
|
|
+ feed_count = 0
|
|
|
+
|
|
|
+ left = total - feed_count
|
|
|
+ cost_de = costor(decrease)
|
|
|
+ cost_in = costor(increase)
|
|
|
+ cost = costor(decrease) + costor(increase)
|
|
|
+ if cost > left:
|
|
|
+ cost_in = round(cost_in * 1.1)
|
|
|
+ cost_de = cost - cost_in
|
|
|
+ cost_de = cost_de if cost_de > 0 else 0
|
|
|
+ else:
|
|
|
+ cost_in = left - cost_de
|
|
|
+ pass
|
|
|
|
|
|
- left = total - cost
|
|
|
- left = 0 if left < 0 else left
|
|
|
+ arrange(decrease,cost_de)
|
|
|
+ arrange(increase,cost_in)
|
|
|
|
|
|
- logger.debug(f'{self._spec}-{self._card_type} total={total} cost={cost} left={left}')
|
|
|
- feeds = self._feed_check(feeds, total)
|
|
|
- self._handle_feed(feeds, left)
|
|
|
+ logger.debug(f'{self._spec}-{self._card_type} total={total} cost={cost_in + cost_de} left={feed_count}')
|
|
|
+ if len(feeds) > 0:
|
|
|
+ feeds = self._feed_check(feeds, total)
|
|
|
+ self._handle_feed(feeds, feed_count)
|
|
|
pass
|
|
|
|
|
|
def _classify_combine(self, chpos, item):
|
|
@@ -162,7 +184,7 @@ class type_spec_chs(object):
|
|
|
feeds.append(chname)
|
|
|
else:
|
|
|
detail = ch_item.detail(dim)
|
|
|
- ratio_fun = lambda cur_commit, cur_succ, per_commit, per_succ, per_profit: cur_succ / cur_commit
|
|
|
+ ratio_fun = lambda cur_commit, cur_succ, per_commit, per_succ, per_profit, radio_log: cur_succ / cur_commit
|
|
|
ratios[chname] = ratio_fun(*detail)
|
|
|
return feeds, ratios
|
|
|
|
|
@@ -184,28 +206,31 @@ class type_spec_chs(object):
|
|
|
result.append((chname, dim))
|
|
|
return result
|
|
|
|
|
|
- def calc_cost(name_dimses):
|
|
|
- cost = 0
|
|
|
- for chname, dim in name_dimses:
|
|
|
- ch_item = self._chs[chname]
|
|
|
- speed = round(ch_item.detail_speed(dim))
|
|
|
- cost += speed
|
|
|
- return cost
|
|
|
+ def find_increase_channel(name_dimses):
|
|
|
+ feeds = []
|
|
|
+ increase = []
|
|
|
+ uncrease = []
|
|
|
|
|
|
- def arrage_high(name_dimses):
|
|
|
for chname, dim in name_dimses:
|
|
|
ch_item = self._chs[chname]
|
|
|
- speed = round(ch_item.detail_speed(dim))
|
|
|
- ch_item.add_reckon_speed(speed)
|
|
|
- pass
|
|
|
+ max_speed, can_increase = ch_item.best_speed()
|
|
|
+ if max_speed is None:
|
|
|
+ feeds.append(name)
|
|
|
+ continue
|
|
|
+
|
|
|
+ max_speed = round(max_speed)
|
|
|
+ if can_increase == False:
|
|
|
+ uncrease.append((chname, max_speed))
|
|
|
+ else:
|
|
|
+ increase.append((chname, max_speed))
|
|
|
+ return feeds, increase, uncrease
|
|
|
|
|
|
combines, feeds = self._classify_combine(chpos, item)
|
|
|
logger.debug(f'high={combines},low={feeds}')
|
|
|
-
|
|
|
name_dimses = name_dims(chpos, item, combines)
|
|
|
- cost = calc_cost(name_dimses)
|
|
|
- arrage_high(name_dimses)
|
|
|
- return cost, combines, feeds
|
|
|
+ _feeds, increase, uncrease = find_increase_channel(name_dimses)
|
|
|
+ feeds.extend(feeds)
|
|
|
+ return feeds, increase, uncrease
|
|
|
|
|
|
def _op_maxsuccs(self, combination, chpos, rate):
|
|
|
def fill_data(combination, chpos, detail_length):
|
|
@@ -258,11 +283,10 @@ class type_spec_chs(object):
|
|
|
logger.debug(f'card_type={self._card_type} spec={self._spec}')
|
|
|
item = combination[index]
|
|
|
return item
|
|
|
-
|
|
|
##############################################################################################################################################
|
|
|
datas = fill_data(combination, chpos, dposmap.dim())
|
|
|
# 按找利润排序,再在里面找满足提单量的
|
|
|
- total = self.cur_speed() * rate
|
|
|
+ total = self.normal_speed() * rate
|
|
|
sumview, combination = sort_per_profit(datas, combination)
|
|
|
item = sort_nearst(sumview, combination, total)
|
|
|
return item
|
|
@@ -324,17 +348,19 @@ class type_spec_chs(object):
|
|
|
cur_speed = item.cur_speed()
|
|
|
logger.debug(f'{name}-{self._spec}-{self._card_type} speed={cur_speed}')
|
|
|
total += cur_speed
|
|
|
- logger.debug(f'{self._spec}-{self._card_type} total={total}')
|
|
|
+ logger.debug(f'{self._spec}-{self._card_type} total speed ={total}')
|
|
|
return total
|
|
|
|
|
|
def normal_speed(self):
|
|
|
total = 0
|
|
|
- for name in self._normal_price:
|
|
|
+ datas = self._normal_price
|
|
|
+ datas.extend(self._no_price)
|
|
|
+ for name in datas:
|
|
|
item = self._chs[name]
|
|
|
cur_speed = item.cur_speed()
|
|
|
logger.debug(f'{name}-{self._spec}-{self._card_type} speed={cur_speed}')
|
|
|
total += cur_speed
|
|
|
- logger.debug(f'{self._spec}-{self._card_type} total={total}')
|
|
|
+ logger.debug(f'{self._spec}-{self._card_type} normal speed={total}')
|
|
|
return total
|
|
|
|
|
|
def get_reckon(self):
|
|
@@ -342,4 +368,4 @@ class type_spec_chs(object):
|
|
|
for key, item in self._chs.items():
|
|
|
speed = item.reckon_speed()
|
|
|
result[key] = speed
|
|
|
- return result
|
|
|
+ return result
|