summaryrefslogtreecommitdiff
path: root/qa/createWikiStats.py
blob: 2689645b5cca4de138b1936c0f40bef9c3c77e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#!/usr/bin/env python3
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import common
import datetime
from tabulate import tabulate

targets_list = ['5.4.5', '6.0.1']

periods_list = [30, 60, 90, 180, 365]

minNumOfDupes = 3

def util_create_wiki_statList():
    return {
        'targets': {t:{'count':0, 'people':{}} for t in targets_list},
        'period': {p:{'count':0, 'people':{}} for p in periods_list},
        'dupesBugs': {},
        'duplicates':
            {
                'regressions': {},
                'enhancements': {},
                'bugs':{},
            },
        'CC':
            {
                'regressions': {},
                'enhancements': {},
                'bugs':{}
            },
        'people': {},
        'stat': {'oldest': datetime.datetime.now(), 'newest': datetime.datetime(2001, 1, 1)}
    }

def util_create_detailed_person(email):
    return { 'email': email,
             'bugs': [],
             'created': 0,
             'comments':0,
             'status_changed': 0,
             'keyword_added': 0,
             'keyword_removed': 0,
             'whiteboard_added': 0,
             'whiteboard_removed': 0,
             'severity_changed': 0,
             'priority_changed': 0,
             'system_changed': 0,
             'metabug_added': 0,
             'metabug_removed': 0
         }

def util_increase_user_actions(statList, bug, mail, targets, action, actionTime):
    if mail == 'libreoffice-commits@lists.freedesktop.org':
        return

    for target in targets:
        if mail not in statList['targets'][target]['people']:
            statList['targets'][target]['people'][mail] = util_create_detailed_person(mail)

        statList['targets'][target]['people'][mail][action] += 1
        statList['targets'][target]['people'][mail]['bugs'].append(bug)

    for period in periods_list:
        if actionTime >= cfg[period]:
            if mail not in statList['period'][period]['people']:
                statList['period'][period]['people'][mail] = util_create_detailed_person(mail)

            statList['period'][period]['people'][mail][action] += 1
            statList['period'][period]['people'][mail]['bugs'].append(bug)

def util_create_bug(summary, component, os, version, keywords, creationDate, count_cc):
    return { 'summary': summary,
             'component': component,
             'os': os,
             'version': version,
             'keywords': keywords,
             'creationDate': creationDate,
             'count': count_cc
        }

