def __call__(self, filtr, event): value = getattr(event, self._attr_name) # event.event_attr if Unknown.is_(value): return Unknown.TINY # Cannot check - missing attribute result = self._eval_func(self._limit, value) # compare value to limit if result is False: # Log rejection filtr.reject(event, "{} incorrect ({} to {})".format( self._attr_name, value, self._limit)) return result
def __call__(self, filtr, event): value = getattr(event, self._attr_name) # event.event_attr if Unknown.is_(value): return Unknown.TINY # Cannot check - missing attribute result = self._eval_func(self._limit, value) # compare value to limit if result is False: # Log rejection filtr.reject(event, self._attr_name, value, self._limit) return result
def check_event(self, event): missing = False # Event is missing no info to start for check in self._check_list: result = check(self, event) if result is False: return False elif Unknown.is_(result): missing = True # Mark Event as missing info # Do a special check for is missing_info is set if self.is_missing_info is not None \ and missing != self.is_missing_info: self.reject(event, "needed information was missing.") return False return True
def check_event(self, event): missing = False # Event is missing no info to start for check in self._check_list: result = check(self, event) if result is False: return False elif Unknown.is_(result): missing = True # Mark Event as missing info # Do a special check for is missing_info is set if self.is_missing_info is not None \ and missing != self.is_missing_info: self.reject(event, "missing_info", missing, self.is_missing_info) return False self.accept(event) return True
def process_raid(self, raid): # type: (Events.RaidEvent) -> None """ Process a raid event and notify alarms if it passes. """ # Update Gym details (if they exist) raid.gym_name = self.__cache.gym_name(raid.gym_id, raid.gym_name) raid.gym_description = self.__cache.gym_desc(raid.gym_id, raid.gym_description) raid.gym_image = self.__cache.gym_image(raid.gym_id, raid.gym_image) # Update Team if Unknown if Unknown.is_(raid.current_team_id): raid.current_team_id = self.__cache.gym_team(raid.gym_id) # Make sure that raids are enabled if self._raids_enabled is False: self._log.debug("Raid ignored: raid notifications are disabled.") return # Skip if previously processed if self.__cache.raid_expiration(raid.gym_id) is not None: self._log.debug("Raid {} was skipped because it was " "previously processed.".format(raid.name)) return self.__cache.raid_expiration(raid.gym_id, raid.raid_end) # Check the time remaining seconds_left = (raid.raid_end - datetime.utcnow()).total_seconds() if seconds_left < self.__time_limit: self._log.debug("Raid {} was skipped because only {} seconds " "remained".format(raid.name, seconds_left)) return # Calculate distance and direction if self.__location is not None: raid.distance = get_earth_dist([raid.lat, raid.lng], self.__location, self.__units) raid.direction = get_cardinal_dir([raid.lat, raid.lng], self.__location) # Check for Rules rules = self.__raid_rules if len(rules) == 0: # If no rules, default to all rules = { "default": Rule(self._raid_filters.keys(), self._alarms.keys()) } rule_ct, alarm_ct = 0, 0 for r_name, rule in rules.iteritems(): # For all rules passed = self._check_filters(raid, self._raid_filters, rule.filter_names) if passed: rule_ct += 1 alarm_ct += len(rule.alarm_names) self._notify_alarms(raid, rule.alarm_names, 'raid_alert') if rule_ct > 0: self._rule_log.info( 'Raid %s passed %s rule(s) and triggered %s alarm(s).', raid.name, rule_ct, alarm_ct) else: self._rule_log.info('Raid %s rejected by all rules.', raid.name)
def process_raid(self, raid): # type: (Events.RaidEvent) -> None """ Process a raid event and notify alarms if it passes. """ # Update Gym details (if they exist) raid.gym_name = self.__cache.gym_name(raid.gym_id, raid.gym_name) raid.gym_description = self.__cache.gym_desc(raid.gym_id, raid.gym_description) raid.gym_image = self.__cache.gym_image(raid.gym_id, raid.gym_image) # Update Team if Unknown if Unknown.is_(raid.current_team_id): raid.current_team_id = self.__cache.gym_team(raid.gym_id) # Make sure that raids are enabled if self.__raids_enabled is False: log.debug("Raid ignored: raid notifications are disabled.") return # Skip if previously processed if self.__cache.raid_expiration(raid.gym_id) is not None: log.debug("Raid {} was skipped because it was previously " "processed.".format(raid.name)) return self.__cache.raid_expiration(raid.gym_id, raid.raid_end) # Check the time remaining seconds_left = (raid.raid_end - datetime.utcnow()).total_seconds() if seconds_left < self.__time_limit: log.debug("Raid {} was skipped because only {} seconds remained" "".format(raid.name, seconds_left)) return # Calculate distance and direction if self.__location is not None: raid.distance = get_earth_dist([raid.lat, raid.lng], self.__location, self.__units) raid.direction = get_cardinal_dir([raid.lat, raid.lng], self.__location) # Check for Rules rules = self.__raid_rules if len(rules) == 0: # If no rules, default to all rules = { "default": Rule(self.__raid_filters.keys(), self.__alarms.keys()) } for r_name, rule in rules.iteritems(): # For all rules for f_name in rule.filter_names: # Check Filters in Rules f = self.__raid_filters.get(f_name) passed = f.check_event(raid) and self.check_geofences(f, raid) if not passed: continue # go to next filter raid.custom_dts = f.custom_dts if self.__quiet is False: log.info("{} raid notification" " has been triggered in rule '{}'!" "".format(raid.name, r_name)) self._trigger_raid(raid, rule.alarm_names) break # Next rule
def process_raid(self, raid): # type: (Events.RaidEvent) -> None """ Process a raid event and notify alarms if it passes. """ # Update Gym details (if they exist) raid.gym_name = self.__cache.gym_name(raid.gym_id, raid.gym_name) raid.gym_description = self.__cache.gym_desc( raid.gym_id, raid.gym_description) raid.gym_image = self.__cache.gym_image(raid.gym_id, raid.gym_image) # Update Team if Unknown if Unknown.is_(raid.current_team_id): raid.current_team_id = self.__cache.gym_team(raid.gym_id) # Make sure that raids are enabled if self._raids_enabled is False: self._log.debug("Raid ignored: raid notifications are disabled.") return # Skip if previously processed if self.__cache.raid_expiration(raid.gym_id) is not None: self._log.debug("Raid {} was skipped because it was " "previously processed.".format(raid.name)) return self.__cache.raid_expiration(raid.gym_id, raid.raid_end) # Check the time remaining seconds_left = (raid.raid_end - datetime.utcnow()).total_seconds() if seconds_left < self.__time_limit: self._log.debug("Raid {} was skipped because only {} seconds " "remained".format(raid.name, seconds_left)) return # Calculate distance and direction if self.__location is not None: raid.distance = get_earth_dist( [raid.lat, raid.lng], self.__location, self.__units) raid.direction = get_cardinal_dir( [raid.lat, raid.lng], self.__location) # Check for Rules rules = self.__raid_rules if len(rules) == 0: # If no rules, default to all rules = {"default": Rule( self._raid_filters.keys(), self._alarms.keys())} rule_ct, alarm_ct = 0, 0 for r_name, rule in rules.iteritems(): # For all rules passed = self._check_filters( raid, self._raid_filters, rule.filter_names) if passed: rule_ct += 1 alarm_ct += len(rule.alarm_names) self._notify_alarms( raid, rule.alarm_names, 'raid_alert') if rule_ct > 0: self._rule_log.info( 'Raid %s passed %s rule(s) and triggered %s alarm(s).', raid.name, rule_ct, alarm_ct) else: self._rule_log.info('Raid %s rejected by all rules.', raid.name)