Subversion Repositories SmartDukaan

Rev

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

Rev 19211 Rev 19584
Line 8... Line 8...
8
import time
8
import time
9
import optparse
9
import optparse
10
from dtr.storage.MemCache import MemCache
10
from dtr.storage.MemCache import MemCache
11
import traceback
11
import traceback
12
import math
12
import math
-
 
13
from pymongo import ASCENDING
13
 
14
 
14
parser = optparse.OptionParser()
15
parser = optparse.OptionParser()
15
parser.add_option("-H", "--host", dest="hostname",
16
parser.add_option("-H", "--host", dest="hostname",
16
                      default="localhost",
17
                      default="localhost",
17
                      type="string", help="The HOST where the DB server is running",
18
                      type="string", help="The HOST where the DB server is running",
Line 30... Line 31...
30
con = None
31
con = None
31
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6,'HOMESHOP18.COM':7}
32
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6,'HOMESHOP18.COM':7}
32
DISCOUNT_TYPE = {'MRP':1,'DP':2}
33
DISCOUNT_TYPE = {'MRP':1,'DP':2}
33
LATEST_UPDATED_ITEMS = []
34
LATEST_UPDATED_ITEMS = []
34
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
35
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
-
 
36
subCatRankList = []
35
 
37
 
36
DEAL_POINTS_MAP = {}
38
DEAL_POINTS_MAP = {}
37
 
39
 
38
now = datetime.now()
40
now = datetime.now()
39
 
41
 
Line 441... Line 443...
441
        return (price - cash_back)
443
        return (price - cash_back)
442
    else:
444
    else:
443
        return price
445
        return price
444
 
446
 
445
 
447
 
-
 
448
def getSubCategoryRanking():
-
 
449
    subCatRanks = get_mongo_connection().Catalog.SubCategoriesRank.find().sort([('rank',ASCENDING)])
-
 
450
    for subCatRank in subCatRanks:
-
 
451
        subCatRankList.append(subCatRank['subCategoryId'])
-
 
452
    
-
 
453
def startBucketing():
-
 
454
    
-
 
455
    """Lets create initial buckets of 25 products each from all valid subCategories"""
-
 
456
    initialMap = {}
-
 
457
    for subCat in subCatRankList:
-
 
458
        products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':{"$gt":0}}).sort([('internalRank',ASCENDING)]).limit(25))
-
 
459
        temp_list = []
-
 
460
        for product in products:
-
 
461
            if product['skuBundleId'] not in temp_list:
-
 
462
                temp_list.append(product['skuBundleId'])
-
 
463
        initialMap[subCat] = temp_list
-
 
464
    laterMap = {}
-
 
465
    for subCat in subCatRankList:
-
 
466
        products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':{"$gt":0}}).sort([('internalRank',ASCENDING)]).skip(25))
-
 
467
        temp_list = []
-
 
468
        for product in products:
-
 
469
            if product['skuBundleId'] not in temp_list:
-
 
470
                temp_list.append(product['skuBundleId'])
-
 
471
        laterMap[subCat] = temp_list
-
 
472
    
-
 
473
    for subCat in subCatRankList:
-
 
474
        no_of_products = len(initialMap.get(subCat))
-
 
475
        if no_of_products < 25:
-
 
476
            toFetch = 25 - no_of_products
-
 
477
            products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':0}).limit(toFetch))
-
 
478
            for product in products:
-
 
479
                initialMap.get(subCat).append(product['skuBundleId'])
-
 
480
            products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':0}).skip(toFetch))
-
 
481
            for product in products:
-
 
482
                laterMap.get(subCat).append(product['skuBundleId'])
-
 
483
        else:
-
 
484
            products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':0}))
-
 
485
            for product in products:
-
 
486
                laterMap.get(subCat).append(product['skuBundleId'])
-
 
487
 
-
 
488
    """Now we have created two diff. maps having product sorted by rank.Lets create buckets (5 products) from initialMap and (10 products) from laterMap"""
-
 
489
    
-
 
490
    dealRankPoints = 0
-
 
491
    for k, v in initialMap.iteritems():
-
 
492
        dealRankPoints = dealRankPoints + len(v)
-
 
493
    for k, v in laterMap.iteritems():
-
 
494
        dealRankPoints = dealRankPoints + len(v)
-
 
495
    
-
 
496
    while(len(initialMap.keys())>0):
-
 
497
        for subCat in subCatRankList:
-
 
498
            v = initialMap.get(subCat)
-
 
499
            if v is None or len(v) ==0:
-
 
500
                initialMap.pop(subCat, None)
-
 
501
                continue
-
 
502
            get_mongo_connection().Catalog.Deals.update({'skuBundleId':v[0]},{"$set":{'dealRankPoints':dealRankPoints}},upsert=False,multi=True)
-
 
503
            dealRankPoints = dealRankPoints-1
-
 
504
            v.pop(0)
-
 
505
            if len(v) == 0:
-
 
506
                initialMap.pop(subCat, None)
-
 
507
    
-
 
508
    
-
 
509
    print "============================================================"
-
 
510
    
-
 
511
    while(len(laterMap.keys())>0):
-
 
512
        for subCat in subCatRankList:
-
 
513
            v = laterMap.get(subCat)
-
 
514
            if v is None or len(v) ==0:
-
 
515
                laterMap.pop(subCat, None)
-
 
516
                continue
-
 
517
            get_mongo_connection().Catalog.Deals.update({'skuBundleId':v[0]},{"$set":{'dealRankPoints':dealRankPoints}},upsert=False,multi=True)
-
 
518
            dealRankPoints = dealRankPoints-1
-
 
519
            v.pop(0)
-
 
520
            if len(v) == 0:
-
 
521
                laterMap.pop(subCat, None)
-
 
522
 
-
 
523
 
-
 
524
 
446
 
525
 
447
# def calculateNetPriceAfterCashback():
526
# def calculateNetPriceAfterCashback():
448
#     for data in LATEST_UPDATED_ITEMS:
527
#     for data in LATEST_UPDATED_ITEMS:
449
#         master = list(get_mongo_connection().Catalog.MasterData.find({'_id':data._id}))
528
#         master = list(get_mongo_connection().Catalog.MasterData.find({'_id':data._id}))
450
#         if master[0]['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
529
#         if master[0]['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
Line 477... Line 556...
477
    print "Add best seller points ", datetime.now()
556
    print "Add best seller points ", datetime.now()
478
    addBestSellerPoints()
557
    addBestSellerPoints()
479
    print "eliminate similar deals ", datetime.now()
558
    print "eliminate similar deals ", datetime.now()
480
    eliminateSimilarDeals()
559
    eliminateSimilarDeals()
481
    print "done ", datetime.now()
560
    print "done ", datetime.now()
-
 
561
    getSubCategoryRanking()
-
 
562
    startBucketing()
-
 
563
    print "Done with bucketing",datetime.now()
-
 
564
    
482
 
565
 
483
 
566
 
484
if __name__=='__main__':
567
if __name__=='__main__':
485
    main()
568
    main()