def check_info_rules(self, p_rule_set, p_stat_info, p_rule_result_info): if p_rule_set.free_play: p_rule_result_info.applying_rules |= INFO_REMAINING_PLAYTIME p_rule_result_info.applying_rule_text_templates.append( (_("Free Play"), {})) else: if p_rule_result_info.minutes_left_today is not None: p_rule_result_info.applying_rules |= INFO_REMAINING_PLAYTIME p_rule_result_info.applying_rule_text_templates.append( (_("Remaining play time today: {hh_mm}"), { "hh_mm": tools.get_duration_as_string( p_seconds=60 * p_rule_result_info.minutes_left_today, p_include_seconds=False) })) current_activity_duration = p_stat_info.current_activity_duration if current_activity_duration is not None and p_rule_result_info.minutes_left_in_session is not None: p_rule_result_info.applying_rules |= INFO_REMAINING_PLAYTIME_THIS_SESSION p_rule_result_info.applying_rule_text_templates.append( (_("Remaining play time in current session: {hh_mm}"), { "hh_mm": tools.get_duration_as_string( p_seconds=60 * p_rule_result_info.minutes_left_in_session, p_include_seconds=False) }))
def __str__(self): fmt = "Activity([{start_time}, {end_time}], {duration}, downtime={downtime})" return fmt.format( start_time=tools.get_timestamp_as_string(self.start_time), end_time=tools.get_timestamp_as_string(self.end_time), duration=tools.get_duration_as_string(self.duration), downtime=tools.get_duration_as_string(self.downtime))
def __str__(self): min_time = tools.get_time_as_string(p_timestamp=self.min_time_of_day) max_time = tools.get_time_as_string(p_timestamp=self.max_time_of_day) date = tools.get_date_as_string(p_date=self.reference_date) duration = tools.get_duration_as_string( p_seconds=self.max_time_per_day) min_break = tools.get_duration_as_string(p_seconds=self.min_break) return "Rule override (user=%s, date=%s, time-of-day=[%s to %s], "\ "max-time-per-day:%s, min-break:%s, free-play:%s)" % ( self.username, date, min_time, max_time, duration, min_break, self.free_play)
def check_min_break(p_rule_set, p_stat_info, p_rule_result_info): if p_rule_set.free_play: return if p_rule_set.min_break is not None and p_rule_set.max_activity_duration is not None: seconds_since_last_activity = p_stat_info.seconds_since_last_activity if p_stat_info.previous_activity_duration is not None: fraction_used = min(1.0 * p_stat_info.previous_activity_duration / p_rule_set.max_activity_duration, 1.0) min_relative_break = fraction_used * p_rule_set.min_break else: min_relative_break = p_rule_set.min_break if seconds_since_last_activity is not None and seconds_since_last_activity < min_relative_break: p_rule_result_info.applying_rules = p_rule_result_info.applying_rules | RULE_MIN_BREAK p_rule_result_info.applying_rule_text_templates.append( (_("Minimum break time {hh_mm} not reached"), {"hh_mm": tools.get_duration_as_string(p_seconds=p_rule_set.min_break)}) ) p_rule_result_info.break_minutes_left = int( (min_relative_break - seconds_since_last_activity + 30) / 60) p_rule_result_info.args['break_minutes_left'] = p_rule_result_info.break_minutes_left return 0
def check_activity_duration(self, p_rule_set, p_stat_info, p_rule_result_info): if p_rule_set.free_play: return if p_rule_set.max_activity_duration is not None: current_activity_duration = p_stat_info.current_activity_duration if current_activity_duration is not None: if current_activity_duration > p_rule_set.max_activity_duration: p_rule_result_info.applying_rules = p_rule_result_info.applying_rules | RULE_ACTIVITY_DURATION p_rule_result_info.applying_rule_text_templates.append( (_("No activity exceeding {hh_mm}"), {"hh_mm": tools.get_duration_as_string(p_seconds=p_rule_set.max_activity_duration, p_include_seconds=False)}) ) else: time_left_in_minutes = int((p_rule_set.max_activity_duration - current_activity_duration + 30) / 60) p_rule_result_info.args['minutes_left_before_logout'] = time_left_in_minutes p_rule_result_info.set_minutes_left_in_session(p_minutes_left=time_left_in_minutes) if time_left_in_minutes <= self._config.warning_before_logout: p_rule_result_info.set_approaching_logout_rule(p_rule=RULE_ACTIVITY_DURATION, p_minutes_left=time_left_in_minutes)
def check_time_per_day(self, p_rule_set, p_stat_info, p_rule_result_info): if p_rule_set.free_play: return if p_rule_set.max_time_per_day is not None: if p_stat_info.todays_activity_duration >= p_rule_set.max_time_per_day: if p_rule_set.max_time_per_day == 0: p_rule_result_info.applying_rules = p_rule_result_info.applying_rules | RULE_DAY_BLOCKED p_rule_result_info.applying_rule_text_templates.append( (_("Day blocked: no activity permitted"), {}) ) else: p_rule_result_info.applying_rules = p_rule_result_info.applying_rules | RULE_TIME_PER_DAY p_rule_result_info.applying_rule_text_templates.append( (_("Activity limited to {hh_mm} per day"), {"hh_mm": tools.get_duration_as_string(p_seconds=p_rule_set.max_time_per_day, p_include_seconds=False)}) ) if p_rule_set.max_time_per_day > 0: time_left_in_minutes = int( (p_rule_set.max_time_per_day - p_stat_info.todays_activity_duration + 30) / 60) p_rule_result_info.set_minutes_left_in_session(p_minutes_left=time_left_in_minutes) if time_left_in_minutes <= self._config.warning_before_logout: p_rule_result_info.set_approaching_logout_rule(p_rule=RULE_TIME_PER_DAY, p_minutes_left=time_left_in_minutes)
def _value(self): if self.invalid_data is not None: return self.invalid_data elif self.data is None: return '-' else: return tools.get_duration_as_string(p_seconds=self.data, p_include_seconds=False)
def __str__(self): return "StatInfo (user=%s, today:%d[s], yesterday:%d[s], ref-time:%s, previous %s, " \ "current %s, secs-since-last-activity:%s)" % ( self.username, self.day_statistics[0].duration, self.day_statistics[1].duration, tools.get_timestamp_as_string(p_timestamp=self.reference_time), str(self.previous_activity) if self.previous_activity is not None else "---", str(self.current_activity) if self.current_activity is not None else "---", tools.get_duration_as_string(p_seconds=self.seconds_since_last_activity) )
def __str__(self): min_time = tools.get_time_as_string(p_timestamp=self.min_time_of_day) max_time = tools.get_time_as_string(p_timestamp=self.max_time_of_day) date = tools.get_date_as_string(p_date=self.reference_date) max_time_per_day = tools.get_duration_as_string( p_seconds=self.max_time_per_day) min_break = tools.get_duration_as_string(p_seconds=self.min_break) max_activity_duration = tools.get_duration_as_string( p_seconds=self.max_activity_duration) fmt = "Rule override (user={user}, date={date}, time-of-day=[{min_time} to {max_time}], "\ "max-time-per-day:{max_time_per_day}, min-break:{min_break}, "\ "max-activity-duration:{max_activity_duration} free-play:{free_play})" return fmt.format(user=self.username, date=date, min_time=min_time, max_time=max_time, max_time_per_day=max_time_per_day, min_break=min_break, max_activity_duration=max_activity_duration, free_play=self.free_play)
def summary(self): context_handler = self.get_context_rule_handler( p_context_name=self.context) texts = [] if context_handler is not None: texts.extend( context_handler.summary(p_context_detail=self.context_details)) if self.max_time_per_day is not None: texts.append(constants.TEXT_SEPERATOR) texts.append("Time per Day") texts.append(": " + tools.get_duration_as_string( p_seconds=self.max_time_per_day, p_include_seconds=False)) return texts
def __str__(self): return "Activity([%s, %s], %s)" % (tools.get_timestamp_as_string( self.start_time), tools.get_timestamp_as_string( self.end_time), tools.get_duration_as_string(self.duration))
def format_seconds(value): return tools.get_duration_as_string(p_seconds=value, p_include_seconds=False)