| 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):
|
22 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints, status, in_stock, maxprice):
|
| 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 34... |
Line 34... |
| 34 |
self.maxDiscount = maxDiscount
|
34 |
self.maxDiscount = maxDiscount
|
| 35 |
self.discountType = discountType
|
35 |
self.discountType = discountType
|
| 36 |
self.dp = dp
|
36 |
self.dp = dp
|
| 37 |
self.nlcPoints = nlcPoints
|
37 |
self.nlcPoints = nlcPoints
|
| 38 |
self.bestSellerPoints = bestSellerPoints
|
38 |
self.bestSellerPoints = bestSellerPoints
|
| 39 |
self.totalPoints = totalPoints
|
39 |
self.totalPoints = totalPoints
|
| - |
|
40 |
self.status = status
|
| - |
|
41 |
self.in_stock = in_stock
|
| - |
|
42 |
self.maxprice = maxprice
|
| 40 |
|
43 |
|
| 41 |
|
44 |
|
| 42 |
def get_mongo_connection(host='localhost', port=27017):
|
45 |
def get_mongo_connection(host='localhost', port=27017):
|
| 43 |
global con
|
46 |
global con
|
| 44 |
if con is None:
|
47 |
if con is None:
|
| Line 62... |
Line 65... |
| 62 |
if len((topSkus)) == 0:
|
65 |
if len((topSkus)) == 0:
|
| 63 |
break
|
66 |
break
|
| 64 |
#topSkus = collection.find( {'_id':664})
|
67 |
#topSkus = collection.find( {'_id':664})
|
| 65 |
for sku in topSkus:
|
68 |
for sku in topSkus:
|
| 66 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
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, \
|
| 67 |
None, None, None, None, None, None)
|
70 |
None, None, None, None, None, None, sku['status'], sku['in_stock'],None)
|
| 68 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
|
71 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'sku':info._id}, {'overrideNlc':1} ]} ))
|
| 69 |
if len(exceptionalNlc) > 0:
|
72 |
if len(exceptionalNlc) > 0:
|
| 70 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
73 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
| 71 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
74 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
| 72 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
75 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| - |
|
76 |
info.maxprice = exceptionalNlc[0]['maxNlc']
|
| 73 |
LATEST_UPDATED_ITEMS.append(info)
|
77 |
LATEST_UPDATED_ITEMS.append(info)
|
| 74 |
continue
|
78 |
continue
|
| 75 |
|
79 |
|
| 76 |
skuSchemeDetails = list(get_mongo_connection().Catalog.SkuSchemeDetails.find( {'sku':info._id}).sort([('addedOn',pymongo.DESCENDING)]).limit(1))
|
80 |
skuSchemeDetails = list(get_mongo_connection().Catalog.SkuSchemeDetails.find( {'sku':info._id}).sort([('addedOn',pymongo.DESCENDING)]).limit(1))
|
| 77 |
if len(skuSchemeDetails) > 0:
|
81 |
if len(skuSchemeDetails) > 0:
|
| 78 |
"""Sku scheme details, populate scheme amount (Recently added)"""
|
82 |
"""Sku scheme details, populate scheme amount (Recently added)"""
|
| - |
|
83 |
|
| - |
|
84 |
#TODO Add start date and end date of scehems
|
| - |
|
85 |
|
| 79 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
86 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
| 80 |
|
87 |
|
| 81 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'sku':info._id} ) )
|
88 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'sku':info._id} ) )
|
| 82 |
if len(skuDealerPrices) > 0:
|
89 |
if len(skuDealerPrices) > 0:
|
| 83 |
info.dp = skuDealerPrices[0]['dp']
|
90 |
info.dp = skuDealerPrices[0]['dp']
|
| Line 88... |
Line 95... |
| 88 |
info.minDiscount = skuDiscount[0]['min_discount']
|
95 |
info.minDiscount = skuDiscount[0]['min_discount']
|
| 89 |
info.discountType = DISCOUNT_TYPE.get(skuDiscount[0]['discountType'].upper())
|
96 |
info.discountType = DISCOUNT_TYPE.get(skuDiscount[0]['discountType'].upper())
|
| 90 |
LATEST_UPDATED_ITEMS.append(info)
|
97 |
LATEST_UPDATED_ITEMS.append(info)
|
| 91 |
continue
|
98 |
continue
|
| 92 |
|
99 |
|
| 93 |
categoryDiscount = list(get_mongo_connection().Dtr.CategoryDiscount.find( {"$and" : [{'brand':sku['brand'].upper()}, {'category_id':sku['category_id']} ]} ))
|
100 |
categoryDiscount = list(get_mongo_connection().Catalog.CategoryDiscount.find( {"$and" : [{'brand':sku['brand'].upper()}, {'category_id':sku['category_id']} ]} ))
|
| 94 |
if len(categoryDiscount) > 0:
|
101 |
if len(categoryDiscount) > 0:
|
| 95 |
info.maxDiscount = categoryDiscount[0]['max_discount']
|
102 |
info.maxDiscount = categoryDiscount[0]['max_discount']
|
| 96 |
info.minDiscount = categoryDiscount[0]['min_discount']
|
103 |
info.minDiscount = categoryDiscount[0]['min_discount']
|
| 97 |
info.discountType = DISCOUNT_TYPE.get(categoryDiscount[0]['discountType'].upper())
|
104 |
info.discountType = DISCOUNT_TYPE.get(categoryDiscount[0]['discountType'].upper())
|
| 98 |
|
105 |
|
| Line 120... |
Line 127... |
| 120 |
if identifier is not None:
|
127 |
if identifier is not None:
|
| 121 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
128 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
| 122 |
obj.mrp = it.mrp
|
129 |
obj.mrp = it.mrp
|
| 123 |
if obj.mrp > 0:
|
130 |
if obj.mrp > 0:
|
| 124 |
obj.minNlc = obj.mrp - (obj.mrp * obj.maxDiscount/100) - obj.schemeAmount
|
131 |
obj.minNlc = obj.mrp - (obj.mrp * obj.maxDiscount/100) - obj.schemeAmount
|
| 125 |
obj.maxNlc = obj.mrp - (obj.mrp * obj.minDiscount/100) - obj.schemeAmount
|
132 |
obj.maxNlc = obj.mrp - (obj.mrp * obj.minDiscount/100) - obj.schemeAmount
|
| - |
|
133 |
obj.maxPrice = obj.maxNlc
|
| 126 |
elif obj.discountType == DISCOUNT_TYPE.get('DP'):
|
134 |
elif obj.discountType == DISCOUNT_TYPE.get('DP'):
|
| 127 |
if obj.dp == 0:
|
135 |
if obj.dp == 0:
|
| 128 |
"""Now dp is zero, so we have to use saholic minimum dp for item"""
|
136 |
"""Now dp is zero, so we have to use saholic minimum dp for item"""
|
| 129 |
if identifier is not None:
|
137 |
if identifier is not None:
|
| 130 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
138 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
| Line 134... |
Line 142... |
| 134 |
obj.dp = min_dp
|
142 |
obj.dp = min_dp
|
| 135 |
except:
|
143 |
except:
|
| 136 |
pass
|
144 |
pass
|
| 137 |
if obj.dp > 0:
|
145 |
if obj.dp > 0:
|
| 138 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
146 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
| 139 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
147 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
| - |
|
148 |
obj.maxprice = obj.maxNlc
|
| 140 |
else:
|
149 |
else:
|
| 141 |
"""No rule found, use saholic min nlc as max and min R-Nlc"""
|
150 |
"""No rule found, use saholic min nlc as max and min R-Nlc"""
|
| 142 |
if identifier is not None:
|
151 |
if identifier is not None:
|
| 143 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
152 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
| 144 |
try:
|
153 |
try:
|
| 145 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
154 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
| 146 |
min_nlc = min(pricing.nlc for pricing in vendorPricing)
|
155 |
min_nlc = min(pricing.nlc for pricing in vendorPricing)
|
| 147 |
obj.maxNlc = min_nlc
|
156 |
obj.maxNlc = min_nlc
|
| 148 |
obj.minNlc = min_nlc
|
157 |
obj.minNlc = min_nlc
|
| - |
|
158 |
obj.maxprice = obj.maxNlc
|
| 149 |
except:
|
159 |
except:
|
| 150 |
pass
|
160 |
pass
|
| 151 |
populated = populated + 300
|
161 |
populated = populated + 300
|
| 152 |
time.sleep(10)
|
162 |
time.sleep(10)
|
| 153 |
|
163 |
|
| 154 |
def calculateNlcPoints():
|
164 |
def calculateNlcPoints():
|
| 155 |
global LATEST_UPDATED_ITEMS
|
165 |
global LATEST_UPDATED_ITEMS
|
| 156 |
for sku in LATEST_UPDATED_ITEMS:
|
166 |
for sku in LATEST_UPDATED_ITEMS:
|
| 157 |
if sku.maxNlc and sku.minNlc:
|
167 |
if sku.maxNlc and sku.minNlc:
|
| - |
|
168 |
|
| - |
|
169 |
"""Create map - TODO"""
|
| - |
|
170 |
|
| - |
|
171 |
if sku.status == 2:
|
| - |
|
172 |
eolWeight = .60
|
| - |
|
173 |
else:
|
| - |
|
174 |
eolWeight = 1.0
|
| - |
|
175 |
if sku.category_id == 3:
|
| - |
|
176 |
basePointPercentage = 5.0
|
| - |
|
177 |
maxNlcPoints = 200
|
| - |
|
178 |
elif sku.category_id == 5:
|
| - |
|
179 |
basePointPercentage = 8.0
|
| - |
|
180 |
maxNlcPoints = 150
|
| - |
|
181 |
else:
|
| - |
|
182 |
basePointPercentage = 10.0
|
| - |
|
183 |
maxNlcPoints = 150
|
| 158 |
discFromMinNlc = (sku.minNlc - sku.available_price)/sku.available_price *100
|
184 |
discFromMinNlc = (sku.minNlc - sku.available_price)/sku.available_price *100
|
| 159 |
discFromMaxNlc = (sku.maxNlc - sku.available_price)/sku.available_price *100
|
185 |
discFromMaxNlc = (sku.maxNlc - sku.available_price)/sku.available_price *100
|
| 160 |
if discFromMinNlc > 0:
|
186 |
if discFromMinNlc > 0:
|
| 161 |
nlcPoints = 100/5 * discFromMinNlc
|
187 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
| 162 |
elif discFromMinNlc < 0 and discFromMaxNlc > 0:
|
188 |
elif discFromMinNlc < 0 and discFromMaxNlc > 0:
|
| 163 |
nlcPoints = 0
|
189 |
nlcPoints = 0
|
| 164 |
else:
|
190 |
else:
|
| 165 |
nlcPoints = 100/5 * discFromMinNlc
|
191 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
| - |
|
192 |
if (min(nlcPoints,maxNlcPoints)) > 0:
|
| - |
|
193 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints)) * eolWeight
|
| - |
|
194 |
else:
|
| 166 |
sku.nlcPoints = min(nlcPoints,300)
|
195 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints))
|
| 167 |
else:
|
196 |
else:
|
| 168 |
sku.nlcPoints = 0
|
197 |
sku.nlcPoints = 0
|
| 169 |
|
198 |
|
| 170 |
def commitData():
|
199 |
def commitData():
|
| 171 |
global LATEST_UPDATED_ITEMS
|
200 |
global LATEST_UPDATED_ITEMS
|
| Line 175... |
Line 204... |
| 175 |
|
204 |
|
| 176 |
|
205 |
|
| 177 |
def addBestSellerPoints():
|
206 |
def addBestSellerPoints():
|
| 178 |
allItems = list(get_mongo_connection().Catalog.Deals.find({}))
|
207 |
allItems = list(get_mongo_connection().Catalog.Deals.find({}))
|
| 179 |
for sku in allItems:
|
208 |
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 "================="
|
| 180 |
bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }] } ))
|
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'] }] } ))
|
| - |
|
216 |
print len(bestSellerPoints)
|
| 181 |
if len(bestSellerPoints) > 0:
|
217 |
if len(bestSellerPoints) > 0:
|
| - |
|
218 |
print bestSellerPoints[0]['points']
|
| - |
|
219 |
if (bestSellerPoints[0]['points']) > 0:
|
| - |
|
220 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage']
|
| - |
|
221 |
else:
|
| 182 |
sku['bestSellerPoints'] = bestSellerPoints[0]['points']
|
222 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
|
| 183 |
else:
|
223 |
else:
|
| 184 |
sku['bestSellerPoints'] = -50
|
224 |
sku['bestSellerPoints'] = -100
|
| - |
|
225 |
print sku['bestSellerPoints']
|
| 185 |
sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
226 |
sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
| 186 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
227 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
| 187 |
|
228 |
|
| 188 |
|
229 |
|
| 189 |
def main():
|
230 |
def main():
|