| 13755 |
kshitij.so |
1 |
import pymongo
|
|
|
2 |
from elixir import *
|
|
|
3 |
from shop2020.model.v1.catalog.impl import DataService
|
|
|
4 |
from shop2020.model.v1.catalog.impl.DataService import Item
|
|
|
5 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
6 |
from dtr.utils.utils import to_java_date
|
|
|
7 |
from datetime import datetime, timedelta
|
|
|
8 |
import time
|
| 14258 |
kshitij.so |
9 |
import optparse
|
| 14325 |
kshitij.so |
10 |
from dtr.storage.MemCache import MemCache
|
| 16635 |
manish.sha |
11 |
import traceback
|
| 13755 |
kshitij.so |
12 |
|
| 14258 |
kshitij.so |
13 |
parser = optparse.OptionParser()
|
| 14263 |
kshitij.so |
14 |
parser.add_option("-H", "--host", dest="hostname",
|
| 14258 |
kshitij.so |
15 |
default="localhost",
|
|
|
16 |
type="string", help="The HOST where the DB server is running",
|
|
|
17 |
metavar="host")
|
|
|
18 |
parser.add_option("-m", "--m", dest="mongoHost",
|
|
|
19 |
default="localhost",
|
|
|
20 |
type="string", help="The HOST where the mongo server is running",
|
|
|
21 |
metavar="mongo_host")
|
| 13755 |
kshitij.so |
22 |
|
| 14258 |
kshitij.so |
23 |
(options, args) = parser.parse_args()
|
| 14325 |
kshitij.so |
24 |
|
|
|
25 |
mc = MemCache(options.mongoHost)
|
|
|
26 |
|
| 14258 |
kshitij.so |
27 |
DataService.initialize(db_hostname=options.hostname)
|
|
|
28 |
|
| 13755 |
kshitij.so |
29 |
con = None
|
| 17034 |
kshitij.so |
30 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6,'HOMESHOP18.COM':7}
|
| 13755 |
kshitij.so |
31 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
|
|
32 |
LATEST_UPDATED_ITEMS = []
|
| 16253 |
kshitij.so |
33 |
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
|
| 13755 |
kshitij.so |
34 |
|
| 16868 |
kshitij.so |
35 |
DEAL_POINTS_MAP = {}
|
|
|
36 |
|
| 13755 |
kshitij.so |
37 |
now = datetime.now()
|
|
|
38 |
|
| 16868 |
kshitij.so |
39 |
class __DealPoints:
|
|
|
40 |
|
|
|
41 |
def __init__(self, manualDealThresholdPrice, points):
|
|
|
42 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
|
|
43 |
self.points = points
|
|
|
44 |
|
|
|
45 |
|
| 13755 |
kshitij.so |
46 |
class __SkuInfo:
|
|
|
47 |
|
|
|
48 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 16534 |
kshitij.so |
49 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
|
| 17649 |
kshitij.so |
50 |
codAvailable,showDp,gross_price, subCategoryId):
|
| 13755 |
kshitij.so |
51 |
self._id = _id
|
|
|
52 |
self.skuBundleId = skuBundleId
|
|
|
53 |
self.category_id = category_id
|
|
|
54 |
self.mrp = mrp
|
|
|
55 |
self.available_price = available_price
|
|
|
56 |
self.source_id = source_id
|
|
|
57 |
self.rank = rank
|
|
|
58 |
self.maxNlc = maxNlc
|
|
|
59 |
self.minNlc = minNlc
|
|
|
60 |
self.schemeAmount = schemeAmount
|
|
|
61 |
self.minDiscount = minDiscount
|
|
|
62 |
self.maxDiscount = maxDiscount
|
|
|
63 |
self.discountType = discountType
|
|
|
64 |
self.dp = dp
|
|
|
65 |
self.nlcPoints = nlcPoints
|
| 13824 |
kshitij.so |
66 |
self.status = status
|
|
|
67 |
self.in_stock = in_stock
|
|
|
68 |
self.maxprice = maxprice
|
| 14035 |
kshitij.so |
69 |
self.brand = brand
|
| 14306 |
kshitij.so |
70 |
self.dealType = dealType
|
| 15063 |
kshitij.so |
71 |
self.brand_id = brand_id
|
| 15271 |
kshitij.so |
72 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
| 16019 |
kshitij.so |
73 |
self.codAvailable = codAvailable
|
| 16253 |
kshitij.so |
74 |
self.showDp = showDp
|
| 16456 |
kshitij.so |
75 |
self.gross_price = gross_price
|
| 17649 |
kshitij.so |
76 |
self.subCategoryId = subCategoryId
|
| 13755 |
kshitij.so |
77 |
|
|
|
78 |
|
| 14258 |
kshitij.so |
79 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 13755 |
kshitij.so |
80 |
global con
|
|
|
81 |
if con is None:
|
|
|
82 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
83 |
try:
|
|
|
84 |
con = pymongo.MongoClient(host, port)
|
|
|
85 |
except Exception, e:
|
|
|
86 |
print e
|
|
|
87 |
return None
|
|
|
88 |
return con
|
|
|
89 |
|
|
|
90 |
def populateStuff():
|
|
|
91 |
print "Inside populate"
|
|
|
92 |
global LATEST_UPDATED_ITEMS
|
|
|
93 |
"""Fetch latest updated items across portals
|
|
|
94 |
and calculate max and min R-Nlc"""
|
|
|
95 |
offset= 0
|
|
|
96 |
while(True):
|
|
|
97 |
print "Fetching records offset %d and limit %d" %(offset,300)
|
|
|
98 |
topSkus = list(get_mongo_connection().Catalog.MasterData.find( {"$and":[{'updatedOn': { "$gt": to_java_date(now - timedelta(hours=4))} }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).skip(offset).limit(300))
|
|
|
99 |
if len((topSkus)) == 0:
|
|
|
100 |
break
|
|
|
101 |
#topSkus = collection.find( {'_id':664})
|
|
|
102 |
for sku in topSkus:
|
| 13908 |
kshitij.so |
103 |
"""Fix this """
|
|
|
104 |
#TODO Compute deal flags else where.
|
| 13755 |
kshitij.so |
105 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
| 17649 |
kshitij.so |
106 |
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'])
|
| 15854 |
kshitij.so |
107 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
| 13755 |
kshitij.so |
108 |
if len(exceptionalNlc) > 0:
|
|
|
109 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
|
|
110 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
|
|
111 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| 14842 |
kshitij.so |
112 |
if info.maxprice == 0:
|
|
|
113 |
info.maxprice = exceptionalNlc[0]['maxNlc']
|
| 13755 |
kshitij.so |
114 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
115 |
continue
|
|
|
116 |
|
| 15854 |
kshitij.so |
117 |
skuSchemeDetails = list(get_mongo_connection().Catalog.SkuSchemeDetails.find( {'skuBundleId':info.skuBundleId}))
|
| 13755 |
kshitij.so |
118 |
if len(skuSchemeDetails) > 0:
|
|
|
119 |
"""Sku scheme details, populate scheme amount (Recently added)"""
|
| 13824 |
kshitij.so |
120 |
|
|
|
121 |
#TODO Add start date and end date of scehems
|
|
|
122 |
|
| 13755 |
kshitij.so |
123 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
|
|
124 |
|
| 15854 |
kshitij.so |
125 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'skuBundleId':info.skuBundleId} ) )
|
| 13755 |
kshitij.so |
126 |
if len(skuDealerPrices) > 0:
|
|
|
127 |
info.dp = skuDealerPrices[0]['dp']
|
| 16253 |
kshitij.so |
128 |
info.showDp = skuDealerPrices[0]['showDp']
|
| 15854 |
kshitij.so |
129 |
skuDiscount = list(get_mongo_connection().Catalog.SkuDiscountInfo.find( {'skuBundleId':info.skuBundleId} ) )
|
| 13755 |
kshitij.so |
130 |
if len(skuDiscount) > 0:
|
|
|
131 |
"""Sku rule found, populate max , min Discount and discount type"""
|
|
|
132 |
info.maxDiscount = skuDiscount[0]['max_discount']
|
|
|
133 |
info.minDiscount = skuDiscount[0]['min_discount']
|
|
|
134 |
info.discountType = DISCOUNT_TYPE.get(skuDiscount[0]['discountType'].upper())
|
|
|
135 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
136 |
continue
|
|
|
137 |
|
| 14035 |
kshitij.so |
138 |
categoryDiscount = list(get_mongo_connection().Catalog.CategoryDiscount.find( {"$and" : [{'brand':sku['brand'].strip().upper()}, {'category_id':sku['category_id']} ]} ))
|
| 13755 |
kshitij.so |
139 |
if len(categoryDiscount) > 0:
|
|
|
140 |
info.maxDiscount = categoryDiscount[0]['max_discount']
|
|
|
141 |
info.minDiscount = categoryDiscount[0]['min_discount']
|
|
|
142 |
info.discountType = DISCOUNT_TYPE.get(categoryDiscount[0]['discountType'].upper())
|
|
|
143 |
|
|
|
144 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
145 |
offset = offset + 300
|
|
|
146 |
for lol in LATEST_UPDATED_ITEMS:
|
|
|
147 |
print lol.__dict__
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
def calculateNlc():
|
|
|
151 |
global LATEST_UPDATED_ITEMS
|
|
|
152 |
populated = 0
|
|
|
153 |
while(populated <= len(LATEST_UPDATED_ITEMS)):
|
|
|
154 |
inventory_client = InventoryClient().get_client()
|
|
|
155 |
for obj in LATEST_UPDATED_ITEMS[populated:300+populated]:
|
|
|
156 |
if obj.maxNlc > 0 and obj.minNlc > 0:
|
|
|
157 |
continue
|
|
|
158 |
saholic_sku = list(get_mongo_connection().Catalog.MasterData.find( {"$and":[{'skuBundleId': obj.skuBundleId}, { 'source_id' : SOURCE_MAP.get('SAHOLIC')}] }))
|
|
|
159 |
identifier = None
|
|
|
160 |
if len(saholic_sku) > 0:
|
|
|
161 |
identifier = saholic_sku[0]['identifier']
|
|
|
162 |
if obj.discountType == DISCOUNT_TYPE.get('MRP'):
|
|
|
163 |
if obj.mrp == 0:
|
|
|
164 |
"""Now mrp is zero, so we have to use saholic MRP"""
|
|
|
165 |
if identifier is not None:
|
|
|
166 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
167 |
obj.mrp = it.mrp
|
|
|
168 |
if obj.mrp > 0:
|
| 14842 |
kshitij.so |
169 |
print obj._id
|
| 13755 |
kshitij.so |
170 |
obj.minNlc = obj.mrp - (obj.mrp * obj.maxDiscount/100) - obj.schemeAmount
|
| 13824 |
kshitij.so |
171 |
obj.maxNlc = obj.mrp - (obj.mrp * obj.minDiscount/100) - obj.schemeAmount
|
| 14842 |
kshitij.so |
172 |
if obj.maxprice == 0:
|
|
|
173 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
174 |
elif obj.discountType == DISCOUNT_TYPE.get('DP'):
|
|
|
175 |
if obj.dp == 0:
|
|
|
176 |
"""Now dp is zero, so we have to use saholic minimum dp for item"""
|
|
|
177 |
if identifier is not None:
|
|
|
178 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
179 |
try:
|
|
|
180 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
|
|
181 |
min_dp = min(pricing.dealerPrice for pricing in vendorPricing)
|
|
|
182 |
obj.dp = min_dp
|
| 16253 |
kshitij.so |
183 |
obj.showDp = 1
|
| 13755 |
kshitij.so |
184 |
except:
|
|
|
185 |
pass
|
|
|
186 |
if obj.dp > 0:
|
|
|
187 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
| 13824 |
kshitij.so |
188 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
| 14842 |
kshitij.so |
189 |
if obj.maxprice == 0:
|
|
|
190 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
191 |
else:
|
|
|
192 |
"""No rule found, use saholic min nlc as max and min R-Nlc"""
|
|
|
193 |
if identifier is not None:
|
|
|
194 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
195 |
try:
|
|
|
196 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
|
|
197 |
min_nlc = min(pricing.nlc for pricing in vendorPricing)
|
|
|
198 |
obj.maxNlc = min_nlc
|
| 13824 |
kshitij.so |
199 |
obj.minNlc = min_nlc
|
| 14842 |
kshitij.so |
200 |
if obj.maxprice == 0:
|
|
|
201 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
202 |
except:
|
|
|
203 |
pass
|
|
|
204 |
populated = populated + 300
|
|
|
205 |
time.sleep(10)
|
|
|
206 |
|
| 14306 |
kshitij.so |
207 |
def addManualDealsInfo():
|
|
|
208 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
209 |
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}))
|
|
|
210 |
if len(manualDeal) > 0:
|
|
|
211 |
sku.dealType = manualDeal[0]['dealType']
|
| 14310 |
kshitij.so |
212 |
|
|
|
213 |
"""Remove deal flag from expired deals"""
|
| 14311 |
kshitij.so |
214 |
manualDeals = list(get_mongo_connection().Catalog.Deals.find({'dealType':1}))
|
| 14310 |
kshitij.so |
215 |
for manualDeal in manualDeals:
|
| 14389 |
kshitij.so |
216 |
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']}))
|
|
|
217 |
if len(d_manualDeal) > 0:
|
| 14310 |
kshitij.so |
218 |
continue
|
|
|
219 |
else:
|
| 16507 |
kshitij.so |
220 |
get_mongo_connection().Catalog.Deals.update({'_id':manualDeal['_id']},{"$set":{'dealType':0}},upsert=False, multi=False)
|
| 14306 |
kshitij.so |
221 |
|
| 13755 |
kshitij.so |
222 |
def calculateNlcPoints():
|
|
|
223 |
global LATEST_UPDATED_ITEMS
|
| 14842 |
kshitij.so |
224 |
print "inside nlc oints"
|
| 13755 |
kshitij.so |
225 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
226 |
if sku.maxNlc and sku.minNlc:
|
| 14842 |
kshitij.so |
227 |
print sku._id
|
| 13824 |
kshitij.so |
228 |
|
|
|
229 |
"""Create map - TODO"""
|
|
|
230 |
|
|
|
231 |
if sku.status == 2:
|
|
|
232 |
eolWeight = .60
|
|
|
233 |
else:
|
|
|
234 |
eolWeight = 1.0
|
|
|
235 |
if sku.category_id == 3:
|
|
|
236 |
basePointPercentage = 5.0
|
|
|
237 |
maxNlcPoints = 200
|
|
|
238 |
elif sku.category_id == 5:
|
|
|
239 |
basePointPercentage = 8.0
|
|
|
240 |
maxNlcPoints = 150
|
| 17540 |
kshitij.so |
241 |
elif sku.category_id == 6:
|
|
|
242 |
basePointPercentage = 5.0
|
|
|
243 |
maxNlcPoints = 200
|
|
|
244 |
|
| 13824 |
kshitij.so |
245 |
else:
|
|
|
246 |
basePointPercentage = 10.0
|
|
|
247 |
maxNlcPoints = 150
|
| 14842 |
kshitij.so |
248 |
discFromMinNlc = float((sku.minNlc - sku.available_price))/sku.available_price *100
|
|
|
249 |
discFromMaxNlc = float((sku.maxNlc - sku.available_price))/sku.available_price *100
|
|
|
250 |
print discFromMinNlc
|
|
|
251 |
print discFromMaxNlc
|
| 13755 |
kshitij.so |
252 |
if discFromMinNlc > 0:
|
| 13824 |
kshitij.so |
253 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
| 13755 |
kshitij.so |
254 |
elif discFromMinNlc < 0 and discFromMaxNlc > 0:
|
|
|
255 |
nlcPoints = 0
|
|
|
256 |
else:
|
| 13824 |
kshitij.so |
257 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
|
|
258 |
if (min(nlcPoints,maxNlcPoints)) > 0:
|
|
|
259 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints)) * eolWeight
|
|
|
260 |
else:
|
|
|
261 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints))
|
| 13755 |
kshitij.so |
262 |
else:
|
|
|
263 |
sku.nlcPoints = 0
|
|
|
264 |
|
|
|
265 |
def commitData():
|
|
|
266 |
global LATEST_UPDATED_ITEMS
|
|
|
267 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
268 |
#get_mongo_connection().Catalog.Deals.update({'_id':sku._id},{'$set' : sku.__dict__},upsert=True,multi=True)
|
| 14020 |
amit.gupta |
269 |
get_mongo_connection().Catalog.Deals.update({'_id':sku._id},{"$set":sku.__dict__},upsert=True)
|
| 13755 |
kshitij.so |
270 |
|
|
|
271 |
|
|
|
272 |
def addBestSellerPoints():
|
|
|
273 |
allItems = list(get_mongo_connection().Catalog.Deals.find({}))
|
|
|
274 |
for sku in allItems:
|
| 13824 |
kshitij.so |
275 |
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'] }] } ))
|
| 13755 |
kshitij.so |
276 |
if len(bestSellerPoints) > 0:
|
| 13824 |
kshitij.so |
277 |
print bestSellerPoints[0]['points']
|
|
|
278 |
if (bestSellerPoints[0]['points']) > 0:
|
| 16253 |
kshitij.so |
279 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage'] * STATUS_WEIGHTAGE.get(sku['status'])
|
| 13824 |
kshitij.so |
280 |
else:
|
|
|
281 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
|
| 13755 |
kshitij.so |
282 |
else:
|
| 16253 |
kshitij.so |
283 |
sku['bestSellerPoints'] = -120
|
| 14114 |
kshitij.so |
284 |
#sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
|
|
285 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints']}},multi=False)
|
|
|
286 |
|
| 14390 |
kshitij.so |
287 |
shortageSkus = get_mongo_connection().Catalog.MasterData.find({"$and":[{'is_shortage': 1 }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).distinct('_id')
|
|
|
288 |
print "Shortage skus"
|
|
|
289 |
print shortageSkus
|
| 14388 |
kshitij.so |
290 |
|
| 14114 |
kshitij.so |
291 |
for sku in allItems:
|
|
|
292 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
| 14142 |
kshitij.so |
293 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
| 14388 |
kshitij.so |
294 |
shortagePoints = 50 if sku['_id'] in shortageSkus else 0
|
| 14391 |
kshitij.so |
295 |
print "Shortage points for ",sku['_id']
|
|
|
296 |
print shortagePoints
|
| 16868 |
kshitij.so |
297 |
|
|
|
298 |
dealPoints = DEAL_POINTS_MAP.get(sku['skuBundleId'])
|
|
|
299 |
|
|
|
300 |
if dealPoints is not None and dealPoints.manualDealThresholdPrice >= sku['available_price']:
|
|
|
301 |
sku['dealPoints'] = dealPoints.points
|
|
|
302 |
sku['manualDealThresholdPrice'] = dealPoints.manualDealThresholdPrice
|
|
|
303 |
else:
|
|
|
304 |
sku['dealPoints'] = 0
|
|
|
305 |
sku['manualDealThresholdPrice'] = None
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints + sku['dealPoints']
|
|
|
309 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints'],'dealPoints':sku['dealPoints'], \
|
|
|
310 |
'manualDealThresholdPrice':sku['manualDealThresholdPrice']}},multi=False)
|
| 15271 |
kshitij.so |
311 |
|
|
|
312 |
|
| 13755 |
kshitij.so |
313 |
|
| 14325 |
kshitij.so |
314 |
def populateNegativeDeals():
|
|
|
315 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
|
|
316 |
mc.set("negative_deals", negativeDeals, 600)
|
|
|
317 |
|
| 16868 |
kshitij.so |
318 |
def eliminateSimilarDeals():
|
| 13912 |
kshitij.so |
319 |
allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
|
|
|
320 |
for skuBundleId in allItems:
|
|
|
321 |
print skuBundleId
|
|
|
322 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 13828 |
kshitij.so |
323 |
bestPrice = float("inf")
|
|
|
324 |
bestOne = None
|
|
|
325 |
bestSellerPoints = 0
|
|
|
326 |
toUpdate = []
|
| 16019 |
kshitij.so |
327 |
prepaidBestPrice = float("inf")
|
|
|
328 |
prepaidBestOne = None
|
|
|
329 |
prepaidBestSellerPoints = 0
|
| 13828 |
kshitij.so |
330 |
for similarItem in similarItems:
|
| 16019 |
kshitij.so |
331 |
if similarItem['codAvailable'] ==1:
|
|
|
332 |
if mc.get("negative_deals") is None:
|
|
|
333 |
populateNegativeDeals()
|
| 16171 |
kshitij.so |
334 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16019 |
kshitij.so |
335 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
336 |
continue
|
| 17675 |
kshitij.so |
337 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
|
| 16019 |
kshitij.so |
338 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
339 |
continue
|
|
|
340 |
if similarItem['available_price'] < bestPrice:
|
|
|
341 |
bestOne = similarItem
|
|
|
342 |
bestPrice = similarItem['available_price']
|
|
|
343 |
bestSellerPoints = similarItem['bestSellerPoints']
|
|
|
344 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
|
|
345 |
bestOne = similarItem
|
|
|
346 |
bestPrice = similarItem['available_price']
|
|
|
347 |
bestSellerPoints = similarItem['bestSellerPoints']
|
|
|
348 |
else:
|
|
|
349 |
pass
|
| 13828 |
kshitij.so |
350 |
else:
|
| 16019 |
kshitij.so |
351 |
if mc.get("negative_deals") is None:
|
|
|
352 |
populateNegativeDeals()
|
| 16171 |
kshitij.so |
353 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16019 |
kshitij.so |
354 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
355 |
continue
|
|
|
356 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
|
|
357 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
358 |
continue
|
| 16869 |
kshitij.so |
359 |
if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
|
|
|
360 |
similarItem['available_price'] = similarItem['gross_price']
|
| 16019 |
kshitij.so |
361 |
if similarItem['available_price'] < prepaidBestPrice:
|
|
|
362 |
prepaidBestOne = similarItem
|
|
|
363 |
prepaidBestPrice = similarItem['available_price']
|
|
|
364 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
|
|
365 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
|
|
366 |
prepaidBestOne = similarItem
|
|
|
367 |
prepaidBestPrice = similarItem['available_price']
|
|
|
368 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
|
|
369 |
else:
|
|
|
370 |
pass
|
| 16026 |
kshitij.so |
371 |
if bestOne is not None or prepaidBestOne is not None:
|
| 13828 |
kshitij.so |
372 |
for similarItem in similarItems:
|
|
|
373 |
toUpdate.append(similarItem['_id'])
|
| 16026 |
kshitij.so |
374 |
if bestOne is not None:
|
|
|
375 |
toUpdate.remove(bestOne['_id'])
|
|
|
376 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
|
|
377 |
if prepaidBestOne is not None:
|
| 16071 |
kshitij.so |
378 |
if bestOne is not None:
|
|
|
379 |
if prepaidBestOne['available_price'] < bestOne['available_price']:
|
|
|
380 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
381 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
|
|
382 |
else:
|
|
|
383 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
384 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 13828 |
kshitij.so |
385 |
if len(toUpdate) > 0:
|
| 16019 |
kshitij.so |
386 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 13755 |
kshitij.so |
387 |
|
| 16868 |
kshitij.so |
388 |
def populateDealPointsBundle():
|
|
|
389 |
global DEAL_POINTS_MAP
|
|
|
390 |
activeDealPoints = get_mongo_connection().Catalog.DealPoints.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
|
|
|
391 |
for activeDeal in activeDealPoints:
|
|
|
392 |
dealPoints = __DealPoints(activeDeal['dealThresholdPrice'], activeDeal['dealPoints'])
|
|
|
393 |
DEAL_POINTS_MAP[activeDeal['skuBundleId']] = dealPoints
|
|
|
394 |
|
| 13755 |
kshitij.so |
395 |
def main():
|
| 14263 |
kshitij.so |
396 |
try:
|
|
|
397 |
populateStuff()
|
|
|
398 |
calculateNlc()
|
| 14306 |
kshitij.so |
399 |
addManualDealsInfo()
|
| 14263 |
kshitij.so |
400 |
finally:
|
|
|
401 |
session.close()
|
| 13755 |
kshitij.so |
402 |
calculateNlcPoints()
|
|
|
403 |
commitData()
|
| 16868 |
kshitij.so |
404 |
populateDealPointsBundle()
|
| 13755 |
kshitij.so |
405 |
addBestSellerPoints()
|
| 16868 |
kshitij.so |
406 |
eliminateSimilarDeals()
|
| 13755 |
kshitij.so |
407 |
|
| 13828 |
kshitij.so |
408 |
|
| 13755 |
kshitij.so |
409 |
if __name__=='__main__':
|
| 14842 |
kshitij.so |
410 |
main()
|