Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add count_skips field to Importance by Component widget #524

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -91,20 +94,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

for component in sdatdict.keys():
for bnum in sdatdict[component].keys():
for importance in sdatdict[component][bnum].keys():
results_dict = defaultdict(int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful!

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
Loading