Skip to content

Commit 890e1bc

Browse files
committed
Update sdks for successful and unsuccessful
1 parent 5c0c3f6 commit 890e1bc

File tree

5 files changed

+97
-29
lines changed

5 files changed

+97
-29
lines changed

backend/api_app/controllers/sdks.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SdksController(Controller):
2929

3030
path = "/api/sdks"
3131

32-
@get(path="/overview", cache=3600)
32+
@get(path="/overview", cache=12000)
3333
async def sdks(self: Self) -> SdksOverview:
3434
"""Handle GET request for all sdks.
3535
@@ -44,30 +44,43 @@ async def sdks(self: Self) -> SdksOverview:
4444
most_sdk_parts = get_sdks()
4545
latest_apps = get_latest_sdks()
4646
user_requested_latest_apps = get_user_requested_latest_sdks()
47+
4748
is_google = most_sdk_parts["store"].str.startswith("Google")
4849
is_google_apps = latest_apps["store"].str.startswith("Google")
4950

51+
is_success = latest_apps["crawl_result"] == 1
52+
5053
android_sdkparts = most_sdk_parts[is_google]
5154
ios_sdkparts = most_sdk_parts[~is_google]
5255

53-
android_latest_apps = latest_apps[is_google_apps]
54-
ios_latest_apps = latest_apps[~is_google_apps]
56+
android_success_latest_apps = latest_apps[is_google_apps & is_success]
57+
ios_success_latest_apps = latest_apps[~is_google_apps & is_success]
5558

56-
user_requested_latest_apps_dict = user_requested_latest_apps.to_dict(
57-
orient="records"
58-
)
59+
android_failed_latest_apps = latest_apps[is_google_apps & ~is_success]
60+
ios_failed_latest_apps = latest_apps[~is_google_apps & ~is_success]
5961

6062
android_sdkparts_dict = android_sdkparts.to_dict(orient="records")
6163
ios_sdkparts_dict = ios_sdkparts.to_dict(orient="records")
6264

63-
android_latest_apps_dict = android_latest_apps.to_dict(orient="records")
64-
ios_latest_apps_dict = ios_latest_apps.to_dict(orient="records")
65+
android_success_latest_apps_dict = android_success_latest_apps.to_dict(
66+
orient="records"
67+
)
68+
ios_success_latest_apps_dict = ios_success_latest_apps.to_dict(orient="records")
69+
android_failed_latest_apps_dict = android_failed_latest_apps.to_dict(
70+
orient="records"
71+
)
72+
ios_failed_latest_apps_dict = ios_failed_latest_apps.to_dict(orient="records")
73+
user_requested_latest_apps_dict = user_requested_latest_apps.to_dict(
74+
orient="records"
75+
)
6576

6677
return SdksOverview(
6778
android_sdkparts=android_sdkparts_dict,
6879
ios_sdkparts=ios_sdkparts_dict,
69-
android_latest_apps=android_latest_apps_dict,
70-
ios_latest_apps=ios_latest_apps_dict,
80+
android_success_latest_apps=android_success_latest_apps_dict,
81+
ios_success_latest_apps=ios_success_latest_apps_dict,
82+
android_failed_latest_apps=android_failed_latest_apps_dict,
83+
ios_failed_latest_apps=ios_failed_latest_apps_dict,
7184
user_requested_latest_apps=user_requested_latest_apps_dict,
7285
)
7386

backend/api_app/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,10 @@ class SdksOverview:
445445

446446
ios_sdkparts: list[dict]
447447
android_sdkparts: list[dict]
448-
ios_latest_apps: list[dict]
449-
android_latest_apps: list[dict]
448+
ios_success_latest_apps: list[dict]
449+
android_success_latest_apps: list[dict]
450+
ios_failed_latest_apps: list[dict]
451+
android_failed_latest_apps: list[dict]
450452
user_requested_latest_apps: list[dict]
451453

452454

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
SELECT * FROM frontend.latest_sdk_scanned_apps;
1+
WITH users_top_apps AS (
2+
SELECT
3+
*,
4+
ROW_NUMBER() OVER (
5+
PARTITION BY
6+
store,
7+
crawl_result
8+
ORDER BY
9+
sdk_crawled_at DESC
10+
) AS my_rank
11+
FROM
12+
frontend.latest_sdk_scanned_apps
13+
)
14+
15+
SELECT *
16+
FROM
17+
users_top_apps
18+
WHERE
19+
crawl_result = 1
20+
AND my_rank <= 20
21+
UNION ALL
22+
SELECT *
23+
FROM
24+
users_top_apps
25+
WHERE
26+
crawl_result != 1
27+
AND my_rank <= 20;

backend/dbcon/sql/query_sdks_user_requested_latest.sql

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
WITH apps AS (
1+
WITH user_requests AS (
22
SELECT DISTINCT ON
33
(urs.store_id)
44
urs.store_id,
@@ -14,12 +14,20 @@ WITH apps AS (
1414
sdk_crawled_at DESC
1515
)
1616

17-
SELECT *
17+
SELECT
18+
ur.store_id,
19+
ur.sdk_crawled_at,
20+
sa.name,
21+
sa.category,
22+
sa.store,
23+
sa.installs,
24+
sa.rating_count,
25+
sa.icon_url_512
1826
FROM
19-
apps AS a
27+
user_requests AS ur
2028
LEFT JOIN store_apps AS sa
2129
ON
22-
a.store_id = sa.store_id
30+
ur.store_id = sa.store_id
2331
ORDER BY
24-
a.sdk_crawled_at DESC
32+
ur.sdk_crawled_at DESC
2533
LIMIT 20;

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,60 @@
2727
{:then mySdksOverview}
2828
<WhiteCard>
2929
{#snippet title()}
30-
Android Apps
30+
Android Successfully Crawled Apps
3131
{/snippet}
3232

33-
{#if mySdksOverview.android_latest_apps.length > 0}
34-
<SDKsLatestAppsTable entries_table={mySdksOverview.android_latest_apps} />
33+
{#if mySdksOverview.android_success_latest_apps && mySdksOverview.android_success_latest_apps.length > 0}
34+
<SDKsLatestAppsTable entries_table={mySdksOverview.android_success_latest_apps} />
3535
{/if}
3636
</WhiteCard>
3737

3838
<WhiteCard>
3939
{#snippet title()}
40-
Android SDKs
40+
iOS Apps SDKs
41+
{/snippet}
42+
43+
{#if mySdksOverview.ios_success_latest_apps && mySdksOverview.ios_success_latest_apps.length > 0}
44+
<SDKsLatestAppsTable entries_table={mySdksOverview.ios_success_latest_apps} />
45+
{/if}
46+
</WhiteCard>
47+
48+
<WhiteCard>
49+
{#snippet title()}
50+
Android Failed to Crawled Apps
51+
{/snippet}
52+
53+
{#if mySdksOverview.android_failed_latest_apps && mySdksOverview.android_failed_latest_apps.length > 0}
54+
<SDKsLatestAppsTable entries_table={mySdksOverview.android_failed_latest_apps} />
55+
{/if}
56+
</WhiteCard>
57+
58+
<WhiteCard>
59+
{#snippet title()}
60+
iOS Failed to Crawled Apps
4161
{/snippet}
4262

43-
{#if mySdksOverview.ios_latest_apps.length > 0}
44-
<SDKsLatestAppsTable entries_table={mySdksOverview.ios_latest_apps} />
63+
{#if mySdksOverview.ios_failed_latest_apps && mySdksOverview.ios_failed_latest_apps.length > 0}
64+
<SDKsLatestAppsTable entries_table={mySdksOverview.ios_failed_latest_apps} />
4565
{/if}
4666
</WhiteCard>
4767

4868
<WhiteCard>
4969
{#snippet title()}
50-
User Requested Android Apps
70+
User Requested Apps
5171
{/snippet}
5272

53-
{#if mySdksOverview.user_requested_latest_apps.length > 0}
73+
{#if mySdksOverview.user_requested_latest_apps && mySdksOverview.user_requested_latest_apps.length > 0}
5474
<SDKsLatestAppsTable entries_table={mySdksOverview.user_requested_latest_apps} />
5575
{/if}
5676
</WhiteCard>
57-
<div></div>
5877

5978
<WhiteCard>
6079
{#snippet title()}
6180
Android SDKs
6281
{/snippet}
6382

64-
{#if mySdksOverview.android_sdkparts.length > 0}
83+
{#if mySdksOverview.android_sdkparts && mySdksOverview.android_sdkparts.length > 0}
6584
<SDKsOverviewTable entries_table={mySdksOverview.android_sdkparts} />
6685
{/if}
6786
</WhiteCard>
@@ -71,7 +90,7 @@
7190
iOS SDKs
7291
{/snippet}
7392

74-
{#if mySdksOverview.ios_sdkparts.length > 0}
93+
{#if mySdksOverview.ios_sdkparts && mySdksOverview.ios_sdkparts.length > 0}
7594
<SDKsOverviewTable entries_table={mySdksOverview.ios_sdkparts} />
7695
{/if}
7796
</WhiteCard>

0 commit comments

Comments
 (0)