def analyze_bugzilla_wiki_stats(statList, bugzillaData, cfg):
    print("Analyzing bugzilla\n", end="", flush=True)
    statNewDate = statList['stat']['newest']
    statOldDate = statList['stat']['oldest']

    for key, row in bugzillaData['bugs'].items():
        rowId = row['id']

        #Ignore META bugs and deletionrequest bugs.
        if not row['summary'].lower().startswith('[meta]') and row['component'].lower() != 'deletionrequest':
            creationDate = datetime.datetime.strptime(row['creation_time'], "%Y-%m-%dT%H:%M:%SZ")
            if creationDate < statOldDate:
                statOldDate = creationDate
            if creationDate > statNewDate:
                statNewDate = creationDate

            rowStatus = row['status']
            rowResolution = row['resolution']

            if rowStatus == 'VERIFIED' or rowStatus == 'RESOLVED':
                rowStatus += "_" + rowResolution

            rowKeywords = row['keywords']

            creatorMail = row['creator']

            whiteboard_list = row['whiteboard'].split(' ')
            bugTargets = []
            for whiteboard in whiteboard_list:
                if whiteboard.startswith("target:"):
                    bugVersion = whiteboard.split(':')[1][:5]
                    if bugVersion in targets_list:
                        bugTargets.append(bugVersion)
                        statList['targets'][bugVersion]['count'] += 1

            for period in periods_list:
                if creationDate >= cfg[period]:
                    statList['period'][period]['count'] += 1

            util_increase_user_actions(statList, key, creatorMail, bugTargets, 'created', creationDate)

            if common.isOpen(rowStatus) and len(row['cc']) >= 10:
                typeName = 'bugs'
                if row['severity'] == "enhancement":
                    typeName = 'enhancements'
                elif 'regression' in rowKeywords:
                    typeName = 'regressions'
                statList['CC'][typeName][rowId] = util_create_bug(
                        row['summary'], row['component'], row['op_sys'], row['version'], rowKeywords, creationDate, len(row['cc']))

            rowDupeOf = common.util_check_duplicated(bugzillaData, rowId)
            if rowDupeOf and str(rowDupeOf) in bugzillaData['bugs'] and \
                        common.isOpen(bugzillaData['bugs'][str(rowDupeOf)]['status']):
                if rowDupeOf not in statList['dupesBugs']:
                    statList['dupesBugs'][rowDupeOf] = []
                statList['dupesBugs'][rowDupeOf].append(rowId)

                typeName = 'bugs'
                if bugzillaData['bugs'][str(rowDupeOf)]['severity'] == "enhancement":
                    typeName = 'enhancements'
                elif 'regression' in bugzillaData['bugs'][str(rowDupeOf)]['keywords']:
                    typeName = 'regressions'

                statList['duplicates'][typeName][rowDupeOf] = util_create_bug(
                bugzillaData['bugs'][str(rowDupeOf)]['summary'],
                bugzillaData['bugs'][str(rowDupeOf)]['component'],
                bugzillaData['bugs'][str(rowDupeOf)]['op_sys'],
                bugzillaData['bugs'][str(rowDupeOf)]['version'],
                bugzillaData['bugs'][str(rowDupeOf)]['keywords'],
                datetime.datetime.strptime(
                    bugzillaData['bugs'][str(rowDupeOf)]['creation_time'], "%Y-%m-%dT%H:%M:%SZ"), 1)

            for action in row['history']:
                actionMail = action['who']
                actionDate = datetime.datetime.strptime(action['when'], "%Y-%m-%dT%H:%M:%SZ")

                # Use this variable in case the status is set before the resolution
                newStatus = None
                for change in action['changes']:
                    if change['field_name'] == 'blocks':
                        if change['added']:
                            for metabug in change['added'].split(', '):
                                continue
                                #TODO
                                #util_increase_user_actions(statList, key, actionMail, bugTargets, 'metabug_added', actionDate)

                        if change['removed']:
                            for metabug in change['removed'].split(', '):
                                continue
                                #TODO
                                #util_increase_user_actions(statList, key, actionMail, bugTargets, 'metabug_added', actionDate)

                    if change['field_name'] == 'status':
                        addedStatus = change['added']
                        removedStatus = change['removed']

                        if  addedStatus == 'RESOLVED' or addedStatus == 'VERIFIED':
                            if(rowResolution):
                                addedStatus = addedStatus + "_" + rowResolution
                                util_increase_user_actions(statList, key, actionMail, bugTargets, 'status_changed', actionDate)
                            else:
                                newStatus = addedStatus
                        else:
                            util_increase_user_actions(statList, key, actionMail, bugTargets, 'status_changed', actionDate)

                    elif change['field_name'] == 'resolution':
                        if newStatus:
                            addedStatus = newStatus + "_" + change['added']
                            util_increase_user_actions(statList, key, actionMail, bugTargets, 'status_changed', actionDate)

                            newStatus = None

                    elif change['field_name'] == 'priority':
                        util_increase_user_actions(statList, key, actionMail, bugTargets, 'priority_changed', actionDate)

                    elif change['field_name'] == 'severity':
                        util_increase_user_actions(statList, key, actionMail, bugTargets, 'severity_changed', actionDate)

                    elif change['field_name'] == 'keywords':
                        keywordsAdded = change['added'].split(", ")
                        for keyword in keywordsAdded:
                            if keyword in common.keywords_list:
                                util_increase_user_actions(statList, key, actionMail, bugTargets, 'keyword_added', actionDate)

                        keywordsRemoved = change['removed'].split(", ")
                        for keyword in keywordsRemoved:
                            if keyword in common.keywords_list:
                                util_increase_user_actions(statList, key, actionMail, bugTargets, 'keyword_removed', actionDate)

                    elif change['field_name'] == 'op_sys':
                        newSystem = change['added']
                        util_increase_user_actions(statList, rowId, actionMail, bugTargets, 'system_changed', actionDate)

            comments = row['comments'][1:]
            for idx, comment in enumerate(comments):
                commentMail = comment['creator']
                commentDate = datetime.datetime.strptime(comment['time'], "%Y-%m-%dT%H:%M:%SZ")

                util_increase_user_actions(statList, rowId, commentMail, bugTargets, 'comments', commentDate)

            #this way we can get the users' name
            for person in row['cc_detail']:
                if person['email'] not in statList['people']:
                    statList['people'][person['email']] = person['real_name']

    statList['stat']['newest'] = statNewDate.strftime("%Y-%m-%d")
    statList['stat']['oldest'] = statOldDate.strftime("%Y-%m-%d")
    print(" from " + statList['stat']['oldest'] + " to " + statList['stat']['newest'])

