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

Detailed trivia no segments #20

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
24 changes: 16 additions & 8 deletions active_statistics/statistics/trivia/detailed_trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def __init__(self) -> None:
self.segment_count = 0

def process_activity(self, activity: Activity) -> None:
self.segment_count += len(activity.segment_efforts)
if activity.segment_efforts is not None:
self.segment_count += len(activity.segment_efforts)

def get_description(self) -> str:
return "Total Number of Segments Completed"
Expand All @@ -25,9 +26,10 @@ def __init__(self) -> None:
self.segment_counter: Counter[int] = Counter()

def process_activity(self, activity: Activity) -> None:
self.segment_counter.update(
segment_effort.segment.id for segment_effort in activity.segment_efforts
)
if activity.segment_efforts is not None:
self.segment_counter.update(
segment_effort.segment.id for segment_effort in activity.segment_efforts
)

def get_description(self) -> str:
return "Total Unique Segments Completed"
Expand All @@ -41,15 +43,21 @@ def __init__(self) -> None:
self.segment_counter: Counter[int] = Counter()

def process_activity(self, activity: Activity) -> None:
self.segment_counter.update(
segment_effort.segment.id for segment_effort in activity.segment_efforts
)
if activity.segment_efforts is not None:
self.segment_counter.update(
segment_effort.segment.id for segment_effort in activity.segment_efforts
)

def get_description(self) -> str:
return "Most Popular Segment"

def get_tidbit(self) -> Optional[str]:
return f"{self.segment_counter.most_common(1)[0][1]} completions"
most_common_segment = self.segment_counter.most_common(1)
if not most_common_segment:
return None

segment_id, num_completions = most_common_segment[0]
return f"{num_completions} completions"

def get_segment_id(self) -> Optional[int]:
return self.segment_counter.most_common(1)[0][0]
Expand Down
10 changes: 9 additions & 1 deletion tests/test_trivia/test_detailed_trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
)


def test_summary_trivia(some_runs_with_segment_efforts) -> None:
def test_detailed_trivia(some_runs_with_segment_efforts) -> None:
"""
A basic test to make sure that if we pump some random data through the
processor, nothing breaks.
"""
detailed_trivia_processor.get_data(some_runs_with_segment_efforts)


def test_detailed_trivia_with_no_segments(some_basic_runs_and_rides) -> None:
"""
When analysing segments, if the user has no activities with segments, this
tidbit should return None instead of breaking.
"""
detailed_trivia_processor.get_data(some_basic_runs_and_rides)