Beispiel #1
0
    def get_teachers(matrix, workratio):
        '''
        input should be a Tabular object, or a path
        workratio is WorkRatio object
        '''
        if type(matrix) is str:
            temp = Tabular()
            temp.load_xls(matrix, strict=True)
            matrix = temp
        ret = []
        header = matrix[0]
        cols = len(header)
        if (cols < 2):
            raise Exception('too few columns')
        idd = 2
        for row in matrix:
            info = ""
            kwargs = dict()
            if (cols >= 3): info = row[2]
            if (cols > 3):
                i = 3
                while i < cols:
                    kwargs[header[i]] = row[i]
                    i += 1
            temp = Teacher(idd, row[0], row[1], info, **kwargs)
            temp._credits = workratio.credits_calc(
                temp.rank) / 10  # just for initial sort
            ret.append(temp)
            idd += 1

        return ret
Beispiel #2
0
    def get_rooms(matrix,workratio):
        '''
        input should be a Tabular object, or a path
        workratio is object of WorkRatio
        '''
        if type(matrix) is str:
            Verifier.verify_room_list(matrix)
            temp = Tabular()
            temp.load_xls(matrix,strict=True)
            matrix = temp
        ret = []
        header = matrix[0]
        cols = len(header)
        if(cols < 2):
            raise Exception('too few columns')

        matrix = matrix[1:]
        for row in matrix:
            capacity = 0
            kwargs = dict()
            if(cols >= 3): capacity = row[2]
            if(cols > 3):
                i = 3
                while i < cols:
                    kwargs[header[i]] = row[i]
                    i += 1
            temp = Room(row[0],row[1],capacity,**kwargs)
            temp.workratio = workratio
            ret.append(temp)

        return ret
Beispiel #3
0
def test_tabular():
    if(not on_travis):
        return

    a = Tabular('spike/excel.xlsx')
    print(a,a[0])
    assert(len(a) == 3)
    assert(len(a[0]) == 3)
    assert(a[0][0] == 'name')
    assert(a[1]['name'] == 'pagal')
    assert(a['name'][0] == 'pagal')
    assert(len(a['name']) == 2)
    a.write_csv('test.csv')
    a.write_json('test.json')
    a.write_xls('test.xlsx')

    # strict
    a.load_xls('spike/strict.xlsx',strict=True)
    assert(len(a) == 8)


    b = Tabular('test.xlsx')
    assert(len(b) == 3)
    assert(len(b[0]) == 3)
    assert(b[0][0] == 'name')
    assert(b[1]['name'] == 'pagal')
    assert(b['name'][0] == 'pagal')
    assert(len(b['name']) == 2)

    c = Tabular('test.csv')
    c = Tabular('test.json')
Beispiel #4
0
    def get_teachers(matrix):
        '''
        input should be a Tabular object, or a path
        '''
        if type(matrix) is str:
            Verifier.verify_teachers_list(matrix)
            temp = Tabular()
            temp.load_xls(matrix,strict=True)
            matrix = temp
        ret = []
        header = matrix[0]
        cols = len(header)
        if(cols < 2):
                raise Exception('too few columns')
        matrix = matrix[1:]
        idd = 2
        for row in matrix:
            info = ""
            kwargs = dict()
            if(cols >= 3): info = row[2]
            if(cols > 3):
                i = 3
                while i < cols:
                    kwargs[header[i]] = row[i]
                    i += 1
            temp = Teacher(idd,row[0],row[1],info,**kwargs)
            ret.append(temp)
            idd += 1

        return ret
Beispiel #5
0
 def _read(file_path):
     matrix = Tabular()
     try:
         matrix.load_xls(file_path,strict=True)
     except:
         print('unable to read file : ',file_path)
         raise
         sys.exit(1)
     return matrix
    def __init__(self, filepath):
        matrix = Tabular()
        matrix.load_xls(filepath, strict=True)
        matrix = matrix.matrix[1:]
        self.ratio = {}
        self.credits = {0: 999999}
        for x in matrix:
            self.ratio[int(x[0])] = float(x[1])

        if not 1 in self.ratio: self.ratio[1] = 100
        for x in matrix:
            self.credits[int(x[0])] = self._credits_calc(int(x[0]))
