Skip to content

Commit

Permalink
Clean up companies tree data
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 31, 2024
1 parent 59d3ac8 commit 9f1062c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 47 deletions.
36 changes: 21 additions & 15 deletions backend/api_app/controllers/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,18 +689,18 @@ async def company_parent_categories(
return df.to_dict(orient="records")

@get(
path="/companies/{company_name:str}/tree",
path="/companies/{queried_domain:str}/tree",
cache=3600,
)
async def company_tree(
self: Self,
company_name: str,
queried_domain: str,
) -> ParentCompanyTree:
"""Handle GET request for company tree.
Args:
----
company_name : str
queried_domain : str
The name of the company to retrieve apps for.
Returns:
Expand All @@ -709,20 +709,25 @@ async def company_tree(
An overview of companies, filtered for the specified company and category.
"""
logger.info(f"GET /api/companies/{company_name}/tree start")
logger.info(f"GET /api/companies/{queried_domain}/tree start")

df = get_company_tree(company_domain=company_name)
df = get_company_tree(company_domain=queried_domain)

parent_company = df["parent_company_name"].tolist()[0]
parent_company_domain = df["parent_company_domain"].tolist()[0]

if parent_company == company_name:
queried_company_name = df[(queried_domain == df["company_domain"])][
"company_name"
].tolist()[0]

if parent_company == queried_domain:
parent_company = None

domains = (
df[
~(parent_company == df["company_name"])
& (company_name == df["company_name"])
# & (queried_domain == df["company_name"])
& (queried_domain == df["company_domain"])
]["company_domain"]
.unique()
.tolist()
Expand All @@ -731,7 +736,7 @@ async def company_tree(
children_companies = (
df[
~(parent_company == df["company_name"])
& (company_name != df["company_name"])
& (queried_domain != df["company_domain"])
]
.rename(columns={"company_domain": "domains"})
.groupby(["company_name"])["domains"]
Expand All @@ -743,7 +748,8 @@ async def company_tree(
tree = ParentCompanyTree(
parent_company_name=parent_company,
parent_company_domain=parent_company_domain,
company_name=company_name,
queried_company_domain=queried_domain,
queried_company_name=queried_company_name,
domains=domains,
children_companies=children_companies,
)
Expand Down Expand Up @@ -926,7 +932,7 @@ async def adtech_type(
return overview

@get(path="/companies/topshort/", cache=True)
async def get_companies_shortlist_top(self: Self) -> list[CompanyDetail]:
async def get_companies_shortlist_top(self: Self) -> TopCompaniesOverviewShort:
"""Handle GET request for a list of adtech company categories.
Returns
Expand All @@ -940,16 +946,18 @@ async def get_companies_shortlist_top(self: Self) -> list[CompanyDetail]:
type_slug="ad-networks", app_category=None, limit=5
)
mmps = get_companies_top(type_slug="ad-attribution", app_category=None, limit=5)
# analytics = get_companies_top(type_slug='analytics', app_category=None, limit=5)
analytics = get_companies_top(
type_slug="product-analytics", app_category=None, limit=5
)
top_ad_networks = make_top_companies(adnetworks)
top_mmps = make_top_companies(mmps)
# top_analytics = make_top_companies(analytics)
top_analytics = make_top_companies(analytics)
logger.info(f"{self.path} return")

top_companies = TopCompaniesOverviewShort(
adnetworks=top_ad_networks,
attribution=top_mmps,
analytics=list(),
analytics=top_analytics,
)

return top_companies
Expand All @@ -970,8 +978,6 @@ async def get_companies_search(self: Self, search_term: str) -> list[CompanyDeta

category_totals_df = get_types_totals()

# cagetory_totals_df['app_category'] = 'all'

overview_df, _category_overview = prep_overview_df(results, category_totals_df)
logger.info(f"{self.path}/{search_term} return")

Expand Down
3 changes: 2 additions & 1 deletion backend/api_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class ParentCompanyTree:

parent_company_name: str | None
parent_company_domain: str | None
company_name: str
queried_company_domain: str
queried_company_name: str
domains: list[str]
children_companies: list[ChildrenCompanyTree]

Expand Down
23 changes: 12 additions & 11 deletions frontend/src/lib/CompaniesLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
let { card1, card2, card3, card4 } = $props();
</script>

<div class="flex flex-col md:flex-row gap-4 md:gap-6">
{@render card1?.()}
{@render card2?.()}
{#if card3}
<!-- This is always true? -->
{@render card3?.()}
<div class="col-span-3">
<div class="flex flex-col gap-4 md:gap-6">
<div class="grid grid-cols-3 gap-4 md:gap-6">
{@render card1?.()}
{@render card2?.()}
{#if card3}
{@render card3?.()}
<div class="col-span-3 flex gap-4">
{@render card4?.()}
</div>
{:else}
{@render card4?.()}
</div>
{:else}
{@render card4?.()}
{/if}
{/if}
</div>
</div>
44 changes: 28 additions & 16 deletions frontend/src/routes/(newcategorical)/companies/[name]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script lang="ts">
import type { CompanyFullDetails } from '../../../../types';
import { page } from '$app/stores';
const { name } = $page.params;
let name = $derived($page.params.name);
import CompanyOverviewTable from '$lib/CompanyOverviewTable.svelte';
import CompanyCategoryPie from '$lib/CompanyCategoryPie.svelte';
Expand Down Expand Up @@ -32,28 +34,38 @@
<p class="text-red-500">Failed to load company tree.</p>
{:else if myTree}
<div class="flex items-center">
{#each myTree.domains as domain}
<ExternalLink {domain} />
{/each}
{#if myTree.queried_company_domain}
{#if myTree.parent_company_domain == myTree.queried_company_domain}
<!-- IS PARENT COMPANY -->
<h2 class="text-xl font-bold text-gray-800 mr-2">{myTree.parent_company_name}</h2>
<div class="h-8 w-px bg-gray-300 mx-2"></div>
<ExternalLink domain={myTree.parent_company_domain} />
{:else}
<h2 class="text-xl font-bold text-gray-800 mr-2">{myTree.queried_company_name}</h2>
<div class="h-8 w-px bg-gray-300 mx-2"></div>
<ExternalLink domain={myTree.queried_company_domain} />
<div class="h-8 w-px bg-gray-300 mx-2"></div>
<!-- HAS PARENT COMPANY -->
<!-- <h2 class="text-xl font-bold text-gray-800 mr-2">PARENT: {myTree.queried_company_domain} {myTree.parent_company_name} AA</h2> -->
<h2 class="h2 text-xl font-bold text-gray-800 mr-2">Parent Company:</h2>
<CompanyButton
companyName={myTree.parent_company_name}
companyDomain={myTree.parent_company_domain}
/>
{/if}
{/if}
<!-- {#if myTree.domains.length > 0}
{#each myTree.domains as domain}
<ExternalLink {domain} />
{/each}
{/if} -->
</div>
{/if}
{:catch error}
<p class="text-red-500">{error.message}</p>
{/await}
</div>

{#await data.companyTree then myTree}
{#if myTree && myTree.parent_company_name && myTree.parent_company_domain}
<div class="flex items-center mt-2 ml-4">
<p class="text-xl font-bold text-gray-800 mr-2">Parent Company:</p>
<CompanyButton
companyName={myTree.parent_company_name}
companyDomain={myTree.parent_company_domain}
/>
</div>
{/if}
{/await}

<CompaniesLayout>
{#snippet card1()}
<WhiteCard>
Expand Down
25 changes: 24 additions & 1 deletion frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
party services which likely collect app data. You can also help expand these lists.
</p>
</a>
<div class="flex flex-col md:flex-col-2 gap-4">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<a href="/companies/types/ad-networks">
<div class="card variant-ghost-surface md:p-4">
<div class="card-header">
Expand Down Expand Up @@ -200,6 +200,29 @@
</div>
</div>
</a>

<a href="/companies/types/product-analytics">
<div class="card variant-ghost-surface md:p-4">
<div class="card-header">
<h3 class="h3">Top Product Analytics</h3>
</div>
<div class="card-content">
Checkout the top product analytics companies.
{#await data.topCompanies}
Loading ...
{:then myTops}
{#if myTops.analytics}
<WhiteCard>
<CompaniesBarChart
plotData={myTops.analytics.sdk}
plotTitle="Top Product Analytics Companies"
/>
</WhiteCard>
{/if}
{/await}
</div>
</div>
</a>
</div>
</div>

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ export interface ChildrenCompanyTree {
}

export interface ParentCompanyTree {
parent_company_name: string | null;
parent_company_domain: string | null;
company_name: string;
parent_company_name: string;
parent_company_domain: string;
queried_company_domain: string;
queried_company_name: string;
domains: string[];
children_companies: ChildrenCompanyTree[];
}
Expand Down

0 comments on commit 9f1062c

Please sign in to comment.