Subversion Repositories SmartDukaan

Rev

Rev 15349 | Rev 15376 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15349 Rev 15375
Line 11... Line 11...
11
from elixir import *
11
from elixir import *
12
from operator import itemgetter
12
from operator import itemgetter
13
import pymongo
13
import pymongo
14
import re
14
import re
15
import traceback
15
import traceback
-
 
16
import random
16
 
17
 
17
con = None
18
con = None
18
 
19
 
19
DataService.initialize(db_hostname="localhost")
20
DataService.initialize(db_hostname="localhost")
20
mc = MemCache("127.0.0.1")
21
mc = MemCache("127.0.0.1")
Line 1196... Line 1197...
1196
                    brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
1197
                    brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
1197
      
1198
      
1198
        mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)  
1199
        mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)  
1199
    
1200
    
1200
    return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
1201
    return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
-
 
1202
 
-
 
1203
def getStaticDeals(offset, limit, category_id):
-
 
1204
    user_specific_deals = mc.get("staticDeals")
-
 
1205
    if user_specific_deals is None:
-
 
1206
        __populateStaticDeals()
-
 
1207
        user_specific_deals = mc.get("staticDeals")
-
 
1208
    return (user_specific_deals.get(category_id))[offset:offset+limit]
-
 
1209
 
-
 
1210
def __populateStaticDeals():
-
 
1211
    print "Populating memcache for static deals"
-
 
1212
    outer_query = []
-
 
1213
    outer_query.append({"showDeal":1})
-
 
1214
    query = {}
-
 
1215
    query['$gte'] = -100
-
 
1216
    outer_query.append({'totalPoints':query})
1201
        
1217
    all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
-
 
1218
    mobile_deals = []
-
 
1219
    tablet_deals = []
-
 
1220
    for deal in all_deals:
-
 
1221
        item = get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']})
-
 
1222
        if deal['category_id'] ==3:
-
 
1223
            mobile_deals.append(getItemObjForStaticDeals(item[0]))
-
 
1224
        elif deal['category_id'] ==5:
-
 
1225
            tablet_deals.append(getItemObjForStaticDeals(item[0]))
-
 
1226
        else:
-
 
1227
            continue
-
 
1228
    
-
 
1229
    random.shuffle(mobile_deals,random.random)
-
 
1230
    random.shuffle(tablet_deals,random.random)
-
 
1231
    
-
 
1232
    mem_cache_val = {3:mobile_deals, 5:tablet_deals}
-
 
1233
    mc.set("staticDeals", mem_cache_val, 3600)
-
 
1234
 
-
 
1235
def getItemObjForStaticDeals(item):
-
 
1236
    return {'marketPlaceUrl':item.get('marketPlaceUrl'),'available_price':item.get('available_price')}
-
 
1237
    
1202
def main():
1238
def main():
1203
    getNewDeals(47, 3, 0, 20, None, None, "brandFilter:64")
1239
    #print getNewDeals(47, 3, 0, 20, None, None, "brandFilter:64")
-
 
1240
    #mc.delete(str(-1))
-
 
1241
    staticDeals = getStaticDeals(0,20,3)
-
 
1242
    print "========="
-
 
1243
    for y in staticDeals:
-
 
1244
        print y
-
 
1245
    
1204
    
1246
    
1205
    
1247
    
1206
if __name__=='__main__':
1248
if __name__=='__main__':
1207
    main()
1249
    main()