Subversion Repositories DevTools

Rev

Rev 4866 | Rev 5101 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4866 Rev 4954
Line 1... Line 1...
1
import json, urllib2, sys, datetime
1
import json, sys, datetime
-
 
2
from urllib.request import urlopen, Request
2
 
3
 
3
CRUCIBLE_URL_TEMPLATE = 'http://cds:8060/rest-service/reviews-v1'
4
CRUCIBLE_URL_TEMPLATE = 'http://cds:8060/rest-service/reviews-v1'
4
RESULTS_KEY = 'results'
5
RESULTS_KEY = 'results'
5
GEOMETRY_KEY = 'geometry'
6
GEOMETRY_KEY = 'geometry'
6
LOCATION_KEY = 'location'
7
LOCATION_KEY = 'location'
Line 17... Line 18...
17
        self.security_defects = {}
18
        self.security_defects = {}
18
        self.unclassified_defect_reviews = [ ]
19
        self.unclassified_defect_reviews = [ ]
19
        self.total_defects = 0
20
        self.total_defects = 0
20
        self.verbose = False
21
        self.verbose = False
21
    def url_to_object(self, url, top=None) :
22
    def url_to_object(self, url, top=None) :
22
        req = urllib2.Request(url)
23
        req = Request(url)
23
        req.add_header('Accept','application/json')
24
        req.add_header('Accept','application/json')
24
        req.add_header('Authorization', 'Basic dGxpdHRsZWY6MCRtb3JQRVRI')
25
        req.add_header('Authorization', 'Basic dGxpdHRsZWY6MCRtb3JQRVRI')
25
        resp = urllib2.urlopen(req).read()
26
        resp = urlopen(req).read()
26
        retval = json.loads(resp)
27
        retval = json.loads(str(resp,'utf-8'))
27
        if top : 
28
        if top : 
28
            retval = retval[top]
29
            retval = retval[top]
29
        return retval
30
        return retval
30
    def get_selected_review_ids(self,min_create_date, max_create_date) :
31
    def get_selected_review_ids(self,min_create_date, max_create_date) :
31
        url = CRUCIBLE_URL_TEMPLATE
32
        url = CRUCIBLE_URL_TEMPLATE
Line 50... Line 51...
50
            0, # maintenance defects
51
            0, # maintenance defects
51
            0, # security defects
52
            0, # security defects
52
            0, # unclassified defects
53
            0, # unclassified defects
53
        ]
54
        ]
54
        for c in reviewDetails:
55
        for c in reviewDetails:
-
 
56
            metrics_keys = list(c['metrics'].keys())
55
            if c['defectRaised'] is False :
57
            if c['defectRaised'] is False :
56
                retval[1] += 1
58
                retval[1] += 1
57
            elif len(c['metrics'].keys()) != 1 : # unclassified - either none of the drop downs or more than one selected
59
            elif len(metrics_keys) != 1 : # unclassified - either none of the drop downs or more than one selected
58
                retval[5] += 1 
60
                retval[5] += 1 
59
                self.unclassified_defect_reviews += [ review_id ]
61
                self.unclassified_defect_reviews += [ review_id ]
60
                self.total_defects += 1
62
                self.total_defects += 1
61
            else :
63
            else :
62
                defect_category_code =  c['metrics'].keys()[0]
64
                defect_category_code =  metrics_keys[0]
63
                defect_type = c['metrics'][defect_category_code]['value']
65
                defect_type = c['metrics'][defect_category_code]['value']
64
                category_defect_map = None
66
                category_defect_map = None
65
                if defect_category_code == 'metric-57' : # maintenance
67
                if defect_category_code == 'metric-57' : # maintenance
66
                    retval[3] += 1
68
                    retval[3] += 1
67
                    category_defect_map = self.maintenance_defects
69
                    category_defect_map = self.maintenance_defects
Line 132... Line 134...
132
            count_for_type = category_types[d]
134
            count_for_type = category_types[d]
133
            percent_for_type = int( (1000.0 * count_for_type)/self.total_defects) * 0.1
135
            percent_for_type = int( (1000.0 * count_for_type)/self.total_defects) * 0.1
134
            count_for_category += count_for_type
136
            count_for_category += count_for_type
135
            percent_for_category += percent_for_type
137
            percent_for_category += percent_for_type
136
            d = d.replace("\u2013","-")
138
            d = d.replace("\u2013","-")
137
            print ( REPORT_PRINTF_FORMAT % ( d, count_for_type, percent_for_type ) )
139
            print ( REPORT_PRINTF_FORMAT % ( 
-
 
140
                d, 
-
 
141
                "%6d" % (count_for_type,),
-
 
142
                "%6.1f" % (percent_for_type,), 
-
 
143
            ) )
138
        print ( REPORT_PRINTF_FORMAT % REPORT_FORMAT_SEPARATOR )
144
        print ( REPORT_PRINTF_FORMAT % REPORT_FORMAT_SEPARATOR )
-
 
145
        print ( REPORT_PRINTF_FORMAT % ( 
139
        print ( REPORT_PRINTF_FORMAT % ( "Total %s" % (category_name,), count_for_category, percent_for_category ) )
146
            "Total %s" % (category_name,), 
-
 
147
            "%6d" % (count_for_category,),
-
 
148
            "%6.1f" % (percent_for_category,),
-
 
149
        ) )
140
        print ( REPORT_PRINTF_FORMAT % REPORT_FORMAT_SEPARATOR ) 
150
        print ( REPORT_PRINTF_FORMAT % REPORT_FORMAT_SEPARATOR ) 
141
    def summarize_by_defect_type(self) :
151
    def summarize_by_defect_type(self) :
142
        self.summarize_for_category("maintenance",self.maintenance_defects)
152
        self.summarize_for_category("maintenance",self.maintenance_defects)
143
        self.summarize_for_category("runtime",self.runtime_defects)
153
        self.summarize_for_category("runtime",self.runtime_defects)
144
        self.summarize_for_category("security",self.security_defects)
154
        self.summarize_for_category("security",self.security_defects)