Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmerlo committed Dec 4, 2024
1 parent e07268d commit eeec789
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions src/apps/answers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,64 +1941,64 @@ async def get_activity_and_flow_ids_by_source_subject(self, source_subject_id: u
async def _filter_out_soft_deleted_subjects(
self, submissions_target: list[dict], submissions_respondent: list[dict]
) -> set[uuid.UUID]:
"""
"""
Filter out soft-deleted source subjects from submissions_target
and soft-deleted target subjects from submissions_respondent
"""
all_submissions = submissions_target + submissions_respondent

subject_ids = set([activityOrFlow["subject_id"] for activityOrFlow in all_submissions])
"""
all_submissions = submissions_target + submissions_respondent

assert self.user_id
existing_subjects = await SubjectsService(self.session, self.user_id).get_by_ids(list(subject_ids))
existing_subject_ids = {subject.id for subject in existing_subjects}
subject_ids = set([activityOrFlow["subject_id"] for activityOrFlow in all_submissions])

return existing_subject_ids
assert self.user_id
existing_subjects = await SubjectsService(self.session, self.user_id).get_by_ids(list(subject_ids))
existing_subject_ids = {subject.id for subject in existing_subjects}

async def get_submissions_by_subject(self, subject_id: uuid.UUID) -> SubmissionsActivityCountBySubject:
submissions_target_coro = AnswersCRUD(self.answer_session).get_submissions_by_target_subject(subject_id)
submissions_respondent_coro = AnswersCRUD(self.answer_session).get_submissions_by_respondent_subject(subject_id)
return existing_subject_ids

submissions_target, submissions_respondent = await asyncio.gather(
submissions_target_coro, submissions_respondent_coro
)
async def get_submissions_by_subject(self, subject_id: uuid.UUID) -> SubmissionsActivityCountBySubject:
submissions_target_coro = AnswersCRUD(self.answer_session).get_submissions_by_target_subject(subject_id)
submissions_respondent_coro = AnswersCRUD(self.answer_session).get_submissions_by_respondent_subject(subject_id)

existing_subject_ids = await self._filter_out_soft_deleted_subjects(submissions_target, submissions_respondent)
submissions_target, submissions_respondent = await asyncio.gather(
submissions_target_coro, submissions_respondent_coro
)

submissions_activity_count = SubmissionsActivityCountBySubject(subject_id=subject_id)
existing_subject_ids = await self._filter_out_soft_deleted_subjects(submissions_target, submissions_respondent)

for activityOrFlow in submissions_target:
activity_counters = submissions_activity_count.activities.setdefault(
uuid.UUID(activityOrFlow["activity_id"]), SubmissionsSubjectCounters()
)
respondent_subject_id = activityOrFlow["subject_id"]
if respondent_subject_id in existing_subject_ids:
activity_counters.respondents.add(respondent_subject_id)
activity_counters.subject_submissions_count += 1
submissions_activity_count = SubmissionsActivityCountBySubject(subject_id=subject_id)

for activityOrFlow in submissions_respondent:
activity_counters = submissions_activity_count.activities.setdefault(
uuid.UUID(activityOrFlow["activity_id"]), SubmissionsSubjectCounters()
)
target_subject_id = activityOrFlow["subject_id"]
if target_subject_id in existing_subject_ids:
activity_counters.subjects.add(target_subject_id)
activity_counters.respondent_submissions_count += 1
for activityOrFlow in submissions_target:
activity_counters = submissions_activity_count.activities.setdefault(
uuid.UUID(activityOrFlow["activity_id"]), SubmissionsSubjectCounters()
)
respondent_subject_id = activityOrFlow["subject_id"]
if respondent_subject_id in existing_subject_ids:
activity_counters.respondents.add(respondent_subject_id)
activity_counters.subject_submissions_count += 1

for activityOrFlow in submissions_respondent:
activity_counters = submissions_activity_count.activities.setdefault(
uuid.UUID(activityOrFlow["activity_id"]), SubmissionsSubjectCounters()
)
target_subject_id = activityOrFlow["subject_id"]
if target_subject_id in existing_subject_ids:
activity_counters.subjects.add(target_subject_id)
activity_counters.respondent_submissions_count += 1

return submissions_activity_count
return submissions_activity_count


class ReportServerService:
def __init__(self, session, arbitrary_session=None):
self.session = session
self._answers_session = arbitrary_session
def __init__(self, session, arbitrary_session=None):
self.session = session
self._answers_session = arbitrary_session

@property
def answers_session(self):
return self._answers_session if self._answers_session else self.session
@property
def answers_session(self):
return self._answers_session if self._answers_session else self.session

async def is_reportable(self, answer: AnswerSchema, is_single_report_flow=False) -> bool:
"""Check is report available for answer or not.
async def is_reportable(self, answer: AnswerSchema, is_single_report_flow=False) -> bool:
"""Check is report available for answer or not.
First check applet report related fields. All fields must be filled.
Second check activities report related fields. If it is flow single
Expand Down

0 comments on commit eeec789

Please sign in to comment.