Exemple #1
0
def get_cr():

    res = get_stats()

    out = (seq(res.data['data'])
           .map(lambda row: row['Stat'])
           .filter(lambda row: int(row['clicks']) >= get_offer_min_clicks(row['offer_id']))
           .filter(lambda row: offer_exists_and_monitoring_true(row['offer_id']))
           .map(lambda row: update_in(row, ['clicks'], int))
           .map(lambda row: update_in(row, ['conversions'], int))
           .map(lambda row: assoc(row, 'value', cr(row['clicks'], row['conversions'])))
           .to_list())

    metric = Metric.objects.get(key='cr')

    for row in out:
        metric_log = MetricLog()
        metric_log.offer_id = row['offer_id']
        metric_log.affiliate_id = row['affiliate_id']
        metric_log.metric = metric
        metric_log.value = row['value']
        metric_log.save()

        min_cr_trigger.delay(metric_log)
        max_cr_trigger.delay(metric_log)
Exemple #2
0
def get_cr():
    print("Getting CR stats")
    data = get_stats()

    # todo: enqueue every row to metric processor
    #       transform
    #       filter
    out = (seq(data)
           .map(lambda row: row['Stat'])
           .filter(lambda row: (
               int(row['clicks']) >= get_offer_min_clicks(row['offer_id'])))
           .filter(lambda row: (
               offer_exists_and_monitoring_true(row['offer_id'])))
           .map(lambda row: update_in(row, ['clicks'], int))
           .map(lambda row: update_in(row, ['conversions'], int))
           .map(lambda row: (
               assoc(row, 'value', cr(row['clicks'], row['conversions']))))
           .to_list())

    metric = Metric.objects.get(key='cr')

    for row in out:
        metric_log = MetricLog()
        metric_log.offer_id = row['offer_id']
        metric_log.affiliate_id = row['affiliate_id']
        metric_log.metric = metric
        metric_log.value = row['value']
        metric_log.save()

        celery_pubsub.publish('metric.loaded', metric_log)
def get_capfill():
    print("Gettings CAP stats")
    prefs = get_prefs()
    res = get_stats(prefs['lookback'])

    out = (seq(res.data['data'])
           .map(lambda row: row['Stat'])
           # .filter(lambda row: int(row['clicks']) >= min_clicks)
           .filter(lambda row: (
               offer_exists_and_monitoring_true(row['offer_id'])))
           .map(lambda row: update_in(row, ['conversions'], int))
           .map(lambda row: (
               assoc(row, 'conversion_cap',
                     get_conversion_cap(row['offer_id'],
                                        row['affiliate_id']))))
           .filter(lambda row: row['conversion_cap'] > 0)
           .map(lambda row: (
               assoc(row, 'value', ((row['conversions'] / prefs['lookback'])
                                    / row['conversion_cap']))))
           .to_list())

    metric = Metric.objects.get(key='cap_fill')

    for row in out:
        metric_log = MetricLog()
        metric_log.offer_id = row['offer_id']
        metric_log.affiliate_id = row['affiliate_id']
        metric_log.metric = metric
        metric_log.value = row['value']
        metric_log.save()

        celery_pubsub.publish('metric.loaded', metric_log)
Exemple #4
0
def get_gr():

    offer_ids = fetch_active_offers()
    offer_ids = list(filter(offer_exists_and_monitoring_true, offer_ids))
    offer_ids = list(filter(offer_has_goal, offer_ids))

    for offer_id in offer_ids:
        offer = Offer.objects.get(pk=offer_id)

        # get stats for the offer
        stats = get_stats(offer_id, offer.one_goal_id, offer.lookback)

        out = (seq(stats)
               .map(lambda row: update_in(row, ['conversions'], int))
               .map(lambda row: update_in(row, ['goal_id'], int))
               .map(lambda row: update_in(row, ['affiliate_id'], int))
               .to_list())

        conversions = seq(out).filter(lambda r: r['goal_id'] == 0).to_list()  # [{aff_id, conversions, goal_id}]
        goals = seq(out).filter(lambda r: r['goal_id'] == offer.one_goal_id).to_list()

        # filter min_conversions
        conversions = seq(conversions).filter(lambda r: r['conversions'] >= offer.min_conversions).to_list()

        # populate with goal count
        conversions = (seq(conversions)
                       .map(lambda r: assoc(r, 'goals', get_goals_count(r['affiliate_id'], goals)))
                       .to_list())

        # populate with gr value
        conversions = (seq(conversions)
                       .map(lambda r: assoc(r, 'value', gr(r['conversions'], r['goals'])))
                       .to_list())

        # create metric
        metric = Metric.objects.get(key='gtr')

        for row in conversions:
            metric_log = MetricLog()
            metric_log.offer_id = offer_id
            metric_log.affiliate_id = row['affiliate_id']
            metric_log.metric = metric
            metric_log.value = row['value']
            metric_log.save()

            # run trigger worker
            min_gr_trigger.delay(metric_log)
