我也不确定这是否是提出此类问题的正确地方。似乎您要求的是算法或一些标准的业务规则,但要求的是最终代码。
好吧,我发布了一种提出新想法的方法。我构建了一个算法列表并测试最高值:
import math
fs = [
('Plain coef', lambda m: math.log(m[1]* units_coef)
+ math.log(m[2]* money_coef) ),
('Coef into log', lambda m: m[1]* units_coef
+ m[2]* money_coef ),
('Coef out log', lambda m: math.log(m[1])* units_coef
+ math.log(m[2]) * money_coef ),
('Coef out log2', lambda m: math.log(m[1],2)* units_coef
+ math.log(m[2],2) * money_coef ),
]
movings = [ ( 'product1', 1500, 75.00 ),
( 'product2', 2, 90000.00 ),
( 'product3', 1200, 8000.00 ),
( 'product4', 6, 4000.00 ),
( 'product5', 500, 1000.00 ),
( 'product6', 800, 1200.00 ),
( 'product7', 300, 800.00 ),
]
units_coef = 1.1
money_coef = 0.04
for (n,f) in fs:
print ''
print n
print '==============================================='
for i in sorted( movings,
key = lambda m: f(m) ,
reverse=True)[:3]:
print i, f(i)
结果:
$ python solds.py
Plain coef
===============================================
('product3', 1200, 8000.0) 12.9537080114
('product6', 800, 1200.0) 10.6511229184
('product5', 500, 1000.0) 9.99879773234
Coef into log
===============================================
('product2', 2, 90000.0) 3602.2
('product1', 1500, 75.0) 1653.0
('product3', 1200, 8000.0) 1640.0
Coef out log
===============================================
('product1', 1500, 75.0) 8.21724195034
('product3', 1200, 8000.0) 8.15857239218
('product6', 800, 1200.0) 7.63667597387
Coef out log2
===============================================
('product1', 1500, 75.0) 11.8549742115
('product3', 1200, 8000.0) 11.7703319309
('product6', 800, 1200.0) 11.0173945564