Changeset 3351 in products
- Timestamp:
- Feb 7, 2012 4:37:01 PM (12 years ago)
- 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 70 70 for="*" 71 71 permission="zope2.ViewManagementScreens" 72 attribute="getSizeInfoByPath"73 72 class=".views.SizeByPath" 73 template="objects_size_stat.pt" 74 74 /> 75 75 -
quintagroup.analytics/branches/update_mt/quintagroup/analytics/browser/views.py
r3090 r3351 1 1 from pprint import pprint 2 from operator import itemgetter 2 3 from Acquisition import aq_base 3 4 from zope.component import getUtility, getMultiAdapter, queryMultiAdapter … … 11 12 from plone.portlets.interfaces import IPortletAssignmentMapping 12 13 from plone.portlets.interfaces import ILocalPortletAssignmentManager 14 15 from plone.memoize import view 13 16 14 17 try: … … 536 539 num /= 1024.0 537 540 # 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]) 539 542 540 543 def getSize(brain): … … 544 547 or 1) 545 548 549 def 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))] 546 552 547 553 class SizeByPath(BrowserView): … … 555 561 bpath = self.request.form.get('basepath') 556 562 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" 558 566 559 567 def _brainsByPath(self, path): … … 614 622 615 623 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.