Skip to content

Commit

Permalink
Returning lastSubmissionDate separated between subject and respondent
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmerlo committed Dec 9, 2024
1 parent 32c1162 commit 53bdd2e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ asyncpg = "==0.30.0"
azure-storage-blob = "==12.23.1"
bcrypt = "==4.2.0"
boto3 = "==1.35.54"
fastapi = "==0.115.4"
fastapi = "==0.115.6"
fastapi-mail = "==1.2.9"
firebase-admin = "==6.5.0"
httpx = "==0.28.0"
Expand Down Expand Up @@ -58,7 +58,7 @@ more-itertools = "==10.5.0"
ipdb = "==0.13.13"
pudb = "==2024.1.3"
pre-commit = "==4.0.1"
ruff = "==0.7.2"
ruff = "==0.8.2"
allure-pytest = "==2.13.5"
pydantic-factories = "==1.17.3"
pytest = "==8.3.4"
Expand All @@ -77,7 +77,7 @@ types-pytz = "==2024.2.0.20241003"
types-aiofiles = "==24.1.0.20240626"
types-cachetools = "==5.5.0.20240820"
greenlet = "==3.1.0"
reproschema = "0.9.0"
reproschema = "*"
cachetools = "==5.3.0"
pyld = "==2.0.4"

Expand Down
26 changes: 13 additions & 13 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/apps/activities/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,18 @@ async def applet_activities_metadata_for_subject(

# Initialize submission counts
respondent_submissions_count = 0
respondent_last_submission_date = None
subject_submissions_count = 0
last_submission_date = None
subject_last_submission_date = None

# Update from submission data
if submission_data:
respondents.update(submission_data.respondents)
subjects.update(submission_data.subjects)
respondent_submissions_count = submission_data.respondent_submissions_count
respondent_last_submission_date = submission_data.respondent_last_submission_date
subject_submissions_count = submission_data.subject_submissions_count
last_submission_date = submission_data.last_submission_date
subject_last_submission_date = submission_data.subject_last_submission_date

# Update from assignment data
if assignments_data:
Expand Down Expand Up @@ -468,8 +470,9 @@ async def applet_activities_metadata_for_subject(
respondents_count=respondents_count,
subjects_count=subjects_count,
respondent_submissions_count=respondent_submissions_count,
respondent_last_submission_date=respondent_last_submission_date,
subject_submissions_count=subject_submissions_count,
last_submission_date=last_submission_date,
subject_last_submission_date=subject_last_submission_date,
)
)

Expand Down
3 changes: 2 additions & 1 deletion src/apps/activities/domain/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ class ActivitySubjectMetadata(PublicModel):
activity_or_flow_id: uuid.UUID
respondents_count: int
respondent_submissions_count: int
respondent_last_submission_date: datetime | None
subjects_count: int
subject_submissions_count: int
last_submission_date: datetime | None
subject_last_submission_date: datetime | None


class ActivitiesMetadata(PublicModel):
Expand Down
17 changes: 14 additions & 3 deletions src/apps/activities/tests/test_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,14 +1359,16 @@ async def test_assigned_activities_auto_assigned(
)
assert flow_metadata["respondentsCount"] == 1
assert flow_metadata["respondentSubmissionsCount"] == 0
assert flow_metadata["respondentLastSubmissionDate"] is None
assert flow_metadata["subjectsCount"] == 1
assert flow_metadata["subjectSubmissionsCount"] == 0
assert flow_metadata["lastSubmissionDate"] is None
assert flow_metadata["subjectLastSubmissionDate"] is None
assert activity_metadata["respondentsCount"] == 1
assert activity_metadata["respondentSubmissionsCount"] == 0
assert activity_metadata["respondentLastSubmissionDate"] is None
assert activity_metadata["subjectsCount"] == 1
assert activity_metadata["subjectSubmissionsCount"] == 0
assert activity_metadata["lastSubmissionDate"] is None
assert activity_metadata["subjectLastSubmissionDate"] is None

@pytest.mark.parametrize(
"subject_type,result_order",
Expand Down Expand Up @@ -1756,9 +1758,18 @@ async def test_assigned_activities_from_submission(
activityOrFlow = result["activitiesOrFlows"][0]
assert activityOrFlow["respondentsCount"] == (1 if subject_type == "target" else 0)
assert activityOrFlow["respondentSubmissionsCount"] == (0 if subject_type == "target" else 1)
assert (
activityOrFlow["respondentLastSubmissionDate"] is None
if subject_type == "target"
else activityOrFlow["respondentLastSubmissionDate"] is not None
)
assert activityOrFlow["subjectsCount"] == (0 if subject_type == "target" else 1)
assert activityOrFlow["subjectSubmissionsCount"] == (1 if subject_type == "target" else 0)
assert activityOrFlow["lastSubmissionDate"] is not None
assert (
activityOrFlow["subjectLastSubmissionDate"] is not None
if subject_type == "target"
else activityOrFlow["subjectLastSubmissionDate"] is None
)

@pytest.mark.parametrize("subject_type", ["target", "respondent"])
async def test_assigned_hidden_activities(
Expand Down
3 changes: 2 additions & 1 deletion src/apps/answers/domain/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,9 @@ class SubmissionsSubjectCounters(InternalModel):
respondents: set[uuid.UUID] = Field(default_factory=set)
subjects: set[uuid.UUID] = Field(default_factory=set)
subject_submissions_count: int = 0
subject_last_submission_date: datetime.datetime | None = None
respondent_submissions_count: int = 0
last_submission_date: datetime.datetime | None = None
respondent_last_submission_date: datetime.datetime | None = None


class SubmissionsActivityMetadataBySubject(InternalModel):
Expand Down
16 changes: 10 additions & 6 deletions src/apps/answers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,10 +2003,12 @@ async def get_submissions_metadata_by_subject(self, subject_id: uuid.UUID) -> Su
if respondent_subject_id in existing_subject_ids:
activity_metadata.respondents.add(respondent_subject_id)
activity_metadata.subject_submissions_count += activity_submissions["submission_count"]
activity_metadata.last_submission_date = (
activity_metadata.subject_last_submission_date = (
activity_submissions["last_submission_date"]
if not activity_metadata.last_submission_date
else max(activity_metadata.last_submission_date, activity_submissions["last_submission_date"])
if not activity_metadata.subject_last_submission_date
else max(
activity_metadata.subject_last_submission_date, activity_submissions["last_submission_date"]
)
)

for activity_submissions in submissions_respondent:
Expand All @@ -2017,10 +2019,12 @@ async def get_submissions_metadata_by_subject(self, subject_id: uuid.UUID) -> Su
if target_subject_id in existing_subject_ids:
activity_metadata.subjects.add(target_subject_id)
activity_metadata.respondent_submissions_count += activity_submissions["submission_count"]
activity_metadata.last_submission_date = (
activity_metadata.respondent_last_submission_date = (
activity_submissions["last_submission_date"]
if not activity_metadata.last_submission_date
else max(activity_metadata.last_submission_date, activity_submissions["last_submission_date"])
if not activity_metadata.respondent_last_submission_date
else max(
activity_metadata.respondent_last_submission_date, activity_submissions["last_submission_date"]
)
)

return submissions_activity_metadata
Expand Down

0 comments on commit 53bdd2e

Please sign in to comment.