Skip to content

Commit

Permalink
Merge pull request #813 from hotosm/feat-UpdateProjectInfo
Browse files Browse the repository at this point in the history
Feat update project info
  • Loading branch information
nrjadkry authored Sep 7, 2023
2 parents 1078970 + c703c78 commit 6d95e39
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ def delete_odk_xform(
return result


def list_odk_xforms(project_id: int, odk_central: project_schemas.ODKCentral = None):
# def list_odk_xforms(project_id: int, odk_central: project_schemas.ODKCentral = None):
def list_odk_xforms(project_id: int, odk_central: project_schemas.ODKCentral = None, metadata:bool = False):
"""List all XForms in an ODK Central project."""
project = get_odk_project(odk_central)
xforms = project.listForms(project_id)
xforms = project.listForms(project_id, metadata)
# FIXME: make sure it's a valid project id
return xforms

Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ def get_project_tiles(
jsonfile.truncate(0)
dump(features, jsonfile)

basemap = basemapper.BaseMapper(boundary_file, base, source)
basemap = basemapper.BaseMapper(boundary_file, base, source, False)
outf = basemapper.DataFile(outfile, basemap.getFormat())
suffix = os.path.splitext(outfile)[1]
if suffix == ".mbtiles":
Expand Down
38 changes: 15 additions & 23 deletions src/backend/app/tasks/tasks_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ async def task_features_count(
db: Session = Depends(database.get_db),
):

task_list = tasks_crud.get_task_lists(db, project_id)

# Get the project object.
project = project_crud.get_project(db, project_id)

Expand All @@ -177,28 +175,22 @@ async def task_features_count(
odk_central_password = project.odk_central_password,
)

def process_task(task):
feature_count_query = text(f"""
select count(*)from features where project_id = {project_id} and task_id = {task}
""")
odk_details = central_crud.list_odk_xforms(project.odkid, odk_credentials, True)

# Assemble the final data list
data = []
for x in odk_details:
feature_count_query = f"""
select count(*) from features where project_id = {project_id} and task_id = {x['xmlFormId']}
"""
result = db.execute(feature_count_query)
feature_count = result.fetchone()

submission_list = central_crud.list_task_submissions(
project.odkid, task, odk_credentials)

# form_details = central_crud.get_form_full_details(project.odkid, task, odk_credentials)
return {
"task_id": task,
"feature_count": feature_count[0],
# 'submission_count': form_details['submissions'],
"submission_count": len(submission_list)
if isinstance(submission_list, list)
else 0,
}

loop = asyncio.get_event_loop()
tasks = [loop.run_in_executor(None, process_task, task) for task in task_list]
processed_results = await asyncio.gather(*tasks)
data.append({
'task_id': x['xmlFormId'],
'submission_count': x['submissions'],
'last_submission': x['lastSubmission'],
'feature_count': feature_count['count']
})

return processed_results
return data

0 comments on commit 6d95e39

Please sign in to comment.