Subversion Repositories SmartDukaan

Rev

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

Rev 13824 Rev 13828
Line 17... Line 17...
17
now = datetime.now()
17
now = datetime.now()
18
 
18
 
19
class __SkuInfo:
19
class __SkuInfo:
20
    
20
    
21
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
21
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
22
                 maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints, status, in_stock, maxprice):
22
                 maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints, status, in_stock, maxprice, showDeal):
23
        self._id = _id
23
        self._id = _id
24
        self.skuBundleId = skuBundleId
24
        self.skuBundleId = skuBundleId
25
        self.category_id = category_id
25
        self.category_id = category_id
26
        self.mrp = mrp
26
        self.mrp = mrp
27
        self.available_price = available_price
27
        self.available_price = available_price
Line 38... Line 38...
38
        self.bestSellerPoints = bestSellerPoints
38
        self.bestSellerPoints = bestSellerPoints
39
        self.totalPoints = totalPoints
39
        self.totalPoints = totalPoints
40
        self.status = status
40
        self.status = status
41
        self.in_stock = in_stock
41
        self.in_stock = in_stock
42
        self.maxprice = maxprice
42
        self.maxprice = maxprice
-
 
43
        self.showDeal = showDeal 
43
 
44
 
44
 
45
 
45
def get_mongo_connection(host='localhost', port=27017):
46
def get_mongo_connection(host='localhost', port=27017):
46
    global con
47
    global con
47
    if con is None:
48
    if con is None:
Line 65... Line 66...
65
        if len((topSkus)) == 0:
66
        if len((topSkus)) == 0:
66
            break
67
            break
67
        #topSkus = collection.find( {'_id':664})
68
        #topSkus = collection.find( {'_id':664})
68
        for sku in topSkus:
69
        for sku in topSkus:
69
            info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
70
            info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
70
                             None, None, None, None, None, None, sku['status'], sku['in_stock'],None)
71
                             None, None, None, None, None, None, sku['status'], sku['in_stock'],None,0)
71
            exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
72
            exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
72
            if len(exceptionalNlc) > 0:
73
            if len(exceptionalNlc) > 0:
73
                """Exceptional nlc found, no need to calculate max and min R-nlc"""
74
                """Exceptional nlc found, no need to calculate max and min R-nlc"""
74
                info.maxNlc = exceptionalNlc[0]['maxNlc']
75
                info.maxNlc = exceptionalNlc[0]['maxNlc']
75
                info.minNlc = exceptionalNlc[0]['minNlc']
76
                info.minNlc = exceptionalNlc[0]['minNlc']
Line 204... Line 205...
204
    
205
    
205
 
206
 
206
def addBestSellerPoints():
207
def addBestSellerPoints():
207
    allItems = list(get_mongo_connection().Catalog.Deals.find({})) 
208
    allItems = list(get_mongo_connection().Catalog.Deals.find({})) 
208
    for sku in allItems:
209
    for sku in allItems:
209
        print sku['_id']
-
 
210
        print sku['category_id']
-
 
211
        print sku['source_id']
-
 
212
        print sku['rank']
-
 
213
        print sku['nlcPoints']
-
 
214
        print "================="
-
 
215
        bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }, { 'source_id' : sku['source_id'] }] } ))
210
        bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }, { 'source_id' : sku['source_id'] }] } ))
216
        print len(bestSellerPoints)
-
 
217
        if len(bestSellerPoints) > 0:
211
        if len(bestSellerPoints) > 0:
218
            print bestSellerPoints[0]['points']
212
            print bestSellerPoints[0]['points']
219
            if (bestSellerPoints[0]['points']) > 0:
213
            if (bestSellerPoints[0]['points']) > 0:
220
                sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage']
214
                sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage']
221
            else:
215
            else:
222
                sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
216
                sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
223
        else:
217
        else:
224
            sku['bestSellerPoints'] = -100
218
            sku['bestSellerPoints'] = -100
225
        print sku['bestSellerPoints']
-
 
226
        sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
219
        sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
227
        get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
220
        get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
228
 
221
 
-
 
222
def elimiateSimilarDeals():
-
 
223
    allItems = list(get_mongo_connection().Catalog.Deals.find())
-
 
224
    for sku in allItems:
-
 
225
        print sku['_id']
-
 
226
        similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort([('available_price',pymongo.ASCENDING)]))
-
 
227
        bestSellerPoints = 0
-
 
228
        bestPrice = float("inf")
-
 
229
        bestOne = None
-
 
230
        bestSellerPoints = 0
-
 
231
        toUpdate = []
-
 
232
        for similarItem in similarItems:
-
 
233
            if similarItem['in_stock'] == 0:
-
 
234
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
-
 
235
                continue
-
 
236
            if similarItem['available_price'] < bestPrice:
-
 
237
                bestOne = similarItem
-
 
238
                bestPrice = similarItem['available_price']
-
 
239
                bestSellerPoints = similarItem['bestSellerPoints']
-
 
240
            elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
-
 
241
                bestOne = similarItem
-
 
242
                bestPrice = similarItem['available_price']
-
 
243
                bestSellerPoints = similarItem['bestSellerPoints']
-
 
244
            else:
-
 
245
                pass
-
 
246
        if bestOne is not None:
-
 
247
            for similarItem in similarItems:
-
 
248
                toUpdate.append(similarItem['_id'])
-
 
249
            toUpdate.remove(bestOne['_id'])
-
 
250
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
-
 
251
        if len(toUpdate) > 0:
-
 
252
            get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }})
229
 
253
 
230
def main():
254
def main():
231
    populateStuff()
255
    populateStuff()
232
    calculateNlc()
256
    calculateNlc()
233
    calculateNlcPoints()
257
    calculateNlcPoints()
234
    commitData()
258
    commitData()
235
    addBestSellerPoints()
259
    addBestSellerPoints()
-
 
260
    elimiateSimilarDeals()
-
 
261
 
236
 
262
 
237
if __name__=='__main__':
263
if __name__=='__main__':
238
    main()
264
    main()
239
265