| Line 322... |
Line 322... |
| 322 |
else:
|
322 |
else:
|
| 323 |
result={}
|
323 |
result={}
|
| 324 |
result['amount'] = 0.0
|
324 |
result['amount'] = 0.0
|
| 325 |
return result
|
325 |
return result
|
| 326 |
|
326 |
|
| - |
|
327 |
def __constructDummyDealObject(skuBundleId):
|
| - |
|
328 |
temp =[]
|
| - |
|
329 |
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})
|
| - |
|
330 |
for d in deals:
|
| - |
|
331 |
d['persPoints'] = 0
|
| - |
|
332 |
temp.append(d)
|
| - |
|
333 |
return temp
|
| - |
|
334 |
|
| - |
|
335 |
|
| - |
|
336 |
|
| 327 |
def __populateCache(userId):
|
337 |
def __populateCache(userId):
|
| - |
|
338 |
try:
|
| - |
|
339 |
if mc.get("featured_deals") is None:
|
| - |
|
340 |
__populateFeaturedDeals()
|
| - |
|
341 |
featuredDeals = mc.get("featured_deals")
|
| - |
|
342 |
|
| - |
|
343 |
except Exception as e:
|
| - |
|
344 |
print traceback.print_exc()
|
| - |
|
345 |
featuredDeals = {3:{},5:{}}
|
| - |
|
346 |
print featuredDeals
|
| - |
|
347 |
|
| - |
|
348 |
fd_bundles = []
|
| - |
|
349 |
|
| - |
|
350 |
for catMap in featuredDeals.itervalues():
|
| - |
|
351 |
for fd_map in catMap.itervalues():
|
| - |
|
352 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
| - |
|
353 |
|
| 328 |
print "Populating memcache for userId",userId
|
354 |
print "Populating memcache for userId",userId
|
| 329 |
outer_query = []
|
355 |
outer_query = []
|
| 330 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
356 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 331 |
query = {}
|
357 |
query = {}
|
| 332 |
query['$gt'] = -100
|
358 |
query['$gt'] = -100
|
| Line 353... |
Line 379... |
| 353 |
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
|
| 354 |
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)]))
|
| 355 |
mobile_deals = []
|
381 |
mobile_deals = []
|
| 356 |
tablet_deals = []
|
382 |
tablet_deals = []
|
| 357 |
for deal in all_deals:
|
383 |
for deal in all_deals:
|
| - |
|
384 |
|
| - |
|
385 |
try:
|
| - |
|
386 |
fd_bundles.remove(deal.get('skuBundleId'))
|
| - |
|
387 |
except:
|
| - |
|
388 |
pass
|
| - |
|
389 |
|
| 358 |
if actionsMap.get(deal['_id']) == 0:
|
390 |
if actionsMap.get(deal['_id']) == 0:
|
| 359 |
fav_weight =.25
|
391 |
fav_weight =.25
|
| 360 |
elif actionsMap.get(deal['_id']) == 1:
|
392 |
elif actionsMap.get(deal['_id']) == 1:
|
| 361 |
fav_weight = 1.5
|
393 |
fav_weight = 1.5
|
| 362 |
else:
|
394 |
else:
|
| Line 395... |
Line 427... |
| 395 |
session.close()
|
427 |
session.close()
|
| 396 |
|
428 |
|
| 397 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
429 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 398 |
tablet_deals = sorted(tablet_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)
|
| 399 |
|
431 |
|
| 400 |
try:
|
432 |
|
| 401 |
if mc.get("featured_deals") is None:
|
433 |
if len(fd_bundles) > 0:
|
| - |
|
434 |
print fd_bundles
|
| - |
|
435 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
| 402 |
__populateFeaturedDeals()
|
436 |
for skuBundleId in fd_bundles:
|
| - |
|
437 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
| 403 |
featuredDeals = mc.get("featured_deals")
|
438 |
for dummyDealObj in dummyDealObjList:
|
| 404 |
|
439 |
if dummyDealObj['category_id'] ==3:
|
| - |
|
440 |
mobile_deals.append(dummyDealObj)
|
| 405 |
except Exception as e:
|
441 |
elif dummyDealObj['category_id'] ==5:
|
| 406 |
print traceback.print_exc()
|
442 |
tablet_deals.append(dummyDealObj)
|
| 407 |
featuredDeals = {3:{},5:{}}
|
443 |
else:
|
| 408 |
print featuredDeals
|
444 |
pass
|
| - |
|
445 |
|
| 409 |
|
446 |
|
| 410 |
sortedMapMobiles = {}
|
447 |
sortedMapMobiles = {}
|
| 411 |
rankMapMobiles = {}
|
448 |
rankMapMobiles = {}
|
| 412 |
rankMobiles = 0
|
449 |
rankMobiles = 0
|
| 413 |
|
450 |
|
| Line 424... |
Line 461... |
| 424 |
|
461 |
|
| 425 |
print "Blocked ranks ", blockedRanksMobiles
|
462 |
print "Blocked ranks ", blockedRanksMobiles
|
| 426 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
463 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
| 427 |
|
464 |
|
| 428 |
for sorted_deal in mobile_deals:
|
465 |
for sorted_deal in mobile_deals:
|
| - |
|
466 |
|
| 429 |
while(True):
|
467 |
while(True):
|
| 430 |
if rankMobiles in blockedRanksMobiles:
|
468 |
if rankMobiles in blockedRanksMobiles:
|
| 431 |
print "skipping rank ",rankMobiles
|
469 |
print "skipping rank ",rankMobiles
|
| 432 |
rankMobiles = rankMobiles +1
|
470 |
rankMobiles = rankMobiles +1
|
| 433 |
else:
|
471 |
else:
|
| Line 452... |
Line 490... |
| 452 |
|
490 |
|
| 453 |
print "Blocked info ", blockedInfoMobiles
|
491 |
print "Blocked info ", blockedInfoMobiles
|
| 454 |
|
492 |
|
| 455 |
for rank in blockedRanksMobiles:
|
493 |
for rank in blockedRanksMobiles:
|
| 456 |
print "Adding rank ",rank
|
494 |
print "Adding rank ",rank
|
| - |
|
495 |
if blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId')) is not None:
|
| 457 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
496 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
| 458 |
print rankMapMobiles[rank]
|
497 |
print rankMapMobiles[rank]
|
| 459 |
|
498 |
|
| 460 |
|
499 |
|
| 461 |
sortedMapTablets = {}
|
500 |
sortedMapTablets = {}
|
| 462 |
rankMapTablets = {}
|
501 |
rankMapTablets = {}
|
| 463 |
rankTablets = 0
|
502 |
rankTablets = 0
|
| Line 501... |
Line 540... |
| 501 |
temp_list.append(sorted_deal)
|
540 |
temp_list.append(sorted_deal)
|
| 502 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
541 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 503 |
|
542 |
|
| 504 |
for rank in blockedRanksTablets:
|
543 |
for rank in blockedRanksTablets:
|
| 505 |
print "Adding rank ",rank
|
544 |
print "Adding rank ",rank
|
| - |
|
545 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
| 506 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
546 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
| 507 |
print rankMapTablets[rank]
|
547 |
print rankMapTablets[rank]
|
| 508 |
|
- |
|
| 509 |
|
- |
|
| 510 |
|
- |
|
| 511 |
|
548 |
|
| 512 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, "3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets }
|
549 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, "3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets }
|
| 513 |
mc.set(str(userId), mem_cache_val)
|
550 |
mc.set(str(userId), mem_cache_val)
|
| 514 |
|
551 |
|
| 515 |
|
552 |
|
| Line 520... |
Line 557... |
| 520 |
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)])
|
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)])
|
| 521 |
for activeFeaturedDeal in activeFeaturedDeals:
|
558 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| 522 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
559 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
| 523 |
for deal in deals:
|
560 |
for deal in deals:
|
| 524 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
561 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
| 525 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id')}
|
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')}
|
| 526 |
if activeFeaturedDeal.get('category_id') == 3:
|
563 |
if activeFeaturedDeal.get('category_id') == 3:
|
| 527 |
featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
564 |
featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
| 528 |
else:
|
565 |
else:
|
| 529 |
featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
566 |
featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
| 530 |
break
|
567 |
break
|
| Line 600... |
Line 637... |
| 600 |
rankMap = filterMap
|
637 |
rankMap = filterMap
|
| 601 |
|
638 |
|
| 602 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
639 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 603 |
temp = []
|
640 |
temp = []
|
| 604 |
if dealList is None or len(dealList)==0:
|
641 |
if dealList is None or len(dealList)==0:
|
| - |
|
642 |
print "Empty deal;lisr"
|
| 605 |
continue
|
643 |
continue
|
| 606 |
for d in dealList:
|
644 |
for d in dealList:
|
| 607 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
645 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 608 |
if len(item) ==0:
|
646 |
if len(item) ==0:
|
| 609 |
continue
|
647 |
continue
|
| Line 1869... |
Line 1907... |
| 1869 |
|
1907 |
|
| 1870 |
|
1908 |
|
| 1871 |
|
1909 |
|
| 1872 |
def main():
|
1910 |
def main():
|
| 1873 |
#generateRedirectUrl(101,1)
|
1911 |
#generateRedirectUrl(101,1)
|
| - |
|
1912 |
print resetCache("47")
|
| 1874 |
print datetime.now()
|
1913 |
print datetime.now()
|
| 1875 |
x= getNewDeals(47, 3, 0, 500, None, None, None)
|
1914 |
x= getNewDeals(47, 3, 0, 500, None, None, None)
|
| - |
|
1915 |
for y in x:
|
| - |
|
1916 |
print y[0]['skuBundleId'],
|
| - |
|
1917 |
print '\t',
|
| - |
|
1918 |
print y[0]['brand']
|
| 1876 |
print datetime.now()
|
1919 |
print datetime.now()
|
| 1877 |
#print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
1920 |
#print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
| 1878 |
#data = {'skuBundleId':32111,'rank':200,'thresholdPrice':10000,'startDate':to_java_date(datetime.now()),'endDate':to_java_date(datetime.now)}
|
1921 |
#data = {'skuBundleId':32111,'rank':200,'thresholdPrice':10000,'startDate':to_java_date(datetime.now()),'endDate':to_java_date(datetime.now)}
|
| 1879 |
#print addFeaturedDeal(data, None)
|
1922 |
#print addFeaturedDeal(data, None)
|
| 1880 |
#getAllFeaturedDeals(0, 50)
|
1923 |
#getAllFeaturedDeals(0, 50)
|