Ejemplo n.º 1
0
    def test_allblank_list(self):

        self.grid = [['', 'A', 'B', 'C'], ['X', [], [], []], ['Y', [], [], []],
                     ['Z', [], [], []]]

        self.expected_results = [['']]

        gridreduce(self.grid, [[]])
        self.assertListEqual(self.grid, self.expected_results)
Ejemplo n.º 2
0
    def test_1blankcol_1blankrow_space_list(self):

        self.grid = [['', 'A', 'B', 'C'], ['X', [], '', ''],
                     ['Y', 'foo', [], ''], ['Z', '', '', 'bar']]

        self.expected_results = [['', 'A', 'C'], ['Y', 'foo', ''],
                                 ['Z', '', 'bar']]

        gridreduce(self.grid, ["", []])
        self.assertListEqual(self.grid, self.expected_results)
Ejemplo n.º 3
0
    def test_1blankcol_1blankrow_space_rectangle(self):

        self.grid = [['', 'A', 'B', 'C', 'D'], ['X', '', '', '', ''],
                     ['Y', 'foo', '', '', 'blah'],
                     ['Z', '', '', 'bar', 'blah']]

        self.expected_results = [['', 'A', 'C', 'D'], ['Y', 'foo', '', 'blah'],
                                 ['Z', '', 'bar', 'blah']]

        gridreduce(self.grid, [""])
        self.assertListEqual(self.grid, self.expected_results)
Ejemplo n.º 4
0
    def test_noblank_list(self):

        import copy

        self.grid = [['', 'A', 'B', 'C'], ['X', ['blah'], ['blah'], ['blah']],
                     ['Y', ['foo'], ['blah'], ['blah']],
                     ['Z', ['blah'], ['blah'], ['bar']]]

        self.expected_results = copy.deepcopy(self.grid)

        gridreduce(self.grid, [[]])
        self.assertListEqual(self.grid, self.expected_results)
Ejemplo n.º 5
0
    def test_allblank_list(self):
        
        self.grid = [['','A','B','C'],
                     ['X',[],[],[]],
                     ['Y',[],[],[]],
                     ['Z',[],[],[]]
                     ]

        self.expected_results = [['']]
        
        gridreduce(self.grid,[[]])
        self.assertListEqual(self.grid,self.expected_results)
Ejemplo n.º 6
0
    def test_1blankcol_1blankrow_space_rectangle(self):
        
        self.grid = [['','A','B','C','D'],
                     ['X','','','',''],
                     ['Y','foo','','','blah'],
                     ['Z','','','bar','blah']]    

        self.expected_results = [['','A','C','D'],
                               ['Y','foo','','blah'],
                               ['Z','','bar','blah']]     
        
        gridreduce(self.grid,[""])
        self.assertListEqual(self.grid,self.expected_results)
Ejemplo n.º 7
0
    def test_1blankcol_1blankrow_space_list(self):
        
        self.grid = [['','A','B','C'],
                     ['X',[],'',''],
                     ['Y','foo',[],''],
                     ['Z','','','bar']]    

        self.expected_results = [['','A','C'],
                                 ['Y','foo',''],
                                 ['Z','','bar']]     
        
        gridreduce(self.grid,["",[]])
        self.assertListEqual(self.grid,self.expected_results)
Ejemplo n.º 8
0
 def test_noblank_list(self):
     
     import copy
     
     self.grid = [['','A','B','C'],
                  ['X',['blah'],['blah'],['blah']],
                  ['Y',['foo'],['blah'],['blah']],
                  ['Z',['blah'],['blah'],['bar']]]
     
     self.expected_results = copy.deepcopy(self.grid)
     
     gridreduce(self.grid,[[]])
     self.assertListEqual(self.grid,self.expected_results)
Ejemplo n.º 9
0
    def test_realexample(self):
        self.grid = [['', u'MO', u'TU', u'TH', u'WE', u'FR'],
                     [u'830-910', [(u'Amelia', u'ELA')], [], [], [], []],
                     [u'910-950', [], [], [], [], []],
                     [u'950-1030', [], [], [], [], []],
                     [u'1030-1110', [], [], [], [], []],
                     [u'1110-1210', [], [], [], [], []],
                     [u'1210-100', [], [], [], [], []],
                     [u'100-140', [], [], [], [], []],
                     [u'140-220', [], [], [], [], []],
                     [u'220-300', [], [], [], [], []],
                     [u'300-330', [], [], [], [], []]]

        self.expected_results = [['', u'MO'],
                                 [u'830-910', [(u'Amelia', u'ELA')]]]

        gridreduce(self.grid, ["", []])
        self.assertListEqual(self.grid, self.expected_results)
