@@ -50,7 +50,6 @@ def load_sql_file(file_name: str) -> str:
5050QUERY_ADTECH_CATEGORY_TYPE = load_sql_file (
5151 "query_adtech_category_type.sql" ,
5252)
53- QUERY_ADTECH_TYPE = load_sql_file ("query_adtech_type.sql" )
5453QUERY_COMPANY_TOPAPPS = load_sql_file ("query_company_top_apps.sql" )
5554QUERY_COMPANY_TOPAPPS_PARENT = load_sql_file ("query_company_top_apps_parent.sql" )
5655QUERY_COMPANY_TOPAPPS_CATEGORY = load_sql_file ("query_company_top_apps_category.sql" )
@@ -72,7 +71,6 @@ def load_sql_file(file_name: str) -> str:
7271QUERY_PARENT_COMPANY_CATEGORIES = load_sql_file ("query_company_parent_category.sql" )
7372QUERY_COMPANY_CATEGORIES = load_sql_file ("query_company_category.sql" )
7473QUERY_TAG_SOURCE_CATEGORY_TOTALS = load_sql_file ("query_category_totals.sql" )
75- QUERY_TAG_SOURCE_TOTALS = load_sql_file ("query_tag_source_totals.sql" )
7674QUERY_SDKS = load_sql_file ("query_sdks.sql" )
7775QUERY_LATEST_SDKS = load_sql_file ("query_sdks_latest.sql" )
7876QUERY_USER_REQUESTED_LATEST_SDKS = load_sql_file ("query_sdks_user_requested_latest.sql" )
@@ -195,23 +193,43 @@ def get_total_counts() -> pd.DataFrame:
195193 return df
196194
197195
198- def get_adtech_category_type (
196+ def get_companies_category_type (
199197 type_slug : str ,
200198 app_category : str | None = None ,
201199) -> pd .DataFrame :
202200 """Get top companies for a category type."""
203- if app_category :
204- df = pd .read_sql (
205- QUERY_ADTECH_CATEGORY_TYPE ,
206- con = DBCON .engine ,
207- params = {"type_slug" : type_slug , "app_category" : app_category },
208- )
201+ if app_category and app_category == "games" :
202+ app_category = "game%"
203+ df = pd .read_sql (
204+ QUERY_ADTECH_CATEGORY_TYPE ,
205+ con = DBCON .engine ,
206+ params = {"type_slug" : type_slug , "app_category" : app_category },
207+ )
208+ if app_category is None :
209+ df ["app_category" ] = "all"
209210 else :
210- df = pd .read_sql (
211- QUERY_ADTECH_TYPE , con = DBCON .engine , params = {"type_slug" : type_slug }
212- )
211+ df .loc [df ["app_category" ].isna (), "app_category" ] = "None"
212+ if app_category == "game%" :
213+ df .loc [
214+ df ["app_category" ].str .contains ("game" ),
215+ "app_category" ,
216+ ] = "games"
217+ df = (
218+ df .groupby (
219+ [
220+ "store" ,
221+ "tag_source" ,
222+ "company_domain" ,
223+ "company_name" ,
224+ "app_category" ,
225+ "type_url_slug" ,
226+ ]
227+ )[["app_count" ]]
228+ .sum ()
229+ .reset_index ()
230+ )
231+
213232 df ["store" ] = df ["store" ].replace ({1 : "Google Play" , 2 : "Apple App Store" })
214- df .loc [df ["app_category" ].isna (), "app_category" ] = "None"
215233 return df
216234
217235
@@ -326,11 +344,28 @@ def get_companies_parent_overview(app_category: str | None = None) -> pd.DataFra
326344 """Get overview of companies from multiple types like sdk and app-ads.txt."""
327345 logger .info ("query companies parent overview start" )
328346 if app_category :
347+ if app_category == "games" :
348+ app_category = "game%"
329349 df = pd .read_sql (
330350 QUERY_COMPANIES_PARENT_OVERVIEW_CATEGORY ,
331351 DBCON .engine ,
332352 params = {"app_category" : app_category },
333353 )
354+ if app_category == "game%" :
355+ df ["app_category" ] = "games"
356+ df = (
357+ df .groupby (
358+ [
359+ "company_domain" ,
360+ "company_name" ,
361+ "store" ,
362+ "app_category" ,
363+ "tag_source" ,
364+ ]
365+ )[["app_count" ]]
366+ .sum ()
367+ .reset_index ()
368+ )
334369 else :
335370 df = pd .read_sql (QUERY_COMPANIES_PARENT_OVERVIEW , DBCON .engine )
336371 logger .info ("query companies parent overview return" )
@@ -346,6 +381,8 @@ def get_companies_top(
346381) -> pd .DataFrame :
347382 """Get overview of companies from multiple types like sdk and app-ads.txt."""
348383 logger .info ("query companies parent top start" )
384+ if app_category == "games" :
385+ app_category = "game%"
349386 if type_slug :
350387 df = pd .read_sql (
351388 QUERY_COMPANIES_CATEGORY_TYPE_TOP ,
@@ -494,19 +531,36 @@ def get_company_parent_categories(company_domain: str) -> pd.DataFrame:
494531 return df
495532
496533
497- @lru_cache (maxsize = 1 )
498- def get_tag_source_category_totals () -> pd .DataFrame :
534+ @lru_cache (maxsize = 100 )
535+ def get_tag_source_category_totals (app_category : str | None = None ) -> pd .DataFrame :
499536 """Get category totals."""
500- df = pd .read_sql (QUERY_TAG_SOURCE_CATEGORY_TOTALS , DBCON .engine )
501- df = df .rename (columns = {"app_count" : "total_app_count" })
502- df ["store" ] = df ["store" ].replace ({1 : "Google Play" , 2 : "Apple App Store" })
503- return df
504-
537+ if app_category :
538+ if app_category == "games" :
539+ app_category = "game%"
540+ df = pd .read_sql (
541+ QUERY_TAG_SOURCE_CATEGORY_TOTALS ,
542+ DBCON .engine ,
543+ params = {"app_category" : app_category },
544+ )
545+ if app_category == "game%" :
546+ df .loc [
547+ df ["app_category" ].str .contains ("game" ),
548+ "app_category" ,
549+ ] = "games"
505550
506- @lru_cache (maxsize = 1 )
507- def get_tag_source_totals () -> pd .DataFrame :
508- """Get types totals."""
509- df = pd .read_sql (QUERY_TAG_SOURCE_TOTALS , DBCON .engine )
551+ else :
552+ df = pd .read_sql (
553+ QUERY_TAG_SOURCE_CATEGORY_TOTALS ,
554+ DBCON .engine ,
555+ params = {"app_category" : "%" },
556+ )
557+ df ["app_category" ] = "all"
558+ df .loc [df ["app_category" ].isna (), "app_category" ] = "None"
559+ df = (
560+ df .groupby (["app_category" , "store" , "tag_source" ])[["app_count" ]]
561+ .sum ()
562+ .reset_index ()
563+ )
510564 df = df .rename (columns = {"app_count" : "total_app_count" })
511565 df ["store" ] = df ["store" ].replace ({1 : "Google Play" , 2 : "Apple App Store" })
512566 return df
@@ -597,7 +651,7 @@ def get_single_apps_adstxt(store_id: str) -> pd.DataFrame:
597651def get_topapps_for_company (
598652 company_domain : str , mapped_category : str | None = None , limit : int = 20
599653) -> pd .DataFrame :
600- """Get top apps for for a network ."""
654+ """Get top apps for for a company ."""
601655 if mapped_category == "games" :
602656 mapped_category = "game%"
603657
@@ -621,6 +675,20 @@ def get_topapps_for_company(
621675 "mylimit" : limit ,
622676 },
623677 )
678+ if mapped_category == "game%" :
679+ df = (
680+ df .groupby (
681+ [
682+ "company_domain" ,
683+ "store" ,
684+ "tag_source" ,
685+ "name" ,
686+ "store_id" ,
687+ ]
688+ )[["installs" , "rating_count" ]]
689+ .sum ()
690+ .reset_index ()
691+ )
624692 else :
625693 df = pd .read_sql (
626694 QUERY_COMPANY_TOPAPPS_PARENT ,
0 commit comments