<commit_before>from uber.common import *

groups, attendees = {}, {}
with open(join(MODULE_ROOT, 'tests', 'test_data.json')) as f:
    dump = json.load(f)

offset_from = EPOCH
def offset_to_datetime(offset):
    return offset_from + timedelta(hours=offset)

words = []
def random_group_name():
    if not words:
        with open('/usr/share/dict/words') as f:
            words[:] = [s.strip() for s in f if len(s) > 3 and re.match('^[a-z]+$', s)]
    return ' '.join(random.choice(words).title() for i in range(2))

def import_groups(session):
    for g in dump['groups']:
        secret_id = g.pop('secret_id')
        g['cost'] = g.pop('amount_owed')
        g['name'] = random_group_name()
        groups[secret_id] = Group(**g)
        session.add(groups[secret_id])

def import_attendees(session):
    for a in dump['attendees']:
        a['group'] = groups.get(a.pop('group_id', None))
        secret_id = a.pop('secret_id')
        attendees[secret_id] = Attendee(**a)
        session.add(attendees[secret_id])

    for f in dump['food']:
        f['attendee'] = attendees[f.pop('attendee_id')]
        session.add(FoodRestrictions(**f))

    for h in dump['hotel']:
        h['attendee'] = attendees[h.pop('attendee_id')]
        session.add(HotelRequests(**h))

def import_events(session):
    event_locs, _ = zip(*EVENT_LOCATION_OPTS)
    for e in dump['events']:
        if e['location'] in event_locs:
            e['start_time'] = offset_to_datetime(e['start_time'])
            panelists = e.pop('panelists')
            event = Event(**e)
            session.add(event)
            for secret_id in panelists:
                session.add(AssignedPanelist(event=event, attendee=attendees[secret_id]))

def import_jobs(session):
    job_locs, _ = zip(*JOB_LOCATION_OPTS)
    for j in dump['jobs']:
        if j['location'] in job_locs:
            j['start_time'] = offset_to_datetime(j['start_time'])
            shifts = j.pop('shifts')
            job = Job(**j)
            session.add(job)
            for secret_id in shifts:
                job.shifts.append(Shift(attendee=attendees[secret_id]))

@entry_point
def import_uber_test_data():<commit_msg>fixed import_uber_test_data by adding a default for sandwich preference<commit_after>from uber.common import *

groups, attendees = {}, {}
with open(join(MODULE_ROOT, 'tests', 'test_data.json')) as f:
    dump = json.load(f)

offset_from = EPOCH
def offset_to_datetime(offset):
    return offset_from + timedelta(hours=offset)

words = []
def random_group_name():
    if not words:
        with open('/usr/share/dict/words') as f:
            words[:] = [s.strip() for s in f if len(s) > 3 and re.match('^[a-z]+$', s)]
    return ' '.join(random.choice(words).title() for i in range(2))

def import_groups(session):
    for g in dump['groups']:
        secret_id = g.pop('secret_id')
        g['cost'] = g.pop('amount_owed')
        g['name'] = random_group_name()
        groups[secret_id] = Group(**g)
        session.add(groups[secret_id])

def import_attendees(session):
    for a in dump['attendees']:
        a['group'] = groups.get(a.pop('group_id', None))
        secret_id = a.pop('secret_id')
        attendees[secret_id] = Attendee(**a)
        session.add(attendees[secret_id])

    for f in dump['food']:
        f['attendee'] = attendees[f.pop('attendee_id')]
        f.setdefault('sandwich_pref', PBJ)  # sandwich_pref didn't exist when the dump was taken
        session.add(FoodRestrictions(**f))

    for h in dump['hotel']:
        h['attendee'] = attendees[h.pop('attendee_id')]
        session.add(HotelRequests(**h))

def import_events(session):
    event_locs, _ = zip(*EVENT_LOCATION_OPTS)
    for e in dump['events']:
        if e['location'] in event_locs:
            e['start_time'] = offset_to_datetime(e['start_time'])
            panelists = e.pop('panelists')
            event = Event(**e)
            session.add(event)
            for secret_id in panelists:
                session.add(AssignedPanelist(event=event, attendee=attendees[secret_id]))

def import_jobs(session):
    job_locs, _ = zip(*JOB_LOCATION_OPTS)
    for j in dump['jobs']:
        if j['location'] in job_locs:
            j['start_time'] = offset_to_datetime(j['start_time'])
            shifts = j.pop('shifts')
            job = Job(**j)
            session.add(job)
            for secret_id in shifts:
                job.shifts.append(Shift(attendee=attendees[secret_id]))

@entry_point
def import_uber_test_data():
{'fraction_non_alphanumeric': 0.14885580982003999, 'fraction_numerical': 0.0008886914019106865, 'mean_word_length': 2.9560632688927946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4987399', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1502, 'n_words': 303}