1234567891011121314151617181920212223 |
-
- from typing import List
- from million.model.message import Message
- from million.model.participant import Participant
-
-
- def count_participations(messages: List[Message], participants: List[Participant]):
- """
- Count the number of messages sent by each participant
- """
- participations = {}
- for participant in participants:
- participations[participant.name] = 0
-
- for message in messages:
- if message.sender_name not in participations:
- participations[message.sender_name] = 1
- else:
- participations[message.sender_name] += 1
-
- ordered_participations = sorted(
- participations.items(), key=lambda x: x[1], reverse=True)
- return [{"name": v[0], "participations": v[1]} for v in ordered_participations]
|