import pandas as pd from tadas.domain import trending_flags from tadas.models.t2509_snowflake.model_config import TRENDING_FLAGS def test_apply_trending_flag(): df = pd.DataFrame({ 'seven_apple_search_streams': [200, 300, 200, 300], 'wow_apple_search_streams': [0.8, 0.5, 0.5, 0.8], }) trending_flags.apply_trending_flag( df=df, flag_name='apple_search', reference_column='wow_apple_search_streams', is_trending_lambda=lambda df: ( (df['seven_apple_search_streams'] >= 250) & (df['wow_apple_search_streams'] >= .65) ), ) assert df['apple_search_flag'].tolist() == [0, 0, 0, 1] assert df['apple_search_lift'].tolist() == [0.8, 0.5, 0.5, 0.8] def test_apply_trending_flags(): df = pd.DataFrame({ 'spotify_collection_streams': [200, 300], 'wow_spotify_collection_streams': [200, 300], 'wow_spotify_active_streams': [200, 300], 'spotify_search_streams': [200, 300], 'wow_spotify_streams': [200, 300], 'wow_spotify_search_streams': [200, 300], 'wow_apple_active_streams': [200, 300], 'seven_apple_search_streams': [200, 300], 'wow_apple_search_streams': [0.8, 0.5], 'seven_apple_streams': [200, 300], 'wow_apple_streams': [0.8, 0.5], 'tt_creations': [200, 300], 'wow_tt_creations': [200, 300], 'tt_likes': [200, 300], 'wow_tt_likes': [200, 300], 'tt_views': [200, 300], 'wow_tt_views': [200, 300], }) trending_flags.apply_trending_flags(df, TRENDING_FLAGS) assert df.to_dict(orient='records') == [ {'apple_all_flag': 1, 'apple_all_lift': 0.8, 'apple_lean_forward_flag': 1, 'apple_lean_forward_lift': 200, 'apple_search_flag': 0, 'apple_search_lift': 0.8, 'insta_reels_creations_country_flag': 0, 'insta_reels_creations_country_lift': 0.0, 'insta_reels_creations_global_flag': 0, 'insta_reels_creations_global_lift': 0.0, 'insta_reels_views_country_flag': 0, 'insta_reels_views_country_lift': 0.0, 'insta_reels_views_global_flag': 0, 'insta_reels_views_global_lift': 0.0, 'seven_apple_search_streams': 200, 'seven_apple_streams': 200, 'shazam_flag': 0, 'shazam_lift': 0.8, 'spotify_all_flag': 1, 'spotify_all_lift': 200, 'spotify_collection_flag': 0, 'spotify_collection_lift': 200, 'spotify_collection_streams': 200, 'spotify_lean_forward_flag': 1, 'spotify_lean_forward_lift': 200, 'spotify_search_flag': 0, 'spotify_search_lift': 200, 'spotify_search_streams': 200, 'tiktok_creations_country_flag': 1, 'tiktok_creations_country_lift': 200, 'tiktok_creations_global_flag': 0, 'tiktok_creations_global_lift': 200, 'tiktok_likes_country_flag': 0, 'tiktok_likes_country_lift': 200, 'tiktok_likes_global_flag': 0, 'tiktok_likes_global_lift': 200, 'tiktok_views_country_flag': 0, 'tiktok_views_country_lift': 200, 'tiktok_views_global_flag': 0, 'tiktok_views_global_lift': 200, 'tt_creations': 200, 'tt_likes': 200, 'tt_views': 200, 'wow_apple_active_streams': 200, 'wow_apple_search_streams': 0.8, 'wow_apple_streams': 0.8, 'wow_spotify_active_streams': 200, 'wow_spotify_collection_streams': 200, 'wow_spotify_search_streams': 200, 'wow_spotify_streams': 200, 'wow_tt_creations': 200, 'wow_tt_likes': 200, 'wow_tt_views': 200}, {'apple_all_flag': 1, 'apple_all_lift': 0.5, 'apple_lean_forward_flag': 1, 'apple_lean_forward_lift': 300, 'apple_search_flag': 1, 'apple_search_lift': 0.5, 'insta_reels_creations_country_flag': 0, 'insta_reels_creations_country_lift': 0.0, 'insta_reels_creations_global_flag': 0, 'insta_reels_creations_global_lift': 0.0, 'insta_reels_views_country_flag': 0, 'insta_reels_views_country_lift': 0.0, 'insta_reels_views_global_flag': 0, 'insta_reels_views_global_lift': 0.0, 'seven_apple_search_streams': 300, 'seven_apple_streams': 300, 'shazam_flag': 0, 'shazam_lift': 0.5, 'spotify_all_flag': 1, 'spotify_all_lift': 300, 'spotify_collection_flag': 1, 'spotify_collection_lift': 300, 'spotify_collection_streams': 300, 'spotify_lean_forward_flag': 1, 'spotify_lean_forward_lift': 300, 'spotify_search_flag': 1, 'spotify_search_lift': 300, 'spotify_search_streams': 300, 'tiktok_creations_country_flag': 1, 'tiktok_creations_country_lift': 300, 'tiktok_creations_global_flag': 0, 'tiktok_creations_global_lift': 300, 'tiktok_likes_country_flag': 0, 'tiktok_likes_country_lift': 300, 'tiktok_likes_global_flag': 0, 'tiktok_likes_global_lift': 300, 'tiktok_views_country_flag': 0, 'tiktok_views_country_lift': 300, 'tiktok_views_global_flag': 0, 'tiktok_views_global_lift': 300, 'tt_creations': 300, 'tt_likes': 300, 'tt_views': 300, 'wow_apple_active_streams': 300, 'wow_apple_search_streams': 0.5, 'wow_apple_streams': 0.5, 'wow_spotify_active_streams': 300, 'wow_spotify_collection_streams': 300, 'wow_spotify_search_streams': 300, 'wow_spotify_streams': 300, 'wow_tt_creations': 300, 'wow_tt_likes': 300, 'wow_tt_views': 300} ]