Ejemplo n.º 10
0
    def test_realexample(self):        
        self.grid = [['', u'MO', u'TU', u'TH', u'WE', u'FR'], 
                     [u'830-910', [(u'Amelia', u'ELA')], [], [], [], []], 
                     [u'910-950', [], [], [], [], []], 
                     [u'950-1030', [], [], [], [], []], 
                     [u'1030-1110', [], [], [], [], []], 
                     [u'1110-1210', [], [], [], [], []], 
                     [u'1210-100', [], [], [], [], []], 
                     [u'100-140', [], [], [], [], []], 
                     [u'140-220', [], [], [], [], []], 
                     [u'220-300', [], [], [], [], []], 
                     [u'300-330', [], [], [], [], []]]
        
        self.expected_results = [['', u'MO'], [u'830-910', [(u'Amelia', u'ELA')]]]

        
        gridreduce(self.grid,["",[]])
        self.assertListEqual(self.grid,self.expected_results)
Ejemplo n.º 11
0
    def viewer(self,yaxis_type,xaxis_type,ztypes, source_type,source_value,
               conflicts_only='N',constraints=None,wratio=None,formatson=False):
            
        if source_value == "":
            source_objs = self.of.query(source_type)
        else:
            source_objs = [self.of.object_get(source_type,source_value)]
            
        xaxis_obj = self.of.query(xaxis_type)
        yaxis_obj = self.of.query(yaxis_type)
        
        count=0
        yaxis_enum = {}
        for _yaxis_obj in yaxis_obj:
            yaxis_enum[_yaxis_obj.name] = count
            count+=1
        
        xaxis_enum = self.enums[xaxis_type]['name2enum']
        
        values = [] # contains the values displayed on the grid

        values = [['']]    
        for yval in yaxis_enum.keys():
            values[0].append(yval)
            
        for xval in xaxis_enum.keys():
            values.append([xval])

        ymax = len(values[0])
        xmax = len(values)-1
        
        def _additem(celltext,item):
            
            if len(celltext) == 0:
                celltext.append(item)
            else:
                try:
                    celltext.index(item)
                except:
                    celltext.append(item)
            return(celltext)
                
        for yval,y in yaxis_enum.iteritems():
            
            for xval,x in xaxis_enum.iteritems():
                celltext=[]
                
                for source_obj in source_objs:
                    if source_obj.lessons.has_key(yval):
                        if source_obj.lessons[yval].has_key(xval):
   
                            _vals = source_obj.lessons[yval][xval]

                            for _val in _vals:
                                
                                if constraints <> None:
                                    flag=False
                                    for objtype,objval in constraints:
                                        
                                        if getattr(_val,objtype).name <> objval:
                                            flag=True
                                    if flag == True:
                                        continue
                                    
                                if ztypes == ['*']:
                                    if celltext == []:
                                        celltext.append(0)
                                    else:
                                        celltext[0] = celltext[0] + 1
                                    continue

                                _celltext = []
                                
                                for ztype in ztypes:
                                    if hasattr(_val,ztype) == True:
                                        zval = getattr(_val,ztype)
                                        
                                        try:
                                            _celltext.index(zval.name)
                                        except:
                                            _celltext = _additem(_celltext,zval.name)
                                            pass
                                            
                                try:      
                                    celltext.index(tuple(_celltext))
                                except:
                                    celltext.append(tuple(_celltext))
                                    
                values[x].append(celltext)
        
        sswizard_utils.gridreduce(values,[[]])

        if formatson==True:                
            for x in range(len(values)):
                for y in range(len(values[x])):
                    _value = values[x][y]

                    if isinstance(_value,list) == True:
                        if _value <> []:
                            values[x][y] = []
                            ''' uncomment if want to generate conflicts report'''
                            #if len(_value) == 1 and conflicts_only <> "Y":
                            if len(_value) == 1:
                                if isinstance(_value[0],tuple) == True:
                                    # 1 item, multi attributes
                                    bgs,fgs = self._color_get_multi(_value[0])
                                    _formats = []
                                    for i in range(len(_value[0])):
                                        _formats.append(dict(value=_value[0][i],bgcolor=bgs[i],fgcolor=fgs[i]))
                                        
                                    values[x][y].append(tuple(_formats))
                                elif isinstance(_value[0],list) == False:
                                    # 1 item, single value
                                    bg,fg = self.color_get(_value[0])

                                    print "1,1 attr",_value[0],bgs,fgs
                            # multiple items
                            ''' uncomment if want to generate conflicts report'''
                            #if len(_value) > 1 and conflicts_only == "Y":
                            if len(_value) > 1:
                                for __value in _value:
                                    bgs,fgs = self._color_get_multi(__value)
                                    _formats = []
                                    for i in range(len(__value)):
                                        _formats.append(dict(value=__value[i],bgcolor=bgs[i],fgcolor=fgs[i]))
                                        
                                    values[x][y].append(tuple(_formats))
                    else:
                        if x == 0 or y == 0:
                            values[x][y] = dict(value=_value,bgcolor=black,fgcolor=white)
                                
            
            return values