def create_wikimedia_table_for_cc_and_duplicates(cfg, statList):

    for nameList in statList['duplicates']:
        for k, v in statList['dupesBugs'].items():
            if k in statList['duplicates'][nameList]:
                if len(v) >= minNumOfDupes:
                    statList['duplicates'][nameList][k]['count'] = len(v)
                else:
                    del statList['duplicates'][nameList][k]

    for typeList in ['duplicates','CC']:
        for nameList in statList[typeList]:
            fileName = typeList + '_' + nameList
            print('Creating wikimedia table for ' + fileName)
            output = ""

            output += '{{TopMenu}}\n'
            output += '{{Menu}}\n'
            output += '{{Menu.QA}}\n'
            output += '\n'
            table = []

            if nameList == 'regressions':
                headers = ['Id', 'Summary', 'Component', 'OS', 'Version', 'Bisected', 'Reported']
            elif nameList == 'enhancements':
                headers = ['Id', 'Summary', 'Component', 'OS', 'Version', 'Reported']
            else:
                headers = ['Id', 'Summary', 'Component', 'OS', 'Version', 'EasyHack', 'Reported']

            if typeList == 'CC':
                headers.append('Total CC')
                output += '{} {} have 10 or more people in the CC list. (sorted in alphabetical order by number of users)\n'.format(
                        len(statList['CC'][nameList]), nameList)
            else:
                headers.append('Total Duplicates')
                output += '{} open {} have 3 or more duplicates. (sorted in alphabetical order by number of duplicates)\n'.format(
                        len(statList['duplicates'][nameList]), nameList)

            for k,v in statList[typeList][nameList].items():
                row = []
                row.append('[' + common.urlShowBug + str(k) + ' #tdf' + str(k) + ']')
                row.append(v['summary'])
                row.append(v['component'])
                row.append(v['os'])
                row.append(v['version'])

                if nameList == 'regressions':
                    if 'bibisectNotNeeded' in v['keywords']:
                        row.append('Not Needed')
                    elif 'bisected' in v['keywords']:
                        row.append('True')
                    else:
                        row.append('False')

                if nameList == 'bugs':
                    if 'easyHack' in v['keywords']:
                        row.append('True')
                    else:
                        row.append('False')

                row.append(v['creationDate'].strftime("%Y-%m-%d %H:%M:%S"))
                row.append(v['count'])
                table.append(row)

            output += tabulate(sorted(table, key = lambda x: x[len(headers) - 1], reverse=True), headers, tablefmt='mediawiki')
            output += "\n"
            output +='Generated on {}.'.format(cfg['todayDate'])
            output += "\n"
            output += '[[Category:EN]]\n'
            output += '[[Category:QA/Stats]]'

            fp = open('/tmp/table_' + fileName + '.txt', 'w', encoding='utf-8')
            print(output.replace('wikitable', 'wikitable sortable'), file=fp)
            fp.close()

