def process_duplicates(app, table, key):
    """
    Condenses all duplicates in the table so we get one record
    per person with all registrations.
    """
    recordframe = at.read_all(app, table, key)
    namegroups = recordframe.groupby('Email Address').groups
    duplicates = list(filter(lambda person : len(namegroups[person]) > 1, namegroups.keys()))
    for duplicator in duplicates:
        records = recordframe[recordframe['Email Address'] == duplicator]
        records = records.sort_values(by='createdTime')
        delids = records.index[:-1]
        outid = records.index[-1] # last one is probably most corrected version?
        records = records.drop(columns=fields)
        updatefields = {}
        for col in records.columns:
            if sum(records[col] == 'X') > 0:
                updatefields[col] = 'X'
        newrecord = {'id': outid, 'fields': updatefields}
        at.update(newrecord, app, table, key)
        for delid in delids:
            at.delete({"id": delid}, app, table, key)
def merge_registrations(app, table, column, coursetable, key):
    """
    Updates registrations in the main table based on marked registration
    in class.
    """
    basetable = at.read_all(app, table, key)
    basetable = basetable.reset_index()
    coursetab = at.read_all(app, coursetable, key)

    merged = basetable.merge(coursetab, on="Email Address", suffixes=("_l", "_r"), how="inner")
    merged = merged[["id", column+"_r"]]
    merged = merged.rename(columns={column+"_r": column})
    merged = merged[["id", column]]

    merged.apply(lambda rec: at.update(make_dict(dict(rec), column), app, table, key), axis=1)
Exemple #3
0
def merge_registrations(app, table, column, coursetable, key):
    """
    Updates registrations in the main table and course tables 
    based on marked registration in class.
    """
    print(coursecol)

    basetable = at.read_all(app, table, key)
    basetable = basetable.reset_index()
    coursetab = at.read_all(app, coursetable, key)

    # copy attendance information from course tables to main table
    merged = basetable.merge(coursetab,
                             on="Email Address",
                             suffixes=("_l", "_r"),
                             how="inner")
    merged = merged[["id", column + "_r"]]
    merged = merged.rename(columns={column + "_r": column})
    merged = merged[["id", column]]

    merged.apply(
        lambda rec: at.update(make_dict(dict(rec), column), app, table, key),
        axis=1)

    basetable = at.read_all(app, table, key)

    # copy course registration information from main table to course table
    sidemerged = coursetab.merge(basetable,
                                 on="Email Address",
                                 suffixes=("_l", ""),
                                 how="right")
    sidemerged = sidemerged[(sidemerged[column] == "X")
                            & (sidemerged[column + "_l"].isnull())]
    sidemerged = sidemerged[[
        "Full Name", "Email Address", "Rice Affiliation",
        "School, Department, or Program", column
    ]]
    sidemerged = sidemerged.iloc[1:]
    print(sidemerged)
    if len(sidemerged) == 0:
        return
    sidemerged.apply(lambda rec: print(rec), axis=1)
    sidemerged.apply(lambda rec: at.create(dict(rec), app, coursetable, key),
                     axis=1)