Пример #1
0
def remove_extra_rows_and_columns(raw_con, raw_acc, raw_enr, hs_set):
    '''Does what it says: First limits the number of entries based on the
    High Schools covered and then reduces the columns of data in each
    table prior to returning a Table class'''
    # First reduce rows in the contact table
    hc = tt.slice_header(raw_con)
    con_in_hs = [x for x in raw_con if x[hc[c.High_School__c]] in hs_set]
    student_set = set([x[hc[c.Id]] for x in con_in_hs]) # for enr
    tt.add_header(con_in_hs, hc)
    big_con = tc.Table(con_in_hs)

    # Second reduce rows in enrollment table
    he = tt.slice_header(raw_enr)
    enr_in_hs = [x for x in raw_enr if x[he[e.Student__c]] in student_set]
    college_set = set([x[he[e.College__c]] for x in enr_in_hs]) # for acc
    tt.add_header(enr_in_hs, he)
    big_enr = tc.Table(enr_in_hs)

    # Third reduce rows in the accounts table
    ha = tt.slice_header(raw_acc)
    acc_in_hs = [x for x in raw_acc if x[ha[a.Id]] in college_set]
    tt.add_header(acc_in_hs, ha)
    big_acc = tc.Table(acc_in_hs)

    # Finally, use the lists defined at the top of this file to reduce the
    # number of columns (this step is necessary so that users that supply
    # a CSV file don't need to supply the exact right columns
    little_con = big_con.new_subtable(con_fields, con_names)
    little_acc = big_acc.new_subtable(acc_fields, acc_names)
    little_enr = big_enr.new_subtable(enr_fields, enr_names)

    return (little_con, little_acc, little_enr)
Пример #2
0
def remove_extra_rows_and_columns(raw_con, raw_acc, raw_enr, hs_set):
    '''Does what it says: First limits the number of entries based on the
    High Schools covered and then reduces the columns of data in each
    table prior to returning a Table class'''
    # First reduce rows in the contact table
    hc = tt.slice_header(raw_con)
    con_in_hs = [x for x in raw_con if x[hc[c.High_School__c]] in hs_set]
    student_set = set([x[hc[c.Id]] for x in con_in_hs])  # for enr
    tt.add_header(con_in_hs, hc)
    big_con = tc.Table(con_in_hs)

    # Second reduce rows in enrollment table
    he = tt.slice_header(raw_enr)
    enr_in_hs = [x for x in raw_enr if x[he[e.Student__c]] in student_set]
    college_set = set([x[he[e.College__c]] for x in enr_in_hs])  # for acc
    tt.add_header(enr_in_hs, he)
    big_enr = tc.Table(enr_in_hs)

    # Third reduce rows in the accounts table
    ha = tt.slice_header(raw_acc)
    acc_in_hs = [x for x in raw_acc if x[ha[a.Id]] in college_set]
    tt.add_header(acc_in_hs, ha)
    big_acc = tc.Table(acc_in_hs)

    # Finally, use the lists defined at the top of this file to reduce the
    # number of columns (this step is necessary so that users that supply
    # a CSV file don't need to supply the exact right columns
    little_con = big_con.new_subtable(con_fields, con_names)
    little_acc = big_acc.new_subtable(acc_fields, acc_names)
    little_enr = big_enr.new_subtable(enr_fields, enr_names)

    return (little_con, little_acc, little_enr)
Пример #3
0
def specify_high_schools(raw_con, hs):
    if hs: #User specified a single HS already
        return [hs]
    else:
        hc = tt.slice_header(raw_con) # we need to remember to add this back
        initial_hs = list(set([x[hc[c.High_School__c]] for x in raw_con]))
        initial_hs = [h for h in initial_hs if type(h) is str]
        initial_hs.sort()
        hs_list = tktools.check_pick_from_list(initial_hs,
                'Pick which High Schools to include in the report')
        tt.add_header(raw_con, hc)
        return hs_list
Пример #4
0
def specify_high_schools(raw_con, hs):
    if hs:  #User specified a single HS already
        return [hs]
    else:
        hc = tt.slice_header(raw_con)  # we need to remember to add this back
        initial_hs = list(set([x[hc[c.High_School__c]] for x in raw_con]))
        initial_hs = [h for h in initial_hs if type(h) is str]
        initial_hs.sort()
        hs_list = tktools.check_pick_from_list(
            initial_hs, 'Pick which High Schools to include in the report')
        tt.add_header(raw_con, hc)
        return hs_list
'''
from botutils.ADB import AlumniDatabaseInterface as aDBi
from botutils.ADB import ContactNamespace as c
from botutils.ADB import AccountNamespace as a
from botutils.ADB import EnrollmentNamespace as e
from botutils.tabletools import tabletools as tt
from botutils.ADB import ssf

#Grab the data tables
restriction = ''
sf = ssf.getSF()
contacts, accounts, enrollments = aDBi.grabThreeMainTables_Analysis(
    restriction, sf)

#Lop off headers
dC = tt.slice_header(contacts)
dA = tt.slice_header(accounts)
dE = tt.slice_header(enrollments)

print('Beginning to parse %d contacts.' % len(contacts))
soFar = 0  #index of number of contacts covered
for student in contacts:
    soFar += 1
    if not soFar % 10: print('.', end='')
    if not soFar % 100: print('%d contacts processed.' % soFar)
    records = [
        row for row in enrollments
        if row[dE[e.Student__c]] == student[dC[c.Id]]
        and row[dE[e.Status__c]] == 'Attending'
    ]
'''
from botutils.ADB import AlumniDatabaseInterface as aDBi
from botutils.ADB import ContactNamespace as c
from botutils.ADB import AccountNamespace as a
from botutils.ADB import EnrollmentNamespace as e
from botutils.tabletools import tabletools as tt
from botutils.ADB import ssf

#Grab the data tables
restriction = ''
sf = ssf.getSF()
contacts, accounts, enrollments = aDBi.grabThreeMainTables_Analysis(
                                                    restriction,sf)

#Lop off headers
dC = tt.slice_header(contacts)
dA = tt.slice_header(accounts)
dE = tt.slice_header(enrollments)

print('Beginning to parse %d contacts.' % len(contacts))
soFar = 0 #index of number of contacts covered
for student in contacts:
    soFar+=1
    if not soFar % 10: print('.', end='')
    if not soFar % 100: print('%d contacts processed.' % soFar)
    records = [row for row in enrollments if row[dE[e.Student__c]] ==
                                                  student[dC[c.Id]] and
                                                  row[dE[e.Status__c]] ==
                                                  'Attending']

    enrolled_at = None