| Line 690... |
Line 690... |
| 690 |
query = {}
|
690 |
query = {}
|
| 691 |
query['$gt'] = 0
|
691 |
query['$gt'] = 0
|
| 692 |
outer_query.append({'dealRankPoints':query})
|
692 |
outer_query.append({'dealRankPoints':query})
|
| 693 |
outer_query.append({'category_id':{"$in":[6]}})
|
693 |
outer_query.append({'category_id':{"$in":[6]}})
|
| 694 |
|
694 |
|
| 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 |
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([('dealRankPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING)]))
|
| 696 |
|
696 |
|
| 697 |
brandPrefMap = {}
|
- |
|
| 698 |
pricePrefMap = {}
|
- |
|
| 699 |
actionsMap = {}
|
697 |
actionsMap = {}
|
| 700 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
- |
|
| 701 |
for x in brand_p:
|
698 |
actionRank = 3
|
| 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 |
action = 1 if x.action == 'like' else 0
|
| 704 |
temp_map = {}
|
701 |
if action==1:
|
| 705 |
if brandPrefMap.has_key((x.brand).strip().upper()):
|
- |
|
| 706 |
val = brandPrefMap.get((x.brand).strip().upper())
|
- |
|
| 707 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
702 |
actionsMap[x.store_product_id] = {'action':action,'rank':actionRank,'dealRankPoints':None}
|
| 708 |
val.append(temp_map)
|
703 |
actionRank = actionRank+3
|
| 709 |
else:
|
704 |
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():
|
- |
|
| 716 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
705 |
actionsMap[x.store_product_id] = {'action':action,'rank':None,'dealRankPoints':None}
|
| 717 |
|
706 |
|
| 718 |
session.close()
|
707 |
session.close()
|
| - |
|
708 |
|
| - |
|
709 |
pseudo_count = 0
|
| - |
|
710 |
|
| - |
|
711 |
if actionsMap:
|
| - |
|
712 |
for k,v in actionsMap.iteritems():
|
| - |
|
713 |
tmp_deal = get_mongo_connection().Catalog.Deals.find_one({'_id':k})
|
| - |
|
714 |
if tmp_deal is None or tmp_deal['category_id']!=6 or tmp_deal['showDeal']!=1 or tmp_deal['prepaidDeal']!=1 :
|
| - |
|
715 |
v['rank'] = None
|
| - |
|
716 |
continue
|
| - |
|
717 |
if v['action'] ==0:
|
| - |
|
718 |
leastDealRankPoints = list(get_mongo_connection().Catalog.Deals.find({'subCategoryId':tmp_deal.get('subCategoryId')}).sort([('dealRankPoints',pymongo.ASCENDING)]).limit(1))
|
| - |
|
719 |
if len(leastDealRankPoints) == 0 or leastDealRankPoints[0].get('dealRankPoints') is None:
|
| - |
|
720 |
v['rank'] = None
|
| - |
|
721 |
continue
|
| - |
|
722 |
v['dealRankPoints'] = leastDealRankPoints[0]['leastDealRankPoints'] - 1
|
| - |
|
723 |
v['rank'] = 999999
|
| - |
|
724 |
else:
|
| - |
|
725 |
v['dealRankPoints'] = tmp_deal.get('dealRankPoints')
|
| 719 |
|
726 |
|
| 720 |
for deal in accessories_deals:
|
727 |
for deal in accessories_deals:
|
| 721 |
|
728 |
|
| 722 |
try:
|
729 |
try:
|
| 723 |
fd_bundles.remove(deal.get('skuBundleId'))
|
730 |
fd_bundles.remove(deal.get('skuBundleId'))
|
| 724 |
except:
|
731 |
except:
|
| 725 |
pass
|
732 |
pass
|
| 726 |
|
- |
|
| 727 |
if actionsMap.get(deal['_id']) == 0:
|
733 |
if actionsMap and actionsMap.get(deal['_id'])!=None:
|
| 728 |
fav_weight =.25
|
- |
|
| 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:
|
734 |
if actionsMap.get(deal['_id']).get('action') ==1 and actionsMap.get(deal['_id']).get('rank')!=None:
|
| 735 |
|
- |
|
| 736 |
brand_weight = 1
|
- |
|
| 737 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
735 |
actionRank = actionsMap.get(deal['_id']).get('rank')
|
| 738 |
if brandInfo.get(deal['category_id']) is not None:
|
736 |
if actionRank < pseudo_count:
|
| 739 |
if brandInfo.get(deal['category_id']) == 1:
|
737 |
deal['dealRankPoints'] = accessories_deals[actionRank-1]['dealRankPoints'] -.5 - pseudo_count
|
| 740 |
brand_weight = 2.0
|
738 |
pseudo_count = pseudo_count+1
|
| 741 |
else:
|
- |
|
| 742 |
brand_weight = 1
|
- |
|
| 743 |
|
- |
|
| 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]:
|
739 |
elif actionsMap.get(deal['_id']).get('action') ==0 and actionsMap.get(deal['_id']).get('rank')!=None:
|
| 747 |
asp_weight = 1.5
|
- |
|
| 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]:
|
740 |
deal['dealRankPoints'] = actionsMap.get(deal['_id']).get('dealRankPoints')
|
| 749 |
asp_weight = 1.2
|
- |
|
| 750 |
else:
|
741 |
else:
|
| 751 |
asp_weight = 1
|
742 |
pass
|
| 752 |
else:
|
- |
|
| 753 |
asp_weight = 1
|
- |
|
| 754 |
|
- |
|
| 755 |
persPoints = deal['dealRankPoints'] * fav_weight * brand_weight * asp_weight
|
- |
|
| 756 |
deal['persPoints'] = persPoints
|
- |
|
| 757 |
|
- |
|
| 758 |
|
- |
|
| 759 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['dealRankPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
|
- |
|
| 760 |
|
743 |
|
| - |
|
744 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['dealRankPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| - |
|
745 |
|
| 761 |
if len(fd_bundles) > 0:
|
746 |
if len(fd_bundles) > 0:
|
| 762 |
print "There is still bundle in feature deals.Lets add info"
|
747 |
print "There is still bundle in feature deals.Lets add info"
|
| 763 |
for skuBundleId in fd_bundles:
|
748 |
for skuBundleId in fd_bundles:
|
| 764 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
749 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
| 765 |
for dummyDealObj in dummyDealObjList:
|
750 |
for dummyDealObj in dummyDealObjList:
|
| Line 1542... |
Line 1527... |
| 1542 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
1527 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
| 1543 |
else:
|
1528 |
else:
|
| 1544 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
1529 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 1545 |
if len(skuData) == 0:
|
1530 |
if len(skuData) == 0:
|
| 1546 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
1531 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 1547 |
user_specific_deals = mc.get(str(userId))
|
1532 |
category_id = skuData[0]['category_id']
|
| 1548 |
if user_specific_deals is None:
|
1533 |
if category_id != 6:
|
| 1549 |
__populateCache(userId)
|
- |
|
| 1550 |
user_specific_deals = mc.get(str(userId))
|
1534 |
user_specific_deals = mc.get(str(userId))
|
| - |
|
1535 |
if user_specific_deals is None:
|
| - |
|
1536 |
__populateCache(userId)
|
| - |
|
1537 |
user_specific_deals = mc.get(str(userId))
|
| - |
|
1538 |
else:
|
| - |
|
1539 |
print "Getting user deals from cache mobiles/tablets"
|
| 1551 |
else:
|
1540 |
else:
|
| - |
|
1541 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
| 1552 |
print "Getting user deals from cache"
|
1542 |
if user_specific_deals is None:
|
| 1553 |
category_id = skuData[0]['category_id']
|
1543 |
__populateCacheForAccessories(userId)
|
| - |
|
1544 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
| - |
|
1545 |
else:
|
| - |
|
1546 |
print "Getting user deals from accessory cache"
|
| - |
|
1547 |
|
| 1554 |
category_specific_deals = user_specific_deals.get(category_id)
|
1548 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 1555 |
|
1549 |
|
| 1556 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
1550 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
| 1557 |
if dealsData is None:
|
1551 |
if dealsData is None:
|
| 1558 |
dealsData = {}
|
1552 |
dealsData = {}
|
| - |
|
1553 |
return {'rank':0, 'description':'Deal deleted from system','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 1559 |
|
1554 |
|
| 1560 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
1555 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
| 1561 |
return {'rank':0,'description':'Category specific deals is empty','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
1556 |
return {'rank':0,'description':'Category specific deals is empty','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| - |
|
1557 |
|
| - |
|
1558 |
if category_id!=6:
|
| 1562 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
1559 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| - |
|
1560 |
else:
|
| - |
|
1561 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['dealRankPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
|
| - |
|
1562 |
|
| 1563 |
sortedMap = {}
|
1563 |
sortedMap = {}
|
| 1564 |
rankMap = {}
|
1564 |
rankMap = {}
|
| 1565 |
rank = 0
|
1565 |
rank = 0
|
| 1566 |
for sorted_deal in sorted_deals:
|
1566 |
for sorted_deal in sorted_deals:
|
| 1567 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
1567 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
| Line 2955... |
Line 2955... |
| 2955 |
}
|
2955 |
}
|
| 2956 |
|
2956 |
|
| 2957 |
]
|
2957 |
]
|
| 2958 |
}
|
2958 |
}
|
| 2959 |
},
|
2959 |
},
|
| 2960 |
"sort": { "internalRank": { "order": "asc" }}
|
2960 |
"sort": { "dealRankPoints": { "order": "desc" }}
|
| 2961 |
}
|
2961 |
}
|
| 2962 |
result = get_elastic_search_connection().search(index="my_index", body=payload, from_=offset, size=limit)
|
2962 |
result = get_elastic_search_connection().search(index="my_index", body=payload, from_=offset, size=limit)
|
| 2963 |
totalCount= result['hits']['total']
|
2963 |
totalCount= result['hits']['total']
|
| 2964 |
temp = []
|
2964 |
temp = []
|
| 2965 |
bundles = []
|
2965 |
bundles = []
|