Subversion Repositories SmartDukaan

Rev

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

Rev 17297 Rev 19186
Line 44... Line 44...
44
        except Exception, e:
44
        except Exception, e:
45
            print e
45
            print e
46
            return None
46
            return None
47
    return con
47
    return con
48
 
48
 
-
 
49
def getNetPriceForItem(itemId, source_id, category_id ,price):
-
 
50
    cash_back_type = 0
-
 
51
    cash_back = 0
-
 
52
    try:
-
 
53
        cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
-
 
54
        if not cashBack or cashBack.get('cash_back_status')!=1:
-
 
55
            cash_back_type = 0
-
 
56
            cash_back = 0 
-
 
57
            
-
 
58
        else:
-
 
59
            if cashBack['cash_back_type'] in (1,2):
-
 
60
                
-
 
61
                if cashBack.get('maxCashBack') is not None:
-
 
62
                    
-
 
63
                    if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
-
 
64
                        cashBack['cash_back_type'] = 2
-
 
65
                        cashBack['cash_back'] = cashBack['maxCashBack']
-
 
66
                    elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
-
 
67
                        cashBack['cash_back'] = cashBack['maxCashBack']
-
 
68
                    else:
-
 
69
                        pass
-
 
70
                
-
 
71
                
-
 
72
                
-
 
73
                cash_back_type = cashBack['cash_back_type']
-
 
74
                cash_back = float(cashBack['cash_back'])
-
 
75
    except Exception as cashBackEx:
-
 
76
        pass
-
 
77
    
-
 
78
    if cash_back_type ==1:
-
 
79
        return (price - float(cash_back)*price/100)
-
 
80
    elif cash_back_type ==2:
-
 
81
        return (price - cash_back)
-
 
82
    else:
-
 
83
        return price
-
 
84
 
-
 
85
 
49
def populate():
86
def populate():
50
    toScrapMap = {}
87
    toScrapMap = {}
51
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
88
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
52
    for bestSeller in bestSellers: 
89
    for bestSeller in bestSellers: 
53
        snapdealBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':3}))
90
        snapdealBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':3}))
Line 159... Line 196...
159
 
196
 
160
    print lowestOfferPrice
197
    print lowestOfferPrice
161
    print instock
198
    print instock
162
    print "Lowest Offer Price for id %d is %d , stock is %d and stock count is %d" %(data['_id'],lowestOfferPrice,instock,stock)
199
    print "Lowest Offer Price for id %d is %d , stock is %d and stock count is %d" %(data['_id'],lowestOfferPrice,instock,stock)
163
    print "*************"
200
    print "*************"
-
 
201
    if instock ==1:
-
 
202
        netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('SNAPDEAL'), data['category_id'], lowestOfferPrice)
-
 
203
    else:
-
 
204
        netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('SNAPDEAL'), data['category_id'], data['available_price'])
-
 
205
    
-
 
206
    
-
 
207
    
164
    if instock  == 1:
208
    if instock  == 1:
165
        get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':instock,'buyBoxFlag':isBuyBox}}, multi=True)
209
        get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':instock,'buyBoxFlag':isBuyBox}}, multi=True)
166
        get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':instock,'codAvailable':data['codAvailable']}}, multi=True)
210
        get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':instock,'codAvailable':data['codAvailable','netPriceAfterCashBack':netPriceAfterCashBack]}}, multi=True)
167
    else:
211
    else:
168
        get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':instock,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':isBuyBox}}, multi=True)
212
        get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':instock,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':isBuyBox}}, multi=True)
169
        get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock,'codAvailable':data['codAvailable']}})
213
        get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock,'codAvailable':data['codAvailable'],'netPriceAfterCashBack':netPriceAfterCashBack}})
170
    
214
    
171
    try:
215
    try:
172
        recomputeDeal(data)
216
        recomputeDeal(data)
173
    except:
217
    except:
174
        print "Unable to compute deal for ",data['skuBundleId']
218
        print "Unable to compute deal for ",data['skuBundleId']
