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 Mar 26, 2022
1 parent 6abc888 commit a92d5c8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

app = FastAPI(title=config.settings.app_name)
if config.settings.sentry_dsn:
sentry_sdk.init(
sentry_sdk.init(
dsn=config.settings.sentry_dsn,
traces_sample_rate=0.01,
environment="production",
Expand Down Expand Up @@ -86,7 +86,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 @@ -110,7 +110,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 @@ -187,7 +187,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 All @@ -203,15 +203,15 @@ def get_summary(appid: str, response: Response):
return None


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
10 changes: 5 additions & 5 deletions backend/app/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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 @@ -208,12 +208,12 @@ def update():
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)
Expand All @@ -222,7 +222,7 @@ def update():
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_month"] = sum(
stats_apps_dict[appid]["installs_last_month"] = sum(
[i[2] for i in dict.values()]
)

Expand All @@ -233,7 +233,7 @@ def update():
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 @@ -302,10 +302,10 @@ def test_app_stats_by_id():
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 @@ -82,10 +82,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(),
},
},
]}
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/application/AppStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ interface Props {

const AppStatistics: FunctionComponent<Props> = ({ stats }) => {
const { t } = useTranslation()
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, t('installs'))
const data = chartStyle(installs_labels, installs_data, t('installs'))
const options = chartOptions(i18n.language)

return (
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 a92d5c8

Please sign in to comment.