| Line 14... |
Line 14... |
| 14 |
DataService.initialize(db_hostname='localhost')
|
14 |
DataService.initialize(db_hostname='localhost')
|
| 15 |
|
15 |
|
| 16 |
class __SkuInfo:
|
16 |
class __SkuInfo:
|
| 17 |
|
17 |
|
| 18 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
18 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 19 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal,persPoints):
|
19 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal,persPoints, \
|
| - |
|
20 |
fav_weight,brand_weight,asp_weight):
|
| 20 |
self._id = _id
|
21 |
self._id = _id
|
| 21 |
self.skuBundleId = skuBundleId
|
22 |
self.skuBundleId = skuBundleId
|
| 22 |
self.category_id = category_id
|
23 |
self.category_id = category_id
|
| 23 |
self.mrp = mrp
|
24 |
self.mrp = mrp
|
| 24 |
self.available_price = available_price
|
25 |
self.available_price = available_price
|
| Line 36... |
Line 37... |
| 36 |
self.totalPoints = totalPoints
|
37 |
self.totalPoints = totalPoints
|
| 37 |
self.in_stock = in_stock
|
38 |
self.in_stock = in_stock
|
| 38 |
self.maxprice = maxprice
|
39 |
self.maxprice = maxprice
|
| 39 |
self.showDeal = showDeal
|
40 |
self.showDeal = showDeal
|
| 40 |
self.persPoints = persPoints
|
41 |
self.persPoints = persPoints
|
| - |
|
42 |
self.fav_weight = fav_weight
|
| - |
|
43 |
self.brand_weight = brand_weight
|
| - |
|
44 |
self.asp_weight = asp_weight
|
| - |
|
45 |
|
| 41 |
|
46 |
|
| 42 |
def get_mongo_connection(host='localhost', port=27017):
|
47 |
def get_mongo_connection(host='localhost', port=27017):
|
| 43 |
global con
|
48 |
global con
|
| 44 |
if con is None:
|
49 |
if con is None:
|
| 45 |
print "Establishing connection %s host and port %d" %(host,port)
|
50 |
print "Establishing connection %s host and port %d" %(host,port)
|
| Line 107... |
Line 112... |
| 107 |
asp_weight = 1
|
112 |
asp_weight = 1
|
| 108 |
else:
|
113 |
else:
|
| 109 |
asp_weight = 1
|
114 |
asp_weight = 1
|
| 110 |
|
115 |
|
| 111 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
116 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
| - |
|
117 |
|
| - |
|
118 |
deal['fav_weight'] = fav_weight
|
| - |
|
119 |
deal['brand_weight'] = brand_weight
|
| - |
|
120 |
deal['asp_weight'] = asp_weight
|
| 112 |
deal['persPoints'] = persPoints
|
121 |
deal['persPoints'] = persPoints
|
| 113 |
|
122 |
|
| 114 |
all_category_deals.append(deal)
|
123 |
all_category_deals.append(deal)
|
| 115 |
|
124 |
|
| 116 |
|
125 |
|
| 117 |
sorted_deals = sorted(all_category_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
126 |
sorted_deals = sorted(all_category_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 118 |
p = []
|
127 |
p = []
|
| 119 |
for x in sorted_deals:
|
128 |
for x in sorted_deals:
|
| 120 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
129 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
| 121 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
130 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
| 122 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['persPoints'])
|
131 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['persPoints'],deal['fav_weight'],deal['brand_weight'],deal['asp_weight'])
|
| 123 |
p.append(s_info)
|
132 |
p.append(s_info)
|
| 124 |
|
133 |
|
| 125 |
|
134 |
|
| 126 |
wbk = xlwt.Workbook()
|
135 |
wbk = xlwt.Workbook()
|
| 127 |
sheet = wbk.add_sheet('User Deals')
|
136 |
sheet = wbk.add_sheet('User Deals')
|
| Line 158... |
Line 167... |
| 158 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
167 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
| 159 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
168 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
| 160 |
sheet.write(0, 25, "Total Points", heading_xf)
|
169 |
sheet.write(0, 25, "Total Points", heading_xf)
|
| 161 |
sheet.write(0, 26, "Pers Points", heading_xf)
|
170 |
sheet.write(0, 26, "Pers Points", heading_xf)
|
| 162 |
sheet.write(0, 27, "Show Deals", heading_xf)
|
171 |
sheet.write(0, 27, "Show Deals", heading_xf)
|
| - |
|
172 |
sheet.write(0, 28, "Fav Weight", heading_xf)
|
| - |
|
173 |
sheet.write(0, 29, "Brand Weight", heading_xf)
|
| - |
|
174 |
sheet.write(0, 30, "Asp Weight", heading_xf)
|
| 163 |
|
175 |
|
| 164 |
it = 1
|
176 |
it = 1
|
| 165 |
for x in p:
|
177 |
for x in p:
|
| 166 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
178 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
| 167 |
sheet.write(it, 0, x._id)
|
179 |
sheet.write(it, 0, x._id)
|
| Line 200... |
Line 212... |
| 200 |
sheet.write(it, 23, x.nlcPoints)
|
212 |
sheet.write(it, 23, x.nlcPoints)
|
| 201 |
sheet.write(it, 24, x.bestSellerPoints)
|
213 |
sheet.write(it, 24, x.bestSellerPoints)
|
| 202 |
sheet.write(it, 25, x.totalPoints)
|
214 |
sheet.write(it, 25, x.totalPoints)
|
| 203 |
sheet.write(it, 26, x.persPoints)
|
215 |
sheet.write(it, 26, x.persPoints)
|
| 204 |
sheet.write(it, 27, x.showDeal)
|
216 |
sheet.write(it, 27, x.showDeal)
|
| - |
|
217 |
sheet.write(it, 28, x.fav_weight)
|
| - |
|
218 |
sheet.write(it, 29, x.brand_weight)
|
| - |
|
219 |
sheet.write(it, 30, x.asp_weight)
|
| 205 |
it+=1
|
220 |
it+=1
|
| 206 |
filename = "/tmp/deal-data-user-specific"+str(datetime.now())+".xls"
|
221 |
filename = "/tmp/deal-data-user-specific"+str(datetime.now())+".xls"
|
| 207 |
wbk.save(filename)
|
222 |
wbk.save(filename)
|
| 208 |
smtpServer = smtplib.SMTP('localhost')
|
223 |
smtpServer = smtplib.SMTP('localhost')
|
| 209 |
#smtpServer.set_debuglevel(1)
|
224 |
#smtpServer.set_debuglevel(1)
|