Line 196... Line 240...
196
#        dealPoints = 0
240
#        dealPoints = 0
197
#        item['manualDealThresholdPrice'] = None
241
#        item['manualDealThresholdPrice'] = None
198
#        
242
#        
199
#    get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
243
#    get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
200
 
244
 
201
    
245
 
202
def recomputeDeal(item):
246
def recomputeDeal(item):
203
    """Lets recompute deal for this bundle"""
247
    """Lets recompute deal for this bundle"""
204
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
248
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
205
    skuBundleId = item['skuBundleId']
249
    skuBundleId = item['skuBundleId']
206
    
250
    
207
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
251
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
208
    bestPrice = float("inf")
252
    bestPrice = float("inf")
209
    bestOne = None
253
    bestOne = None
210
    bestSellerPoints = 0
254
    bestSellerPoints = 0
211
    toUpdate = []
255
    toUpdate = []
212
    prepaidBestPrice = float("inf")
256
    prepaidBestPrice = float("inf")
Line 220... Line 264...
220
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
264
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
221
                continue
265
                continue
222
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
266
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
223
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
267
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
224
                continue
268
                continue
225
            if similarItem['available_price'] < bestPrice:
269
            if similarItem.get('netPriceAfterCashBack') < bestPrice:
226
                bestOne = similarItem
270
                bestOne = similarItem
227
                bestPrice = similarItem['available_price']
271
                bestPrice = similarItem.get('netPriceAfterCashBack')
228
                bestSellerPoints = similarItem['bestSellerPoints']
272
                bestSellerPoints = similarItem['bestSellerPoints']
229
            elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
273
            elif similarItem.get('netPriceAfterCashBack') == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
230
                bestOne = similarItem
274
                bestOne = similarItem
231
                bestPrice = similarItem['available_price']
275
                bestPrice = similarItem.get('netPriceAfterCashBack')
232
                bestSellerPoints = similarItem['bestSellerPoints']
276
                bestSellerPoints = similarItem['bestSellerPoints']
233
            else:
277
            else:
234
                pass
278
                pass
235
        else:
279
        else:
236
            if mc.get("negative_deals") is None:
280
            if mc.get("negative_deals") is None:
Line 239... Line 283...
239
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
283
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
240
                continue
284
                continue
241
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
285
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
242
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
286
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
243
                continue
287
                continue
244
            if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
-
 
245
                similarItem['available_price'] = similarItem['gross_price']
-
 
246
            if similarItem['available_price'] < prepaidBestPrice:
288
            if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
247
                prepaidBestOne = similarItem
289
                prepaidBestOne = similarItem
248
                prepaidBestPrice = similarItem['available_price']
290
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
249
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
291
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
250
            elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
292
            elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
251
                prepaidBestOne = similarItem
293
                prepaidBestOne = similarItem
252
                prepaidBestPrice = similarItem['available_price']
294
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
253
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
295
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
254
            else:
296
            else:
255
                pass
297
                pass
256
    if bestOne is not None or prepaidBestOne is not None:
298
    if bestOne is not None or prepaidBestOne is not None:
257
        for similarItem in similarItems:
299
        for similarItem in similarItems:
Line 259... Line 301...
259
        if bestOne is not None:
301
        if bestOne is not None:
260
            toUpdate.remove(bestOne['_id'])
302
            toUpdate.remove(bestOne['_id'])
261
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
303
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
262
        if prepaidBestOne is not None:
304
        if prepaidBestOne is not None:
263
            if bestOne is not None:
305
            if bestOne is not None:
264
                if prepaidBestOne['available_price'] < bestOne['available_price']: 
306
                if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'): 
265
                    toUpdate.remove(prepaidBestOne['_id'])
307
                    toUpdate.remove(prepaidBestOne['_id'])
266
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
308
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
267
            else:
309
            else:
268
                toUpdate.remove(prepaidBestOne['_id'])
310
                toUpdate.remove(prepaidBestOne['_id'])
269
                get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
311
                get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
270
    if len(toUpdate) > 0:
312
    if len(toUpdate) > 0:
271
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
313
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
-
 
314
    
272
        
315
        
273
def main():
316
def main():
274
    populate()
317
    populate()
275
 
318
 
276
if __name__=='__main__':
319
if __name__=='__main__':