Exemple #1
0
 def random_inactivity_for_timestamp(self, cid: str,
                                     timestamp: int) -> float:
     """Queries the activity distribution and generates a random sample."""
     return draw_from_distribution(self.__distribution_for_hour(
         cid, *timestamp_to_day(timestamp)).inactivity,
                                   min_value=self.__xmin,
                                   max_value=self.__xmax)
Exemple #2
0
 def _activity_time(self,
                    timestamp: int = None,
                    day: int = None,
                    hour: int = None):
     """Distribution for the activity by the user."""
     if timestamp is not None:
         day, hour = timestamp_to_day(timestamp)
     if not is_workhour(day, hour):
         return DISTRIBUTION(ACTIVITY / 10, 30)
     return DISTRIBUTION(ACTIVITY, 600)
Exemple #3
0
 def _user_shutdown_time(self,
                         cid: str,
                         timestamp: int = None,
                         day: int = None,
                         hour: int = None):
     """Distribution for the shutdown triggered by the user."""
     if timestamp is not None:
         day, hour = timestamp_to_day(timestamp)
     if hour == OUT_TIME or not is_workhour(day, hour):
         return self._user_shutdown_time_next_in_time(cid, day, hour)
     return DISTRIBUTION(SMALL_SHUTDOWN, 900)
Exemple #4
0
    def _inactivity_time(self,
                         cid: str,
                         timestamp: int = None,
                         day: int = None,
                         hour: int = None):
        """Distribution for the inactivity by the user."""
        if timestamp is not None:
            day, hour = timestamp_to_day(timestamp)

        if hour >= OUT_TIME:
            if self.off_frequency_for_hour(cid, day, hour) < 1.0:
                return self._user_shutdown_time_next_in_time(cid, day, hour)

        return DISTRIBUTION(INACTIVITY, 600)
Exemple #5
0
 def off_interval_for_timestamp(self, cid: str, timestamp: int) -> float:
     """Samples an off interval for the day and hour provided"""
     return draw_from_distribution(self.__distribution_for_hour(
         cid, *timestamp_to_day(timestamp)).off_duration,
                                   min_value=self.__xmin,
                                   max_value=self.__xmax)
Exemple #6
0
 def optimal_idle_timeout(self, cid: str) -> float:
     """Calculates the value of the idle timer for a given satisfaction."""
     return self.__optimal_timeout_timestamp(
         cid, *timestamp_to_day(self.__config.env.now))