mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 23:08:22 -05:00
Remove unused PromoteDates code
This commit is contained in:
@@ -223,53 +223,6 @@ def pushup_permacache(verbosity=1000):
|
||||
print 'Done %d: %r' % (done, keys[-1])
|
||||
populate(keys)
|
||||
|
||||
# alter table bids DROP constraint bids_pkey;
|
||||
# alter table bids add column campaign integer;
|
||||
# update bids set campaign = 0;
|
||||
# alter table bids ADD primary key (transaction, campaign);
|
||||
def promote_v2():
|
||||
# alter table bids add column campaign integer;
|
||||
# update bids set campaign = 0;
|
||||
from r2.models import Link, NotFound, PromoteDates, Bid
|
||||
from datetime import datetime
|
||||
from pylons import g
|
||||
for p in PromoteDates.query():
|
||||
try:
|
||||
l = Link._by_fullname(p.thing_name,
|
||||
data = True, return_dict = False)
|
||||
if not l:
|
||||
raise NotFound, p.thing_name
|
||||
|
||||
# update the promote status
|
||||
l.promoted = True
|
||||
l.promote_status = getattr(l, "promote_status", STATUS.unseen)
|
||||
l._date = datetime(*(list(p.start_date.timetuple()[:7]) + [g.tz]))
|
||||
set_status(l, l.promote_status)
|
||||
|
||||
# add new campaign
|
||||
print (l, (p.start_date, p.end_date), p.bid, None)
|
||||
if not p.bid:
|
||||
print "no bid? ", l
|
||||
p.bid = 20
|
||||
new_campaign(l, (p.start_date, p.end_date), p.bid, None)
|
||||
print "updated: %s (%s)" % (l, l._date)
|
||||
|
||||
except NotFound:
|
||||
print "NotFound: %s" % p.thing_name
|
||||
|
||||
print "updating campaigns"
|
||||
for b in Bid.query():
|
||||
l = Link._byID(int(b.thing_id))
|
||||
print "updating: ", l
|
||||
campaigns = getattr(l, "campaigns", {}).copy()
|
||||
indx = b.campaign
|
||||
if indx in campaigns:
|
||||
sd, ed, bid, sr, trans_id = campaigns[indx]
|
||||
campaigns[indx] = sd, ed, bid, sr, b.transaction
|
||||
l.campaigns = campaigns
|
||||
l._commit()
|
||||
else:
|
||||
print "no campaign information: ", l
|
||||
|
||||
def port_cassavotes():
|
||||
from r2.models import Vote, Account, Link, Comment
|
||||
|
||||
@@ -343,137 +343,7 @@ class Bid(Sessionized, Base):
|
||||
def refund(self):
|
||||
self.set_status(self.STATUS.REFUND)
|
||||
|
||||
#TODO: decommission and drop tables once the patch is working
|
||||
class PromoteDates(Sessionized, Base):
|
||||
__tablename__ = "promote_date"
|
||||
|
||||
thing_name = Column(String, primary_key = True, autoincrement = False)
|
||||
|
||||
account_id = Column(BigInteger, index = True, autoincrement = False)
|
||||
|
||||
start_date = Column(Date(), nullable = False, index = True)
|
||||
end_date = Column(Date(), nullable = False, index = True)
|
||||
|
||||
actual_start = Column(DateTime(timezone = True), index = True)
|
||||
actual_end = Column(DateTime(timezone = True), index = True)
|
||||
|
||||
bid = Column(Float)
|
||||
refund = Column(Float)
|
||||
|
||||
@classmethod
|
||||
def update(cls, thing, start_date, end_date):
|
||||
try:
|
||||
promo = cls.one(thing)
|
||||
promo.start_date = start_date.date()
|
||||
promo.end_date = end_date.date()
|
||||
promo._commit()
|
||||
except NotFound:
|
||||
promo = cls._new(thing, thing.author_id, start_date, end_date)
|
||||
|
||||
@classmethod
|
||||
def update_bid(cls, thing):
|
||||
bid = thing.promote_bid
|
||||
refund = 0
|
||||
if thing.promote_trans_id < 0:
|
||||
refund = bid
|
||||
elif hasattr(thing, "promo_refund"):
|
||||
refund = thing.promo_refund
|
||||
promo = cls.one(thing)
|
||||
promo.bid = bid
|
||||
promo.refund = refund
|
||||
promo._commit()
|
||||
|
||||
@classmethod
|
||||
def log_start(cls, thing):
|
||||
promo = cls.one(thing)
|
||||
promo.actual_start = datetime.datetime.now(g.tz)
|
||||
promo._commit()
|
||||
cls.update_bid(thing)
|
||||
|
||||
@classmethod
|
||||
def log_end(cls, thing):
|
||||
promo = cls.one(thing)
|
||||
promo.actual_end = datetime.datetime.now(g.tz)
|
||||
promo._commit()
|
||||
cls.update_bid(thing)
|
||||
|
||||
@classmethod
|
||||
def for_date(cls, date):
|
||||
if isinstance(date, datetime.datetime):
|
||||
date = date.date()
|
||||
q = cls.query().filter(and_(cls.start_date <= date,
|
||||
cls.end_date > date))
|
||||
return q.all()
|
||||
|
||||
@classmethod
|
||||
def for_date_range(cls, start_date, end_date, account_id = None):
|
||||
if isinstance(start_date, datetime.datetime):
|
||||
start_date = start_date.date()
|
||||
if isinstance(end_date, datetime.datetime):
|
||||
end_date = end_date.date()
|
||||
# Three cases to be included:
|
||||
# 1) start date is in the provided interval
|
||||
start_inside = and_(cls.start_date >= start_date,
|
||||
cls.start_date < end_date)
|
||||
# 2) end date is in the provided interval
|
||||
end_inside = and_(cls.end_date >= start_date,
|
||||
cls.end_date < end_date)
|
||||
# 3) interval is a subset of a promoted interval
|
||||
surrounds = and_(cls.start_date <= start_date,
|
||||
cls.end_date >= end_date)
|
||||
|
||||
q = cls.query().filter(or_(start_inside, end_inside, surrounds))
|
||||
if account_id is not None:
|
||||
q = q.filter(cls.account_id == account_id)
|
||||
|
||||
return q.all()
|
||||
|
||||
@classmethod
|
||||
@memoize('promodates.bid_history', time = 10 * 60)
|
||||
def bid_history(cls, start_date, end_date = None, account_id = None):
|
||||
end_date = end_date or datetime.datetime.now(g.tz)
|
||||
q = cls.for_date_range(start_date, end_date, account_id = account_id)
|
||||
|
||||
d = start_date.date()
|
||||
end_date = end_date.date()
|
||||
res = []
|
||||
while d < end_date:
|
||||
bid = 0
|
||||
refund = 0
|
||||
for i in q:
|
||||
end = i.actual_end.date() if i.actual_end else i.end_date
|
||||
start = i.actual_start.date() if i.actual_start else None
|
||||
if start and start <= d and end > d:
|
||||
duration = float((end - start).days)
|
||||
bid += i.bid / duration
|
||||
refund += i.refund / duration
|
||||
res.append([d, bid, refund])
|
||||
d += datetime.timedelta(1)
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
@memoize('promodates.top_promoters', time = 10 * 60)
|
||||
def top_promoters(cls, start_date, end_date = None):
|
||||
end_date = end_date or datetime.datetime.now(g.tz)
|
||||
q = cls.for_date_range(start_date, end_date)
|
||||
|
||||
d = start_date
|
||||
res = []
|
||||
accounts = Account._byID([i.account_id for i in q],
|
||||
return_dict = True, data = True)
|
||||
res = {}
|
||||
for i in q:
|
||||
if i.bid is not None and i.actual_start is not None:
|
||||
r = res.setdefault(i.account_id, [0, 0, set()])
|
||||
r[0] += i.bid
|
||||
r[1] += i.refund
|
||||
r[2].add(i.thing_name)
|
||||
res = [ ([accounts[k]] + v) for (k, v) in res.iteritems() ]
|
||||
res.sort(key = lambda x: x[1] - x[2], reverse = True)
|
||||
|
||||
return res
|
||||
|
||||
# eventual replacement for PromoteDates
|
||||
class PromotionWeights(Sessionized, Base):
|
||||
__tablename__ = "promotion_weight"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user