def process_absent_members(config, historical_members): absent_members = [] for tag, member in historical_members.items(): if member['status'] == 'absent': absent_members.append( FormerMember(config=config, historical_member=member, player_tag=tag, processed_events=history.process_member_events( config, member['events']))) return sorted(absent_members, key=lambda k: k.timestamp, reverse=True)
def enrich_member_with_history(self, member, historical_member): days_from_donation_reset = self.days_from_donation_reset member.join_date = historical_member['join_date'] member.last_activity_date = historical_member['last_activity_date'] member.last_donation_date = historical_member['last_donation_date'] member.donations_last_week = historical_member['donations_last_week'] member.days_inactive = ( self.now - datetime.fromtimestamp(member.last_activity_date)).days member.days_inactive = member.days_inactive if member.days_inactive >= 0 else 0 if member.last_seen: last_seen = datetime.strptime( member.last_seen.split('.')[0], '%Y%m%dT%H%M%S') else: last_seen = config['crtools']['timestamp'] member.last_seen_formatted = last_seen.strftime('%c') last_seen_delta = self.now - last_seen member.last_seen_delta = '' if last_seen_delta.days >= 1: member.last_seen_delta = '{} {}, '.format( last_seen_delta.days, self.config['strings']['labelDays']) hours = round(last_seen_delta.seconds / 3600) if hours < 1: member.last_seen_delta += '{} {}'.format( round(last_seen_delta.seconds / 60), self.config['strings']['labelMinutes']) else: member.last_seen_delta += '{} {}'.format( hours, self.config['strings']['labelHours']) if member.join_date == 0: member.join_date_label = self.config['strings'][ 'labelBeforeHistory'] else: member.join_date_label = datetime.fromtimestamp( member.join_date).strftime('%x') member.activity_date_label = datetime.fromtimestamp( member.last_activity_date).strftime('%x') join_datetime = datetime.fromtimestamp(member.join_date) member.days_from_join = (self.now - join_datetime).days if member.days_from_join <= 10: member.new = True logger.debug('New member {}'.format(member.name)) else: member.new = False if days_from_donation_reset > member.days_from_join: days_from_donation_reset = member.days_from_join if member.days_inactive > 7: member.donations_last_week = 0 member.total_donations = member.donations + member.donations_last_week if member.days_from_join > days_from_donation_reset + 7: days_from_donation_reset += 7 else: days_from_donation_reset = member.days_from_join if (days_from_donation_reset > 0): member.donations_daily = round(member.total_donations / days_from_donation_reset) else: member.donations_daily = member.total_donations member.events = history.process_member_events( self.config, historical_member['events'])