Skip to content

Commit

Permalink
Working sorting!
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 20, 2024
1 parent f4f3fb7 commit 911364a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
11 changes: 11 additions & 0 deletions backend/api_app/controllers/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,19 @@ def get_overviews(category: str | None = None) -> CompaniesOverview:
.sum()
.reset_index()
).sort_values(by=["app_count"], ascending=False)


overview_df['percentage'] = overview_df['app_count'] / overview_df['total_app_count']

overview_df['store_tag'] = np.where(overview_df['store'].str.contains('Google'), 'google', 'apple')

overview_df['store_tag_source'] = overview_df['store_tag'] + '_' + overview_df['tag_source']


new_overview_df = overview_df.pivot(index=['company_name', 'company_domain'], columns=["store_tag_source"], values="percentage").reset_index()



ios_sdk = overview_df[
(~overview_df["store"].str.contains("google", case=False))
& (overview_df["tag_source"] == "sdk")
Expand Down Expand Up @@ -192,6 +202,7 @@ def get_overviews(category: str | None = None) -> CompaniesOverview:
]

results = CompaniesOverview(
companies_overview=new_overview_df.to_dict(orient="records"),
sdk=PlatformCompanies(
android=android_sdk.to_dict(orient="records"),
ios=ios_sdk.to_dict(orient="records"),
Expand Down
1 change: 1 addition & 0 deletions backend/api_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class CompaniesOverview:

"""Contains a list of CompanyDetail objects representing the top networks identified."""

companies_overview: list[CompanyDetail]
sdk: PlatformCompanies
adstxt_direct: PlatformCompanies
adstxt_reseller: PlatformCompanies
Expand Down
8 changes: 0 additions & 8 deletions backend/dbcon/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
from config import MODULE_DIR, get_logger
from dbcon.connections import get_db_connection

from cachetools import cached, TTLCache

logger = get_logger(__name__)


TWODAYCACHE = TTLCache(maxsize=100, ttl=2 * 24 * 60 * 60) # 2 days = 172800 seconds
ONEDAYCACHE = TTLCache(maxsize=100, ttl=1 * 24 * 60 * 60) # 1 day = 86400 seconds

SQL_DIR = pathlib.Path(MODULE_DIR, "dbcon/sql/")

Expand Down Expand Up @@ -117,7 +114,6 @@ def get_recent_apps(collection: str, limit: int = 20) -> pd.DataFrame:
return df


@cached(cache=TWODAYCACHE)
def get_appstore_categories() -> pd.DataFrame:
"""Get categories for both appstores."""
df = pd.read_sql(QUERY_APPSTORE_CATEGORIES, DBCON.engine)
Expand Down Expand Up @@ -192,7 +188,6 @@ def get_history_top_ranks(
return df


@cached(cache=TWODAYCACHE)
def get_store_collection_category_map() -> pd.DataFrame:
"""Get store collection and category map."""
df = pd.read_sql(QUERY_STORE_COLLECTION_CATEGORY_MAP, con=DBCON.engine)
Expand Down Expand Up @@ -232,7 +227,6 @@ def get_app_package_details(store_id: str) -> pd.DataFrame:
return df


@cached(cache=ONEDAYCACHE)
def get_companies_parent_overview(app_category: str | None = None) -> pd.DataFrame:
"""Get overview of companies from multiple types like sdk and app-ads.txt."""
logger.info("query companies parent overview start")
Expand All @@ -247,7 +241,6 @@ def get_companies_parent_overview(app_category: str | None = None) -> pd.DataFra
return df


@cached(cache=ONEDAYCACHE)
def get_companies_top(app_category: str | None = None, limit: int = 10) -> pd.DataFrame:
"""Get overview of companies from multiple types like sdk and app-ads.txt."""
logger.info("query companies parent top start")
Expand Down Expand Up @@ -318,7 +311,6 @@ def get_company_parent_categories(company_domain: str) -> pd.DataFrame:
df.loc[df["app_category"].isna(), "app_category"] = "None"
return df

@cached(cache=TWODAYCACHE)
def get_category_totals() -> pd.DataFrame:
"""Get category totals."""
df = pd.read_sql(QUERY_CATEGORY_TOTALS, DBCON.engine)
Expand Down
42 changes: 24 additions & 18 deletions frontend/src/lib/CompaniesOverviewTable.svelte
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<script lang="ts">
import Pagination from './Pagination.svelte';
// import Pagination from './Pagination.svelte';
import { DataHandler } from '@vincjo/datatables/remote';
import type { State } from '@vincjo/datatables/remote';
// import { DataHandler } from '@vincjo/datatables/remote';
import { DataHandler } from '@vincjo/datatables';
// import type { State } from '@vincjo/datatables/remote';
import type { CompaniesOverviewEntries } from '../types';
import ThSort from './ThSort.svelte';
export let entries_table: CompaniesOverviewEntries[];
const totalRows = entries_table.length;
const rowsPerPage = 100;
const handler = new DataHandler<CompaniesOverviewEntries>([], {
const handler = new DataHandler<CompaniesOverviewEntries>(entries_table, {
rowsPerPage: rowsPerPage,
totalRows: totalRows
// totalRows: totalRows
});
const rows = handler.getRows();
handler.onChange((state: State) =>
Promise.resolve(
entries_table.slice(
0 + (state.pageNumber - 1) * state.rowsPerPage,
state.rowsPerPage * state.pageNumber
)
)
);
// handler.onChange((state: State) =>
// Promise.resolve(
// entries_table.slice(
// 0 + (state.pageNumber - 1) * state.rowsPerPage,
// state.rowsPerPage * state.pageNumber
// )
// )
// );
handler.invalidate();
// handler.invalidate();
console.log(`TABLE Companies: ${totalRows}`);
</script>

Expand All @@ -36,8 +40,10 @@
<thead>
<tr>
<th class="table-cell-fit"></th>
<th class="table-cell-fit">Company</th>
<th class="table-cell-fit">Apps</th>
<ThSort {handler} orderBy="company_name">Company</ThSort>
<ThSort {handler} orderBy="percentage">Apps</ThSort>
<!-- <th class="table-cell-fit">Company</th> -->
<!-- <th class="table-cell-fit">Apps</th> -->
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -67,9 +73,9 @@
</table>
<footer class="flex justify-between">
<!-- <RowCount {handler} /> -->
{#if totalRows > rowsPerPage}
<!-- {#if totalRows > rowsPerPage}
<Pagination {handler} />
{/if}
{/if} -->
</footer>
</div>
</div>
Expand Down

0 comments on commit 911364a

Please sign in to comment.