| Line 33... |
Line 33... |
| 33 |
now = datetime.now()
|
33 |
now = datetime.now()
|
| 34 |
|
34 |
|
| 35 |
class __SkuInfo:
|
35 |
class __SkuInfo:
|
| 36 |
|
36 |
|
| 37 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
37 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 38 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id, manualDealThresholdPrice):
|
38 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id, manualDealThresholdPrice,\
|
| - |
|
39 |
codAvailable):
|
| 39 |
self._id = _id
|
40 |
self._id = _id
|
| 40 |
self.skuBundleId = skuBundleId
|
41 |
self.skuBundleId = skuBundleId
|
| 41 |
self.category_id = category_id
|
42 |
self.category_id = category_id
|
| 42 |
self.mrp = mrp
|
43 |
self.mrp = mrp
|
| 43 |
self.available_price = available_price
|
44 |
self.available_price = available_price
|
| Line 57... |
Line 58... |
| 57 |
self.brand = brand
|
58 |
self.brand = brand
|
| 58 |
self.dealType = dealType
|
59 |
self.dealType = dealType
|
| 59 |
self.dealPoints = dealPoints
|
60 |
self.dealPoints = dealPoints
|
| 60 |
self.brand_id = brand_id
|
61 |
self.brand_id = brand_id
|
| 61 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
62 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
| - |
|
63 |
self.codAvailable = codAvailable
|
| 62 |
|
64 |
|
| 63 |
|
65 |
|
| 64 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
66 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 65 |
global con
|
67 |
global con
|
| 66 |
if con is None:
|
68 |
if con is None:
|
| Line 86... |
Line 88... |
| 86 |
#topSkus = collection.find( {'_id':664})
|
88 |
#topSkus = collection.find( {'_id':664})
|
| 87 |
for sku in topSkus:
|
89 |
for sku in topSkus:
|
| 88 |
"""Fix this """
|
90 |
"""Fix this """
|
| 89 |
#TODO Compute deal flags else where.
|
91 |
#TODO Compute deal flags else where.
|
| 90 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
92 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
| 91 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'], None)
|
93 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'], None, sku['codAvailable'])
|
| 92 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
94 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
| 93 |
if len(exceptionalNlc) > 0:
|
95 |
if len(exceptionalNlc) > 0:
|
| 94 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
96 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
| 95 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
97 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
| 96 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
98 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| Line 295... |
Line 297... |
| 295 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
297 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 296 |
bestPrice = float("inf")
|
298 |
bestPrice = float("inf")
|
| 297 |
bestOne = None
|
299 |
bestOne = None
|
| 298 |
bestSellerPoints = 0
|
300 |
bestSellerPoints = 0
|
| 299 |
toUpdate = []
|
301 |
toUpdate = []
|
| - |
|
302 |
prepaidBestPrice = float("inf")
|
| - |
|
303 |
prepaidBestOne = None
|
| - |
|
304 |
prepaidBestSellerPoints = 0
|
| 300 |
for similarItem in similarItems:
|
305 |
for similarItem in similarItems:
|
| - |
|
306 |
if similarItem['codAvailable'] ==1:
|
| 301 |
if mc.get("negative_deals") is None:
|
307 |
if mc.get("negative_deals") is None:
|
| 302 |
populateNegativeDeals()
|
308 |
populateNegativeDeals()
|
| 303 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
309 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| 304 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
310 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 305 |
continue
|
311 |
continue
|
| 306 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
312 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 307 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
313 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 308 |
continue
|
314 |
continue
|
| 309 |
if similarItem['available_price'] < bestPrice:
|
315 |
if similarItem['available_price'] < bestPrice:
|
| 310 |
bestOne = similarItem
|
316 |
bestOne = similarItem
|
| 311 |
bestPrice = similarItem['available_price']
|
317 |
bestPrice = similarItem['available_price']
|
| 312 |
bestSellerPoints = similarItem['bestSellerPoints']
|
318 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 313 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
319 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 314 |
bestOne = similarItem
|
320 |
bestOne = similarItem
|
| 315 |
bestPrice = similarItem['available_price']
|
321 |
bestPrice = similarItem['available_price']
|
| 316 |
bestSellerPoints = similarItem['bestSellerPoints']
|
322 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
323 |
else:
|
| - |
|
324 |
pass
|
| 317 |
else:
|
325 |
else:
|
| - |
|
326 |
if mc.get("negative_deals") is None:
|
| - |
|
327 |
populateNegativeDeals()
|
| - |
|
328 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| - |
|
329 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| - |
|
330 |
continue
|
| - |
|
331 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| - |
|
332 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| - |
|
333 |
continue
|
| - |
|
334 |
if similarItem['available_price'] < prepaidBestPrice:
|
| - |
|
335 |
prepaidBestOne = similarItem
|
| - |
|
336 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
337 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
338 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| - |
|
339 |
prepaidBestOne = similarItem
|
| - |
|
340 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
341 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
342 |
else:
|
| 318 |
pass
|
343 |
pass
|
| 319 |
if bestOne is not None:
|
344 |
if bestOne is not None and prepaidBestOne is not None:
|
| 320 |
for similarItem in similarItems:
|
345 |
for similarItem in similarItems:
|
| 321 |
toUpdate.append(similarItem['_id'])
|
346 |
toUpdate.append(similarItem['_id'])
|
| 322 |
toUpdate.remove(bestOne['_id'])
|
347 |
toUpdate.remove(bestOne['_id'])
|
| - |
|
348 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 323 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
|
349 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| - |
|
350 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 324 |
if len(toUpdate) > 0:
|
351 |
if len(toUpdate) > 0:
|
| 325 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
|
352 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 326 |
|
353 |
|
| 327 |
def main():
|
354 |
def main():
|
| 328 |
try:
|
355 |
try:
|
| 329 |
populateStuff()
|
356 |
populateStuff()
|
| 330 |
calculateNlc()
|
357 |
calculateNlc()
|