<commit_before>from common import *

def weighted_hours(staffer, location):
    shifts = Shift.objects.filter(attendee = staffer).select_related()
    return sum([shift.job.real_duration * shift.job.weight
                for shift in shifts
                if shift.job.location == int(location)],
               0.0)

@all_renderable(PEOPLE)
class Root:
    def index(self, location = ARCADE):
        by_id = {}
        jobs = defaultdict(list)
        for job in Job.objects.filter(location = location):
            by_id[job.id] = job
            jobs[job.start_time if not job.start_time.minute else job.start_time - timedelta(minutes = 30)].append(job)
        
        for job in by_id.values():
            job._shifts = []
        for shift in Shift.objects.filter(job__location = location):
            by_id[shift.job_id]._shifts.append(shift)
        
        jobs, shifts, attendees = Job.everything(location)
        by_start = defaultdict(list)
        for job in jobs:
            by_start[job.start_time].append(job)
        times = [state.EPOCH + timedelta(hours = i) for i in range(CON_LENGTH)]
        times = [(t, t + timedelta(hours = 1), by_start[t]) for i,t in enumerate(times)]
        return {
            "location": location,
            "times":    times
        }
    
    def signups(self, location = ARCADE):
        jobs, shifts, attendees = Job.everything(location)
        return {
            "location": location,
            "jobs":     jobs,
            "shifts":   Shift.serialize(shifts)
        }
    
    def everywhere(self, message="", show_restricted=""):
        jobs, shifts, attendees = Job.everything()
        return {
            "message":   message,
            "attendees": attendees,
            "shifts":    Shift.serialize(shifts),
            "show_restricted": show_restricted,
            "jobs":      [job for job in jobs if (show_restricted or not job.restricted)
                                             and datetime.now() < job.start_time + timedelta(hours = job.duration)]
        }
    
    def staffers(self, location = ARCADE):
        jobs, shifts, attendees = Job.everything(location)
        return {
            "location":           location,
            "attendees":          attendees,
            "emails":             ",".join(a.email for a in attendees),
            "regular_total":      sum(j.total_hours for j in jobs if not j.restricted),
            "restricted_total":   sum(j.total_hours for j in jobs if j.restricted),
            "all_total":          sum(j.total_hours for j in jobs),
            "regular_signups":    sum(s.job.weighted_hours for s in shifts if not s.job.restricted),<commit_msg>fixed Staffer Summary page so even when at the con it will only show relevant staffers<commit_after>from common import *

def weighted_hours(staffer, location):
    shifts = Shift.objects.filter(attendee = staffer).select_related()
    return sum([shift.job.real_duration * shift.job.weight
                for shift in shifts
                if shift.job.location == int(location)],
               0.0)

@all_renderable(PEOPLE)
class Root:
    def index(self, location = ARCADE):
        by_id = {}
        jobs = defaultdict(list)
        for job in Job.objects.filter(location = location):
            by_id[job.id] = job
            jobs[job.start_time if not job.start_time.minute else job.start_time - timedelta(minutes = 30)].append(job)
        
        for job in by_id.values():
            job._shifts = []
        for shift in Shift.objects.filter(job__location = location):
            by_id[shift.job_id]._shifts.append(shift)
        
        jobs, shifts, attendees = Job.everything(location)
        by_start = defaultdict(list)
        for job in jobs:
            by_start[job.start_time].append(job)
        times = [state.EPOCH + timedelta(hours = i) for i in range(CON_LENGTH)]
        times = [(t, t + timedelta(hours = 1), by_start[t]) for i,t in enumerate(times)]
        return {
            "location": location,
            "times":    times
        }
    
    def signups(self, location = ARCADE):
        jobs, shifts, attendees = Job.everything(location)
        return {
            "location": location,
            "jobs":     jobs,
            "shifts":   Shift.serialize(shifts)
        }
    
    def everywhere(self, message="", show_restricted=""):
        jobs, shifts, attendees = Job.everything()
        return {
            "message":   message,
            "attendees": attendees,
            "shifts":    Shift.serialize(shifts),
            "show_restricted": show_restricted,
            "jobs":      [job for job in jobs if (show_restricted or not job.restricted)
                                             and datetime.now() < job.start_time + timedelta(hours = job.duration)]
        }
    
    def staffers(self, location = ARCADE):
        jobs, shifts, attendees = Job.everything(location)
        attendees = [a for a in attendees if int(location) in a.assigned]
        return {
            "location":           location,
            "attendees":          attendees,
            "emails":             ",".join(a.email for a in attendees),
            "regular_total":      sum(j.total_hours for j in jobs if not j.restricted),
            "restricted_total":   sum(j.total_hours for j in jobs if j.restricted),
            "all_total":          sum(j.total_hours for j in jobs),
            "regular_signups":    sum(s.job.weighted_hours for s in shifts if not s.job.restricted),
{'fraction_non_alphanumeric': 0.10634834508952794, 'fraction_numerical': 0.0018086453246518358, 'mean_word_length': 1.944621938232162, 'pattern_counts': {'":': 34, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7281528', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1514, 'n_words': 402}