Subversion Repositories SmartDukaan

Rev

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

Rev 19574 Rev 19575
Line 365... Line 365...
365
def __constructDummyDealObject(skuBundleId):
365
def __constructDummyDealObject(skuBundleId):
366
    temp =[]
366
    temp =[]
367
    deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
367
    deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
368
    for d in deals:
368
    for d in deals:
369
        d['persPoints'] = 0
369
        d['persPoints'] = 0
370
        d['internalRank'] = 999999
370
        d['dealRankPoints'] = 0
371
        temp.append(d)
371
        temp.append(d)
372
    return temp
372
    return temp
373
    
373
    
374
    
374
    
375
 
375
 
Line 416... Line 416...
416
        else:
416
        else:
417
            temp = []
417
            temp = []
418
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
418
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
419
            temp.append(temp_map)
419
            temp.append(temp_map)
420
            brandPrefMap[(x.brand).strip().upper()] = temp
420
            brandPrefMap[(x.brand).strip().upper()] = temp
421
        
421
            
422
    for x in session.query(user_actions).filter_by(user_id=userId).all():
422
    for x in session.query(user_actions).filter_by(user_id=userId).all():
423
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
423
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
-
 
424
        
-
 
425
    session.close()
-
 
426
    
424
    all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
427
    all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
425
    mobile_deals = []
428
    mobile_deals = []
426
    tablet_deals = []
429
    tablet_deals = []
427
    #accessories_deals = []
430
    #accessories_deals = []
428
    for deal in all_deals:
431
    for deal in all_deals:
Line 470... Line 473...
470
        #elif deal['category_id'] ==6:
473
        #elif deal['category_id'] ==6:
471
        #    accessories_deals.append(deal)
474
        #    accessories_deals.append(deal)
472
        else:
475
        else:
473
            continue
476
            continue
474
    
477
    
475
    session.close()
-
 
476
    
-
 
477
    mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
478
    mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
478
    tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
479
    tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
479
    #accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
480
    #accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
480
    
481
    
481
    
482
    
Line 686... Line 687...
686
    print "Populating accessory memcache for userId",userId
687
    print "Populating accessory memcache for userId",userId
687
    outer_query = []
688
    outer_query = []
688
    outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
689
    outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
689
    query = {}
690
    query = {}
690
    query['$gt'] = 0
691
    query['$gt'] = 0
691
    outer_query.append({'internalRank':query})
692
    outer_query.append({'dealRankPoints':query})
692
    outer_query.append({'category_id':{"$in":[6]}})
693
    outer_query.append({'category_id':{"$in":[6]}})
693
 
694
 
694
    accessories_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'bestSellerPoints':1,'nlcPoints':1,'totalPoints':1,'internalRank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('internalRank',pymongo.ASCENDING),('bestSellerPoints',pymongo.DESCENDING)]))
695
    accessories_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'bestSellerPoints':1,'nlcPoints':1,'totalPoints':1,'dealRankPoints':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('internalRank',pymongo.ASCENDING),('bestSellerPoints',pymongo.DESCENDING)]))
695
    
696
    
-
 
697
    brandPrefMap = {}
-
 
698
    pricePrefMap = {}
696
    actionsMap = {}
699
    actionsMap = {}
697
    
-
 
-
 
700
    brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
698
    actionRank = 3
701
    for x in brand_p:
-
 
702
        pricePrefMap[x.category_id] = [x.min_price,x.max_price]
699
    for x in session.query(user_actions).filter_by(user_id=userId).order_by(asc(user_actions.created)).all():
703
    for x in session.query(brand_preferences).filter_by(user_id=userId).all():
700
        #actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
704
        temp_map = {}
701
        action = 1 if x.action == 'like' else 0
705
        if brandPrefMap.has_key((x.brand).strip().upper()):
702
        if action==1:
706
            val = brandPrefMap.get((x.brand).strip().upper())
703
            actionsMap[x.store_product_id] = {'action':action,'rank':actionRank}
707
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
704
            actionRank = actionRank+3
708
            val.append(temp_map)
705
        else:
709
        else:
-
 
710
            temp = []
-
 
711
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
-
 
712
            temp.append(temp_map)
-
 
713
            brandPrefMap[(x.brand).strip().upper()] = temp
-
 
714
        
-
 
715
    for x in session.query(user_actions).filter_by(user_id=userId).all():
706
            actionsMap[x.store_product_id] = {'action':action,'rank':None}
716
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
707
    
717
    
708
    session.close()
718
    session.close()
709
    
-
 
710
    psuedo_count = 1
