| Line 33... |
Line 33... |
| 33 |
now = datetime.now()
|
33 |
now = datetime.now()
|
| 34 |
|
34 |
|
| 35 |
class __SkuInfo:
|
35 |
class __SkuInfo:
|
| 36 |
|
36 |
|
| 37 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
37 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 38 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id):
|
38 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id, manualDealThresholdPrice):
|
| 39 |
self._id = _id
|
39 |
self._id = _id
|
| 40 |
self.skuBundleId = skuBundleId
|
40 |
self.skuBundleId = skuBundleId
|
| 41 |
self.category_id = category_id
|
41 |
self.category_id = category_id
|
| 42 |
self.mrp = mrp
|
42 |
self.mrp = mrp
|
| 43 |
self.available_price = available_price
|
43 |
self.available_price = available_price
|
| Line 56... |
Line 56... |
| 56 |
self.maxprice = maxprice
|
56 |
self.maxprice = maxprice
|
| 57 |
self.brand = brand
|
57 |
self.brand = brand
|
| 58 |
self.dealType = dealType
|
58 |
self.dealType = dealType
|
| 59 |
self.dealPoints = dealPoints
|
59 |
self.dealPoints = dealPoints
|
| 60 |
self.brand_id = brand_id
|
60 |
self.brand_id = brand_id
|
| - |
|
61 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
| 61 |
|
62 |
|
| 62 |
|
63 |
|
| 63 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
64 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 64 |
global con
|
65 |
global con
|
| 65 |
if con is None:
|
66 |
if con is None:
|
| Line 85... |
Line 86... |
| 85 |
#topSkus = collection.find( {'_id':664})
|
86 |
#topSkus = collection.find( {'_id':664})
|
| 86 |
for sku in topSkus:
|
87 |
for sku in topSkus:
|
| 87 |
"""Fix this """
|
88 |
"""Fix this """
|
| 88 |
#TODO Compute deal flags else where.
|
89 |
#TODO Compute deal flags else where.
|
| 89 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
90 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
| 90 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'])
|
91 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'], None)
|
| 91 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
|
92 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
|
| 92 |
if len(exceptionalNlc) > 0:
|
93 |
if len(exceptionalNlc) > 0:
|
| 93 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
94 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
| 94 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
95 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
| 95 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
96 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| Line 189... |
Line 190... |
| 189 |
def addManualDealsInfo():
|
190 |
def addManualDealsInfo():
|
| 190 |
for sku in LATEST_UPDATED_ITEMS:
|
191 |
for sku in LATEST_UPDATED_ITEMS:
|
| 191 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':sku.source_id, 'sku':sku._id}))
|
192 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':sku.source_id, 'sku':sku._id}))
|
| 192 |
if len(manualDeal) > 0:
|
193 |
if len(manualDeal) > 0:
|
| 193 |
sku.dealType = manualDeal[0]['dealType']
|
194 |
sku.dealType = manualDeal[0]['dealType']
|
| - |
|
195 |
if sku.available_price <= manualDeal[0]['dealThresholdPrice']:
|
| - |
|
196 |
sku.dealPoints = manualDeal[0]['dealPoints']
|
| - |
|
197 |
sku.manualDealThresholdPrice = manualDeal[0]['dealThresholdPrice']
|
| 194 |
|
198 |
else:
|
| - |
|
199 |
sku.dealPoints = 0
|
| 195 |
|
200 |
|
| 196 |
"""Remove deal flag from expired deals"""
|
201 |
"""Remove deal flag from expired deals"""
|
| 197 |
manualDeals = list(get_mongo_connection().Catalog.Deals.find({'dealType':1}))
|
202 |
manualDeals = list(get_mongo_connection().Catalog.Deals.find({'dealType':1}))
|
| 198 |
for manualDeal in manualDeals:
|
203 |
for manualDeal in manualDeals:
|
| 199 |
d_manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':manualDeal['source_id'], 'sku':manualDeal['_id']}))
|
204 |
d_manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':manualDeal['source_id'], 'sku':manualDeal['_id']}))
|
| 200 |
if len(d_manualDeal) > 0:
|
205 |
if len(d_manualDeal) > 0:
|
| 201 |
continue
|
206 |
continue
|
| 202 |
else:
|
207 |
else:
|
| 203 |
get_mongo_connection().Catalog.Deals.update({'_id':manualDeal['_id']},{"$set":{'dealType':0}},upsert=False, multi=True)
|
208 |
get_mongo_connection().Catalog.Deals.update({'_id':manualDeal['_id']},{"$set":{'dealType':0,'dealPoints':0,'manualDealThresholdPrice':None}},upsert=False, multi=False)
|
| 204 |
|
209 |
|
| 205 |
|
210 |
|
| 206 |
def calculateNlcPoints():
|
211 |
def calculateNlcPoints():
|
| 207 |
global LATEST_UPDATED_ITEMS
|
212 |
global LATEST_UPDATED_ITEMS
|
| 208 |
print "inside nlc oints"
|
213 |
print "inside nlc oints"
|
| Line 272... |
Line 277... |
| 272 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
277 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
| 273 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
278 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
| 274 |
shortagePoints = 50 if sku['_id'] in shortageSkus else 0
|
279 |
shortagePoints = 50 if sku['_id'] in shortageSkus else 0
|
| 275 |
print "Shortage points for ",sku['_id']
|
280 |
print "Shortage points for ",sku['_id']
|
| 276 |
print shortagePoints
|
281 |
print shortagePoints
|
| 277 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints
|
282 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints + sku['dealPoints']
|
| 278 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
283 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
| - |
|
284 |
|
| 279 |
|
285 |
|
| 280 |
|
286 |
|
| 281 |
def populateNegativeDeals():
|
287 |
def populateNegativeDeals():
|
| 282 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
288 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
| 283 |
mc.set("negative_deals", negativeDeals, 600)
|
289 |
mc.set("negative_deals", negativeDeals, 600)
|
| 284 |
|
290 |
|