Skip to content

Commit

Permalink
user wise submission count api
Browse files Browse the repository at this point in the history
  • Loading branch information
nrjadkry committed Sep 14, 2023
1 parent 66e5659 commit e4feac2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/backend/app/submission/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from ..projects import project_crud, project_schemas
from osm_fieldwork.json2osm import JsonDump
from pathlib import Path
from ..central import central_crud
from collections import defaultdict


def get_submission_of_project(db: Session, project_id: int, task_id: int = None):
Expand Down Expand Up @@ -707,4 +709,30 @@ async def get_submission_count_of_a_project(db:Session,
if json_data_value:
files.extend(json_data_value)

return len(files)
return len(files)


async def get_odk_user_info(db: Session, project_id):
project = project_crud.get_project(db, project_id)
odkid = project.odkid

# Get odk credentials from project.
odk_credentials = {
"odk_central_url": project.odk_central_url,
"odk_central_user": project.odk_central_user,
"odk_central_password": project.odk_central_password,
}

odk_credentials = project_schemas.ODKCentral(**odk_credentials)

odk_project = central_crud.get_odk_project(odk_credentials)
filters = {
"$select":"username"
}
result = odk_project.getAllSubmissions(odkid, None, filters)

username_counts = defaultdict(int)
for item in result:
username = item["username"]
username_counts[username] += 1
return username_counts
9 changes: 8 additions & 1 deletion src/backend/app/submission/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,11 @@ async def get_osm_xml(

# Create a plain XML response
response = Response(content=processed_xml_string, media_type="application/xml")
return response
return response


@router.get("/user_info/{project_id}")
async def get_user_info(project_id: int,
db: Session = Depends(database.get_db)
):
return await submission_crud.get_odk_user_info(db, project_id)

0 comments on commit e4feac2

Please sign in to comment.