Skip to content

Commit 5c0c3f6

Browse files
committed
Add more data for SDKs page
1 parent ab217bb commit 5c0c3f6

File tree

7 files changed

+203
-14
lines changed

7 files changed

+203
-14
lines changed

backend/api_app/controllers/sdks.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
)
1515
from config import get_logger
1616
from dbcon.queries import (
17+
get_latest_sdks,
1718
get_sdk_pattern,
1819
get_sdk_pattern_companies,
1920
get_sdks,
21+
get_user_requested_latest_sdks,
2022
)
2123

2224
logger = get_logger(__name__)
@@ -39,18 +41,34 @@ async def sdks(self: Self) -> SdksOverview:
3941
"""
4042
logger.info("GET /api/sdks/overview start")
4143

42-
overview = get_sdks()
44+
most_sdk_parts = get_sdks()
45+
latest_apps = get_latest_sdks()
46+
user_requested_latest_apps = get_user_requested_latest_sdks()
47+
is_google = most_sdk_parts["store"].str.startswith("Google")
48+
is_google_apps = latest_apps["store"].str.startswith("Google")
4349

44-
is_google = overview["store"].str.startswith("Google")
50+
android_sdkparts = most_sdk_parts[is_google]
51+
ios_sdkparts = most_sdk_parts[~is_google]
4552

46-
android_overview = overview[is_google]
47-
ios_overview = overview[~is_google]
53+
android_latest_apps = latest_apps[is_google_apps]
54+
ios_latest_apps = latest_apps[~is_google_apps]
4855

49-
android_overview_dict = android_overview.to_dict(orient="records")
50-
ios_overview_dict = ios_overview.to_dict(orient="records")
56+
user_requested_latest_apps_dict = user_requested_latest_apps.to_dict(
57+
orient="records"
58+
)
59+
60+
android_sdkparts_dict = android_sdkparts.to_dict(orient="records")
61+
ios_sdkparts_dict = ios_sdkparts.to_dict(orient="records")
62+
63+
android_latest_apps_dict = android_latest_apps.to_dict(orient="records")
64+
ios_latest_apps_dict = ios_latest_apps.to_dict(orient="records")
5165

5266
return SdksOverview(
53-
android_overview=android_overview_dict, ios_overview=ios_overview_dict
67+
android_sdkparts=android_sdkparts_dict,
68+
ios_sdkparts=ios_sdkparts_dict,
69+
android_latest_apps=android_latest_apps_dict,
70+
ios_latest_apps=ios_latest_apps_dict,
71+
user_requested_latest_apps=user_requested_latest_apps_dict,
5472
)
5573

5674
@get(path="/{value_pattern:str}", cache=3600)

backend/api_app/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ class SdksOverview:
443443
Representing the top sdks identified.
444444
"""
445445

446-
ios_overview: list[dict]
447-
android_overview: list[dict]
446+
ios_sdkparts: list[dict]
447+
android_sdkparts: list[dict]
448+
ios_latest_apps: list[dict]
449+
android_latest_apps: list[dict]
450+
user_requested_latest_apps: list[dict]
448451

449452

450453
@dataclass

backend/dbcon/queries.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def load_sql_file(file_name: str) -> str:
7474
QUERY_TAG_SOURCE_CATEGORY_TOTALS = load_sql_file("query_category_totals.sql")
7575
QUERY_TAG_SOURCE_TOTALS = load_sql_file("query_tag_source_totals.sql")
7676
QUERY_SDKS = load_sql_file("query_sdks.sql")
77+
QUERY_LATEST_SDKS = load_sql_file("query_sdks_latest.sql")
78+
QUERY_USER_REQUESTED_LATEST_SDKS = load_sql_file("query_sdks_user_requested_latest.sql")
7779
QUERY_SDK_PATTERN = load_sql_file("query_sdk_pattern.sql")
7880
QUERY_SDK_PATTERN_COMPANIES = load_sql_file("query_sdk_pattern_companies.sql")
7981

@@ -679,6 +681,19 @@ def get_sdks() -> pd.DataFrame:
679681
return df
680682

681683

