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

user wise submission count api #832

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
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)
Loading