def create_wikimedia_table_by_target(cfg, statList):
    for kT,vT in sorted(statList['targets'].items()):
        print('Creating wikimedia table for release ' + kT)
        output = ""

        output += '{{TopMenu}}\n'
        output += '{{Menu}}\n'
        output += '{{Menu.QA}}\n'
        output += '\n'

        output += '{} people helped to triage {} bugs tagged with target:{}. (sorted in alphabetical order by user\'s name)\n'.format(
            len(vT['people']), vT['count'], kT)
        output += '\n'
        table = []
        headers = ['Name', 'Created', 'Comments', 'Status Changed', 'Keyword Added', 'Keyword Removed',
                   'Severity Changed', 'Priority Changed', 'System Changed', 'Total Bugs']

        for kP, vP in vT['people'].items():
            name = ''
            if vP['email'] in statList['people']:
                name = statList['people'][kP]
            if not name:
                name = vP['email'].split('@')[0]

            row = []
            row.append(name)
            row.append(vP['created'])
            row.append(vP['comments'])
            row.append(vP['status_changed'])
            row.append(vP['keyword_added'])
            row.append(vP['keyword_removed'])
            row.append(vP['severity_changed'])
            row.append(vP['priority_changed'])
            row.append(vP['system_changed'])
            row.append(len(set(vP['bugs'])))
            table.append(row)

        output += tabulate(sorted(table, key = lambda x: x[0]), headers, tablefmt='mediawiki')
        output += "\n"
        output +='Generated on {}.'.format(cfg['todayDate'])
        output += "\n"
        output += '[[Category:EN]]\n'
        output += '[[Category:QA/Stats]]'

        fp = open('/tmp/table_' + kT + '.txt', 'w', encoding='utf-8')
        print(output.replace('wikitable', 'wikitable sortable'), file=fp)
        fp.close()

def create_wikimedia_table_by_period(cfg, statList):
    for kT,vT in sorted(statList['period'].items()):
        print('Creating wikimedia table for actions done in the last {} days.'.format(kT))
        output = ""

        output += '{{TopMenu}}\n'
        output += '{{Menu}}\n'
        output += '{{Menu.QA}}\n'
        output += '\n'

        output += '{} people helped to triage {} bugs in the last {} days. (sorted in alphabetical order by user\'s name)\n'.format(
            len(vT['people']), vT['count'], kT)
        output += '\n'
        table = []
        headers = ['Name', 'Created', 'Comments', 'Status Changed', 'Keyword Added', 'Keyword Removed',
                   'Severity Changed', 'Priority Changed', 'System Changed', 'Total Bugs']

        for kP, vP in vT['people'].items():
            name = ''
            if vP['email'] in statList['people']:
                name = statList['people'][kP]
            if not name:
                name = vP['email'].split('@')[0]

            row = []
            row.append(name)
            row.append(vP['created'])
            row.append(vP['comments'])
            row.append(vP['status_changed'])
            row.append(vP['keyword_added'])
            row.append(vP['keyword_removed'])
            row.append(vP['severity_changed'])
            row.append(vP['priority_changed'])
            row.append(vP['system_changed'])
            row.append(len(set(vP['bugs'])))
            table.append(row)

        output += tabulate(sorted(table, key = lambda x: x[0]), headers, tablefmt='mediawiki')
        output += "\n"
        output += 'Generated on {}.'.format(cfg['todayDate'])
        output += "\n"
        output += '[[Category:EN]]\n'
        output += '[[Category:QA/Stats]]'

        fp = open('/tmp/period_' + str(kT) + '.txt', 'w', encoding='utf-8')
        print(output.replace('wikitable', 'wikitable sortable'), file=fp)
        fp.close()

def runCfg():
    cfg = {}
    cfg['todayDate'] = datetime.datetime.now().replace(hour=0, minute=0,second=0)

    for period in periods_list:
        cfg[period] = common.util_convert_days_to_datetime(period)

    return cfg

if __name__ == '__main__':
    print("Reading and writing data to " + common.dataDir)

    cfg = runCfg()

    bugzillaData = common.get_bugzilla()

    statList = util_create_wiki_statList()

    analyze_bugzilla_wiki_stats(statList, bugzillaData, cfg)

    create_wikimedia_table_by_target(cfg, statList)
    create_wikimedia_table_by_period(cfg, statList)
    create_wikimedia_table_for_cc_and_duplicates(cfg, statList)

    print('End of report')