Files
lucidia-main/human_machine/feedback_mechanisms.py
Alexa Amundson 855585cb0e sync: update from blackroad-operator 2026-03-14
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/lucidia
BlackRoad OS — Pave Tomorrow.

RoadChain-SHA2048: fe729062952871e7
RoadChain-Identity: alexa@sovereign
RoadChain-Full: fe729062952871e77147cf6d938b799096e87d9024d7005a14c9e209e12e8ad0c825b624c7bc649fc7eeb4c284fdcab8231af77980065cc04d9f36fca479ffc2346ed3c1b73de6f240d8f9485f47c995ad5b81142f7179b84932c67914dff1c08db039349ba28fca36cb57688093bf0199268dd1c2f3448c9383000bc77cc9663066ff57b834370afc8838b18466ea9029908018b961555cccaabf2ce21649cf3cabc7f64bdcc4abdf2da259b210c342835a2cecf92bdd3b4e109b4d6e622f6934e13b2b123607bd61ce3d0f20454c9ab594f9284cffe18716619c52db57ce5f4ee2856cb96e1fa3748fe1fe65435bec297c5ab3ab58d570ec1064aea29931dd
2026-03-14 15:09:52 -05:00

60 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from dataclasses import dataclass
from typing import List, Optional
@dataclass
class Feedback:
"""Represents a piece of user feedback with an optional numeric rating.
Attributes
----------
user_id : str
Identifier of the user providing feedback.
message : str
The textual content of the feedback.
rating : Optional[int]
Optional numeric rating (e.g., 15) associated with the feedback.
"""
user_id: str
message: str
rating: Optional[int] = None
class FeedbackManager:
"""
Collects and processes feedback from users.
This manager stores feedback entries and can compute simple statistics
over them.
"""
def __init__(self) -> None:
self._feedback: List[Feedback] = []
def submit(self, feedback: Feedback) -> None:
"""Submit new feedback."""
self._feedback.append(feedback)
def average_rating(self) -> Optional[float]:
"""Compute the average rating across all feedback that has a rating."""
ratings = [f.rating for f in self._feedback if f.rating is not None]
if ratings:
return sum(ratings) / len(ratings)
return None
def messages(self) -> List[str]:
"""Return a list of all feedback messages."""
return [f.message for f in self._feedback]
if __name__ == "__main__":
mgr = FeedbackManager()
mgr.submit(Feedback(user_id="u1", message="Great job!", rating=5))
mgr.submit(Feedback(user_id="u2", message="Could be better.", rating=3))
mgr.submit(Feedback(user_id="u3", message="Loved the experience!"))
print("Average rating:", mgr.average_rating())
print("Messages:", mgr.messages())