Ejemplo n.º 12
0
def dataset_pivot(of,
                  enums,
                  yaxis_type,
                  xaxis_type,
                  ztypes,
                  source_type,
                  source_value,
                  conflicts_only='N',
                  constraints=None,
                  wratio=None,
                  formatson=False,
                  rollupson=False):
    ''' query in memory objects; pivot data and create a table of results; return in 2d array '''

    log.log(thisfuncname(),
            3,
            yaxis_type=yaxis_type,
            xaxis_type=xaxis_type,
            ztypes=ztypes,
            source_type=source_type,
            source_value=source_value,
            conflicts_only=conflicts_only,
            constraints=constraints,
            wratio=wratio,
            formatson=formatson,
            rollupson=rollupson)

    if source_value == "":
        source_objs = of.query(source_type)
    else:
        source_objs = [of.object_get(source_type, source_value)]

    xaxis_obj = of.query(xaxis_type)
    yaxis_obj = of.query(yaxis_type)

    count = 1

    # uncomment here to make DOW's present in order
    yaxis_enum = OrderedDict()
    #yaxis_enum = {}
    for _yaxis_obj in yaxis_obj:
        yaxis_enum[_yaxis_obj.name] = count
        count += 1

    count = 1
    xaxis_enum = OrderedDict()
    #xaxis_enum = {}
    for _xaxis_obj in xaxis_obj:
        xaxis_enum[_xaxis_obj.name] = count
        count += 1

    # use these if want to drive pivot axes from ref table rather than the  values
    # used so far by actual objects
    #xaxis_enum = enums[xaxis_type]['name2enum']

    values = []  # contains the values displayed on the grid

    values = [['']]
    for yval in yaxis_enum.keys():
        values[0].append(yval)

    for xval in xaxis_enum.keys():
        values.append([xval])

    ymax = len(values[0])
    xmax = len(values) - 1

    def _additem(celltext, item):

        if len(celltext) == 0:
            celltext.append(item)
        else:
            try:
                celltext.index(item)
            except:
                celltext.append(item)
        return (celltext)

    for yval, y in yaxis_enum.iteritems():

        for xval, x in xaxis_enum.iteritems():
            celltext = []

            for source_obj in source_objs:
                if source_obj.lessons.has_key(yval):
                    if source_obj.lessons[yval].has_key(xval):

                        _vals = source_obj.lessons[yval][xval]

                        for _val in _vals:

                            if constraints <> None and constraints <> []:
                                flag = False

                                for objtype, objval in constraints:

                                    lobjvals = objval.split(",")

                                    match = None
                                    for lobjval in lobjvals:
                                        if str(getattr(
                                                _val,
                                                objtype).name) <> str(lobjval):
                                            if match <> False:
                                                match = True
                                        else:
                                            match = False
                                    if match == True:
                                        flag = True

                                if flag == True:
                                    continue

                            if ztypes == ['*']:
                                if celltext == []:
                                    celltext.append(1)
                                else:
                                    celltext[0] = celltext[0] + 1
                                continue

                            _celltext = []

                            for ztype in ztypes:
                                if hasattr(_val, ztype) == True:
                                    zval = getattr(_val, ztype)

                                    try:
                                        _celltext.index(zval.name)
                                    except:
                                        if hasattr(zval, 'name'):
                                            _celltext = _additem(
                                                _celltext, zval.name)
                                        else:
                                            _celltext = _additem(
                                                _celltext, zval)
                                        pass

                            try:
                                celltext.index(tuple(_celltext))
                            except:
                                celltext.append(tuple(_celltext))

            values[x].append(celltext)

    sswizard_utils.gridreduce(values, [[]])

    if rollupson == True:
        sswizard_utils.gridrollup(values, ['subject', 'adult'],
                                  dict(ztypes='subject,adult,student'))

    return values