Skip to content

Commit

Permalink
Add count_skips field to Importance by Component widget (ibutsu#524)
Browse files Browse the repository at this point in the history
* Add count_skips field to Importance by Component widget

* Add a more verbose and complete counting of results
  • Loading branch information
Fynardo committed Nov 25, 2024
1 parent c881c38 commit 4bf305b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
7 changes: 7 additions & 0 deletions backend/ibutsu_server/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@
"default": 5,
"required": False,
},
{
"name": "count_skips",
"description": "Count skips against the pass rate.",
"type": "boolean",
"required": False,
"default": False,
},
],
"type": "widget",
},
Expand Down
24 changes: 20 additions & 4 deletions backend/ibutsu_server/widgets/importance_component.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import defaultdict

from ibutsu_server.constants import BARCHART_MAX_BUILDS, JJV_RUN_LIMIT
from ibutsu_server.db.models import Result, Run
from ibutsu_server.filters import string_to_column
Expand All @@ -11,6 +13,7 @@ def get_importance_component(
builds=5,
components="",
project=None,
count_skips=False,
):
# taken from get_jenkins_line_chart in jenkins_job_analysis.py
run_limit = int((JJV_RUN_LIMIT / BARCHART_MAX_BUILDS) * builds)
Expand Down Expand Up @@ -89,20 +92,33 @@ def get_importance_component(
sdatdict[component][bnum][importance] = []

# this is to change result values into numbers
# TODO: This doesn't handle xpassed, xfailed, skipped, etc. so figure that out
for component in sdatdict.keys():
for bnum in sdatdict[component].keys():
for importance in sdatdict[component][bnum].keys():
results_dict = defaultdict(int)
total = 0
passed = 0
res_list = []
for item in sdatdict[component][bnum][importance]:
total += 1
results_dict[item["result"]] += 1
res_list.append(item["result_id"])
if item["result"] == "passed":
passed += 1

if total != 0:
if count_skips:
passed = total - (
results_dict["error"]
+ results_dict["skipped"]
+ results_dict["failed"]
+ results_dict["xpassed"]
+ results_dict["xfailed"]
)
else:
passed = total - (
results_dict["error"]
+ results_dict["failed"]
+ results_dict["xpassed"]
+ results_dict["xfailed"]
)
sdatdict[component][bnum][importance] = {
"percentage": round(passed / total, 2),
"result_list": res_list,
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/widgets/importancecomponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import {
Card,
CardBody,
CardFooter,
Text
} from '@patternfly/react-core';

Expand All @@ -20,7 +21,7 @@ import { Link } from 'react-router-dom';

import { HttpClient } from '../services/http';
import { Settings } from '../settings';
import { WidgetHeader } from '../components/widget-components';
import { ParamDropdown, WidgetHeader } from '../components/widget-components';

export class ImportanceComponentWidget extends React.Component {
static propTypes = {
Expand All @@ -39,6 +40,7 @@ export class ImportanceComponentWidget extends React.Component {
table_data: []
},
isLoading: true,
countSkips: 'No',
};
}

Expand Down Expand Up @@ -70,6 +72,13 @@ export class ImportanceComponentWidget extends React.Component {
}
}

onSkipSelect = (value) => {
this.setState({countSkips: value}, () => {
this.props.params.count_skips = (value === 'Yes');
this.getData();
});
}

toPercent(num) {
if (typeof(num) === 'number') {
return Math.round(num * 100)
Expand Down Expand Up @@ -114,6 +123,14 @@ export class ImportanceComponentWidget extends React.Component {
))}
</CardBody>
}
<CardFooter>
<ParamDropdown
dropdownItems={['Yes', 'No']}
handleSelect={this.onSkipSelect}
defaultValue={this.state.countSkips}
tooltip="Count skips as failure:"
/>
</CardFooter>
</Card>
);
}
Expand Down

0 comments on commit 4bf305b

Please sign in to comment.