684+
def get_latest_sdks() -> pd.DataFrame:
685+
"""Get latest sdks."""
686+
df = pd.read_sql(QUERY_LATEST_SDKS, DBCON.engine)
687+
df["store"] = df["store"].replace({1: "Google Play", 2: "Apple App Store"})
688+
return df
689+
690+
691+
def get_user_requested_latest_sdks() -> pd.DataFrame:
692+
"""Get user requested latest sdks."""
693+
df = pd.read_sql(QUERY_USER_REQUESTED_LATEST_SDKS, DBCON.engine)
694+
return df
695+
696+
682697
def get_sdk_pattern(value_pattern: str) -> pd.DataFrame:
683698
"""Get sdk pattern."""
684699
df = pd.read_sql(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM frontend.latest_sdk_scanned_apps;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
WITH apps AS (
2+
SELECT DISTINCT ON
3+
(urs.store_id)
4+
urs.store_id,
5+
MAX(urs.created_at) AS sdk_crawled_at
6+
FROM
7+
user_requested_scan AS urs
8+
WHERE
9+
urs.created_at <= CURRENT_DATE - INTERVAL '12 hours'
10+
GROUP BY
11+
urs.store_id
12+
ORDER BY
13+
urs.store_id ASC,
14+
sdk_crawled_at DESC
15+
)
16+
17+
SELECT *
18+
FROM
19+
apps AS a
20+
LEFT JOIN store_apps AS sa
21+
ON
22+
a.store_id = sa.store_id
23+
ORDER BY
24+
a.sdk_crawled_at DESC
25+
LIMIT 20;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<script lang="ts">
2+
import Pagination from './Pagination.svelte';
3+
4+
import { DataHandler } from '@vincjo/datatables/legacy/remote';
5+
import type { State } from '@vincjo/datatables/legacy/remote';
6+
import type { CompanyOverviewApps } from '../types';
7+
8+
export let entries_table: CompanyOverviewApps[];
9+
10+
const totalRows = entries_table.length;
11+
12+
const rowsPerPage = 100;
13+
14+
const handler = new DataHandler<CompanyOverviewApps>([], {
15+
rowsPerPage: rowsPerPage,
16+
totalRows: totalRows
17+
});
18+
const rows = handler.getRows();
19+
20+
handler.onChange((state: State) =>
21+
Promise.resolve(
22+
entries_table.slice(
23+
0 + (state.pageNumber - 1) * state.rowsPerPage,
24+
state.rowsPerPage * state.pageNumber
25+
)
26+
)
27+
);
28+
29+
handler.invalidate();
30+
console.log(`TABLE Company: ${totalRows}`);
31+
32+
$: firstRowInstalls =
33+
entries_table && entries_table.length > 0 && entries_table[0].installs != 'N/A';
34+
</script>
35+
36+
<div class="table-container space-y-4">
37+
<div class="overflow-x-auto pl-0">
38+
<table class="md:table table-hover md:table-compact table-auto w-full text-xs">
39+
<thead>
40+
<tr>
41+
<th class="table-cell-fit"></th>
42+
<th class="table-cell-fit">Time App Analyzed</th>
43+
<th class="table-cell-fit">Version Code</th>
44+
<th class="table-cell-fit">Crawl Result</th>
45+
<th class="table-cell-fit">App</th>
46+
<th class="table-cell-fit">
47+
{#if firstRowInstalls}
48+
Installs
49+
{:else}
50+
Ratings
51+
{/if}
52+
</th>
53+
</tr>
54+
</thead>
55+
<tbody>
56+
{#each $rows as row, index}
57+
<tr class="px-0">
58+
<td class="table-cell-fit">
59+
{index + 1}
60+
</td>
61+
<td class="table-cell-fit">
62+
{new Date(row.sdk_crawled_at).toISOString().slice(0, 16).replace('T', ' ')}
63+
</td>
64+
<td class="table-cell-fit">
65+
{row.version_code}
66+
</td>
67+
<td class="table-cell-fit">
68+
{row.crawl_result}
69+
</td>
70+
<td class="table-cell-fit">
71+
<a href="/apps/{row.store_id}" style="cursor: pointer;">
72+
{row.name}
73+
</a>
74+
</td>
75+
76+
<td class="table-cell-fit">
77+
{#if row.installs && row.installs != 'N/A'}
78+
{row.installs}
79+
{:else}
80+
{row.rating_count}
81+
{/if}
82+
</td>
83+
</tr>
84+
{/each}
85+
</tbody>
86+
</table>
87+
<footer class="flex justify-between">
88+
<!-- <RowCount {handler} /> -->
89+
{#if totalRows > rowsPerPage}
90+
<Pagination {handler} />
91+
{/if}
92+
</footer>
93+
</div>
94+
</div>

frontend/src/routes/sdks/+page.svelte

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<script lang="ts">
22
import SDKsOverviewTable from '$lib/SDKsOverviewTable.svelte';
3-
let { data } = $props();
3+
import SDKsLatestAppsTable from '$lib/SDKsLatestAppsTable.svelte';
44
import WhiteCard from '$lib/WhiteCard.svelte';
5+
6+
let { data } = $props();
57
</script>
68

79
<h1 class="text-2xl font-bold text-primary-900-100">SDKs</h1>
@@ -23,13 +25,44 @@
2325
{#await data.sdksOverview}
2426
loading
2527
{:then mySdksOverview}
28+
<WhiteCard>
29+
{#snippet title()}
30+
Android Apps
31+
{/snippet}
32+
33+
{#if mySdksOverview.android_latest_apps.length > 0}
34+
<SDKsLatestAppsTable entries_table={mySdksOverview.android_latest_apps} />
35+
{/if}
36+
</WhiteCard>
37+
38+
<WhiteCard>
39+
{#snippet title()}
40+
Android SDKs
41+
{/snippet}
42+
43+
{#if mySdksOverview.ios_latest_apps.length > 0}
44+
<SDKsLatestAppsTable entries_table={mySdksOverview.ios_latest_apps} />
45+
{/if}
46+
</WhiteCard>
47+
48+
<WhiteCard>
49+
{#snippet title()}
50+
User Requested Android Apps
51+
{/snippet}
52+
53+
{#if mySdksOverview.user_requested_latest_apps.length > 0}
54+
<SDKsLatestAppsTable entries_table={mySdksOverview.user_requested_latest_apps} />
55+
{/if}
56+
</WhiteCard>
57+
<div></div>
58+
2659
<WhiteCard>
2760
{#snippet title()}
2861
Android SDKs
2962
{/snippet}
3063

31-
{#if mySdksOverview.android_overview.length > 0}
32-
<SDKsOverviewTable entries_table={mySdksOverview.android_overview} />
64+
{#if mySdksOverview.android_sdkparts.length > 0}
65+
<SDKsOverviewTable entries_table={mySdksOverview.android_sdkparts} />
3366
{/if}
3467
</WhiteCard>
3568

@@ -38,8 +71,8 @@
3871
iOS SDKs
3972
{/snippet}
4073

41-
{#if mySdksOverview.ios_overview.length > 0}
42-
<SDKsOverviewTable entries_table={mySdksOverview.ios_overview} />
74+
{#if mySdksOverview.ios_sdkparts.length > 0}
75+
<SDKsOverviewTable entries_table={mySdksOverview.ios_sdkparts} />
4376
{/if}
4477
</WhiteCard>
4578
{/await}

0 commit comments

Comments
 (0)