Coverage for src/mesh/views/components/review_summary.py: 94%
25 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-28 07:45 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-28 07:45 +0000
1from __future__ import annotations
3from dataclasses import dataclass, field
6@dataclass
7class CountWithTotal:
8 value: int
9 total: int
11 def __post_init__(self):
12 if self.value > self.total: 12 ↛ 13line 12 didn't jump to line 13 because the condition on line 12 was never true
13 raise ValueError("CountWithTotal: a value greater than the total has been set.")
16@dataclass
17class ReviewSummary:
18 current_version: int
19 reviewers_count: CountWithTotal | None = field(default=None)
20 reports_count: CountWithTotal | None = field(default=None)
23def build_review_summary(submission):
24 """
25 Returns the submission review summary:
26 - Current version / round
27 - Nb of answered/pending reviewer requests
28 - Nb of review reports out of accepted requests
29 """
31 summary = ReviewSummary(
32 current_version=submission.current_version.number if submission.current_version else 0,
33 reviewers_count=CountWithTotal(value=0, total=0),
34 reports_count=CountWithTotal(value=0, total=0),
35 )
37 if submission.current_version:
38 reviews = submission.current_version.reviews.all()
39 if reviews:
40 answered_reviews = [r for r in reviews if r.accepted is not None]
41 summary.reviewers_count = CountWithTotal(
42 value=len(answered_reviews), total=len(reviews)
43 )
45 accepted_reviews = [r for r in answered_reviews if r.accepted]
46 completed_reviews = sum(1 for r in accepted_reviews if r.submitted)
47 summary.reports_count = CountWithTotal(
48 value=completed_reviews, total=len(accepted_reviews)
49 )
51 return summary