Пример #1
0
def calc_revenues():
    ad_campaign= dict((e['id'], e['campaign_id']) for e in db.shopping_ad.find())
    revenues_popego= defaultdict(int)
    revenues_boobox= defaultdict(int)

    cursor= db.publisher_shopping_ad.find(timeout=False)
    p= Progress(cursor.count())

    pop_sum= 0
    boo_sum= 0

    for doc in cursor:
        p.inc()
        pub_id= doc['publisher_id']
        camp_id= ad_campaign[doc['shopping_ad_id']]
        deal= get_deal(camp_id, pub_id)
        #XXX
        if any([v is None for v in deal.itervalues()]): continue

        popego= defaultdict(int)
        boobox= defaultdict(int)
        for str_date, subdoc in doc['counters'].iteritems():
            popego['views']+= subdoc.get('views_popego',0)
            popego['clicks']+= subdoc.get('clicks_popego',0)
            popego['actions']+= subdoc.get('actions_popego',0)

            boobox['views']+= subdoc.get('views',0)
            boobox['clicks']+= subdoc.get('clicks',0)
            boobox['actions']+= subdoc.get('actions',0)

        cost_popego= calc_money(deal['paid_pricing_type'], deal['paid_pricing_value'], popego)
        won_popego= calc_money(deal['received_pricing_type'], deal['received_pricing_value'], popego)

        cost_boobox= calc_money(deal['paid_pricing_type'], deal['paid_pricing_value'], boobox)
        won_boobox= calc_money(deal['received_pricing_type'], deal['received_pricing_value'], boobox)

        if won_popego is not None and cost_popego is not None\
            and won_boobox is not None and cost_boobox is not None:
            revenue_popego= won_popego- cost_popego
            revenues_popego[camp_id,pub_id]+= revenue_popego

            revenue_boobox= won_boobox-cost_boobox
            revenues_boobox[camp_id,pub_id]+= revenue_boobox

            # sumo el ratio para comparar sobre el ratio posta
            pop_sum+= popego['views']
            boo_sum+= boobox['views']


    return dict(revenues_popego), dict(revenues_boobox), float(pop_sum)/(pop_sum+boo_sum)
Пример #2
0
def get_deals_distr(popego=False):
    cursor= db.publisher_shopping_ad.find(timeout=False)
    p= Progress(cursor.count())
    paid= defaultdict(int)
    received= defaultdict(int)
    ad_campaign= dict((e['id'], e['campaign_id']) for e in db.shopping_ad.find())
    for doc in cursor:
        p.inc()
        pub_id= doc['publisher_id']
        #if pub_id == 13409 and doc['shopping_ad_id'] == 31975: import ipdb;ipdb.set_trace()
        camp_id= ad_campaign[doc['shopping_ad_id']]
        deal= get_deal(camp_id, pub_id)

        k= 'views' + ('_popego' if popego else '')
        for date, subdoc in doc['counters'].iteritems():
            paid[deal['paid_pricing_type']]+=subdoc.get(k,0)
            received[deal['received_pricing_type']]+=subdoc.get(k,0)
    
    return dict(paid), dict(received)