Changeset 32 for trunk/AnalyzeCustomField
- Timestamp:
- 02/16/2012 11:46:39 PM (15 months ago)
- Location:
- trunk/AnalyzeCustomField
- Files:
-
- 2 edited
-
analyzecustomfield/admin.py (modified) (5 diffs)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/AnalyzeCustomField/analyzecustomfield/admin.py
r31 r32 3 3 4 4 from pkg_resources import ResourceManager 5 from trac.admin.api import IAdminPanelProvider 5 from trac.admin.api import IAdminPanelProvider, IAdminCommandProvider 6 6 from trac.core import Component, implements 7 7 from trac.ticket.api import TicketSystem 8 8 from trac.util.translation import _ 9 9 from trac.web.chrome import ITemplateProvider 10 import json 10 11 11 12 # なにを見たいか? … … 19 20 # レポートを書き換える必要があるかもしれない 20 21 21 class Analyzer(Component):22 def analyze(self): 22 23 count_values = """ 23 24 SELECT name, COUNT(value) FROM ( … … 27 28 count_all = "SELECT count(id) from ticket" 28 29 29 implements(ITemplateProvider, IAdminPanelProvider ) 30 ticket = TicketSystem(self.env) 31 cfields = ticket.get_custom_fields() 32 db = self.env.get_read_db() 33 cursor = db.cursor() 34 # QTY of Valid data, without Default value 35 valid = {} 36 cursor.execute(count_valid) 37 for name, count in cursor: 38 valid[name] = count 39 # QTY of data valiation for valiation 40 cursor.execute(count_values) 41 valiation = {} 42 for name, count in cursor: 43 valiation[name] = count 44 # rebuild cfields 45 for field in cfields: 46 field['valiation'] = valiation.get(field['name'], 0) 47 field['valid'] = valid.get(field['name'], 0) 48 data = {'cfields':cfields} 49 # Ticket QTY 50 cursor.execute(count_all) 51 data['qty'] = cursor.fetchone() 52 # build notdefined list 53 notdefined = [] 54 for name in [name for name in valid.keys() if name not in [field.get('name') for field in cfields]]: 55 notdefined.append({ 56 'name':name, 57 'label':'N/A', 58 'type':'N/A', 59 'valiation':valiation.get(name, 0), 60 'valid':valid.get(name, 0)}) 61 data['notdefined'] = notdefined 62 return data 63 64 class AdminPanel(Component): 65 implements(ITemplateProvider, IAdminPanelProvider) 30 66 31 67 # ITemplateProvider methods … … 36 72 return [] 37 73 38 # IAdminPanelProvider methods74 # IAdminPanelProvider methods 39 75 def get_admin_panels(self,req): 40 76 if 'TICKET_ADMIN' in req.perm: … … 44 80 def render_admin_panel(self, req, category, page, path_info): 45 81 req.perm.require('TICKET_ADMIN') 46 data = self._analyze()82 data = analyze(self) 47 83 return ('analayzecustomfield.html', data) 48 84 49 def _analyze(self): 50 ticket = TicketSystem(self.env) 51 cfields = ticket.get_custom_fields() 52 db = self.env.get_read_db() 53 cursor = db.cursor() 54 # QTY of Valid data, without Default value 55 valid = {} 56 cursor.execute(self.count_valid) 57 for name, count in cursor: 58 valid[name] = count 59 # QTY of data valiation for valiation 60 cursor.execute(self.count_values) 61 valiation = {} 62 for name, count in cursor: 63 valiation[name] = count 64 # rebuild cfields 65 for field in cfields: 66 field['valiation'] = valiation.get(field['name'], 0) 67 field['valid'] = valid.get(field['name'], 0) 68 data = {'cfields':cfields} 69 # Ticket QTY 70 cursor.execute(self.count_all) 71 data['qty'] = cursor.fetchone() 72 # build notdefined list 73 notdefined = [] 74 for name in [name for name in valid.keys() if name not in [field.get('name') for field in cfields]]: 75 notdefined.append({ 76 'name':name, 77 'label':'N/A', 78 'type':'N/A', 79 'valiation':valiation.get(name, 0), 80 'valid':valid.get(name, 0)}) 81 data['notdefined'] = notdefined 82 return data 85 class Command(Component): 86 implements(IAdminCommandProvider) 87 88 # IAdminCommandProvider methods 89 def get_admin_commands(self): 90 yield ('customfield analyze', '', 'Analyze custom field', None, self.command) 91 92 def command(self): 93 data = analyze(self) 94 print json.dumps(data, indent=2) -
trunk/AnalyzeCustomField/setup.py
r31 r32 6 6 setup( 7 7 name='AnalyzeCustomField', 8 version='0. 1',8 version='0.2', 9 9 license='Modified BSD', 10 10 author='MATOBA Akihiro',
Note: See TracChangeset
for help on using the changeset viewer.