Subversion Repositories SmartDukaan

Rev

Rev 16804 | Rev 16869 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16804 Rev 16868
Line 30... Line 30...
30
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
30
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
31
DISCOUNT_TYPE = {'MRP':1,'DP':2}
31
DISCOUNT_TYPE = {'MRP':1,'DP':2}
32
LATEST_UPDATED_ITEMS = []
32
LATEST_UPDATED_ITEMS = []
33
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
33
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
34
 
34
 
-
 
35
DEAL_POINTS_MAP = {}
-
 
36
 
35
now = datetime.now()
37
now = datetime.now()
36
 
38
 
-
 
39
class __DealPoints:
-
 
40
    
-
 
41
    def __init__(self, manualDealThresholdPrice, points):
-
 
42
        self.manualDealThresholdPrice = manualDealThresholdPrice
-
 
43
        self.points = points
-
 
44
        
-
 
45
 
37
class __SkuInfo:
46
class __SkuInfo:
38
    
47
    
39
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
48
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
40
                 maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
49
                 maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
41
                 codAvailable,showDp,gross_price):
50
                 codAvailable,showDp,gross_price):
Line 278... Line 287...
278
        deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
287
        deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
279
        sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
288
        sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
280
        shortagePoints = 50 if sku['_id'] in shortageSkus else 0
289
        shortagePoints = 50 if sku['_id'] in shortageSkus else 0
281
        print "Shortage points for ",sku['_id']
290
        print "Shortage points for ",sku['_id']
282
        print shortagePoints
291
        print shortagePoints
-
 
292
        
-
 
293
        dealPoints = DEAL_POINTS_MAP.get(sku['skuBundleId'])
283
        try:
294
        
284
            sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints + sku['dealPoints'] 
295
        if dealPoints is not None and dealPoints.manualDealThresholdPrice >= sku['available_price']:
-
 
296
            sku['dealPoints'] = dealPoints.points
285
            get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
297
            sku['manualDealThresholdPrice'] = dealPoints.manualDealThresholdPrice
286
        except:
298
        else:
-
 
299
            sku['dealPoints'] = 0
287
            print 'Error Comes for Sku Id :- ', sku['_id']
300
            sku['manualDealThresholdPrice'] = None
288
            traceback.print_exc()
301
            
-
 
302
        
-
 
303
        sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints + sku['dealPoints'] 
-
 
304
        get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints'],'dealPoints':sku['dealPoints'], \
-
 
305
                                                                                    'manualDealThresholdPrice':sku['manualDealThresholdPrice']}},multi=False)
289
    
306
    
290
    
307
    
291
 
308
 
292
def populateNegativeDeals():
309
def populateNegativeDeals():
293
    negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
310
    negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
294
    mc.set("negative_deals", negativeDeals, 600)   
311
    mc.set("negative_deals", negativeDeals, 600)   
295
 
312
 
296
def elimiateSimilarDeals():
313
def eliminateSimilarDeals():
297
    allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
314
    allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
298
    for skuBundleId in allItems:
315
    for skuBundleId in allItems:
299
        print skuBundleId
316
        print skuBundleId
300
        similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
317
        similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
301
        bestPrice = float("inf")
318
        bestPrice = float("inf")
Line 359... Line 376...
359
                    toUpdate.remove(prepaidBestOne['_id'])
376
                    toUpdate.remove(prepaidBestOne['_id'])
360
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
377
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
361
        if len(toUpdate) > 0:
378
        if len(toUpdate) > 0:
362
            get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
379
            get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
363
 
380
 
-
 
381
def populateDealPointsBundle():
-
 
382
    global DEAL_POINTS_MAP
-
 
383
    activeDealPoints = get_mongo_connection().Catalog.DealPoints.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
-
 
384
    for activeDeal in activeDealPoints:
-
 
385
        dealPoints = __DealPoints(activeDeal['dealThresholdPrice'], activeDeal['dealPoints'])
-
 
386
        DEAL_POINTS_MAP[activeDeal['skuBundleId']] = dealPoints 
-
 
387
 
364
def main():
388
def main():
365
    try:
389
    try:
366
        populateStuff()
390
        populateStuff()
367
        calculateNlc()
391
        calculateNlc()
368
        addManualDealsInfo()
392
        addManualDealsInfo()
369
    finally:
393
    finally:
370
        session.close()
394
        session.close()
371
    calculateNlcPoints()
395
    calculateNlcPoints()
372
    commitData()
396
    commitData()
-
 
397
    populateDealPointsBundle()
373
    addBestSellerPoints()
398
    addBestSellerPoints()
374
    elimiateSimilarDeals()
399
    eliminateSimilarDeals()
375
 
400
 
376
 
401
 
377
if __name__=='__main__':
402
if __name__=='__main__':
378
    main()
403
    main()