| 9881 |
kshitij.so |
1 |
from elixir import *
|
|
|
2 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
3 |
from shop2020.model.v1.catalog.impl import DataService
|
|
|
4 |
from shop2020.model.v1.catalog.impl.DataService import SnapdealItem, MarketplaceItems, Item, \
|
|
|
5 |
Category, SourcePercentageMaster, MarketPlaceHistory
|
|
|
6 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
|
|
7 |
from shop2020.thriftpy.model.v1.catalog.ttypes import CompetitionCategory, CompetitionBasis, SalesPotential
|
|
|
8 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
9 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
10 |
import urllib2
|
|
|
11 |
import time
|
|
|
12 |
from datetime import date, datetime
|
|
|
13 |
import simplejson as json
|
|
|
14 |
import sys
|
|
|
15 |
|
|
|
16 |
config_client = ConfigClient()
|
|
|
17 |
host = config_client.get_property('staging_hostname')
|
|
|
18 |
DataService.initialize(db_hostname=host)
|
|
|
19 |
|
|
|
20 |
class __Exception:
|
|
|
21 |
SERVER_SIDE=1
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
class __SnapdealDetails:
|
|
|
25 |
def __init__(self, ourSp, ourInventory, otherInventory, rank, lowestSellerName, lowestSellerCode,lowestSp,secondLowestSellerName, secondLowestSellerCode,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice, totalSeller):
|
|
|
26 |
self.ourSp = ourSp
|
|
|
27 |
self.ourOfferPrice = ourOfferPrice
|
|
|
28 |
self.ourInventory = ourInventory
|
|
|
29 |
self.otherInventory = otherInventory
|
|
|
30 |
self.rank = rank
|
|
|
31 |
self.lowestSellerName = lowestSellerName
|
|
|
32 |
self.lowestSellerCode = lowestSellerCode
|
|
|
33 |
self.lowestSp = lowestSp
|
|
|
34 |
self.lowestOfferPrice = lowestOfferPrice
|
|
|
35 |
self.secondLowestSellerName = secondLowestSellerName
|
|
|
36 |
self.secondLowestSellerCode = secondLowestSellerCode
|
|
|
37 |
self.secondLowestSellerSp = secondLowestSellerSp
|
|
|
38 |
self.secondLowestSellerOfferPrice = secondLowestSellerOfferPrice
|
|
|
39 |
self.secondLowestSellerInventory = secondLowestSellerInventory
|
|
|
40 |
self.totalSeller = totalSeller
|
|
|
41 |
|
|
|
42 |
class __SnapdealItemInfo:
|
|
|
43 |
|
|
|
44 |
def __init__(self, supc, nlc, courierCost, item_id, product_group, brand, model_name, model_number, color, weight, parent_category, risky, warehouseId, vatRate):
|
|
|
45 |
self.supc = supc
|
|
|
46 |
self.nlc = nlc
|
|
|
47 |
self.courierCost = courierCost
|
|
|
48 |
self.item_id = item_id
|
|
|
49 |
self.product_group = product_group
|
|
|
50 |
self.brand = brand
|
|
|
51 |
self.model_name = model_name
|
|
|
52 |
self.model_number = model_number
|
|
|
53 |
self.color = color
|
|
|
54 |
self.weight = weight
|
|
|
55 |
self.parent_category = parent_category
|
|
|
56 |
self.risky = risky
|
|
|
57 |
self.warehouseId = warehouseId
|
|
|
58 |
self.vatRate = vatRate
|
|
|
59 |
|
|
|
60 |
class __SnapdealPricing:
|
|
|
61 |
|
|
|
62 |
def __init__(self, ourSp, ourTp, lowestTp, lowestPossibleTp, competitionBasis, secondLowestSellerTp, lowestPossibleSp):
|
|
|
63 |
self.ourTp = ourTp
|
|
|
64 |
self.lowestTp = lowestTp
|
|
|
65 |
self.lowestPossibleTp = lowestPossibleTp
|
|
|
66 |
self.competitionBasis = competitionBasis
|
|
|
67 |
self.ourSp = ourSp
|
|
|
68 |
self.secondLowestSellerTp = secondLowestSellerTp
|
|
|
69 |
self.lowestPossibleSp = lowestPossibleSp
|
|
|
70 |
|
|
|
71 |
def fetchDetails(supc_code):
|
|
|
72 |
url="http://www.snapdeal.com/json/gvbps?supc=%s&catId=91"%(supc_code)
|
|
|
73 |
print url
|
|
|
74 |
time.sleep(1)
|
|
|
75 |
req = urllib2.Request(url)
|
|
|
76 |
response = urllib2.urlopen(req)
|
|
|
77 |
json_input = response.read()
|
|
|
78 |
vendorInfo = json.loads(json_input)
|
|
|
79 |
rank ,otherInventory ,ourInventory, ourOfferPrice, ourSp, iterator, secondLowestSellerSp, secondLowestSellerInventory, \
|
|
|
80 |
lowestOfferPrice, secondLowestSellerOfferPrice = (0,)*10
|
|
|
81 |
lowestSellerName , lowestSellerCode, secondLowestSellerName, secondLowestSellerCode=('',)*4
|
|
|
82 |
for vendor in vendorInfo:
|
|
|
83 |
if iterator == 0:
|
|
|
84 |
lowestSellerName = vendor['vendorDisplayName']
|
|
|
85 |
lowestSellerCode = vendor['vendorCode']
|
|
|
86 |
try:
|
|
|
87 |
lowestSp = vendor['sellingPriceBefIntCashBack']
|
|
|
88 |
except:
|
|
|
89 |
lowestSp = vendor['sellingPrice']
|
|
|
90 |
lowestOfferPrice = vendor['sellingPrice']
|
|
|
91 |
|
|
|
92 |
if iterator ==1:
|
|
|
93 |
secondLowestSellerName = vendor['vendorDisplayName']
|
|
|
94 |
secondLowestSellerCode =vendor['vendorCode']
|
|
|
95 |
try:
|
|
|
96 |
secondLowestSellerSp = vendor['sellingPriceBefIntCashBack']
|
|
|
97 |
except:
|
|
|
98 |
secondLowestSellerSp = vendor['sellingPrice']
|
|
|
99 |
secondLowestSellerOfferPrice = vendor['sellingPrice']
|
|
|
100 |
secondLowestSellerInventory = vendor['buyableInventory']
|
|
|
101 |
|
|
|
102 |
if vendor['vendorDisplayName'] == 'MobilesnMore':
|
|
|
103 |
ourInventory = vendor['buyableInventory']
|
|
|
104 |
try:
|
|
|
105 |
ourSp = vendor['sellingPriceBefIntCashBack']
|
|
|
106 |
except:
|
|
|
107 |
ourSp = vendor['sellingPrice']
|
|
|
108 |
ourOfferPrice = vendor['sellingPrice']
|
|
|
109 |
rank = iterator +1
|
|
|
110 |
else:
|
|
|
111 |
if rank==0:
|
|
|
112 |
otherInventory = otherInventory +vendor['buyableInventory']
|
|
|
113 |
iterator+=1
|
|
|
114 |
snapdealDetails = __SnapdealDetails(ourSp,ourInventory,otherInventory,rank,lowestSellerName, lowestSellerCode,lowestSp,secondLowestSellerName,secondLowestSellerCode,secondLowestSellerSp,secondLowestSellerInventory,lowestOfferPrice,secondLowestSellerOfferPrice,ourOfferPrice,len(vendorInfo))
|
|
|
115 |
return snapdealDetails
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
def populateStuff():
|
|
|
119 |
itemInfo = []
|
|
|
120 |
items = session.query(SnapdealItem).all()
|
|
|
121 |
spm = SourcePercentageMaster.get_by(source=OrderSource.SNAPDEAL)
|
|
|
122 |
for snapdeal_item in items:
|
|
|
123 |
it = Item.query.filter_by(id=snapdeal_item.item_id).one()
|
|
|
124 |
category = Category.query.filter_by(id=it.category).one()
|
|
|
125 |
snapdealItemInfo = __SnapdealItemInfo(snapdeal_item.supc, snapdeal_item.maxNlc,snapdeal_item.courierCost, it.id, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, snapdeal_item.warehouseId, None)
|
|
|
126 |
itemInfo.append(snapdealItemInfo)
|
|
|
127 |
return itemInfo, spm
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
def decideCategory(itemInfo,spm):
|
|
|
131 |
cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin = [],[],[],[],[],[]
|
|
|
132 |
catalog_client = CatalogClient().get_client()
|
|
|
133 |
inventory_client = InventoryClient().get_client()
|
|
|
134 |
|
|
|
135 |
for val in itemInfo:
|
|
|
136 |
try:
|
|
|
137 |
snapdealDetails = fetchDetails(val.supc)
|
|
|
138 |
except:
|
|
|
139 |
exceptionItems.append(val)
|
|
|
140 |
continue
|
|
|
141 |
mpItem = MarketplaceItems.get_by(itemId=val.item_id,source=OrderSource.SNAPDEAL)
|
|
|
142 |
warehouse = inventory_client.getWarehouse(val.warehouseId)
|
|
|
143 |
if snapdealDetails.rank==0:
|
|
|
144 |
snapdealDetails.ourSp = mpItem.currentSp
|
|
|
145 |
snapdealDetails.ourOfferPrice = mpItem.currentSp
|
|
|
146 |
ourSp = mpItem.currentSp
|
|
|
147 |
else:
|
|
|
148 |
ourSp = snapdealDetails.ourSp
|
|
|
149 |
vatRate = catalog_client.getVatPercentageForItem(val.item_id, warehouse.stateId, snapdealDetails.ourSp)
|
|
|
150 |
val.vatRate = vatRate
|
|
|
151 |
if (snapdealDetails.rank==1):
|
|
|
152 |
temp=[]
|
|
|
153 |
temp.append(snapdealDetails)
|
|
|
154 |
temp.append(val)
|
|
|
155 |
if (snapdealDetails.secondLowestSellerOfferPrice == snapdealDetails.secondLowestSellerSp) and snapdealDetails.ourOfferPrice==snapdealDetails.ourSp:
|
|
|
156 |
competitionBasis = 'SP'
|
|
|
157 |
else:
|
|
|
158 |
competitionBasis = 'TP'
|
|
|
159 |
secondLowestTp=0 if snapdealDetails.totalSeller==1 else getOtherTp(snapdealDetails,val,spm)
|
|
|
160 |
snapdealPricing = __SnapdealPricing(snapdealDetails.ourSp,getOurTp(snapdealDetails,val,spm,mpItem),None,getLowestPossibleTp(snapdealDetails,val,spm,mpItem),competitionBasis,secondLowestTp,getLowestPossibleSp(snapdealDetails,val,spm,mpItem))
|
|
|
161 |
temp.append(snapdealPricing)
|
|
|
162 |
temp.append(mpItem)
|
|
|
163 |
buyBoxItems.append(temp)
|
|
|
164 |
continue
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
lowestTp = getOtherTp(snapdealDetails,val,spm)
|
|
|
168 |
ourTp = getOurTp(snapdealDetails,val,spm,mpItem)
|
|
|
169 |
lowestPossibleTp = getLowestPossibleTp(snapdealDetails,val,spm,mpItem)
|
|
|
170 |
lowestPossibleSp = getLowestPossibleSp(snapdealDetails,val,spm,mpItem)
|
|
|
171 |
|
|
|
172 |
if (ourTp<lowestPossibleTp):
|
|
|
173 |
temp=[]
|
|
|
174 |
temp.append(snapdealDetails)
|
|
|
175 |
temp.append(val)
|
|
|
176 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,None,None)
|
|
|
177 |
temp.append(snapdealPricing)
|
|
|
178 |
negativeMargin.append(temp)
|
|
|
179 |
continue
|
|
|
180 |
|
|
|
181 |
if (snapdealDetails.lowestOfferPrice == snapdealDetails.lowestSp) and snapdealDetails.ourOfferPrice == snapdealDetails.ourSp:
|
|
|
182 |
competitionBasis ='SP'
|
|
|
183 |
else:
|
|
|
184 |
competitionBasis ='TP'
|
|
|
185 |
|
|
|
186 |
if competitionBasis=='SP':
|
|
|
187 |
if snapdealDetails.lowestSp > lowestPossibleSp and snapdealDetails.ourInventory!=0:
|
|
|
188 |
temp=[]
|
|
|
189 |
temp.append(snapdealDetails)
|
|
|
190 |
temp.append(val)
|
|
|
191 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,'SP',None,lowestPossibleSp)
|
|
|
192 |
temp.append(snapdealPricing)
|
|
|
193 |
temp.append(mpItem)
|
|
|
194 |
competitive.append(temp)
|
|
|
195 |
continue
|
|
|
196 |
else:
|
|
|
197 |
if lowestTp > lowestPossibleTp and snapdealDetails.ourInventory!=0:
|
|
|
198 |
temp=[]
|
|
|
199 |
temp.append(snapdealDetails)
|
|
|
200 |
temp.append(val)
|
|
|
201 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,'TP',None,lowestPossibleSp)
|
|
|
202 |
temp.append(snapdealPricing)
|
|
|
203 |
temp.append(mpItem)
|
|
|
204 |
competitive.append(temp)
|
|
|
205 |
continue
|
|
|
206 |
|
|
|
207 |
if competitionBasis=='SP':
|
|
|
208 |
if snapdealDetails.lowestSp > lowestPossibleSp and snapdealDetails.ourInventory==0:
|
|
|
209 |
temp=[]
|
|
|
210 |
temp.append(snapdealDetails)
|
|
|
211 |
temp.append(val)
|
|
|
212 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,'SP',None,lowestPossibleSp)
|
|
|
213 |
temp.append(snapdealPricing)
|
|
|
214 |
temp.append(mpItem)
|
|
|
215 |
competitiveNoInventory.append(temp)
|
|
|
216 |
continue
|
|
|
217 |
else:
|
|
|
218 |
if lowestTp > lowestPossibleTp and snapdealDetails.ourInventory==0:
|
|
|
219 |
temp=[]
|
|
|
220 |
temp.append(snapdealDetails)
|
|
|
221 |
temp.append(val)
|
|
|
222 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,'TP',None,lowestPossibleSp)
|
|
|
223 |
temp.append(snapdealPricing)
|
|
|
224 |
temp.append(mpItem)
|
|
|
225 |
competitiveNoInventory.append(temp)
|
|
|
226 |
continue
|
|
|
227 |
|
|
|
228 |
temp=[]
|
|
|
229 |
temp.append(snapdealDetails)
|
|
|
230 |
temp.append(val)
|
|
|
231 |
snapdealPricing = __SnapdealPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,competitionBasis,None,lowestPossibleSp)
|
|
|
232 |
temp.append(snapdealPricing)
|
|
|
233 |
temp.append(mpItem)
|
|
|
234 |
cantCompete.append(temp)
|
|
|
235 |
|
|
|
236 |
return cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
def commitExceptionList(exceptionList,timestamp):
|
|
|
240 |
for item in exceptionList:
|
|
|
241 |
mpHistory = MarketPlaceHistory()
|
|
|
242 |
mpHistory.item_id =item.item_id
|
|
|
243 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
244 |
mpHistory.competitiveCategory = CompetitionCategory.EXCEPTION
|
|
|
245 |
mpHistory.risky = item.risky
|
|
|
246 |
mpHistory.timestamp = timestamp
|
|
|
247 |
session.commit()
|
|
|
248 |
|
|
|
249 |
def commitNegativeMargin(negativeMargin,timestamp):
|
|
|
250 |
for item in negativeMargin:
|
|
|
251 |
snapdealDetails = item[0]
|
|
|
252 |
snapdealItemInfo = item[1]
|
|
|
253 |
snapdealPricing = item[2]
|
|
|
254 |
mpHistory = MarketPlaceHistory()
|
|
|
255 |
mpHistory.item_id = snapdealItemInfo.item_id
|
|
|
256 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
257 |
mpHistory.ourOfferPrice = snapdealDetails.ourOfferPrice
|
|
|
258 |
mpHistory.ourSellingPrice = snapdealPricing.ourSp
|
|
|
259 |
mpHistory.ourTp = snapdealPricing.ourTp
|
|
|
260 |
mpHistory.ourNlc = snapdealItemInfo.nlc
|
|
|
261 |
mpHistory.ourInventory = snapdealDetails.ourInventory
|
|
|
262 |
mpHistory.otherInventory = snapdealDetails.otherInventory
|
|
|
263 |
mpHistory.ourRank = snapdealDetails.rank
|
|
|
264 |
mpHistory.competitiveCategory = CompetitionCategory.NEGATIVE_MARGIN
|
|
|
265 |
mpHistory.totalSeller = snapdealDetails.totalSeller
|
|
|
266 |
mpHistory.timestamp = timestamp
|
|
|
267 |
session.commit()
|
|
|
268 |
|
|
|
269 |
def commitCompetitive(competitive,timestamp):
|
|
|
270 |
for item in competitive:
|
|
|
271 |
snapdealDetails = item[0]
|
|
|
272 |
snapdealItemInfo = item[1]
|
|
|
273 |
snapdealPricing = item[2]
|
|
|
274 |
mpItem = item[3]
|
|
|
275 |
mpHistory = MarketPlaceHistory()
|
|
|
276 |
mpHistory.item_id = snapdealItemInfo.item_id
|
|
|
277 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
278 |
mpHistory.lowestTp = snapdealPricing.lowestTp
|
|
|
279 |
mpHistory.lowestPossibleTp = snapdealPricing.lowestPossibleTp
|
|
|
280 |
mpHistory.lowestPossibleSp = snapdealPricing.lowestPossibleSp
|
|
|
281 |
mpHistory.ourInventory = snapdealDetails.ourInventory
|
|
|
282 |
mpHistory.otherInventory = snapdealDetails.otherInventory
|
|
|
283 |
mpHistory.ourRank = snapdealDetails.rank
|
|
|
284 |
mpHistory.competitionBasis = CompetitionBasis._NAMES_TO_VALUES.get(snapdealPricing.competitionBasis)
|
|
|
285 |
mpHistory.competitiveCategory = CompetitionCategory.COMPETITIVE
|
|
|
286 |
mpHistory.risky = snapdealItemInfo.risky
|
|
|
287 |
mpHistory.lowestOfferPrice = snapdealDetails.lowestOfferPrice
|
|
|
288 |
mpHistory.lowestSellingPrice = snapdealDetails.lowestSp
|
|
|
289 |
mpHistory.lowestSellerName = snapdealDetails.lowestSellerName
|
|
|
290 |
mpHistory.lowestSellerCode = snapdealDetails.lowestSellerCode
|
|
|
291 |
mpHistory.ourOfferPrice = snapdealDetails.ourOfferPrice
|
|
|
292 |
mpHistory.ourSellingPrice = snapdealPricing.ourSp
|
|
|
293 |
mpHistory.ourTp = snapdealPricing.ourTp
|
|
|
294 |
mpHistory.ourNlc = snapdealItemInfo.nlc
|
|
|
295 |
if (snapdealPricing.competitionBasis=='SP'):
|
|
|
296 |
proposed_sp = max(snapdealDetails.lowestSp - max((10, snapdealDetails.lowestSp*0.001)), snapdealPricing.lowestPossibleSp)
|
|
|
297 |
proposed_tp = getTargetTp(proposed_sp,mpItem)
|
|
|
298 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
299 |
mpHistory.proposedTp = proposed_tp
|
|
|
300 |
else:
|
|
|
301 |
proposed_tp = max(snapdealPricing.lowestTp - max((10, snapdealPricing.lowestTp*0.001)), snapdealPricing.lowestPossibleTp)
|
|
|
302 |
proposed_sp = getTargetSp(proposed_tp,mpItem)
|
|
|
303 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
304 |
mpHistory.proposedTp = proposed_tp
|
|
|
305 |
mpHistory.totalSeller = snapdealDetails.totalSeller
|
|
|
306 |
mpHistory.salesPotential = SalesPotential._NAMES_TO_VALUES.get(getSalesPotential(snapdealDetails.lowestOfferPrice,snapdealItemInfo.nlc))
|
|
|
307 |
mpHistory.timestamp = timestamp
|
|
|
308 |
session.commit()
|
|
|
309 |
|
|
|
310 |
def commitCompetitiveNoInventory(competitiveNoInventory,timestamp):
|
|
|
311 |
for item in competitiveNoInventory:
|
|
|
312 |
snapdealDetails = item[0]
|
|
|
313 |
snapdealItemInfo = item[1]
|
|
|
314 |
snapdealPricing = item[2]
|
|
|
315 |
mpItem = item[3]
|
|
|
316 |
mpHistory = MarketPlaceHistory()
|
|
|
317 |
mpHistory.item_id = snapdealItemInfo.item_id
|
|
|
318 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
319 |
mpHistory.lowestTp = snapdealPricing.lowestTp
|
|
|
320 |
mpHistory.lowestPossibleTp = snapdealPricing.lowestPossibleTp
|
|
|
321 |
mpHistory.lowestPossibleSp = snapdealPricing.lowestPossibleSp
|
|
|
322 |
mpHistory.ourInventory = snapdealDetails.ourInventory
|
|
|
323 |
mpHistory.otherInventory = snapdealDetails.otherInventory
|
|
|
324 |
mpHistory.ourRank = snapdealDetails.rank
|
|
|
325 |
mpHistory.competitionBasis = CompetitionBasis._NAMES_TO_VALUES.get(snapdealPricing.competitionBasis)
|
|
|
326 |
mpHistory.competitiveCategory = CompetitionCategory.COMPETITIVE_NO_INVENTORY
|
|
|
327 |
mpHistory.risky = snapdealItemInfo.risky
|
|
|
328 |
mpHistory.lowestOfferPrice = snapdealDetails.lowestOfferPrice
|
|
|
329 |
mpHistory.lowestSellingPrice = snapdealDetails.lowestSp
|
|
|
330 |
mpHistory.lowestSellerName = snapdealDetails.lowestSellerName
|
|
|
331 |
mpHistory.lowestSellerCode = snapdealDetails.lowestSellerCode
|
|
|
332 |
mpHistory.ourOfferPrice = snapdealDetails.ourOfferPrice
|
|
|
333 |
mpHistory.ourSellingPrice = snapdealPricing.ourSp
|
|
|
334 |
mpHistory.ourTp = snapdealPricing.ourTp
|
|
|
335 |
mpHistory.ourNlc = snapdealItemInfo.nlc
|
|
|
336 |
if (snapdealPricing.competitionBasis=='SP'):
|
|
|
337 |
proposed_sp = max(snapdealDetails.lowestSp - max((10, snapdealDetails.lowestSp*0.001)), snapdealPricing.lowestPossibleSp)
|
|
|
338 |
proposed_tp = getTargetTp(proposed_sp,mpItem)
|
|
|
339 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
340 |
mpHistory.proposedTp = proposed_tp
|
|
|
341 |
else:
|
|
|
342 |
proposed_tp = max(snapdealPricing.lowestTp - max((10, snapdealPricing.lowestTp*0.001)), snapdealPricing.lowestPossibleTp)
|
|
|
343 |
proposed_sp = getTargetSp(proposed_tp,mpItem)
|
|
|
344 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
345 |
mpHistory.proposedTp = proposed_tp
|
|
|
346 |
mpHistory.totalSeller = snapdealDetails.totalSeller
|
|
|
347 |
mpHistory.salesPotential = SalesPotential._NAMES_TO_VALUES.get(getSalesPotential(snapdealDetails.lowestOfferPrice,snapdealItemInfo.nlc))
|
|
|
348 |
mpHistory.timestamp = timestamp
|
|
|
349 |
session.commit()
|
|
|
350 |
|
|
|
351 |
def commitCantCompete(cantCompete,timestamp):
|
|
|
352 |
for item in cantCompete:
|
|
|
353 |
snapdealDetails = item[0]
|
|
|
354 |
snapdealItemInfo = item[1]
|
|
|
355 |
snapdealPricing = item[2]
|
|
|
356 |
mpItem = item[3]
|
|
|
357 |
mpHistory = MarketPlaceHistory()
|
|
|
358 |
mpHistory.item_id = snapdealItemInfo.item_id
|
|
|
359 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
360 |
mpHistory.lowestTp = snapdealPricing.lowestTp
|
|
|
361 |
mpHistory.lowestPossibleTp = snapdealPricing.lowestPossibleTp
|
|
|
362 |
mpHistory.lowestPossibleSp = snapdealPricing.lowestPossibleSp
|
|
|
363 |
mpHistory.ourInventory = snapdealDetails.ourInventory
|
|
|
364 |
mpHistory.otherInventory = snapdealDetails.otherInventory
|
|
|
365 |
mpHistory.ourRank = snapdealDetails.rank
|
|
|
366 |
mpHistory.competitionBasis = CompetitionBasis._NAMES_TO_VALUES.get(snapdealPricing.competitionBasis)
|
|
|
367 |
mpHistory.competitiveCategory = CompetitionCategory.CANT_COMPETE
|
|
|
368 |
mpHistory.risky = snapdealItemInfo.risky
|
|
|
369 |
mpHistory.lowestOfferPrice = snapdealDetails.lowestOfferPrice
|
|
|
370 |
mpHistory.lowestSellingPrice = snapdealDetails.lowestSp
|
|
|
371 |
mpHistory.lowestSellerName = snapdealDetails.lowestSellerName
|
|
|
372 |
mpHistory.lowestSellerCode = snapdealDetails.lowestSellerCode
|
|
|
373 |
mpHistory.ourOfferPrice = snapdealDetails.ourOfferPrice
|
|
|
374 |
mpHistory.ourSellingPrice = snapdealPricing.ourSp
|
|
|
375 |
mpHistory.ourTp = snapdealPricing.ourTp
|
|
|
376 |
mpHistory.ourNlc = snapdealItemInfo.nlc
|
|
|
377 |
if (snapdealPricing.competitionBasis=='SP'):
|
|
|
378 |
proposed_sp = snapdealDetails.lowestSp - max(10, snapdealDetails.lowestSp*0.001)
|
|
|
379 |
proposed_tp = getTargetTp(proposed_sp,mpItem)
|
|
|
380 |
target_nlc = proposed_tp - snapdealPricing.lowestPossibleTp + snapdealItemInfo.nlc
|
|
|
381 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
382 |
mpHistory.proposedTp = proposed_tp
|
|
|
383 |
mpHistory.targetNlc = target_nlc
|
|
|
384 |
else:
|
|
|
385 |
proposed_tp = snapdealPricing.lowestTp - max(10, snapdealPricing.lowestTp*0.001)
|
|
|
386 |
proposed_sp = getTargetSp(proposed_tp,mpItem)
|
|
|
387 |
target_nlc = proposed_tp - snapdealPricing.lowestPossibleTp + snapdealItemInfo.nlc
|
|
|
388 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
389 |
mpHistory.proposedTp = proposed_tp
|
|
|
390 |
mpHistory.targetNlc = target_nlc
|
|
|
391 |
mpHistory.totalSeller = snapdealDetails.totalSeller
|
|
|
392 |
mpHistory.salesPotential = SalesPotential._NAMES_TO_VALUES.get(getSalesPotential(snapdealDetails.lowestOfferPrice,snapdealItemInfo.nlc))
|
|
|
393 |
mpHistory.timestamp = timestamp
|
|
|
394 |
session.commit()
|
|
|
395 |
|
|
|
396 |
def commitBuyBox(buyBoxItems,timestamp):
|
|
|
397 |
for item in buyBoxItems:
|
|
|
398 |
snapdealDetails = item[0]
|
|
|
399 |
snapdealItemInfo = item[1]
|
|
|
400 |
snapdealPricing = item[2]
|
|
|
401 |
mpItem = item[3]
|
|
|
402 |
mpHistory = MarketPlaceHistory()
|
|
|
403 |
mpHistory.item_id = snapdealItemInfo.item_id
|
|
|
404 |
mpHistory.source = OrderSource.SNAPDEAL
|
|
|
405 |
mpHistory.lowestPossibleTp = snapdealPricing.lowestPossibleTp
|
|
|
406 |
mpHistory.lowestPossibleSp = snapdealPricing.lowestPossibleSp
|
|
|
407 |
mpHistory.ourInventory = snapdealDetails.ourInventory
|
|
|
408 |
mpHistory.secondLowestInventory = snapdealDetails.secondLowestSellerInventory
|
|
|
409 |
mpHistory.ourRank = snapdealDetails.rank
|
|
|
410 |
mpHistory.competitionBasis = CompetitionBasis._NAMES_TO_VALUES.get(snapdealPricing.competitionBasis)
|
|
|
411 |
mpHistory.competitiveCategory = CompetitionCategory.BUY_BOX
|
|
|
412 |
mpHistory.risky = snapdealItemInfo.risky
|
|
|
413 |
mpHistory.lowestOfferPrice = snapdealDetails.lowestOfferPrice
|
|
|
414 |
mpHistory.lowestSellingPrice = snapdealDetails.lowestSp
|
|
|
415 |
mpHistory.lowestSellerName = snapdealDetails.lowestSellerName
|
|
|
416 |
mpHistory.lowestSellerCode = snapdealDetails.lowestSellerCode
|
|
|
417 |
mpHistory.ourOfferPrice = snapdealDetails.ourOfferPrice
|
|
|
418 |
mpHistory.ourSellingPrice = snapdealPricing.ourSp
|
|
|
419 |
mpHistory.ourTp = snapdealPricing.ourTp
|
|
|
420 |
mpHistory.ourNlc = snapdealItemInfo.nlc
|
|
|
421 |
mpHistory.secondLowestSellerName = snapdealDetails.secondLowestSellerName
|
|
|
422 |
mpHistory.secondLowestSellerCode = snapdealDetails.secondLowestSellerCode
|
| 9885 |
kshitij.so |
423 |
mpHistory.secondLowestSellingPrice = snapdealDetails.secondLowestSellerSp
|
| 9888 |
kshitij.so |
424 |
mpHistory.secondLowestOfferPrice = snapdealDetails.secondLowestSellerOfferPrice
|
| 9881 |
kshitij.so |
425 |
mpHistory.secondLowestTp = snapdealPricing.secondLowestSellerTp
|
|
|
426 |
if (snapdealPricing.competitionBasis=='SP'):
|
|
|
427 |
proposed_sp = max(snapdealDetails.secondLowestSellerSp - max((20, snapdealDetails.secondLowestSellerSp*0.002)), snapdealPricing.lowestPossibleSp)
|
|
|
428 |
proposed_tp = getTargetTp(proposed_sp,mpItem)
|
|
|
429 |
#target_nlc = proposed_tp - snapdealPricing.lowestPossibleTp + snapdealItemInfo.nlc
|
|
|
430 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
431 |
mpHistory.proposedTp = proposed_tp
|
|
|
432 |
#mpHistory.targetNlc = target_nlc
|
|
|
433 |
else:
|
|
|
434 |
proposed_tp = max(snapdealPricing.secondLowestSellerTp - max((20, snapdealPricing.secondLowestSellerTp*0.002)), snapdealPricing.lowestPossibleTp)
|
|
|
435 |
proposed_sp = getTargetSp(proposed_tp,mpItem)
|
|
|
436 |
#target_nlc = proposed_tp - snapdealPricing.lowestPossibleTp + snapdealItemInfo.nlc
|
|
|
437 |
mpHistory.proposedSellingPrice = proposed_sp
|
|
|
438 |
mpHistory.proposedTp = proposed_tp
|
|
|
439 |
#mpHistory.targetNlc = target_nlc
|
|
|
440 |
mpHistory.marginIncreasedPotential = proposed_tp - snapdealPricing.ourTp
|
|
|
441 |
mpHistory.totalSeller = snapdealDetails.totalSeller
|
|
|
442 |
mpHistory.timestamp = timestamp
|
|
|
443 |
session.commit()
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
def getOtherTp(snapdealDetails,val,spm):
|
|
|
447 |
if val.parent_category==10011:
|
|
|
448 |
commissionPercentage = spm.competitorCommissionAccessory
|
|
|
449 |
else:
|
|
|
450 |
commissionPercentage = spm.competitorCommissionOther
|
|
|
451 |
if snapdealDetails.rank==1:
|
|
|
452 |
return snapdealDetails.secondLowestSellerSp- snapdealDetails.secondLowestSellerSp*(commissionPercentage/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost+spm.closingFee)*(1+(spm.serviceTax/100));
|
|
|
453 |
return snapdealDetails.lowestSp- snapdealDetails.lowestSp*(commissionPercentage/100+spm.emiFee/100)*(1+(spm.serviceTax/100))-(val.courierCost+spm.closingFee)*(1+(spm.serviceTax/100));
|
|
|
454 |
|
|
|
455 |
def getLowestPossibleTp(snapdealDetails,val,spm,mpItem):
|
|
|
456 |
if snapdealDetails.rank==0:
|
|
|
457 |
return mpItem.minimumPossibleTp
|
|
|
458 |
vat = (snapdealDetails.ourSp/(1+(val.vatRate/100))-(val.nlc/(1+(val.vatRate/100))))*(val.vatRate/100);
|
|
|
459 |
inHouseCost = 15+vat+(mpItem.returnProvision/100)*snapdealDetails.ourSp+mpItem.otherCost;
|
|
|
460 |
lowest_possible_tp = val.nlc+inHouseCost;
|
|
|
461 |
return lowest_possible_tp
|
|
|
462 |
|
|
|
463 |
def getOurTp(snapdealDetails,val,spm,mpItem):
|
|
|
464 |
if snapdealDetails.rank==0:
|
|
|
465 |
return mpItem.currentTp
|
|
|
466 |
return snapdealDetails.ourSp- snapdealDetails.ourSp*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100));
|
|
|
467 |
|
|
|
468 |
def getLowestPossibleSp(snapdealDetails,val,spm,mpItem):
|
|
|
469 |
if snapdealDetails.rank==0:
|
|
|
470 |
return mpItem.minimumPossibleSp
|
|
|
471 |
return (val.nlc+(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate/100))+(15+mpItem.otherCost)*(1+(val.vatRate)/100))/(1-(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate)/100)-(mpItem.returnProvision/100)*(1+(val.vatRate)/100));
|
|
|
472 |
|
|
|
473 |
def getTargetTp(targetSp,mpItem):
|
|
|
474 |
return targetSp- targetSp*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-(mpItem.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100));
|
|
|
475 |
|
|
|
476 |
def getTargetSp(targetTp,mpItem):
|
|
|
477 |
return targetTp+(mpItem.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100))/(1-((mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))))
|
|
|
478 |
|
|
|
479 |
def getSalesPotential(lowestOfferPrice,ourNlc):
|
|
|
480 |
if lowestOfferPrice - ourNlc < 0:
|
|
|
481 |
return 'HIGH'
|
|
|
482 |
elif (lowestOfferPrice - ourNlc)/lowestOfferPrice >=0 and (lowestOfferPrice - ourNlc)/lowestOfferPrice <=.02:
|
|
|
483 |
return 'MEDIUM'
|
|
|
484 |
else:
|
|
|
485 |
return 'LOW'
|
|
|
486 |
|
|
|
487 |
def main():
|
|
|
488 |
itemInfo,spm= populateStuff()
|
|
|
489 |
cantCompete, buyBoxItems, competitive, \
|
|
|
490 |
competitiveNoInventory, exceptionItems, negativeMargin = decideCategory(itemInfo,spm)
|
|
|
491 |
timestamp = datetime.now()
|
|
|
492 |
commitExceptionList(exceptionItems,timestamp)
|
|
|
493 |
commitCantCompete(cantCompete,timestamp)
|
|
|
494 |
commitBuyBox(buyBoxItems,timestamp)
|
|
|
495 |
commitCompetitive(competitive,timestamp)
|
|
|
496 |
commitCompetitiveNoInventory(competitiveNoInventory,timestamp)
|
|
|
497 |
commitNegativeMargin(negativeMargin,timestamp)
|
|
|
498 |
if __name__ == '__main__':
|
|
|
499 |
main()
|