apache/kibble-1

Decimal value in trends widget

Opened this issue · 2 comments

amunz commented

Hello,
I would like to add an issues closed over issues opened ratio to the trends widget in the Issue Trackers page. I have gotten it to show up, but the value is displayed as an integer when I would like for it to be a decimal.
issuesclosedopenedratio

I edited the /api/pages/issue/trends.py file to add the ratio.

    trends = {
        "created": {
            'before': no_issues_created_before,
            'after': no_issues_created,
            'title': "Issues opened this period"
        },
        "authors": {
            'before': no_creators_before,
            'after': no_creators,
            'title': "People opening issues this period"
        },
        "closed": {
            'before': no_issues_closed_before,
            'after': no_issues_closed,
            'title': "Issues closed this period"
        },
        "closers": {
            'before': no_closers_before,
            'after': no_closers,
            'title': "People closing issues this period"
        },
        "ratio":{
            'before': no_issues_closed_before / no_issues_created_before,
            'after': no_issues_closed/no_issues_created,
            'title': "Ratio of Issues Closed / Issues Opened"
        }
    }

I have tried casting the variables to a float, but the UI still displays an integer.
Any help would be appreciated. Thanks.

I suspect the JS is forcing integer values. I'll look into that. Perhaps we need to add an extra argument to the JSON output to specify that this is a float and should be presented as a float.

oh, I see the issue. You have to specify in python (2.7 at least) that you want a floating point result, or it will turn it into an integer. Something like:

"ratio":{
'before': 100 * no_issues_closed_before / no_issues_created_before / 100.0,
'after': 100 * no_issues_closed / no_issues_created / 100.0,
'title': "Ratio of Issues Closed / Issues Opened"
}