Skip to content

Commit

Permalink
Adding new adstxt queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Jan 29, 2025
1 parent f181cec commit 36edacc
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
30 changes: 20 additions & 10 deletions backend/api_app/controllers/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,30 @@ async def company_overview(
df = get_company_overview(company_domain=company_domain)

if df["tag_source"].str.contains("app_ads").any():
ad_domain_overview = get_company_adstxt_ad_domain_overview(
company_domain
).to_dict(orient="records")
publishers_overview = get_company_adstxt_publishers_overview(
company_domain
).to_dict(orient="records")
ad_domain_overview = get_company_adstxt_ad_domain_overview(company_domain)
final_ad_domain_overview = (
ad_domain_overview.set_index(["store", "relationship"])
.groupby(level=[0, 1])
.apply(lambda x: x.iloc[0].dropna().to_dict())
.unstack(level=0)
.to_dict()
)
publishers_overview = get_company_adstxt_publishers_overview(company_domain)
final_publishers_overview = (
publishers_overview.set_index(["store", "relationship"])
.groupby(level=[0, 1])
.apply(lambda x: x.to_dict(orient="records"))
.unstack(level=0)
.to_dict()
)
else:
ad_domain_overview = None
publishers_overview = None
final_ad_domain_overview = None
final_publishers_overview = None

overview = make_company_category_sums(df=df)

overview.adstxt_ad_domain_overview = ad_domain_overview
overview.adstxt_publishers_overview = publishers_overview
overview.adstxt_ad_domain_overview = final_ad_domain_overview
overview.adstxt_publishers_overview = final_publishers_overview

duration = round((time.perf_counter() * 1000 - start), 2)
logger.info(f"GET /api/companies/{company_domain} took {duration}ms")
Expand Down
4 changes: 4 additions & 0 deletions backend/dbcon/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ def get_company_adstxt_publishers_overview(
DBCON.engine,
params={"ad_domain_url": ad_domain_url, "pubrank_limit": limit},
)
df["store"] = df["store"].replace({1: "google", 2: "apple"})
df["relationship"] = df["relationship"].str.lower()
return df


Expand All @@ -388,6 +390,8 @@ def get_company_adstxt_ad_domain_overview(ad_domain_url: str) -> pd.DataFrame:
DBCON.engine,
params={"ad_domain_url": ad_domain_url},
)
df["store"] = df["store"].replace({1: "google", 2: "apple"})
df["relationship"] = df["relationship"].str.lower()
return df


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script lang="ts">
import type { CompanyFullDetails } from '../../../../types';
import CompanyCategoryPie from '$lib/CompanyCategoryPie.svelte';
import AdsTxtPubIDsTable from '$lib/AdsTxtPubIDsTable.svelte';
import CompanyCategoryPie from '$lib/CompanyCategoryPie.svelte';
import AdsTxtTotalsBox from '$lib/AdsTxtTotalsBox.svelte';
import CompanyTableGrid from '$lib/CompanyTableGrid.svelte';
import CompanyTree from '$lib/CompanyTree.svelte';
import CompanySDKs from '$lib/CompanySDKs.svelte';
Expand Down Expand Up @@ -37,6 +39,11 @@
>{formatNumber(myData.map((d) => d.value).reduce((a, b) => a + b, 0))}</span
>
</p>
{#await data.companyDetails}
<div><span>Loading...</span></div>
{:then detailsData}
<AdsTxtTotalsBox myTotals={detailsData.adstxt_ad_domain_overview} />
{/await}
</WhiteCard>
{/if}
{:catch error}
Expand Down Expand Up @@ -108,6 +115,18 @@
{#await data.companyDetails}
<div><span>Loading...</span></div>
{:then detailsData}
<div class="card preset-tonal p-2 md:p-8 mt-2 md:mt-4">
<div class="grid md:grid-cols-2 gap-4">
<div>
<h2 class="text-lg font-semibold mb-4">ANDROID DIRECT PUBLISHER IDS</h2>
<AdsTxtPubIDsTable entries_table={detailsData.adstxt_publishers_overview.google.direct} />
</div>
<div>
<h2 class="text-lg font-semibold mb-4">IOS DIRECT PUBLISHER IDS</h2>
<AdsTxtPubIDsTable entries_table={detailsData.adstxt_publishers_overview.apple.direct} />
</div>
</div>
</div>
{#await data.companyTopApps}
<div><span>Loading...</span></div>
{:then tableData}
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,37 @@ export interface CompanyPatternsDict {
};
}

export interface AdsTxtAdDomainDetails {
publisher_id_count: number;
develoepr_count: number;
app_count: number;
}

export interface AdsTxtAdDomainOverview {
google: {
direct: AdsTxtAdDomainDetails;
reseller: AdsTxtAdDomainDetails;
};
apple: {
direct: AdsTxtAdDomainDetails;
reseller: AdsTxtAdDomainDetails;
};
}

export interface AdsTxtPublishersOverview {
google: {
direct: AdsTxtEntries[];
reseller: AdsTxtEntries[];
};
apple: {
direct: AdsTxtEntries[];
reseller: AdsTxtEntries[];
};
}

export interface CompanyCategoryOverview {
adstxt_ad_domain_overview: AdsTxtAdDomainOverview;
adstxt_publishers_overview: AdsTxtPublishersOverview;
categories: {
[key: string]: CategoryAppStats;
};
Expand Down

0 comments on commit 36edacc

Please sign in to comment.