Exemple #5
0
def get_pacc():

    api = Hasoffers(network_token=settings.HASOFFERS_NETWORK_TOKEN,
                    network_id=settings.HASOFFERS_NETWORK_ID,
                    proxies=settings.PROXIES)

    from_date = datetime.datetime.now(pytz.timezone(
        settings.TIME_ZONE)) - datetime.timedelta(days=1)

    res = api.Report.getStats(fields=['Stat.gross_clicks', 'Stat.profit'],
                              groups=['Stat.offer_id', 'Stat.affiliate_id'],
                              filters={
                                  'Stat.date': {
                                      'conditional':
                                      'GREATER_THAN_OR_EQUAL_TO',
                                      'values': str(from_date.date())
                                  },
                                  'Stat.hour': {
                                      'conditional':
                                      'GREATER_THAN_OR_EQUAL_TO',
                                      'values': from_date.hour
                                  }
                              },
                              limit=10000)

    out = (seq(
        res.data['data']).map(lambda row: row['Stat']).filter(lambda row: int(
            row['gross_clicks']) >= get_offer_min_clicks(row['offer_id'])).
           filter(lambda row: offer_exists_and_monitoring_true(row['offer_id'])
                  ).map(lambda row: update_in(row, ['profit'], float)).
           map(lambda row: update_in(row, ['gross_clicks'], int)).map(
               lambda row: assoc(row, 'value', (row['profit'] - (row[
                   'gross_clicks'] * settings.CLICK_COST)))).to_list())

    metric = Metric.objects.get(key='pacc')

    for row in out:
        metric_log = MetricLog()
        metric_log.offer_id = row['offer_id']
        metric_log.affiliate_id = row['affiliate_id']
        metric_log.metric = metric
        metric_log.value = row['value']
        metric_log.save()

        pacc_trigger.delay(metric_log)
def get_clicks_if_zero_conv():
    print("Getting Clicks stats")
    api = Hasoffers(network_token=settings.HASOFFERS_NETWORK_TOKEN,
                    network_id=settings.HASOFFERS_NETWORK_ID,
                    proxies=settings.PROXIES)

    from_date = (datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)) -
                 datetime.timedelta(days=1))

    res = api.Report.getStats(fields=['Stat.clicks', 'Stat.conversions'],
                              groups=['Stat.offer_id', 'Stat.affiliate_id'],
                              filters={
                                  'Stat.date': {
                                      'conditional':
                                      'GREATER_THAN_OR_EQUAL_TO',
                                      'values': str(from_date.date())
                                  },
                                  'Stat.hour': {
                                      'conditional':
                                      'GREATER_THAN_OR_EQUAL_TO',
                                      'values': from_date.hour
                                  }
                              },
                              limit=10000)

    out = (seq(
        res.data['data']).map(lambda row: row['Stat']).filter(lambda row: (int(
            row['clicks']) >= get_offer_min_clicks(row['offer_id']))).filter(
                lambda row: (offer_exists_and_monitoring_true(row['offer_id']))
            ).map(lambda row: update_in(row, ['conversions'], int)).map(
                lambda row: update_in(row, ['clicks'], int)).filter(
                    lambda row: row['conversions'] == 0).map(lambda row: assoc(
                        row, 'value', row['clicks'])).to_list())

    metric = Metric.objects.get(key='clicks_zero_conv')

    for row in out:
        metric_log = MetricLog()
        metric_log.offer_id = row['offer_id']
        metric_log.affiliate_id = row['affiliate_id']
        metric_log.metric = metric
        metric_log.value = row['value']
        metric_log.save()

        celery_pubsub.publish('metric.loaded', metric_log)
def load_offer_caps(offer_id):
    api = Hasoffers(network_token=settings.HASOFFERS_NETWORK_TOKEN,
                    network_id=settings.HASOFFERS_NETWORK_ID,
                    proxies=settings.PROXIES)

    resp = api.Offer.getConversionCaps(id=offer_id)

    if resp.data:
        out = (seq(resp.data.items(
        )).map(lambda r: r[1]).map(lambda r: r['OfferConversionCap']).map(
            lambda r: update_in(r, ['offer_id'], int)
        ).map(lambda r: update_in(r, ['affiliate_id'], int)).map(
            lambda r: update_in(r, ['conversion_cap'], int)).map(
                lambda r: dict(offer_id=r['offer_id'],
                               affiliate_id=r['affiliate_id'],
                               conversion_cap=r['conversion_cap'])).to_list())

        for row in out:
            persist_affiliate_cap.delay(row)