Subversion Repositories SmartDukaan

Rev

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

Rev 19637 Rev 20347
Line 10... Line 10...
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, DESCENDING
13
from pymongo import ASCENDING, DESCENDING
14
 
14
 
-
 
15
 
15
parser = optparse.OptionParser()
16
parser = optparse.OptionParser()
16
parser.add_option("-H", "--host", dest="hostname",
17
parser.add_option("-H", "--host", dest="hostname",
17
                      default="localhost",
18
                      default="localhost",
18
                      type="string", help="The HOST where the DB server is running",
19
                      type="string", help="The HOST where the DB server is running",
19
                      metavar="host")
20
                      metavar="host")
Line 42... Line 43...
42
 
43
 
43
DEAL_POINTS_MAP = {}
44
DEAL_POINTS_MAP = {}
44
 
45
 
45
now = datetime.now()
46
now = datetime.now()
46
 
47
 
-
 
48
DEAL_PRIORITY = [4, 2, 1, 5, 6, 7, 3]  #Increasing order of source deal priority
-
 
49
 
47
class __DealPoints:
50
class __DealPoints:
48
    
51
    
49
    def __init__(self, manualDealThresholdPrice, points):
52
    def __init__(self, manualDealThresholdPrice, points):
50
        self.manualDealThresholdPrice = manualDealThresholdPrice
53
        self.manualDealThresholdPrice = manualDealThresholdPrice
51
        self.points = points
54
        self.points = points
Line 53... Line 56...
53
 
56
 
54
class __SkuInfo:
57
class __SkuInfo:
55
    
58
    
56
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
59
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
57
                 maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
60
                 maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
58
                 codAvailable,showDp,gross_price, subCategoryId,subCategory,shippingCost,netPriceAfterCashBack):
61
                 codAvailable,showDp,gross_price, subCategoryId,subCategory,shippingCost,netPriceAfterCashBack, exclusive):
59
        self._id = _id
62
        self._id = _id
60
        self.skuBundleId = skuBundleId
63
        self.skuBundleId = skuBundleId
61
        self.category_id = category_id
64
        self.category_id = category_id
62
        self.mrp = mrp
65
        self.mrp = mrp
63
        self.available_price = available_price
66
        self.available_price = available_price
Line 83... Line 86...
83
        self.gross_price = gross_price
86
        self.gross_price = gross_price
84
        self.subCategoryId = subCategoryId
87
        self.subCategoryId = subCategoryId
85
        self.subCategory = subCategory
88
        self.subCategory = subCategory
86
        self.shippingCost = shippingCost
89
        self.shippingCost = shippingCost
87
        self.netPriceAfterCashBack = netPriceAfterCashBack
90
        self.netPriceAfterCashBack = netPriceAfterCashBack
-
 
91
        self.exclusive = exclusive
88
 
92
 
89
 
93
 
90
def get_mongo_connection(host=options.mongoHost, port=27017):
94
def get_mongo_connection(host=options.mongoHost, port=27017):
91
    global con
95
    global con
92
    if con is None:
96
    if con is None:
Line 121... Line 125...
121
                else:
125
                else:
122
                    netPriceAfterCashBack = getNetPriceForItem(sku['_id'], sku['source_id'], sku['category_id'], sku['available_price'])
126
                    netPriceAfterCashBack = getNetPriceForItem(sku['_id'], sku['source_id'], sku['category_id'], sku['available_price'])
123
            
127
            
124
            info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
128
            info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
125
                             None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, sku['brand_id'], None, sku['codAvailable'], 0, sku['gross_price'], sku['subCategoryId'], \
129
                             None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, sku['brand_id'], None, sku['codAvailable'], 0, sku['gross_price'], sku['subCategoryId'], \
126
                             sku['subCategory'],sku['shippingCost'],netPriceAfterCashBack)
130
                             sku['subCategory'],sku['shippingCost'],netPriceAfterCashBack, sku['exclusive'])
127
            exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
131
            exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
128
            if len(exceptionalNlc) > 0:
132
            if len(exceptionalNlc) > 0:
129
                """Exceptional nlc found, no need to calculate max and min R-nlc"""
133
                """Exceptional nlc found, no need to calculate max and min R-nlc"""
130
                info.maxNlc = exceptionalNlc[0]['maxNlc']
134
                info.maxNlc = exceptionalNlc[0]['maxNlc']
131
                info.minNlc = exceptionalNlc[0]['minNlc']
135
                info.minNlc = exceptionalNlc[0]['minNlc']
Line 355... Line 359...
355
                    continue
359
                    continue
356
                if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
360
                if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
357
                    get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
361
                    get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
358
                    continue
362
                    continue
359
                if similarItem['netPriceAfterCashBack'] < bestPrice:
363
                if similarItem['netPriceAfterCashBack'] < bestPrice:
-
 
364
                    
360
                    bestOne = similarItem
365
                    bestOne = similarItem
361
                    bestPrice = similarItem['netPriceAfterCashBack']
366
                    bestPrice = similarItem['netPriceAfterCashBack']
362
                    bestSellerPoints = similarItem['bestSellerPoints']
367
                    bestSellerPoints = similarItem['bestSellerPoints']
363
                elif similarItem['netPriceAfterCashBack'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
368
                elif similarItem['netPriceAfterCashBack'] == bestPrice:
-
 
369
                    
-
 
370
                    try:
-
 
371
                        if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(bestOne['source_id']))):
-
 
372
                            continue
-
 
373
                    except:
-
 
374
                        traceback.print_exc()
-
 
375
                    
364
                    bestOne = similarItem
376
                    bestOne = similarItem
365
                    bestPrice = similarItem['netPriceAfterCashBack']
377
                    bestPrice = similarItem['netPriceAfterCashBack']
366
                    bestSellerPoints = similarItem['bestSellerPoints']
378
                    bestSellerPoints = similarItem['bestSellerPoints']
367
                else:
379
                else:
368
                    pass
380
                    pass
Line 377... Line 389...
377
                    continue
389
                    continue
378
                if similarItem['netPriceAfterCashBack'] < prepaidBestPrice:
390
                if similarItem['netPriceAfterCashBack'] < prepaidBestPrice:
379
                    prepaidBestOne = similarItem
391
                    prepaidBestOne = similarItem
380
                    prepaidBestPrice = similarItem['netPriceAfterCashBack']
392
                    prepaidBestPrice = similarItem['netPriceAfterCashBack']
381
                    prepaidBestSellerPoints = similarItem['bestSellerPoints']
393
                    prepaidBestSellerPoints = similarItem['bestSellerPoints']
382
                elif similarItem['netPriceAfterCashBack'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
394
                elif similarItem['netPriceAfterCashBack'] == prepaidBestPrice:
-
 
395
                    
-
 
396
                    try:
-
 
397
                        if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(bestOne['source_id']))):
-
 
398
                            continue
-
 
399
                    except:
-
 
400
                        traceback.print_exc()
-
 
401
                        
383
                    prepaidBestOne = similarItem
402
                    prepaidBestOne = similarItem
384
                    prepaidBestPrice = similarItem['netPriceAfterCashBack']
403
                    prepaidBestPrice = similarItem['netPriceAfterCashBack']
385
                    prepaidBestSellerPoints = similarItem['bestSellerPoints']
404
                    prepaidBestSellerPoints = similarItem['bestSellerPoints']
386
                else:
405
                else:
387
                    pass
406
                    pass