Changeset 3351 in products


Ignore:
Timestamp:
Feb 7, 2012 4:37:01 PM (12 years ago)
Author:
enkidu
Message:

changeset from http://codereview.corp.quintagroup.com/142241/show

Location:
quintagroup.analytics/branches/update_mt/quintagroup/analytics/browser
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.analytics/branches/update_mt/quintagroup/analytics/browser/configure.zcml

    r3090 r3351  
    7070        for="*" 
    7171        permission="zope2.ViewManagementScreens" 
    72         attribute="getSizeInfoByPath" 
    7372        class=".views.SizeByPath" 
     73        template="objects_size_stat.pt" 
    7474        /> 
    7575 
  • quintagroup.analytics/branches/update_mt/quintagroup/analytics/browser/views.py

    r3090 r3351  
    11from pprint import pprint 
     2from operator import itemgetter 
    23from Acquisition import aq_base 
    34from zope.component import getUtility, getMultiAdapter, queryMultiAdapter 
     
    1112from plone.portlets.interfaces import IPortletAssignmentMapping 
    1213from plone.portlets.interfaces import ILocalPortletAssignmentManager 
     14 
     15from plone.memoize import view 
    1316 
    1417try: 
     
    536539        num /= 1024.0 
    537540    # add more suffixes if you need them 
    538     return '%.2f %sB' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude]) 
     541    return '%.0f %sB' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude]) 
    539542 
    540543def getSize(brain): 
     
    544547                 or 1) 
    545548 
     549def matrix_tranform(a): 
     550    b = [0 for i in range(len(a)-1)] 
     551    return [b[:i]+[a[i]]+b[i:] for i in range(len(a))] 
    546552 
    547553class SizeByPath(BrowserView): 
     
    555561        bpath = self.request.form.get('basepath') 
    556562        self.basepath = bpath and "/"+bpath.strip("/") or "" 
    557  
     563        # set default value for type by size stats 
     564        if not hasattr(self.request, 'type_name'): 
     565            self.request['type_name'] = "File" 
    558566 
    559567    def _brainsByPath(self, path): 
     
    614622         
    615623        return infos 
     624 
     625    @view.memoize 
     626    def get_data(self, serh_type="File"): 
     627        if serh_type != "all": 
     628            objects_by_types_info = [i for i in self.getSizeInfoByPath() if i['type']==serh_type] 
     629        else: 
     630            objects_by_types_info = self.getSizeInfoByPath() 
     631        return sorted([ {'h_size': human_format(i['size']),  
     632                          'size' : i['size'], 
     633                          'path' : i['path'], 
     634                          'id'   : i['path'].split('/')[-1]}  
     635                        for i in objects_by_types_info ], 
     636                      key=itemgetter('size'), 
     637                      reverse=True) 
     638 
     639    def getChart(self): 
     640        type_name = self.request['type_name'] 
     641        info_obj = self.get_data(type_name)[:10] 
     642        if not info_obj: 
     643            return "<h2>Not found objetcs of '%s' type</h2>" % type_name 
     644        path, data = zip(*map(itemgetter('path','size'), info_obj)) 
     645        max_value = data[0] 
     646        #We need transpozed dataset, matrix_tranform does trabspozition 
     647        chart = VerticalBarStack(matrix_tranform(data)) 
     648        chart.title('Objects of "%s" type by size'%type_name) 
     649        chart.bar('a', 10, 0).legend_pos("b")#.legend(*path) 
     650        chart.color(*COLORS) 
     651        chart.size(800, 375).scale(0,max_value) 
     652        chart.axes('xy').axes.type("y").axes.range(0,0,max_value) 
     653        return chart.img() 
     654         
Note: See TracChangeset for help on using the changeset viewer.