Пример #1
0
def fix_student_names(csvin):
    """CATME csv files use 'Student Name' as the label and 'Last,
    First' as the name column.  This function breaks that into seperate last and
    first columns and rewrites the csv file."""
    #Last Name	First Name
    mydb = txt_database.db_from_file(csvin)
    lower_labels = [item.lower() for item in mydb.labels]
    mylist = ['last name', 'lastname', 'lname']
    for label in mylist:
        if label in lower_labels:
            #exit now
            return
        
    #keep going only if we didn't find a last name column
    if "Student Name" not in mydb.labels:
        #problem, bail
        raise(KeyError, "did not find 'Student Name' in column labels")

    student_names = mydb.Student_Name
    last_names = []
    first_names = []

    for name in student_names:
        last, first = name.split(',',1)
        last = last.strip()
        first = first.strip()
        last_names.append(last)
        first_names.append(first)
        
    new_data = column_stack([last_names, first_names, mydb.data])
    new_labels = numpy.append(["Last Name", "First Name"], mydb.labels)
    mydb.data = new_data
    mydb.labels = new_labels
    mydb.save(csvin, delim=',')
Пример #2
0
def fix_student_names(csvin):
    """CATME csv files use 'Student Name' as the label and 'Last,
    First' as the name column.  This function breaks that into seperate last and
    first columns and rewrites the csv file."""
    #Last Name	First Name
    mydb = txt_database.db_from_file(csvin)
    lower_labels = [item.lower() for item in mydb.labels]
    mylist = ['last name', 'lastname', 'lname']
    for label in mylist:
        if label in lower_labels:
            #exit now
            return
        
    #keep going only if we didn't find a last name column
    if "Student Name" not in mydb.labels:
        #problem, bail
        raise(KeyError, "did not find 'Student Name' in column labels")

    student_names = mydb.Student_Name
    last_names = []
    first_names = []

    for name in student_names:
        last, first = name.split(',',1)
        last = last.strip()
        first = first.strip()
        last_names.append(last)
        first_names.append(first)
        
    new_data = column_stack([last_names, first_names, mydb.data])
    new_labels = numpy.append(["Last Name", "First Name"], mydb.labels)
    mydb.data = new_data
    mydb.labels = new_labels
    mydb.save(csvin, delim=',')
Пример #3
0
    def validate_spreadsheet(self, path, debug=1):
        db = txt_database.db_from_file(path)
        mylist = txt_mixin.txt_list(db.labels)
        
        def get_db_attr_by_pat(pat):
            inds = mylist.findallre(pat)
            assert len(inds) > 0, "did not find a match for %s in labels" % pat
            assert len(inds) == 1, "found more than one match for %s" %s
            ind = inds[0]
            fn_label = db.labels[ind] 
            attr = db.attr_label_dict[fn_label]
            vect = getattr(db, attr)
            return vect

        fn_pat = '[Ff]irst[ _][Nn]ame'
        try:
            self.first_names = get_db_attr_by_pat(fn_pat)
        except:
            print('delimited text file must have a column label that matches %s' % \
                  fn_pat)
        self.emails = get_db_attr_by_pat('[Ee]mail')
        
        if debug:
            print('first_names:' + str(self.first_names))
            print('emails:' + str(self.emails))

        check_for_blanks(self.first_names)
        check_for_blanks(self.emails)
        assert len(self.first_names) == len(self.emails), \
               "lengthes of first names and emails do not match"
Пример #4
0
def get_banner_ids(filename):
    if type(filename) == list:
        filename = filename[0]
    # mysheet = spreadsheet.TabDelimSpreadSheet(filename)
    # mysheet.ReadData()
    # ids = mysheet.get_col(2)
    mydb = txt_database.db_from_file(filename)
    ids = mydb.ID
    if ids[0].lower() == "id":
        ids.pop(0)
    return ids
Пример #5
0
    def __init__(self, filename):
        self.filename = filename
        listin = load_bb_csv(filename)

        fno, ext = os.path.splitext(filename)
        outname = fno + '_clean' + ext

        clean_list = clean_bb_csv_list(listin)
        txt_mixin.dump(outname, clean_list)
        
        self.db = txt_database.db_from_file(outname)
Пример #6
0
def get_banner_ids(filename):
    if type(filename) == list:
        filename = filename[0]
    #mysheet = spreadsheet.TabDelimSpreadSheet(filename)
    #mysheet.ReadData()
    #ids = mysheet.get_col(2)
    mydb = txt_database.db_from_file(filename)
    ids = mydb.ID
    if ids[0].lower() == 'id':
        ids.pop(0)
    return ids
Пример #7
0
    def __init__(self, filename):
        self.filename = filename
        listin = load_bb_csv(filename)

        fno, ext = os.path.splitext(filename)
        outname = fno + '_clean' + ext

        clean_list = clean_bb_csv_list(listin)
        txt_mixin.dump(outname, clean_list)

        self.db = txt_database.db_from_file(outname)
Пример #8
0
    def __init__(self, csvpathin, folderout='out', \
                 basename_pat='report_%0.2i.rst',
                 title_pat='My Title %i', \
                 ignorecols=[]):
        self.csvpathin = csvpathin
        self.folderout = folderout
        self.basename_pat = basename_pat
        self.title_pat = title_pat
        self.ignorecols = ignorecols
        self.db = txt_database.db_from_file(csvpathin)
        self.N = len(self.db.data)

        self.filt_labels = [item for item in self.db.labels if item not in ignorecols]
Пример #9
0
def get_names_from_Banner_txt(filename):
    # this approach assumes labels are in the top row (1 row of labels
    # only) and that the column label for the student names is "Student Name"
    mydb = txt_database.db_from_file(filename)
    names = mydb.Student_Name
    return names
Пример #10
0
def get_names_from_Banner_txt(filename):
    #this approach assumes labels are in the top row (1 row of labels
    #only) and that the column label for the student names is "Student Name"
    mydb = txt_database.db_from_file(filename)
    names = mydb.Student_Name
    return names