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

Lakeland Features: TotalSessionTime #240

Open
LswaN58 opened this issue Nov 18, 2024 · 1 comment
Open

Lakeland Features: TotalSessionTime #240

LswaN58 opened this issue Nov 18, 2024 · 1 comment
Assignees
Labels
Extractor Create or improve a Feature Extractor class Lakeland Issues related to Lakeland game

Comments

@LswaN58
Copy link
Member

LswaN58 commented Nov 18, 2024

This should be a time-counting feature similar to what we're doing in Aqualab for TotalSessionTime (can ask @smitpatel8 for details/code to share, and/or check work on the feature/aqualab branch).

In particular:

  • In event filter, request "all_events", so that every event is seen by the feature
  • In the init function, accept an extra argument called threshold or something similar. We'll use this in the update function
    • Also set up counters for "active" and "idle" time. We'll add together to get total time.
    • You could also count total time and idle time, subtract to get active time, whatever is easiest. Just as long as we can get all 3 in the end.
  • In the update function, take the difference in time between the current event passed in, and the most recent event (so at end of this function, make sure to save current event timestamp as self.previous_timestamp or similar). Then:
    • If the difference in time is > self.threshold, it counts as idle time.
    • If the difference is < self.threshold, it counts as active time.
    • The difference always counts as total time.
  • In the Subfeatures function, we want to define the following subfeatures:
    • Seconds
    • Idle
    • IdleSeconds
    • Active
    • ActiveSeconds
  • In the calculate function, calculate and return:
    [total_time, total_seconds, idle_time, idle_seconds, active_time, active_seconds], where:
    • total_time is the total time as a stringified timedelta, and total_seconds is the result of calling total_time.total_seconds() function.
    • similar for the idle time
    • similar for the active time
@LswaN58 LswaN58 added the new feature New feature or request label Nov 18, 2024
@LswaN58
Copy link
Member Author

LswaN58 commented Nov 18, 2024

The current SessionDuration feature from Aqualab is a good reference for the general algorithm, though the code itself could be cleaner and make better use of local variables (e.g. not repeatedly calculating event.Timestamp - self.previous_time):

class SessionDuration(SessionFeature):

    def __init__(self, params:GeneratorParameters, threshold:int):
        self.threshold = threshold
        super().__init__(params=params)
        self.max_idle = timedelta(0)
        self.previous_time = None
        self.idle_time = timedelta(0)
        self.total_session_time = timedelta(0)
        # self._session_duration = 0
    def Subfeatures(self) -> List[str]:
            return ["Total", "Seconds", "Active", "ActiveSeconds", "Idle" "IdleSeconds", "MaxIdle"]
    # *** IMPLEMENT ABSTRACT FUNCTIONS ***
    @classmethod
    def _eventFilter(cls, mode:ExtractionMode) -> List[str]:
        return ["all_events"]

    @classmethod
    def _featureFilter(cls, mode:ExtractionMode) -> List[str]:
        return []

    def _updateFromEvent(self, event:Event) -> None:
        if event.EventSource == EventSource.GAME:
            if self.previous_time is not None:
                self.total_session_time += (event.Timestamp - self.previous_time)
                if (event.Timestamp - self.previous_time) > timedelta(minutes=1):
                    self.idle_time += (event.Timestamp - self.previous_time)
                    if self.max_idle < (event.Timestamp - self.previous_time):
                        self.max_idle = event.Timestamp - self.previous_time
            self.previous_time = event.Timestamp

    def _updateFromFeatureData(self, feature:FeatureData):
        return

    def _getFeatureValues(self) -> List[Any]:
        if self.total_session_time is not None:
            return [self.total_session_time, self.total_session_time.total_seconds(), (self.total_session_time - self.idle_time), (self.total_session_time - self.idle_time).total_seconds(), self.idle_time, self.idle_time.total_seconds(), self.max_idle]
        else:
            return ["No events"]

    # *** Optionally override public functions. ***

    @staticmethod
    def AvailableModes() -> List[ExtractionMode]:
        return [ExtractionMode.SESSION]

@LswaN58 LswaN58 added Extractor Create or improve a Feature Extractor class Lakeland Issues related to Lakeland game and removed new feature New feature or request labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Extractor Create or improve a Feature Extractor class Lakeland Issues related to Lakeland game
Projects
None yet
Development

No branches or pull requests

2 participants