| Line 340... |
Line 340... |
| 340 |
__populateFeaturedDeals()
|
340 |
__populateFeaturedDeals()
|
| 341 |
featuredDeals = mc.get("featured_deals")
|
341 |
featuredDeals = mc.get("featured_deals")
|
| 342 |
|
342 |
|
| 343 |
except Exception as e:
|
343 |
except Exception as e:
|
| 344 |
print traceback.print_exc()
|
344 |
print traceback.print_exc()
|
| 345 |
featuredDeals = {3:{},5:{}}
|
345 |
featuredDeals = {3:{},5:{},6:{}}
|
| 346 |
print featuredDeals
|
346 |
print featuredDeals
|
| 347 |
|
347 |
|
| 348 |
fd_bundles = []
|
348 |
fd_bundles = []
|
| 349 |
|
349 |
|
| 350 |
for catMap in featuredDeals.itervalues():
|
350 |
for catMap in featuredDeals.itervalues():
|
| Line 378... |
Line 378... |
| 378 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
378 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
| 379 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
379 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 380 |
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}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
380 |
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}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 381 |
mobile_deals = []
|
381 |
mobile_deals = []
|
| 382 |
tablet_deals = []
|
382 |
tablet_deals = []
|
| - |
|
383 |
accessories_deals = []
|
| 383 |
for deal in all_deals:
|
384 |
for deal in all_deals:
|
| 384 |
|
385 |
|
| - |
|
386 |
|
| 385 |
try:
|
387 |
try:
|
| 386 |
fd_bundles.remove(deal.get('skuBundleId'))
|
388 |
fd_bundles.remove(deal.get('skuBundleId'))
|
| 387 |
except:
|
389 |
except:
|
| 388 |
pass
|
390 |
pass
|
| 389 |
|
391 |
|
| Line 393... |
Line 395... |
| 393 |
fav_weight = 1.5
|
395 |
fav_weight = 1.5
|
| 394 |
else:
|
396 |
else:
|
| 395 |
fav_weight = 1
|
397 |
fav_weight = 1
|
| 396 |
|
398 |
|
| 397 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
399 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
| - |
|
400 |
|
| 398 |
brand_weight = 1
|
401 |
brand_weight = 1
|
| 399 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
402 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
| 400 |
if brandInfo.get(deal['category_id']) is not None:
|
403 |
if brandInfo.get(deal['category_id']) is not None:
|
| 401 |
if brandInfo.get(deal['category_id']) == 1:
|
404 |
if brandInfo.get(deal['category_id']) == 1:
|
| 402 |
brand_weight = 2.0
|
405 |
brand_weight = 2.0
|
| Line 419... |
Line 422... |
| 419 |
|
422 |
|
| 420 |
if deal['category_id'] ==3:
|
423 |
if deal['category_id'] ==3:
|
| 421 |
mobile_deals.append(deal)
|
424 |
mobile_deals.append(deal)
|
| 422 |
elif deal['category_id'] ==5:
|
425 |
elif deal['category_id'] ==5:
|
| 423 |
tablet_deals.append(deal)
|
426 |
tablet_deals.append(deal)
|
| - |
|
427 |
elif deal['category_id'] ==6:
|
| - |
|
428 |
accessories_deals.append(deal)
|
| 424 |
else:
|
429 |
else:
|
| 425 |
continue
|
430 |
continue
|
| 426 |
|
431 |
|
| 427 |
session.close()
|
432 |
session.close()
|
| 428 |
|
433 |
|
| 429 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
434 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 430 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
435 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| - |
|
436 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 431 |
|
437 |
|
| 432 |
|
438 |
|
| 433 |
if len(fd_bundles) > 0:
|
439 |
if len(fd_bundles) > 0:
|
| 434 |
print fd_bundles
|
440 |
print fd_bundles
|
| 435 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
441 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
| Line 438... |
Line 444... |
| 438 |
for dummyDealObj in dummyDealObjList:
|
444 |
for dummyDealObj in dummyDealObjList:
|
| 439 |
if dummyDealObj['category_id'] ==3:
|
445 |
if dummyDealObj['category_id'] ==3:
|
| 440 |
mobile_deals.append(dummyDealObj)
|
446 |
mobile_deals.append(dummyDealObj)
|
| 441 |
elif dummyDealObj['category_id'] ==5:
|
447 |
elif dummyDealObj['category_id'] ==5:
|
| 442 |
tablet_deals.append(dummyDealObj)
|
448 |
tablet_deals.append(dummyDealObj)
|
| - |
|
449 |
elif dummyDealObj['category_id'] ==6:
|
| - |
|
450 |
accessories_deals.append(dummyDealObj)
|
| 443 |
else:
|
451 |
else:
|
| 444 |
pass
|
452 |
pass
|
| 445 |
|
453 |
|
| - |
|
454 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
| - |
|
455 |
for val in categoryFeaturedDeals.itervalues():
|
| - |
|
456 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
| - |
|
457 |
for dummyDealObj in dummyDealObjList:
|
| - |
|
458 |
if super_category == dummyDealObj['category_id']:
|
| - |
|
459 |
continue
|
| 446 |
|
460 |
|
| - |
|
461 |
if super_category ==3:
|
| - |
|
462 |
mobile_deals.append(dummyDealObj)
|
| - |
|
463 |
elif super_category ==5:
|
| - |
|
464 |
tablet_deals.append(dummyDealObj)
|
| - |
|
465 |
elif super_category ==6:
|
| - |
|
466 |
accessories_deals.append(dummyDealObj)
|
| - |
|
467 |
else:
|
| - |
|
468 |
pass
|
| - |
|
469 |
|
| 447 |
sortedMapMobiles = {}
|
470 |
sortedMapMobiles = {}
|
| 448 |
rankMapMobiles = {}
|
471 |
rankMapMobiles = {}
|
| 449 |
rankMobiles = 0
|
472 |
rankMobiles = 0
|
| 450 |
|
473 |
|
| 451 |
blockedRanksMobiles = []
|
474 |
blockedRanksMobiles = []
|
| Line 453... |
Line 476... |
| 453 |
blockedInfoMobiles = {}
|
476 |
blockedInfoMobiles = {}
|
| 454 |
|
477 |
|
| 455 |
featuredDealsMobiles = featuredDeals.get(3)
|
478 |
featuredDealsMobiles = featuredDeals.get(3)
|
| 456 |
|
479 |
|
| 457 |
for k, v in featuredDealsMobiles.iteritems():
|
480 |
for k, v in featuredDealsMobiles.iteritems():
|
| 458 |
if v.get('category_id') == 3:
|
- |
|
| 459 |
blockedRanksMobiles.append(k-1)
|
481 |
blockedRanksMobiles.append(k-1)
|
| 460 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
482 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
| 461 |
|
483 |
|
| 462 |
print "Blocked ranks ", blockedRanksMobiles
|
484 |
print "Blocked ranks ", blockedRanksMobiles
|
| 463 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
485 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
| 464 |
|
486 |
|
| 465 |
for sorted_deal in mobile_deals:
|
487 |
for sorted_deal in mobile_deals:
|
| Line 507... |
Line 529... |
| 507 |
|
529 |
|
| 508 |
featuredDealsTablets = featuredDeals.get(5)
|
530 |
featuredDealsTablets = featuredDeals.get(5)
|
| 509 |
|
531 |
|
| 510 |
|
532 |
|
| 511 |
for k, v in featuredDealsTablets.iteritems():
|
533 |
for k, v in featuredDealsTablets.iteritems():
|
| 512 |
if v.get('category_id') == 5:
|
- |
|
| 513 |
blockedRanksTablets.append(k-1)
|
534 |
blockedRanksTablets.append(k-1)
|
| 514 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
535 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
| 515 |
|
536 |
|
| 516 |
print "Blocked ranks ", blockedRanksTablets
|
537 |
print "Blocked ranks ", blockedRanksTablets
|
| 517 |
print "Blocked bundles ", blockedSkuBundlesTablets
|
538 |
print "Blocked bundles ", blockedSkuBundlesTablets
|
| 518 |
|
539 |
|
| 519 |
for sorted_deal in tablet_deals:
|
540 |
for sorted_deal in tablet_deals:
|
| 520 |
while(True):
|
541 |
while(True):
|
| Line 543... |
Line 564... |
| 543 |
for rank in blockedRanksTablets:
|
564 |
for rank in blockedRanksTablets:
|
| 544 |
print "Adding rank ",rank
|
565 |
print "Adding rank ",rank
|
| 545 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
566 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
| 546 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
567 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
| 547 |
print rankMapTablets[rank]
|
568 |
print rankMapTablets[rank]
|
| - |
|
569 |
|
| - |
|
570 |
|
| - |
|
571 |
sortedMapAccessories = {}
|
| - |
|
572 |
rankMapAccessories = {}
|
| - |
|
573 |
rankAccessories = 0
|
| - |
|
574 |
|
| - |
|
575 |
blockedRanksAccessories = []
|
| - |
|
576 |
blockedSkuBundlesAccessories = []
|
| - |
|
577 |
blockedInfoAccessories = {}
|
| - |
|
578 |
|
| - |
|
579 |
featuredDealsAccessories = featuredDeals.get(6)
|
| - |
|
580 |
|
| - |
|
581 |
for k, v in featuredDealsAccessories.iteritems():
|
| - |
|
582 |
blockedRanksAccessories.append(k-1)
|
| - |
|
583 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
| - |
|
584 |
|
| - |
|
585 |
print "Blocked ranks ", blockedRanksAccessories
|
| - |
|
586 |
print "Blocked bundles ", blockedSkuBundlesAccessories
|
| - |
|
587 |
|
| - |
|
588 |
for sorted_deal in accessories_deals:
|
| - |
|
589 |
|
| - |
|
590 |
while(True):
|
| - |
|
591 |
if rankAccessories in blockedRanksAccessories:
|
| - |
|
592 |
print "skipping rank ",rankAccessories
|
| - |
|
593 |
rankAccessories = rankAccessories +1
|
| - |
|
594 |
else:
|
| - |
|
595 |
break
|
| - |
|
596 |
|
| - |
|
597 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
| - |
|
598 |
print "Yes sorted deal in blocked ",sorted_deal['skuBundleId']
|
| - |
|
599 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
| - |
|
600 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
| - |
|
601 |
else:
|
| - |
|
602 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
| - |
|
603 |
continue
|
| - |
|
604 |
|
| - |
|
605 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
| - |
|
606 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
| - |
|
607 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
| - |
|
608 |
rankAccessories = rankAccessories +1
|
| - |
|
609 |
else:
|
| - |
|
610 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
| - |
|
611 |
temp_list.append(sorted_deal)
|
| - |
|
612 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 548 |
|
613 |
|
| - |
|
614 |
print "Blocked info ", blockedInfoAccessories
|
| - |
|
615 |
|
| - |
|
616 |
for rank in blockedRanksAccessories:
|
| - |
|
617 |
print "Adding rank acc ",rank
|
| - |
|
618 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
| - |
|
619 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
| - |
|
620 |
print rankMapAccessories[rank]
|
| - |
|
621 |
|
| - |
|
622 |
print rankMapAccessories
|
| - |
|
623 |
|
| 549 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, "3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets }
|
624 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 6: accessories_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets,"6_rankMap": rankMapAccessories }
|
| 550 |
mc.set(str(userId), mem_cache_val)
|
625 |
mc.set(str(userId), mem_cache_val)
|
| 551 |
|
626 |
|
| 552 |
|
627 |
|
| 553 |
def __populateFeaturedDeals():
|
628 |
def __populateFeaturedDeals():
|
| 554 |
print "Populating featured deals....."
|
629 |
print "Populating featured deals....."
|
| 555 |
featuredDealsMobiles = {}
|
630 |
featuredDealsMobiles = {}
|
| 556 |
featuredDealsTablets = {}
|
631 |
featuredDealsTablets = {}
|
| - |
|
632 |
featuredDealsAccessories = {}
|
| 557 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort([('rank',pymongo.DESCENDING)])
|
633 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort([('rank',pymongo.DESCENDING)])
|
| 558 |
for activeFeaturedDeal in activeFeaturedDeals:
|
634 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| 559 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
635 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
| 560 |
for deal in deals:
|
636 |
for deal in deals:
|
| 561 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
637 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
| - |
|
638 |
for category_id, rank in activeFeaturedDeal['otherInfo'].iteritems():
|
| 562 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id'),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
639 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':rank,'category_id':int(category_id),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
| 563 |
if activeFeaturedDeal.get('category_id') == 3:
|
640 |
if f_deal['category_id'] == 3:
|
| 564 |
featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
641 |
featuredDealsMobiles[rank] = f_deal
|
| 565 |
else:
|
642 |
elif f_deal['category_id']==5:
|
| 566 |
featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
643 |
featuredDealsTablets[rank] = f_deal
|
| - |
|
644 |
elif f_deal['category_id']==6:
|
| - |
|
645 |
featuredDealsAccessories[rank] = f_deal
|
| 567 |
break
|
646 |
break
|
| - |
|
647 |
|
| - |
|
648 |
# f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id'),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
| - |
|
649 |
# if activeFeaturedDeal.get('category_id') == 3:
|
| - |
|
650 |
# featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
| - |
|
651 |
# else:
|
| - |
|
652 |
# featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
| - |
|
653 |
# break
|
| - |
|
654 |
|
| 568 |
|
655 |
|
| 569 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets}, 600)
|
656 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets,6:featuredDealsAccessories}, 600)
|
| 570 |
print mc.get("featured_deals")
|
657 |
print mc.get("featured_deals")
|
| 571 |
|
658 |
|
| 572 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
659 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| 573 |
if not bool(mc.get("category_cash_back")):
|
660 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 574 |
populateCashBack()
|
661 |
populateCashBack()
|
| 575 |
|
662 |
|
| 576 |
dealsListMap = []
|
663 |
dealsListMap = []
|
| 577 |
user_specific_deals = mc.get(str(userId))
|
664 |
user_specific_deals = mc.get(str(userId))
|
| 578 |
if user_specific_deals is None:
|
665 |
if user_specific_deals is None:
|
| Line 725... |
Line 812... |
| 725 |
return [trend['skuBundleId'] for trend in brandsFiltered]
|
812 |
return [trend['skuBundleId'] for trend in brandsFiltered]
|
| 726 |
return [i['skuBundleId'] for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
813 |
return [i['skuBundleId'] for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
| 727 |
|
814 |
|
| 728 |
|
815 |
|
| 729 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
816 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 730 |
if not bool(mc.get("category_cash_back")):
|
817 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 731 |
populateCashBack()
|
818 |
populateCashBack()
|
| 732 |
rank = 1
|
819 |
rank = 1
|
| 733 |
deals = {}
|
820 |
deals = {}
|
| 734 |
outer_query = []
|
821 |
outer_query = []
|
| 735 |
outer_query.append({"showDeal":1})
|
822 |
outer_query.append({"showDeal":1})
|
| Line 771... |
Line 858... |
| 771 |
rank +=1
|
858 |
rank +=1
|
| 772 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
859 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
| 773 |
|
860 |
|
| 774 |
def getItem(skuId,showDp=None):
|
861 |
def getItem(skuId,showDp=None):
|
| 775 |
temp = []
|
862 |
temp = []
|
| 776 |
if not bool(mc.get("category_cash_back")):
|
863 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 777 |
populateCashBack()
|
864 |
populateCashBack()
|
| 778 |
try:
|
865 |
try:
|
| 779 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
866 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
| 780 |
if skuData is None:
|
867 |
if skuData is None:
|
| 781 |
raise
|
868 |
raise
|
| Line 810... |
Line 897... |
| 810 |
return temp
|
897 |
return temp
|
| 811 |
except:
|
898 |
except:
|
| 812 |
return []
|
899 |
return []
|
| 813 |
|
900 |
|
| 814 |
def getCashBack(skuId, source_id, category_id):
|
901 |
def getCashBack(skuId, source_id, category_id):
|
| 815 |
if not bool(mc.get("category_cash_back")):
|
902 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 816 |
populateCashBack()
|
903 |
populateCashBack()
|
| 817 |
itemCashBackMap = mc.get("item_cash_back")
|
904 |
itemCashBackMap = mc.get("item_cash_back")
|
| 818 |
itemCashBack = itemCashBackMap.get(skuId)
|
905 |
itemCashBack = itemCashBackMap.get(skuId)
|
| 819 |
if itemCashBack is not None:
|
906 |
if itemCashBack is not None:
|
| 820 |
return itemCashBack
|
907 |
return itemCashBack
|
| Line 892... |
Line 979... |
| 892 |
|
979 |
|
| 893 |
return {'rank':0,'description':'Rank not found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
980 |
return {'rank':0,'description':'Rank not found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 894 |
|
981 |
|
| 895 |
|
982 |
|
| 896 |
def getCashBackDetails(identifier, source_id):
|
983 |
def getCashBackDetails(identifier, source_id):
|
| 897 |
if not bool(mc.get("category_cash_back")):
|
984 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 898 |
populateCashBack()
|
985 |
populateCashBack()
|
| 899 |
|
986 |
|
| 900 |
if source_id in (1,2,4,5,6,7):
|
987 |
if source_id in (1,2,4,5,6,7):
|
| 901 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
988 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
| 902 |
elif source_id == 3:
|
989 |
elif source_id == 3:
|
| Line 1158... |
Line 1245... |
| 1158 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
1245 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 1159 |
if len(master) > 0:
|
1246 |
if len(master) > 0:
|
| 1160 |
val['brand'] = master[0]['brand']
|
1247 |
val['brand'] = master[0]['brand']
|
| 1161 |
val['source_product_name'] = master[0]['source_product_name']
|
1248 |
val['source_product_name'] = master[0]['source_product_name']
|
| 1162 |
val['skuBundleId'] = master[0]['skuBundleId']
|
1249 |
val['skuBundleId'] = master[0]['skuBundleId']
|
| 1163 |
val['category'] = 'Mobiles' if val['category_id'] == 3 else 'Tablets'
|
- |
|
| 1164 |
else:
|
1250 |
else:
|
| 1165 |
val['brand'] = ""
|
1251 |
val['brand'] = ""
|
| 1166 |
val['source_product_name'] = ""
|
1252 |
val['source_product_name'] = ""
|
| 1167 |
val['skuBundleId'] = ""
|
1253 |
val['skuBundleId'] = ""
|
| 1168 |
val['category'] = ""
|
- |
|
| 1169 |
data.append(val)
|
1254 |
data.append(val)
|
| 1170 |
return data
|
1255 |
return data
|
| 1171 |
|
1256 |
|
| 1172 |
def addFeaturedDeal(data, multi):
|
1257 |
def addFeaturedDeal(data, multi):
|
| 1173 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
1258 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 1174 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
1259 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
| 1175 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
1260 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
| 1176 |
if master is None:
|
1261 |
if master is None:
|
| 1177 |
return {0:"BundleId is wrong"}
|
1262 |
return {0:"BundleId is wrong"}
|
| 1178 |
data['category_id'] = master['category_id']
|
1263 |
otherInfoObj = data['otherInfo']
|
| - |
|
1264 |
toPop = []
|
| - |
|
1265 |
for x,y in otherInfoObj.iteritems():
|
| - |
|
1266 |
if y==0:
|
| - |
|
1267 |
toPop.append(x)
|
| - |
|
1268 |
|
| - |
|
1269 |
for popItem in toPop:
|
| - |
|
1270 |
otherInfoObj.pop(popItem)
|
| - |
|
1271 |
if len(otherInfoObj.keys())==0:
|
| - |
|
1272 |
return {0:"No rank info to add"}
|
| - |
|
1273 |
|
| - |
|
1274 |
for x,y in otherInfoObj.iteritems():
|
| 1179 |
exist = collection.find({'rank':data['rank'],'category_id':data['category_id']})
|
1275 |
exist = get_mongo_connection().Catalog.FeaturedDeals.find({'otherInfo.'+x:y})
|
| - |
|
1276 |
if exist.count() >0:
|
| - |
|
1277 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
| 1180 |
if cursor.count() > 0:
|
1278 |
if cursor.count() > 0:
|
| 1181 |
return {0:"SkuBundleId information already present."}
|
1279 |
return {0:"SkuBundleId information already present."}
|
| 1182 |
elif exist.count() >0:
|
- |
|
| 1183 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
- |
|
| 1184 |
else:
|
1280 |
else:
|
| 1185 |
collection.insert(data)
|
1281 |
collection.insert(data)
|
| 1186 |
return {1:"Data added successfully"}
|
1282 |
return {1:"Data added successfully"}
|
| 1187 |
|
1283 |
|
| 1188 |
def searchCollection(class_name, sku, skuBundleId):
|
1284 |
def searchCollection(class_name, sku, skuBundleId):
|
| Line 1374... |
Line 1470... |
| 1374 |
return data
|
1470 |
return data
|
| 1375 |
|
1471 |
|
| 1376 |
def getBrandsForFilter(category_id):
|
1472 |
def getBrandsForFilter(category_id):
|
| 1377 |
if mc.get("brandFilter") is None:
|
1473 |
if mc.get("brandFilter") is None:
|
| 1378 |
print "Populating brand data for category_id %d" %(category_id)
|
1474 |
print "Populating brand data for category_id %d" %(category_id)
|
| 1379 |
tabData, mobData = [], []
|
1475 |
tabData, mobData, accData = [], [], []
|
| 1380 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
1476 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 1381 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}}
|
1477 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 1382 |
},
|
1478 |
},
|
| 1383 |
{"$group" :
|
1479 |
{"$group" :
|
| 1384 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1480 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| Line 1391... |
Line 1487... |
| 1391 |
{"$group" :
|
1487 |
{"$group" :
|
| 1392 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1488 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| 1393 |
}
|
1489 |
}
|
| 1394 |
])
|
1490 |
])
|
| 1395 |
|
1491 |
|
| - |
|
1492 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| - |
|
1493 |
{"$match":{"category_id":6,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| - |
|
1494 |
},
|
| - |
|
1495 |
{"$group" :
|
| - |
|
1496 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| - |
|
1497 |
}
|
| - |
|
1498 |
])
|
| - |
|
1499 |
|
| 1396 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
1500 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 1397 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":-100}}
|
1501 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 1398 |
},
|
1502 |
},
|
| 1399 |
{"$group" :
|
1503 |
{"$group" :
|
| 1400 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1504 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| Line 1423... |
Line 1527... |
| 1423 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
1527 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
| 1424 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
1528 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
| 1425 |
tempMap['count'] = tabletDeal.get('count')
|
1529 |
tempMap['count'] = tabletDeal.get('count')
|
| 1426 |
tabData.append(tempMap)
|
1530 |
tabData.append(tempMap)
|
| 1427 |
|
1531 |
|
| - |
|
1532 |
for accessoryDeal in accessoriesDeals['result']:
|
| - |
|
1533 |
if accessoryDeal.get('_id').get('brand_id') != 0:
|
| - |
|
1534 |
tempMap = {}
|
| - |
|
1535 |
tempMap['brand'] = accessoryDeal.get('_id').get('brand')
|
| - |
|
1536 |
tempMap['brand_id'] = accessoryDeal.get('_id').get('brand_id')
|
| - |
|
1537 |
tempMap['count'] = accessoryDeal.get('count')
|
| - |
|
1538 |
accData.append(tempMap)
|
| - |
|
1539 |
|
| 1428 |
|
1540 |
|
| 1429 |
brandMap = {}
|
1541 |
brandMap = {}
|
| 1430 |
for allDeal in allDeals['result']:
|
1542 |
for allDeal in allDeals['result']:
|
| 1431 |
if allDeal.get('_id').get('brand_id') != 0:
|
1543 |
if allDeal.get('_id').get('brand_id') != 0:
|
| 1432 |
if brandMap.has_key(allDeal.get('_id').get('brand')):
|
1544 |
if brandMap.has_key(allDeal.get('_id').get('brand')):
|
| Line 1436... |
Line 1548... |
| 1436 |
else:
|
1548 |
else:
|
| 1437 |
temp = []
|
1549 |
temp = []
|
| 1438 |
temp.append(allDeal.get('_id').get('brand_id'))
|
1550 |
temp.append(allDeal.get('_id').get('brand_id'))
|
| 1439 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
1551 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
| 1440 |
|
1552 |
|
| 1441 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)
|
1553 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData, 6:accData}, 600)
|
| 1442 |
|
1554 |
|
| 1443 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
|
1555 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
|
| 1444 |
|
1556 |
|
| 1445 |
def getStaticDeals(offset, limit, category_id, direction):
|
1557 |
def getStaticDeals(offset, limit, category_id, direction):
|
| 1446 |
user_specific_deals = mc.get("staticDeals")
|
1558 |
user_specific_deals = mc.get("staticDeals")
|
| Line 1476... |
Line 1588... |
| 1476 |
|
1588 |
|
| 1477 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
1589 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
| 1478 |
mc.set("staticDeals", mem_cache_val, 3600)
|
1590 |
mc.set("staticDeals", mem_cache_val, 3600)
|
| 1479 |
|
1591 |
|
| 1480 |
def getItemObjForStaticDeals(item):
|
1592 |
def getItemObjForStaticDeals(item):
|
| 1481 |
return {'marketPlaceUrl':item.get('marketPlaceUrl'),'available_price':item.get('available_price'),'source_product_name':item.get('source_product_name'),'thumbnail':item.get('thumbnail'),'source_id':int(item.get('source_id'))}
|
1593 |
return {'marketPlaceUrl':item.get('marketPlaceUrl'),'available_price':int(item.get('available_price')),'source_product_name':item.get('source_product_name'),'thumbnail':item.get('thumbnail'),'source_id':int(item.get('source_id'))}
|
| 1482 |
|
1594 |
|
| 1483 |
def getItemByMerchantIdentifier(identifier, source_id):
|
1595 |
def getItemByMerchantIdentifier(identifier, source_id):
|
| 1484 |
skuData = None
|
1596 |
skuData = None
|
| 1485 |
if source_id in (1,2,4,5,6,7):
|
1597 |
if source_id in (1,2,4,5,6,7):
|
| 1486 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
1598 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
| Line 1877... |
Line 1989... |
| 1877 |
for deal in all_deals:
|
1989 |
for deal in all_deals:
|
| 1878 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
1990 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
| 1879 |
returnObj.append(getItemObjForStaticDeals(item[0]))
|
1991 |
returnObj.append(getItemObjForStaticDeals(item[0]))
|
| 1880 |
return returnObj
|
1992 |
return returnObj
|
| 1881 |
|
1993 |
|
| 1882 |
def searchDummyDeals(search_term , limit):
|
1994 |
def searchDummyDeals(search_term , limit, offset):
|
| 1883 |
data = []
|
1995 |
data = []
|
| 1884 |
uniqueMap = {}
|
1996 |
uniqueMap = {}
|
| 1885 |
if search_term is not None:
|
1997 |
if search_term is not None:
|
| 1886 |
terms = search_term.split(' ')
|
1998 |
terms = search_term.split(' ')
|
| 1887 |
outer_query = []
|
1999 |
outer_query = []
|
| Line 1897... |
Line 2009... |
| 1897 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
2009 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
| 1898 |
for record in collection:
|
2010 |
for record in collection:
|
| 1899 |
data.append(record)
|
2011 |
data.append(record)
|
| 1900 |
for x in data:
|
2012 |
for x in data:
|
| 1901 |
if not uniqueMap.has_key(x['skuBundleId']):
|
2013 |
if not uniqueMap.has_key(x['skuBundleId']):
|
| 1902 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId']}
|
2014 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId'],'thumbnail':x['thumbnail']}
|
| 1903 |
return uniqueMap.values()[0:limit]
|
- |
|
| 1904 |
|
- |
|
| 1905 |
|
- |
|
| 1906 |
|
- |
|
| 1907 |
|
2015 |
|
| - |
|
2016 |
if (offset + limit) > len(uniqueMap.values()):
|
| - |
|
2017 |
limit = len(uniqueMap.values()) - offset - 1
|
| - |
|
2018 |
|
| - |
|
2019 |
count = 0
|
| - |
|
2020 |
# for x in uniqueMap.values():
|
| - |
|
2021 |
# print count,
|
| - |
|
2022 |
# print '\t',
|
| - |
|
2023 |
# print x
|
| - |
|
2024 |
# count = count+1
|
| - |
|
2025 |
|
| - |
|
2026 |
print offset
|
| - |
|
2027 |
print limit
|
| - |
|
2028 |
|
| - |
|
2029 |
return uniqueMap.values()[offset:limit+offset]
|
| 1908 |
|
2030 |
|
| - |
|
2031 |
|
| - |
|
2032 |
def getDummyPricing(skuBundleId):
|
| - |
|
2033 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()},'skuBundleId':skuBundleId,'in_stock':1})
|
| - |
|
2034 |
print collection.count()
|
| - |
|
2035 |
cheapest = 99999999
|
| - |
|
2036 |
cheapestDetails= None
|
| - |
|
2037 |
returnMap = {}
|
| - |
|
2038 |
|
| - |
|
2039 |
for d in collection:
|
| - |
|
2040 |
if d['available_price'] < cheapest:
|
| - |
|
2041 |
cheapestDetails = d
|
| - |
|
2042 |
cheapest = int(d['available_price'])
|
| - |
|
2043 |
if returnMap.has_key(d['source_id']):
|
| - |
|
2044 |
d = getItemObjForStaticDeals(d)
|
| - |
|
2045 |
d['toShowStore'] = 0
|
| - |
|
2046 |
returnMap[d['source_id']].append(d)
|
| - |
|
2047 |
else:
|
| - |
|
2048 |
temp = []
|
| - |
|
2049 |
d = getItemObjForStaticDeals(d)
|
| - |
|
2050 |
d['toShowStore'] = 1
|
| - |
|
2051 |
temp.append(d)
|
| - |
|
2052 |
returnMap[d['source_id']] = temp
|
| - |
|
2053 |
returnMap['cheapest'] = cheapestDetails
|
| - |
|
2054 |
for y in returnMap.itervalues():
|
| - |
|
2055 |
if isinstance(y, (list, tuple)):
|
| - |
|
2056 |
(y[len(y)-1])['lastElement'] = 1
|
| - |
|
2057 |
else:
|
| - |
|
2058 |
pass
|
| - |
|
2059 |
if returnMap['cheapest'] ==None:
|
| - |
|
2060 |
dum = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':skuBundleId,'source_id':{"$in":SOURCE_MAP.keys()}})
|
| - |
|
2061 |
returnMap['cheapest'] = {'thumbnail':dum['thumbnail'],'source_product_name':dum['source_product_name']}
|
| - |
|
2062 |
return returnMap
|
| 1909 |
|
2063 |
|
| 1910 |
def main():
|
2064 |
def main():
|
| 1911 |
#generateRedirectUrl(101,1)
|
2065 |
featuredDeals = mc.get("featured_deals")
|
| 1912 |
print resetCache("47")
|
2066 |
print resetCache("47")
|
| 1913 |
print datetime.now()
|
2067 |
print datetime.now()
|
| 1914 |
x= getNewDeals(47, 3, 0, 500, None, None, None)
|
2068 |
x= getNewDeals(47, 6, 0, 20, None, None, None)
|
| 1915 |
for y in x:
|
2069 |
for y in x:
|
| 1916 |
print y[0]['skuBundleId'],
|
2070 |
print y[0]['skuBundleId'],
|
| 1917 |
print '\t',
|
2071 |
print '\t',
|
| 1918 |
print y[0]['brand']
|
2072 |
print y[0]['brand']
|
| 1919 |
print datetime.now()
|
2073 |
print datetime.now()
|
| 1920 |
#print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
- |
|
| 1921 |
#data = {'skuBundleId':32111,'rank':200,'thresholdPrice':10000,'startDate':to_java_date(datetime.now()),'endDate':to_java_date(datetime.now)}
|
- |
|
| 1922 |
#print addFeaturedDeal(data, None)
|
- |
|
| 1923 |
#getAllFeaturedDeals(0, 50)
|
- |
|
| 1924 |
|
2074 |
|
| 1925 |
|
2075 |
|
| 1926 |
|
2076 |
|
| 1927 |
if __name__=='__main__':
|
2077 |
if __name__=='__main__':
|
| 1928 |
main()
|
2078 |
main()
|
| - |
|
2079 |
|