Beispiel #7
0
    def get_sessions(matrix, room_data):
        '''
        input matrix should be a Tabular object, or a path
        room_data should be a tabular object or a path
        '''
        if type(matrix) is str:
            Verifier.verify_schedule_list(matrix)
            temp = Tabular()
            temp.load_xls(matrix, strict=True)
            matrix = temp
        if type(room_data) is str:
            room_data = Room.get_rooms(room_data)

        room_json = {}
        for room in room_data:
            room_json[room.name] = room

        ret = []
        header = matrix[0][1:]  # remove first elem from header
        cols = len(header) + 1
        if (cols < 2):
            raise Exception('too few columns')
        for i in range(1, len(matrix)):
            row = matrix[i]
            room_list = []
            for room in header:
                need = row[room]
                if need == 'y' or need == 'Y':
                    if room in room_json:
                        room_list.append(room_json[room].copy())
                    else:
                        # raise Exception('Room ' +room+ ' not present in rooms file')
                        Colour.print(
                            'Room ' + room + ' not present in room list',
                            Colour.RED)
                        sys.exit()

            temp = Session(row[0], room_list)
            ret.append(temp)

        return ret
Beispiel #8
0
    def get_sessions(matrix,room_data,workratio):
        '''
        input matrix should be a Tabular object, or a path
        room_data should be a tabular object or a path
        workratio is obj of WorkRatio
        '''
        if type(matrix) is str:
            Verifier.verify_schedule_list(matrix)
            temp = Tabular()
            temp.load_xls(matrix,strict=True)
            matrix = temp
        if type(room_data) is str:
            room_data = Room.get_rooms(room_data,workratio)

        room_json = {}
        for room in room_data:
            room_json[room.name] = room

        ret = []
        header = matrix[0][1:] # remove first elem from header
        cols = len(header) + 1
        if(cols < 2):
                raise Exception('too few columns')
        for row in matrix:
            room_list = []
            for room in header:
                need = row[room]
                if need == 'y' or need == 'Y':
                    if room in room_json:
                        room_list.append(room_json[room].copy())
                    else:
                        raise Exception('Room ' +room+ ' not present in rooms file')

            if (len(room_list) > 0): # dont consider empty session
                temp = Session(row[0], room_list)
                ret.append(temp)

        return ret
Beispiel #9
0
class Output:
    def __init__(self, filename):
        '''
        belives that file is already compiled
        '''
        self.mat = Tabular()
        self.mat.load_xls(filename, strict=True)

    def json(self):
        debugcols = ['_rank', '_total', '_res', '_credits', 's_d_m_d']
        infocols = ['Info', 'Name of Faculty Member', 'Total', 'mail']
        header = []
        for col in self.mat[0]:
            if col in debugcols:
                continue
            header.append(col)

        ret_json = []
        for row in self.mat:
            teacher = dict()
            teacher['duties'] = dict()
            for head in header:
                if head in infocols:
                    teacher[head] = row[head]
                elif row[head] and row[head] != '-':
                    teacher['duties'][head] = row[head]
            ret_json.append(teacher)
        return ret_json

    def mail(self, email, password, custom_message=''):
        subject = "Alloted Duties In examination"
        header = self.mat[0]
        if not 'mail' in header:
            return 0
        sent = 0
        for teacher in self.mat:
            if teacher['mail']:
                data = [[], []]
                for i in range(0, len(header) - 1):
                    if (not teacher[i]) or teacher[i] == '-':
                        continue
                    data[0].append(header[i])
                    data[1].append(teacher[i])
                try:
                    Output.__send_email(
                        email, password, teacher['mail'],
                        Output.__makebody(data, custom_message), subject)
                    sent += 1
                except:
                    pass
        return sent

    @staticmethod
    def __makebody(data, custom_message):
        infocols = [
            'Info', 'Name of Faculty Member', 'Total', 'mail', '_rank',
            '_total', '_res', '_credits', 's_d_m_d'
        ]
        duties = ''
        for i in range(len(data[0])):
            print(data[0][i])
            if (data[0][i] in infocols):
                continue
            duties += str(data[0][i]) + ' : ' + str(data[1][i]) + '\n'
        body = mainbody.format(name=data[1][0],
                               dutiesdata=duties,
                               custom_message=custom_message)
        print(body)
        return body

    @staticmethod
    def __send_email(email, password, toaddr, body='', subject=''):
        mail = Email()
        mail.fromaddr = email
        mail.password = password
        mail.toaddr = toaddr
        mail.subject = subject
        mail.body = body
        mail.send()