summaryrefslogtreecommitdiff
path: root/qa/createBlogReport.py
blob: c82769385615a62fe2855b445797e9ea4831abc7 (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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/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 https://mozilla.org/MPL/2.0/.
#

import common
import math
from datetime import datetime, timedelta

import matplotlib
import matplotlib.pyplot as plt

lKeywords = ['havebacktrace', 'regression', 'bisected']

oldBugsYears = 4

def util_create_basic_schema():
    return {
        'id': [],
        'author': {},
        'day': {},
        'difftime': []
        }

def util_create_statList():
    return {
        'created': util_create_basic_schema(),
        'confirmed': util_create_basic_schema(),
        'verified': util_create_basic_schema(),
        'wfm': util_create_basic_schema(),
        'duplicate': util_create_basic_schema(),
        'fixed': util_create_basic_schema(),
        'resolvedStatuses' : {},
        'criticalFixed': {},
        'highFixed': {},
        'crashFixed': {},
        'perfFixed': {},
        'oldBugsFixed': {},
        'metabug': util_create_basic_schema(),
        'keywords': { k : util_create_basic_schema() for k in lKeywords},
        'people' : {},
        'unconfirmedCount' : {},
        'regressionCount' : {},
        'bibisectRequestCount' : {},
        'highestCount' : {},
        'highCount' : {},
        'stat': {'oldest': datetime.now(), 'newest': datetime(2001, 1, 1)}
    }

def util_increase_action(value, rowId, creatorMail, day, difftime=-1):
    value['id'].append(rowId)
    if creatorMail not in value['author']:
        value['author'][creatorMail] = 0
    value['author'][creatorMail] += 1

    if day not in value['day']:
        value['day'][day] = 0
    value['day'][day] += 1

    if difftime >= 0:
        value['difftime'].append(difftime)

def util_decrease_action(value, creatorMail, day):
    value['id'].pop()
    value['author'][creatorMail] -= 1
    value['day'][day] -= 1

    if value['difftime']:
        value['difftime'].pop()


def daterange(cfg):
    for n in range(int ((cfg.Date[1] - cfg.Date[0]).days)):
        yield cfg.Date[0] + timedelta(n)

def analyze_bugzilla_data(statList, bugzillaData, cfg):
    print("Analyzing bugzilla\n", end="", flush=True)


    unconfirmedCountPerDay = {}
    regressionsCountPerDay = {}
    bibisectRequestCountPerDay = {}
    highestCountPerDay = {}
    highCountPerDay = {}
    fixedBugs = {}

    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.strptime(row['creation_time'], "%Y-%m-%dT%H:%M:%SZ")


            #Some old bugs were directly created as NEW, skipping the UNCONFIRMED status
            #Use the oldest bug ID in the unconfirmed list
            if rowId >= 89589:
                actionDay = creationDate.strftime("%Y-%m-%d")
                if actionDay not in unconfirmedCountPerDay:
                    unconfirmedCountPerDay[actionDay] = 0
                unconfirmedCountPerDay[actionDay] += 1

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

            rowKeywords = row['keywords']

            creatorMail = row['creator']

            #get information about created bugs in the period of time
            if common.util_check_range_time(creationDate, cfg):
                creationDay = str(creationDate.strftime("%Y-%m-%d"))
                util_increase_action(statList['created'], rowId, creatorMail, creationDay)

                if row['severity'] == 'enhancement':
                    if 'enhancement' not in statList['created']:
                        statList['created']['enhancement'] = 0
                    statList['created']['enhancement'] += 1

            common.util_check_bugzilla_mail(
                    statList, creatorMail, row['creator_detail']['real_name'], creationDate, rowId)

            isFixed = False
            isWFM = False
            isDuplicate = False
            isResolved = False
            isConfirmed = False
            isVerified = False
            dayConfirmed = None
            dayVerified = None
            dayWFM = None
            dayDuplicate = None
            authorConfirmed = None
            authorVerified = None
            authorWFM = None
            authorDuplicate = None
            isRegression = False
            isRegressionClosed = False
            isBibisectRequest = False
            isBibisectRequestClosed = False
            isHighest = False
            isHighestClosed = False
            isHigh = False
            isHighClosed = False
            isThisBugClosed = False

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

                common.util_check_bugzilla_mail(
                        statList, actionMail, '', actionDate, rowId)

                actionDay = str(actionDate.strftime("%Y-%m-%d"))
                diffTime = (actionDate - creationDate).days

                for change in action['changes']:
                    if change['field_name'] == 'priority':
                        addedPriority = change['added']
                        removedPriority = change['removed']

                        # Sometimes the priority is increased to highest after the bug is fixed
                        # Ignore those cases
                        if not isThisBugClosed and not isHighestClosed:
                            if not isHighest and addedPriority == "highest":
                                if actionDay not in highestCountPerDay:
                                    highestCountPerDay[actionDay] = 0
                                highestCountPerDay[actionDay] += 1
                                isHighest = True

                            if isHighest and removedPriority == "highest":
                                if actionDay not in highestCountPerDay:
                                    highestCountPerDay[actionDay] = 0
                                highestCountPerDay[actionDay] -= 1
                                isHighest = False

                        # TODO: IsThisBugClosed should be check here, but the result is not accurate
                        if not isHighClosed:
                            if not isHigh and addedPriority == "high":
                                if actionDay not in highCountPerDay:
                                    highCountPerDay[actionDay] = 0
                                highCountPerDay[actionDay] += 1
                                isHigh = True

                            if isHigh and removedPriority == "high":
                                if actionDay not in highCountPerDay:
                                    highCountPerDay[actionDay] = 0
                                highCountPerDay[actionDay] -= 1
                                isHigh = False

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

                        if common.isOpen(addedStatus):
                            isThisBugClosed = False
                        else:
                            isThisBugClosed = True

                        #See above
                        if rowId >= 89589:
                            if removedStatus == "UNCONFIRMED":
                                if actionDay not in unconfirmedCountPerDay:
                                    unconfirmedCountPerDay[actionDay] = 0
                                unconfirmedCountPerDay[actionDay] -= 1

                            elif addedStatus == 'UNCONFIRMED':
                                if actionDay not in unconfirmedCountPerDay:
                                    unconfirmedCountPerDay[actionDay] = 0
                                unconfirmedCountPerDay[actionDay] += 1

                        if isRegression:
                            # the regression is being reopened
                            if isRegressionClosed and not isThisBugClosed:
                                if actionDay not in regressionsCountPerDay:
                                    regressionsCountPerDay[actionDay] = 0
                                regressionsCountPerDay[actionDay] += 1
                                isRegressionClosed = False

                            # the regression is being closed
                            if not isRegressionClosed and isThisBugClosed:
                                if actionDay not in regressionsCountPerDay:
                                    regressionsCountPerDay[actionDay] = 0
                                regressionsCountPerDay[actionDay] -= 1
                                isRegressionClosed = True

                        if isBibisectRequest:
                            # the bibisectRequest is being reopened
                            if isBibisectRequestClosed and not isThisBugClosed:
                                if actionDay not in bibisectRequestCountPerDay:
                                    bibisectRequestCountPerDay[actionDay] = 0
                                bibisectRequestCountPerDay[actionDay] += 1
                                isBibisectRequestClosed = False

                            # the bibisectRequest is being closed
                            if not isBibisectRequestClosed and isThisBugClosed:
                                if actionDay not in bibisectRequestCountPerDay:
                                    bibisectRequestCountPerDay[actionDay] = 0
                                bibisectRequestCountPerDay[actionDay] -= 1
                                isBibisectRequestClosed = True

                        if isHighest:
                            # the Highest priority bug is being reopened
                            if isHighestClosed and not isThisBugClosed:
                                if actionDay not in highestCountPerDay:
                                    highestCountPerDay[actionDay] = 0
                                highestCountPerDay[actionDay] += 1
                                isHighestClosed = False

                            # the Highest priority bug is being closed
                            if not isHighestClosed and isThisBugClosed:
                                if actionDay not in highestCountPerDay:
                                    highestCountPerDay[actionDay] = 0
                                highestCountPerDay[actionDay] -= 1
                                isHighestClosed = True

                        if isHigh:
                            # the High priority bug is being reopened
                            if isHighClosed and not isThisBugClosed:
                                if actionDay not in highCountPerDay:
                                    highCountPerDay[actionDay] = 0
                                highCountPerDay[actionDay] += 1
                                isHighClosed = False

                            # the High priority bug is being closed
                            if not isHighClosed and isThisBugClosed:
                                if actionDay not in highCountPerDay:
                                    highCountPerDay[actionDay] = 0
                                highCountPerDay[actionDay] -= 1
                                isHighClosed = True

                        if common.util_check_range_time(actionDate, cfg):
                            if removedStatus == "UNCONFIRMED":
                                util_increase_action(statList['confirmed'], rowId, actionMail, actionDay, diffTime)
                                dayConfirmed = actionDay
                                authorConfirmed = actionMail
                                isConfirmed = True

                            elif addedStatus == 'UNCONFIRMED' and isConfirmed:
                                util_decrease_action(statList['confirmed'], authorConfirmed, dayConfirmed)
                                isConfirmed = False

                            if addedStatus == 'VERIFIED':
                                util_increase_action(statList['verified'], rowId, actionMail, actionDay, diffTime)
                                dayVerified = actionDay
                                authorVerified = actionMail
                                isVerified = True

                            elif removedStatus == 'VERIFIED' and isVerified and common.isOpen(addedStatus):
                                util_decrease_action(statList['verified'], authorVerified, dayVerified)
                                isVerified = False

                    elif change['field_name'] == 'resolution':
                        if common.util_check_range_time(actionDate, cfg):
                            addedResolution = change['added']
                            removedResolution = change['removed']

                            if isResolved and removedResolution:
                                statList['resolvedStatuses'][removedResolution] -= 1
                                isResolved = False

                            if addedResolution:
                                if addedResolution not in statList['resolvedStatuses']:
                                    statList['resolvedStatuses'][addedResolution] = 0
                                statList['resolvedStatuses'][addedResolution] += 1
                                isResolved = True

                            if addedResolution == 'FIXED':
                                fixedBugs[rowId] = actionDate
                                isFixed = True
                            elif removedResolution == 'FIXED' and isFixed:
                                del fixedBugs[rowId]
                                isFixed = False

                            if addedResolution == 'WORKSFORME':
                                isWFM = True
                                dayWFM = actionDay
                                authorWFM = actionMail
                                util_increase_action(statList['wfm'], rowId, actionMail, actionDay, diffTime)
                            elif removedResolution == 'WORKSFORME' and isWFM:
                                util_decrease_action(statList['wfm'], authorWFM, dayWFM)
                                isWFM = False

                            if addedResolution == 'DUPLICATE':
                                isDuplicate = True
                                dayDuplicate = actionDay
                                authorDuplicate = actionMail
                                util_increase_action(statList['duplicate'], rowId, actionMail, actionDay, diffTime)
                            elif removedResolution == 'DUPLICATE' and isDuplicate:
                                util_decrease_action(statList['duplicate'], authorDuplicate, dayDuplicate)
                                isDuplicate = False

                    elif change['field_name'] == 'keywords':
                        keywordsAdded = change['added'].lower().split(", ")
                        keywordsRemoved = change['removed'].lower().split(", ")

                        if common.util_check_range_time(actionDate, cfg):
                            for keyword in keywordsAdded:
                                if keyword in lKeywords:
                                    util_increase_action(statList['keywords'][keyword], rowId, actionMail, actionDay, diffTime)

                        # TODO: IsThisBugClosed should be check here, but the result is not accurate
                        if not isRegressionClosed:
                            if not isRegression and 'regression' in keywordsAdded:
                                if actionDay not in regressionsCountPerDay:
                                    regressionsCountPerDay[actionDay] = 0
                                regressionsCountPerDay[actionDay] += 1
                                isRegression = True

                            if isRegression and 'regression' in keywordsRemoved:
                                if actionDay not in regressionsCountPerDay:
                                    regressionsCountPerDay[actionDay] = 0
                                regressionsCountPerDay[actionDay] -= 1
                                isRegression = False

                        # In the past, 'bibisectRequest' was added after the bug got fixed
                        # to find the commit fixing it. Ignore them
                        if not isThisBugClosed and not isBibisectRequestClosed:
                            if not isBibisectRequest and 'bibisectrequest' in keywordsAdded:
                                if actionDay not in bibisectRequestCountPerDay:
                                    bibisectRequestCountPerDay[actionDay] = 0
                                bibisectRequestCountPerDay[actionDay] += 1
                                isBibisectRequest = True

                            if isBibisectRequest and 'bibisectrequest' in keywordsRemoved:
                                if actionDay not in bibisectRequestCountPerDay:
                                    bibisectRequestCountPerDay[actionDay] = 0
                                bibisectRequestCountPerDay[actionDay] -= 1
                                isBibisectRequest = False

                    elif change['field_name'] == 'blocks':
                        if common.util_check_range_time(actionDate, cfg):
                            if change['added']:
                                for metabug in change['added'].split(', '):
                                    if int(metabug) in row['blocks']:
                                        util_increase_action(statList['metabug'], rowId, actionMail, actionDay, diffTime)

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

                common.util_check_bugzilla_mail(
                        statList, commentMail, '', commentDate, rowId)

                if common.util_check_range_time(commentDate, cfg) and rowId in fixedBugs:
                    if commentMail == "libreoffice-commits@lists.freedesktop.org":
                        commentText = comment['text']
                        author =  commentText.split(' committed a patch related')[0]
                        if author not in bugFixers and 'uitest' not in commentText.lower() and\
                                'unittest' not in commentText.lower():
                            bugFixers.append(author)
                            diffTime = (commentDate - creationDate).days
                            commentDay = commentDate.strftime("%Y-%m-%d")
                            util_increase_action(statList['fixed'], rowId, author, commentDay, diffTime)
                            commitNoticiation = True

                            if row['priority'] == "highest":
                                statList['criticalFixed'][rowId]= {'summary': row['summary'], 'author': author}
                            if row['priority'] == "high":
                                statList['highFixed'][rowId]= {'summary': row['summary'], 'author': author}
                            if 'crash' in row['summary'].lower():
                                statList['crashFixed'][rowId]= {'summary': row['summary'], 'author': author}
                            if 'perf' in row['keywords']:
                                statList['perfFixed'][rowId]= {'summary': row['summary'], 'author': author}
                            if creationDate < common.util_convert_days_to_datetime(oldBugsYears * 365):
                                statList['oldBugsFixed'][rowId]= {'summary': row['summary'], 'author': author}

            if rowId in fixedBugs and not commitNoticiation:
                actionDate = fixedBugs[rowId]
                actionDay = actionDate.strftime("%Y-%m-%d")
                diffTime = (actionDate - creationDate).days
                util_increase_action(statList['fixed'], rowId, 'UNKNOWN', actionDay, diffTime)

            for person in row['cc_detail']:
                email = person['email']
                if commentMail == email or actionMail == email:
                    common.util_check_bugzilla_mail(statList, email, person['real_name'])

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

        statList['people'][k]['oldest'] = statList['people'][k]['oldest'].strftime("%Y-%m-%d")
        statList['people'][k]['newest'] = statList['people'][k]['newest'].strftime("%Y-%m-%d")

    for single_date in daterange(cfg):
        single_day = single_date.strftime("%Y-%m-%d")

        #Fill empty days to be displayed on the charts
        for k0, v0 in statList.items():
            if k0 == 'keywords':
                for k1, v1 in statList['keywords'].items():
                    if single_day not in statList['keywords'][k1]['day']:
                        statList['keywords'][k1]['day'][single_day] = 0
            else:
                if 'day' in statList[k0]:
                    if single_day not in statList[k0]['day']:
                        statList[k0]['day'][single_day] = 0

        totalCount1 = 0
        for k, v in unconfirmedCountPerDay.items():
            xDay = datetime.strptime( k, "%Y-%m-%d")
            if xDay < single_date:
                totalCount1 += v

        statList['unconfirmedCount'][single_day] = totalCount1

        totalCount2 = 0
        for k, v in regressionsCountPerDay.items():
            xDay = datetime.strptime( k, "%Y-%m-%d")
            if xDay < single_date:
                totalCount2 += v

        statList['regressionCount'][single_day] = totalCount2

        totalCount3 = 0
        for k, v in highestCountPerDay.items():
            xDay = datetime.strptime( k, "%Y-%m-%d")
            if xDay < single_date:
                totalCount3 += v

        statList['highestCount'][single_day] = totalCount3

        totalCount4 = 0
        for k, v in highCountPerDay.items():
            xDay = datetime.strptime( k, "%Y-%m-%d")
            if xDay < single_date:
                totalCount4 += v

        statList['highCount'][single_day] = totalCount4

        totalCount5 = 0
        for k, v in bibisectRequestCountPerDay.items():
            xDay = datetime.strptime( k, "%Y-%m-%d")
            if xDay < single_date:
                totalCount5 += v

        statList['bibisectRequestCount'][single_day] = totalCount5

def makeStrong(text):
    return "<strong>" + str(text) + "</strong>"

def makeLI(text):
    return "<li>" + str(text) + "</li>"

def makeH2(text):
    return "<h2>" + str(text) + "</h2>"

def makeLink(url, text):
    return '<a href="' + url + '">' + text + '</a>'

def savePlot(plt, plotLabel):
    filePath = "/tmp/" + plotLabel.replace(" ", "_") + ".png"
    print("Saving plot " + plotLabel + " to " + filePath)
    plt.savefig(filePath)
    plt.gcf().clear()

def createPlot(valueDict, plotType, plotTitle, plotLabel, plotColor):

    x, y = zip(*sorted(valueDict.items(), key = lambda x:datetime.strptime(x[0], '%Y-%m-%d')))
    if plotType == "line":
        plt.plot(y, label=plotLabel, linewidth=2, color=plotColor)
    elif plotType == "bar":
        plt.bar(range(len(y)), y, label=plotLabel, width=0.8, color=plotColor)

    plt.xticks(range(len(x)), x, rotation=90)
    plt.title(plotTitle)
    plt.xlabel("Date")
    plt.legend();
    ax = plt.gca()
    ax.grid(axis="y", linestyle='--')
    #Remove labels depending on number of elements
    total = math.ceil( len(ax.get_xticklabels()) / 20 )
    for idx, val in enumerate(ax.get_xticklabels()):
        #Hide all tick labels by default, otherwise it doesn't work
        val.set_visible(False)
        if idx % total == 0:
            val.set_visible(True)

    savePlot(plt, plotLabel)

def createDonut(valueDict, plotTitle):
    total = sum(valueDict.values())
    newDict = {}
    for k, v in valueDict.items():
        perc = v * 100 / total
        # Ignore values smaller than 3%
        if perc < 3:
            if 'OTHERS' not in newDict:
                newDict['OTHERS'] = 0
            newDict['OTHERS'] += perc
        else:
            newDict[k] = perc

    names=newDict.keys()
    size=newDict.values()

    # Create a circle for the center of the plot
    my_circle=plt.Circle( (0,0), 0.3, color='white')
    plt.pie(size, labels=names, radius=1.3, autopct='%1.1f%%')
    p=plt.gcf()
    p.gca().add_artist(my_circle)

    savePlot(plt, plotTitle)

def createDonutSection(fp, value, sectionName):
    print(makeH2(sectionName), file=fp)
    total = sum(value.values())
    print("{} bugs have been set to RESOLVED.".format(
        makeStrong(total)), file=fp)
    print('<img src="PATH_HERE/{}.png" alt="" width="640" height="480" class="alignnone size-full" />'.format(
        sectionName.replace(" ", "_")), file=fp)
    createDonut(value, sectionName)
    print('Check the following sections for more information about bugs resolved as FIXED, WORKSFORME and DUPLICATE.', file=fp)

def createSection(fp, value, sectionName, action, actionPerson, plotColor):
    print(makeH2(sectionName), file=fp)
    if 'enhancement' in value:
        print("{} bugs, {} of which are enhancements, have been {} by {} people.".format(
            makeStrong(len(value["id"])), makeStrong(value['enhancement']), action,
            makeStrong(len(value["author"]))), file=fp)
    else:
        print("{} bugs have been {} by {} people.".format(
            makeStrong(len(value["id"])), action,
            makeStrong(len(value["author"]))), file=fp)

    print(file=fp)
    print(makeStrong("Top 10 " + actionPerson), file=fp)
    print('<a href="PATH_HERE/' + sectionName.replace(' ', '_') + \
            '.png" rel="noopener"><img class="alignright" src="PATH_HERE/' + sectionName.replace(' ', '_') + \
            '.png" alt="" width="300" height="225" /></a>', file=fp)
    print("<ol>", file=fp)
    sortedList = sorted(value["author"].items(), key=lambda x: x[1], reverse=True)
    itCount = 1
    for item in sortedList:
        if itCount > 10:
            break
        if action == 'fixed':
            if item[0] == 'UNKNOWN':
                continue
            print(makeLI("{} ( {} )".format(item[0], item[1])), file=fp)
        else:
            print(makeLI("{} ( {} )".format(statList['people'][item[0]]['name'], item[1])), file=fp)
        itCount += 1

    print("</ol>", file=fp)

    while itCount <= 10:
        print("&nbsp;",file=fp)
        itCount += 1

    createPlot(value['day'], "bar", sectionName + " Per Day", sectionName, plotColor)

def createEvolutionSection(fp, value, sectionName, urlParam, color):
    urlPath = "https://bugs.documentfoundation.org/buglist.cgi?"
    print(makeH2("Evolution of {}".format(sectionName)), file=fp)
    print("Check the current list of {} {}".format(sectionName.lower(), makeLink(urlPath + urlParam, "here")), file=fp)
    print('<img src="PATH_HERE/{}.png" alt="" width="640" height="480" class="alignnone size-full" />'.format(
        sectionName.replace(" ", "_")), file=fp)
    createPlot(value, "line", sectionName + " Over Time", sectionName, color)


def createList(fp, value, listName):
    urlPath = "https://bugs.documentfoundation.org/show_bug.cgi?id="
    print(makeStrong(listName), file=fp)
    print("<ol>", file=fp)
    for k, v in value.items():
        print(makeLI("{} {} ( Thanks to {} )".format(makeLink(urlPath + str(k), "tdf#" +  str(k)),
            v['summary'], v['author'])), file=fp)
    print("</ol>", file=fp)
    print(file=fp)

def createReport(statList):
    fileName = '/tmp/blogReport.txt'
    fp = open(fileName, 'w', encoding='utf-8')
    print("creating Blog Report in " + fileName)
    createSection(fp, statList['created'], "Reported Bugs", "reported", "Reporters", "red")
    createSection(fp, statList['confirmed'], "Triaged Bugs", "triaged", "Triagers", "gold")
    createDonutSection(fp, statList['resolvedStatuses'], 'Resolution of resolved bugs')
    createSection(fp, statList['fixed'], "Fixed Bugs", "fixed", "Fixers", "darksalmon")
    createList(fp, statList['criticalFixed'], "List of critical bugs fixed")
    createList(fp, statList['highFixed'], "List of high severity bugs fixed")
    createList(fp, statList['crashFixed'], "List of crashes fixed")
    createList(fp, statList['perfFixed'], "List of performance issues fixed")
    createList(fp, statList['oldBugsFixed'], "List of old bugs ( more than {} years old ) fixed".format(oldBugsYears))
    createSection(fp, statList['wfm'], "WORKSFORME bugs", "retested", "testers", "m")
    createSection(fp, statList['duplicate'], "DUPLICATED bugs", "duplicated", "testers", "c")
    createSection(fp, statList['verified'], "Verified bug fixes", "verified", "Verifiers", "palegreen")
    createSection(fp, statList['metabug'], "Categorized Bugs", "categorized with a metabug", "Categorizers", "lightpink")
    createSection(fp, statList['keywords']['regression'], "Regression Bugs", "set as regressions", "", "mediumpurple")
    createSection(fp, statList['keywords']['bisected'], "Bisected Bugs", "bisected", "Bisecters", "orange")

    createEvolutionSection(
        fp, statList['unconfirmedCount'], "Unconfirmed Bugs",
        "bug_status=UNCONFIRMED&query_format=advanced&resolution=---", "blue")
    createEvolutionSection(
        fp, statList['regressionCount'], "Open Regressions",
        "bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&keywords=regression%2C &keywords_type=allwords&query_format=advanced&resolution=---", "green")
    createEvolutionSection(
        fp, statList['bibisectRequestCount'], "Open bibisectRequests",
        "bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&keywords=bibisectRequest%2C &keywords_type=allwords&query_format=advanced&resolution=---", "lightpink")
    createEvolutionSection(
        fp, statList['highestCount'], "Highest Priority Bugs",
        "bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&priority=highest&query_format=advanced&resolution=---", "sandybrown")
    createEvolutionSection(
        fp, statList['highCount'], "High Priority Bugs",
        "bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&priority=high&query_format=advanced&resolution=---", "indianred")

    print(makeStrong('Thank you all for making Libreoffice rock!'), file=fp)
    print(makeStrong('Join us and help to keep LibreOffice super reliable!'), file=fp)
    print(makeStrong('Check <a href="https://wiki.documentfoundation.org/QA/GetInvolved">the Get Involved page</a> out now!'), file=fp)
    fp.close()

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

    bugzillaData = common.get_bugzilla()

    statList = util_create_statList()

    analyze_bugzilla_data(statList, bugzillaData, args)

    createReport(statList)

    print('End of report')