Skip to content

Commit

Permalink
Change fields to correctly reflect, that we return the installs
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed May 8, 2022
1 parent 9c6211a commit 0918966
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
14 changes: 7 additions & 7 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_category(

ids = apps.get_category(category)

sorted_ids = sort_ids_by_downloads(ids)
sorted_ids = sort_ids_by_installs(ids)

if page is None:
return sorted_ids
Expand All @@ -128,7 +128,7 @@ def get_developer(
response.status_code = 404
return response

sorted_ids = sort_ids_by_downloads(ids)
sorted_ids = sort_ids_by_installs(ids)

return sorted_ids

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_stats(response: Response):

@app.get("/stats/{appid}", status_code=200)
def get_stats_for_app(appid: str, response: Response):
if value := stats.get_downloads_by_ids([appid]).get(appid, None):
if value := stats.get_installs_by_ids([appid]).get(appid, None):
return value

response.status_code = 404
Expand Down Expand Up @@ -283,15 +283,15 @@ def canon_app_id(app_id: str):
}


def sort_ids_by_downloads(ids):
def sort_ids_by_installs(ids):
if len(ids) <= 1:
return ids

downloads = stats.get_downloads_by_ids(ids)
installs = stats.get_installs_by_ids(ids)
sorted_ids = sorted(
ids,
key=lambda appid: downloads.get(appid, {"downloads_last_month": 0}).get(
"downloads_last_month", 0
key=lambda appid: installs.get(appid, {"installs_last_month": 0}).get(
"installs_last_month", 0
),
reverse=True,
)
Expand Down
20 changes: 10 additions & 10 deletions backend/app/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _is_app(app_id: str) -> bool:
return "/" not in app_id


def get_downloads_by_ids(ids: List[str]):
def get_installs_by_ids(ids: List[str]):
result = defaultdict()
for app_id in ids:
if not _is_app(app_id):
Expand Down Expand Up @@ -210,31 +210,31 @@ def update(all_app_ids: list):
if _is_app(appid):
# Index 0 is install and update count index 1 would be the update count
# Index 2 is the install count
stats_apps_dict[appid]["downloads_total"] = sum(
stats_apps_dict[appid]["installs_total"] = sum(
[i[2] for i in dict.values()]
)

if appid in app_stats_per_day:
stats_apps_dict[appid]["downloads_per_day"] = app_stats_per_day[appid]
stats_apps_dict[appid]["installs_per_day"] = app_stats_per_day[appid]

sdate_30_days = edate - datetime.timedelta(days=30 - 1)
stats_30_days = _get_stats_for_period(sdate_30_days, edate)

stats_downloads: List = []
stats_installs: List = []
for appid, dict in stats_30_days.items():
if _is_app(appid):
# Index 0 is install and update count index 1 would be the update count
# Index 2 is the install count
downloads_last_month = sum([i[2] for i in dict.values()])
stats_apps_dict[appid]["downloads_last_month"] = downloads_last_month
installs_last_month = sum([i[2] for i in dict.values()])
stats_apps_dict[appid]["installs_last_month"] = installs_last_month
if appid in all_app_ids:
stats_downloads.append(
stats_installs.append(
{
"id": utils.get_clean_app_id(appid),
"downloads_last_month": downloads_last_month,
"installs_last_month": installs_last_month,
}
)
search.update_apps(stats_downloads)
search.update_apps(stats_installs)

sdate_7_days = edate - datetime.timedelta(days=7 - 1)
stats_7_days = _get_stats_for_period(sdate_7_days, edate)
Expand All @@ -243,7 +243,7 @@ def update(all_app_ids: list):
if _is_app(appid):
# Index 0 is install and update count index 1 would be the update count
# Index 2 is the install count
stats_apps_dict[appid]["downloads_last_7_days"] = sum(
stats_apps_dict[appid]["installs_last_7_days"] = sum(
[i[2] for i in dict.values()]
)

Expand Down
8 changes: 4 additions & 4 deletions backend/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ def test_app_stats_by_id(client):
today = datetime.date.today()
day_before_yesterday = today - datetime.timedelta(days=2)
expected = {
"downloads_total": 7,
"downloads_per_day": {day_before_yesterday.isoformat(): 6},
"downloads_last_month": 7,
"downloads_last_7_days": 7,
"installs_total": 7,
"installs_per_day": {day_before_yesterday.isoformat(): 6},
"installs_last_month": 7,
"installs_last_7_days": 7,
}

assert response.status_code == 200
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/application/AdditionalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ const AdditionalInfo = ({
items={[
{
icon: <MdCloudDownload />,
header: t("downloads"),
header: t("installs"),
content: {
type: "text",
text: stats.downloads_total.toLocaleString(
text: stats.installs_total.toLocaleString(
i18n.language.substring(0, 2),
),
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/application/AppStats.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.downloads {
.installs {
height: 300px;
padding-top: 16px;
padding-bottom: 48px;
Expand Down
22 changes: 11 additions & 11 deletions frontend/src/components/application/AppStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ interface Props {
const AppStatistics: FunctionComponent<Props> = ({ stats }) => {
const { t } = useTranslation()
const { resolvedTheme } = useTheme()
let downloads_labels: Date[] = []
let downloads_data: number[] = []
if (stats.downloads_per_day) {
for (const [key, value] of Object.entries(stats.downloads_per_day)) {
downloads_labels.push(new Date(key))
downloads_data.push(value)
let installs_labels: Date[] = []
let installs_data: number[] = []
if (stats.installs_per_day) {
for (const [key, value] of Object.entries(stats.installs_per_day)) {
installs_labels.push(new Date(key))
installs_data.push(value)
}
}

// Remove current day
downloads_labels.pop()
downloads_data.pop()
installs_labels.pop()
installs_data.pop()

const data = chartStyle(
downloads_labels,
downloads_data,
installs_labels,
installs_data,
t("installs"),
resolvedTheme,
)
const options = chartOptions(i18n.language)

return (
<div className={styles.downloads}>
<div className={styles.installs}>
<h3>{t("installs-over-time")}</h3>
<Line data={data} options={options} />
</div>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export async function fetchAppStats(appId: string): Promise<AppStats> {
if (!statsJson) {
console.log("No stats data for ", appId)
statsJson = {
downloads_per_day: {},
downloads_last_7_days: 0,
downloads_last_month: 0,
downloads_total: 0,
installs_per_day: {},
installs_last_7_days: 0,
installs_last_month: 0,
installs_total: 0,
}
}
return statsJson
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/types/AppStats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface AppStats {
downloads_last_month: number
downloads_total: number
downloads_last_7_days: number
downloads_per_day: { [key: string]: number }
installs_last_month: number
installs_total: number
installs_last_7_days: number
installs_per_day: { [key: string]: number }
}

0 comments on commit 0918966

Please sign in to comment.