added rstat.getRFrame() method
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2093 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									f5b4675a3d
								
							
						
					
					
						commit
						84ffc7ff6e
					
				
					 1 changed files with 31 additions and 1 deletions
				
			
		| 
						 | 
					@ -32,7 +32,6 @@ from cybertools.pyscript.plot import registerImage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# not used (yet?):
 | 
					# not used (yet?):
 | 
				
			||||||
 | 
					 | 
				
			||||||
class RWrapper(object):
 | 
					class RWrapper(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, context):
 | 
					    def __init__(self, context):
 | 
				
			||||||
| 
						 | 
					@ -73,3 +72,34 @@ class RStat(object):
 | 
				
			||||||
        key = registerImage(fn)
 | 
					        key = registerImage(fn)
 | 
				
			||||||
        return '%s/@@plot?image=%s.jpg' % (absoluteURL(context, request), key)
 | 
					        return '%s/@@plot?image=%s.jpg' % (absoluteURL(context, request), key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def getRFrame(self, data):
 | 
				
			||||||
 | 
					        """ Return an R data.frame.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            The ``data`` argument is a sequence of tuples
 | 
				
			||||||
 | 
					            (rowId, columnId, value). Elements with a columnId
 | 
				
			||||||
 | 
					            that is not present in all rows is omitted.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        def checkColumnId(rows, columnId):
 | 
				
			||||||
 | 
					            for row in rows.values():
 | 
				
			||||||
 | 
					                if columnId not in row:
 | 
				
			||||||
 | 
					                    return False
 | 
				
			||||||
 | 
					            return True
 | 
				
			||||||
 | 
					        data = sorted(data)
 | 
				
			||||||
 | 
					        rows = {}
 | 
				
			||||||
 | 
					        for rowId, columnId, value in data:
 | 
				
			||||||
 | 
					            element = rows.setdefault(rowId, [])
 | 
				
			||||||
 | 
					            element.append(rowId)
 | 
				
			||||||
 | 
					        columnsToOmit = []
 | 
				
			||||||
 | 
					        for rowId, row in rows.items():
 | 
				
			||||||
 | 
					            for columnId in row:
 | 
				
			||||||
 | 
					                if not checkColumnId(rows, columnId):
 | 
				
			||||||
 | 
					                    columnsToOmit.append(columnId)
 | 
				
			||||||
 | 
					        r.library('ltm')
 | 
				
			||||||
 | 
					        result = {}
 | 
				
			||||||
 | 
					        for rowId, columnId, value in data:
 | 
				
			||||||
 | 
					            if columnId not in columnsToOmit:
 | 
				
			||||||
 | 
					                element = result.setdefault(rowId, [])
 | 
				
			||||||
 | 
					                element.append(value)
 | 
				
			||||||
 | 
					        rpy.set_default_mode(rpy.NO_CONVERSION)
 | 
				
			||||||
 | 
					        matrix = r.data_frame(**result)
 | 
				
			||||||
 | 
					        return matrix
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue