Subversion Repositories SmartDukaan

Rev

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

Rev 19584 Rev 19631
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
from pymongo import ASCENDING, DESCENDING
14
 
14
 
15
parser = optparse.OptionParser()
15
parser = optparse.OptionParser()
16
parser.add_option("-H", "--host", dest="hostname",
16
parser.add_option("-H", "--host", dest="hostname",
17
                      default="localhost",
17
                      default="localhost",
18
                      type="string", help="The HOST where the DB server is running",
18
                      type="string", help="The HOST where the DB server is running",
19
                      metavar="host")
19
                      metavar="host")
20
parser.add_option("-m", "--m", dest="mongoHost",
20
parser.add_option("-m", "--m", dest="mongoHost",
21
                      default="localhost",
21
                      default="localhost",
22
                      type="string", help="The HOST where the mongo server is running",
22
                      type="string", help="The HOST where the mongo server is running",
23
                      metavar="mongo_host")
23
                      metavar="mongo_host")
-
 
24
parser.add_option("-s", "--s", dest="shuffle",
-
 
25
                      default="false",
-
 
26
                      type="string", help="Shuffle ranks for accessories",
-
 
27
                      metavar="shuffle")
-
 
28
 
24
 
29
 
25
(options, args) = parser.parse_args()
30
(options, args) = parser.parse_args()
26
 
31
 
27
mc = MemCache(options.mongoHost)
32
mc = MemCache(options.mongoHost)
28
 
33
 
Line 518... Line 523...
518
            dealRankPoints = dealRankPoints-1
523
            dealRankPoints = dealRankPoints-1
519
            v.pop(0)
524
            v.pop(0)
520
            if len(v) == 0:
525
            if len(v) == 0:
521
                laterMap.pop(subCat, None)
526
                laterMap.pop(subCat, None)
522
 
527
 
523
 
-
 
524
 
-
 
525
 
528
def shuffle():
526
# def calculateNetPriceAfterCashback():
529
    for subCat in subCatRankList:
-
 
530
        products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':0},{'skuBundleId':1}))
527
#     for data in LATEST_UPDATED_ITEMS:
531
        if len(products) >0:
528
#         master = list(get_mongo_connection().Catalog.MasterData.find({'_id':data._id}))
532
            max_rank = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat}).sort([('internalRank',DESCENDING)]).limit(1))
529
#         if master[0]['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
533
            rank_to_assign = max_rank[0]['internalRank'] + 1
-
 
534
            for p in products:
530
#             netPriceAfterCashBack = getNetPriceForItem(data._id, master[0]['source_id'], master[0]['category_id'], master[0]['available_price'])
535
                get_mongo_connection().Catalog.MasterData.update({'skuBundleId':p['skuBundleId']},{"$set":{'internalRank':rank_to_assign}},upsert=False,multi=True)
-
 
536
                rank_to_assign = rank_to_assign + 1
-
 
537
        
-
 
538
        new_rank =1
-
 
539
        start = 0
-
 
540
        end = 5
531
#             get_mongo_connection().Catalog.Deals.update({'_id':data._id},{"$set":{'available_price':master[0]['available_price'],'in_stock':master[0]['in_stock'],'netPriceAfterCashBack':netPriceAfterCashBack}})
541
        products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':{"$gt":0}},{'skuBundleId':1}).sort([('internalRank',ASCENDING)]).limit(25))
532
#         else:
542
        while(True):
-
 
543
            temp_list = products[start:end]
-
 
544
            shuffled_list = temp_list[1:] + temp_list[:1]
533
#             if master[0]['codAvailable'] ==0:
545
            if len(shuffled_list) > 0:
-
 
546
                for p in shuffled_list:
534
#                 netPriceAfterCashBack = getNetPriceForItem(data._id, master[0]['source_id'], master[0]['category_id'], master[0]['gross_price'])
547
                    get_mongo_connection().Catalog.MasterData.update({'skuBundleId':p['skuBundleId']},{"$set":{'internalRank':new_rank}},upsert=False,multi=True)
-
 
548
                    new_rank = new_rank + 1
-
 
549
                start = end
-
 
550
                end = end + 5
535
#             else:
551
            else:
-
 
552
                break
536
#                 netPriceAfterCashBack = getNetPriceForItem(data._id, master[0]['source_id'], master[0]['category_id'], master[0]['available_price'])
553
        products = list(get_mongo_connection().Catalog.MasterData.find({'subCategoryId':subCat,'internalRank':{"$gt":0}},{'skuBundleId':1}).sort([('internalRank',ASCENDING)]).skip(25))
-
 
554
        start = 0
-
 
555
        end = 10
-
 
556
        while(True):
-
 
557
            temp_list = products[start:end]
-
 
558
            shuffled_list = temp_list[1:] + temp_list[:1]
-
 
559
            if len(shuffled_list) > 0:
-
 
560
                for p in shuffled_list:
537
#             get_mongo_connection().Catalog.Deals.update({'_id':data._id},{"$set":{'available_price':master[0]['available_price'],'gross_price':master[0]['gross_price'],'in_stock':master[0]['in_stock'],'netPriceAfterCashBack':netPriceAfterCashBack}})
561
                    get_mongo_connection().Catalog.MasterData.update({'skuBundleId':p['skuBundleId']},{"$set":{'internalRank':new_rank}},upsert=False,multi=True)
-
 
562
                    new_rank = new_rank + 1
-
 
563
                start = end
-
 
564
                end = end + 10
-
 
565
            else:
-
 
566
                break
538
#         
567
              
539
 
-
 
540
def main():
568
def main():
541
    try:
569
    try:
542
        print "Starting populating stuff ", datetime.now()
570
        print "Starting populating stuff ", datetime.now()
543
        populateStuff()
571
        populateStuff()
544
        print "Starting calculate nlc stuff ", datetime.now()
572
        print "Starting calculate nlc stuff ", datetime.now()
Line 557... Line 585...
557
    addBestSellerPoints()
585
    addBestSellerPoints()
558
    print "eliminate similar deals ", datetime.now()
586
    print "eliminate similar deals ", datetime.now()
559
    eliminateSimilarDeals()
587
    eliminateSimilarDeals()
560
    print "done ", datetime.now()
588
    print "done ", datetime.now()
561
    getSubCategoryRanking()
589
    getSubCategoryRanking()
-
 
590
    if options.shuffle=='true':
-
 
591
        print "Shuffling products"
-
 
592
        shuffle()
562
    startBucketing()
593
    #startBucketing()
563
    print "Done with bucketing",datetime.now()
594
    print "Done with bucketing",datetime.now()
564
    
595
    
565
 
596
 
566
 
597
 
567
if __name__=='__main__':
598
if __name__=='__main__':