@@ -0,0 +1,39 @@
|
||||
import json, re, math, collections
|
||||
exec(open('build.py', encoding='utf-8').read().split('# ---------- Excel ----------')[0])
|
||||
|
||||
# 店铺覆盖度:一家店能供的料越多越优先(省运费)
|
||||
cover = collections.Counter()
|
||||
REL = {}
|
||||
for r in L:
|
||||
sid = r['sid'] or ''
|
||||
if not sid.startswith('C'): continue
|
||||
items = [i for i in TB.get(sid, {}).get('items', []) if i['price']]
|
||||
rel = [i for i in items if relevant(sid, r, i)]
|
||||
for i in rel:
|
||||
i['p'] = float(i['price']); i['s'] = sales_n(i['sales'])
|
||||
REL[sid] = (r, rel)
|
||||
for s in {i['shop'] for i in rel}:
|
||||
cover[s] += 1
|
||||
|
||||
def cat2(r):
|
||||
m = r['mid'] or ''
|
||||
if re.match(r'0402WGF|RHC|FRC|HoGT|NCP18|CL\d|GRM|0402CG|T491|470uF|6.3TPV', m): return 'passive'
|
||||
return 'other'
|
||||
|
||||
plan = []
|
||||
for sid, (r, rel) in REL.items():
|
||||
lp = lcsc_price(sid, r['total'])[0]
|
||||
cands = []
|
||||
for i in rel:
|
||||
bad = cat2(r) == 'other' and lp and i['p'] < 0.3 * lp and lp > 1.0
|
||||
score = 3 * math.log1p(cover[i['shop']]) + math.log1p(i['s']) - (4 if i.get('series') else 0) - (8 if bad else 0) - (3 if i['s'] == 0 else 0)
|
||||
cands.append((score, i))
|
||||
cands.sort(key=lambda x: -x[0])
|
||||
plan.append({'sid': sid, 'mid': r['mid'], 'desc': r['desc'], 'need': r['total'], 'lcsc': lp,
|
||||
'cands': [dict(id=i['id'], tmall=i['tmall'], shop=i['shop'], p=i['p'], sales=i['sales'], title=i['title'], score=round(s, 2)) for s, i in cands[:3]]})
|
||||
json.dump(plan, open('cost_plan.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=1)
|
||||
shops = collections.Counter(p['cands'][0]['shop'] for p in plan if p['cands'])
|
||||
print(len(plan), 'shops', len(shops)); print(shops.most_common(15))
|
||||
for p in plan:
|
||||
c = p['cands'][0] if p['cands'] else None
|
||||
print(p['mid'][:22].ljust(22), p['need'], p['lcsc'], '|', c and (c['p'], c['shop'][:10], c['title'][:40]))
|
||||
在新工单中引用
屏蔽一个用户