adselect.stats package¶
adselect.stats.cache module¶
Add keywords to cache per banner per publisher
Parameters: - publisher_id –
- banner_size –
- keyword –
- keyword_score –
- banner_id –
- limit –
Returns:
-
adselect.stats.cache.delete_impression_count(banner_id)[source]¶ Removes banner impression count.
Parameters: banner_id – Banner identifier. Returns:
Reset the KEYWORDS_BANNERS cache to empty.
Returns: None
adselect.stats.tasks module¶
-
adselect.stats.tasks.calculate_last_round_score(*args, **kwargs)[source]¶ Parameters: - publisher_id –
- banner_id –
- keyword –
Returns:
-
adselect.stats.tasks.clean_database(*args, **kwargs)[source]¶ Remove finished campaigns and associated stats.
Returns:
-
adselect.stats.tasks.recalculate_stats(*args, **kwargs)[source]¶ Dump all data from cache to database, reload cache data and recalculate everything.
Returns:
Save scores. 1. Get scores from database. 2. Validate active banners. 3. For each banner get impression count
Returns:
-
adselect.stats.tasks.save_impression_count(*args, **kwargs)[source]¶ Save impression count data from cache to database.
Returns:
-
adselect.stats.tasks.save_keyword_payments(*args, **kwargs)[source]¶ Save payment per keywords data from cache to database.
Returns:
Save scores for new banners
Parameters: db_banners – Set of banners already scored. Returns:
adselect.stats.utils module¶
-
adselect.stats.utils.genkey(key, val, delimiter='_')[source]¶ Generate keyword identifier, ex. {‘animal’: ‘dog’} becomes ‘animal_dog’
Parameters: - key – Key
- val – Value
- delimiter – Delimiter, default “_”
Returns: Generated identifier
Get publisher banners and get only best ones for keywords, with included cutoff.
Parameters: - publisher_id – Id of the publisher
- banner_size – Banner size
- sbest_pi_keys – Best paid keywords
- banners_per_keyword_cutoff – Number of banners returned
Returns:
-
adselect.stats.utils.initialize_stats(*args, **kwargs)[source]¶ Initialize data cache. Load data from the database into memory.
Returns:
Check if banner is in the database, together with the campaign and if the campaign is active.
Parameters: banner – Banner id or banner document. Returns: True or False
-
adselect.stats.utils.is_campaign_active(campaign_doc)[source]¶ Compare campaign’s start and end times with current time.
Parameters: campaign_doc – Campaign document. Returns: True for active campaigns, False for inactive.
-
adselect.stats.utils.iterate_deferred(*args, **kwargs)[source]¶ Auxiliary function to iterate a function over a deferred resource.
Parameters: - deferred – Deferred we iteravet over
- func – Function executed for each item
Returns: None
Load only active banners to cache.
-
adselect.stats.utils.load_impression_counts(*args, **kwargs)[source]¶ Load impressions/events counts to cache.
-
adselect.stats.utils.load_scores(*args, **kwargs)[source]¶ Load best paid keywords taking into account scores.
- Get banner scores.
- For each one, get banner.
- Get
Parameters: scores_db_stats –
Add new banners without payment statistic
Parameters: - selected_banners – Pre-selected banners
- propositions_nb – Amount of banners returned
- new_banners – Banners with amount of payments below threshold
Returns:
-
adselect.stats.utils.process_impression(banner_id, publisher_id, impression_keywords, paid_amount, increment=True)[source]¶ Update impression cache.
- Increase impression count.
- If paid (paid > 0), update keyword paid amount.
Parameters: - banner_id – Banner identifier.
- publisher_id – Publisher identifier.
- impression_keywords – Dictionary of keywords (with values).
- paid_amount – Amount paid for the impression.
- increment – Increment views
Returns:
Select banners with appropriate size for given keywords.
- Get best paid keywords (limited to a cutoff value)
- Find common keywords from given keywords and best paid keywords.
- Find best paid banners for give keywords and size.
- Add new banners, which have no payments statistic yet.
- Shuffle the banners.
- Return a list of banners, size limited to the defined cutoff value.
Parameters: - publisher_id – Publisher identifier.
- banner_size – Banner size (width x height) in string format.
- sbest_pi_keys – Best Keywords for this impression and publisher
Returns: List of banners.
-
adselect.stats.utils.select_best_keywords(publisher_id, banner_size, impression_keywords_dict, best_keywords_cutoff=100)[source]¶ Parameters: - publisher_id – Publisher identifier.
- banner_size – Banner size (width x height) in string format.
- impression_keywords_dict – Dictionary of keywords for the request.
- best_keywords_cutoff – Cutoff of the number of best paid keywords taking into account.
Returns:
Return banners ids without payment statistic.
The function doesn’t allow to display banners more than notpaid_display_cutoff times without payment.
- Get banners with the right size.
- Choose random banners from that population.
- Filter out banners which were displayed less times than notpaid_display_cutoff
- Return chosen banners.
Parameters: - publisher_id – Publisher identifier.
- banner_size – Banner size (width x height) in string format.
- new_banners_proposition_nb – The max amount of new banners.
Returns: List of banners.