-
 
711
 
-
 
712
    if actionsMap:
-
 
713
        for k,v in actionsMap.iteritems():
-
 
714
            if v['action'] == 0:
-
 
715
                tmp_deal = get_mongo_connection().Catalog.Deals.find_one({'_id':k})
-
 
716
                if tmp_deal is None:
-
 
717
                    v['rank'] = 999999
-
 
718
                    continue
-
 
719
                max_rank = list(get_mongo_connection().Catalog.Deals.find({'subCategoryId':tmp_deal.get('subCategoryId')}).sort([('internalRank',pymongo.DESCENDING)]).limit(1))
-
 
720
                if len(max_rank) == 0 or max_rank[0].get('internalRank') is None:
-
 
721
                    v['rank'] = 999999
-
 
722
                    continue
-
 
723
                v['rank'] = max_rank[0]['internalRank'] + 1
-
 
724
                 
719
                     
725
    for deal in accessories_deals:
720
    for deal in accessories_deals:
726
 
721
 
727
        try:
722
        try:
728
            fd_bundles.remove(deal.get('skuBundleId'))
723
            fd_bundles.remove(deal.get('skuBundleId'))
729
        except:
724
        except:
730
            pass
725
            pass
-
 
726
        
731
        if actionsMap and actionsMap.get(deal['_id'])!=None:
727
        if actionsMap.get(deal['_id']) == 0:
-
 
728
            fav_weight =.25
732
            if actionsMap.get(deal['_id']).get('action') ==1:
729
        elif actionsMap.get(deal['_id']) == 1:
-
 
730
            fav_weight = 1.5
-
 
731
        else:
-
 
732
            fav_weight = 1
-
 
733
        
-
 
734
        if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
-
 
735
 
-
 
736
            brand_weight = 1
733
                actionRank = actionsMap.get(deal['_id']).get('rank')
737
            for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
734
                if actionRank < psuedo_count:
738
                if brandInfo.get(deal['category_id']) is not None:
-
 
739
                    if brandInfo.get(deal['category_id']) == 1:
735
                    deal['internalRank'] = actionRank
740
                        brand_weight = 2.0
736
                
741
        else:
-
 
742
            brand_weight = 1
-
 
743
        
737
            elif actionsMap.get(deal['_id']).get('action') ==0:
744
        if pricePrefMap.get(deal['category_id']) is not None:
-
 
745
        
-
 
746
            if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
-
 
747
                asp_weight = 1.5
738
                actionRank = actionsMap.get(deal['_id']).get('rank')
748
            elif  deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] - 0.5 * pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1] + 0.5 * pricePrefMap.get(deal['category_id'])[1]:
739
                deal['internalRank'] = actionRank
749
                asp_weight = 1.2
740
            else:
750
            else:
741
                pass
751
                asp_weight = 1
-
 
752
        else:
-
 
753
            asp_weight = 1
-
 
754
        
-
 
755
        persPoints = deal['dealRankPoints'] * fav_weight * brand_weight * asp_weight
742
        psuedo_count = psuedo_count+1
756
        deal['persPoints'] = persPoints
743
    
757
        
744
    if actionsMap:
758
        
745
        accessories_deals = sorted(accessories_deals, key = lambda x: (-x['internalRank'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
759
    accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['dealRankPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
746
    
760
    
747
    if len(fd_bundles) > 0:
761
    if len(fd_bundles) > 0:
748
        print "There is still bundle in feature deals.Lets add info"
762
        print "There is still bundle in feature deals.Lets add info"
749
        for skuBundleId in fd_bundles:
763
        for skuBundleId in fd_bundles:
750
            dummyDealObjList = __constructDummyDealObject(skuBundleId)
764
            dummyDealObjList = __constructDummyDealObject(skuBundleId)
Line 1228... Line 1242...
1228
            continue
1242
            continue
1229
        for d in dealList:
1243
        for d in dealList:
1230
            item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
1244
            item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
1231
            if len(item) ==0:
1245
            if len(item) ==0:
1232
                continue
1246
                continue
1233
            item[0]['internalRankDeals'] = d.get('internalRank')
1247
            item[0]['dealRankPoints'] = d.get('dealRankPoints')
1234
            if d['dealType'] == 1 and d['source_id'] ==1:
1248
            if d['dealType'] == 1 and d['source_id'] ==1:
1235
                try:
1249
                try:
1236
                    manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'sku':d['_id'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
1250
                    manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'sku':d['_id'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
1237
                    item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
1251
                    item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
1238
                except:
1252
                except: