Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add endpoint for getting the numbers of visits for a page #90

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/api/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ def get_page_visits(request: Request, page: str, start: Optional[str] = None, en

return add_continous_datapoints_to_log(visits, start_date, end_date, Interval.day)

@router.get('/get-all-page-visits')
def get_all_page_visits(request: Request, page: str, token: AccessTokenPayload = Depends(authorize_admin)):
db = get_database(request)
pipeline = [
{"$match": {"metaData": page}},
{"$group": {
"_id": "$metaData",
"count": {"$sum": 1}
}}
]
res = db.pageVisitLog.aggregate(pipeline)

if res == None:
raise HTTPException(500, "Problems retrieving page from database")

page_visits_list = list(res)
if len(page_visits_list) == 0:
raise HTTPException(404, "Could not find page")
visits = page_visits_list[0]
return {"visits": visits["count"]}

@router.get('/most_visited_pages_last_month')
def get_most_visited_page(request: Request, token: AccessTokenPayload = Depends(authorize_admin)):
db = get_database(request)
Expand Down
Loading