Subversion Repositories SmartDukaan

Rev

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

Rev 14259 Rev 14325
Line 4... Line 4...
4
from sqlalchemy.sql.functions import now
4
from sqlalchemy.sql.functions import now
5
from datetime import datetime, timedelta
5
from datetime import datetime, timedelta
6
import pymongo
6
import pymongo
7
from dtr.utils.utils import to_java_date
7
from dtr.utils.utils import to_java_date
8
import optparse
8
import optparse
-
 
9
from dtr.storage.MemCache import MemCache
9
 
10
 
10
dealsMap = {}
11
dealsMap = {}
11
con = None
12
con = None
12
dealsCatalogIds = []
13
dealsCatalogIds = []
13
itemCatalogMap = {}
14
itemCatalogMap = {}
Line 21... Line 22...
21
                      default="localhost",
22
                      default="localhost",
22
                      type="string", help="The HOST where the mongo server is running",
23
                      type="string", help="The HOST where the mongo server is running",
23
                      metavar="mongo_host")
24
                      metavar="mongo_host")
24
 
25
 
25
(options, args) = parser.parse_args()
26
(options, args) = parser.parse_args()
-
 
27
 
-
 
28
mc = MemCache(options.mongoHost)
-
 
29
 
26
DataService.initialize(db_hostname=options.hostname)
30
DataService.initialize(db_hostname=options.hostname)
27
 
31
 
28
def get_mongo_connection(host=options.mongoHost, port=27017):
32
def get_mongo_connection(host=options.mongoHost, port=27017):
29
    global con
33
    global con
30
    if con is None:
34
    if con is None:
Line 119... Line 123...
119
        try:
123
        try:
120
            recomputeDeal(saholicCatalogId['skuBundleId'])
124
            recomputeDeal(saholicCatalogId['skuBundleId'])
121
        except:
125
        except:
122
            print "Unable to compute deal for ",saholicCatalogId['skuBundleId']
126
            print "Unable to compute deal for ",saholicCatalogId['skuBundleId']
123
 
127
 
-
 
128
def populateNegativeDeals():
-
 
129
    negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
-
 
130
    mc.set("negative_deals", negativeDeals, 600)  
-
 
131
 
124
def recomputeDeal(skuBundleId):
132
def recomputeDeal(skuBundleId):
125
    """Lets recompute deal for this bundle"""
133
    """Lets recompute deal for this bundle"""
126
    print "Recomputing for bundleId",skuBundleId
134
    print "Recomputing for bundleId",skuBundleId
127
    
135
    
128
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
136
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
129
    bestPrice = float("inf")
137
    bestPrice = float("inf")
130
    bestOne = None
138
    bestOne = None
131
    bestSellerPoints = 0
139
    bestSellerPoints = 0
132
    toUpdate = []
140
    toUpdate = []
133
    for similarItem in similarItems:
141
    for similarItem in similarItems:
-
 
142
        if mc.get("negativeDeals") is None:
-
 
143
            populateNegativeDeals()
134
        if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price']:
144
        if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negativeDeals"):
135
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
145
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
136
            continue
146
            continue
137
        if similarItem['available_price'] < bestPrice:
147
        if similarItem['available_price'] < bestPrice:
138
            bestOne = similarItem
148
            bestOne = similarItem
139
            bestPrice = similarItem['available_price']
149
            bestPrice = similarItem['available_price']