Skip to content

Commit

Permalink
Fix calculation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
asankov committed Sep 20, 2021
1 parent 9def326 commit 78313c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
23 changes: 13 additions & 10 deletions tcms/templates/include/tc_executions.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ <h2 class="card-pf-title">
<a href="{% url 'test_plan_url_short' execution.run.plan.pk %}">TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}</a>
</div>
<div class="list-group-item-text">
<div class="completion-rate-container">{% trans 'Completion rate' %}: <span class="completion-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
</div>
</div>
<div class="failure-rate-container">{% trans 'Failure rate' %}:<span class="failure-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
<div class="completion-rate-container">{% trans 'Completion rate' %}:
<span class="completion-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
</div>
</div>
<div class="failure-rate-container">{% trans 'Failure rate' %}:
<span class="failure-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
</div>
</div>
</div>
</div>
</div>
</div> <!-- /main info -->
</div> <!-- /header -->
</div>
{% endifchanged %}
<!-- start caseruns -->
<div class="list-group-item-container container-fluid">
Expand Down
37 changes: 25 additions & 12 deletions tcms/testcases/static/testcases/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@ $(document).ready(function () {
jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => {
const res = {}
let planId = 0
let positive = 0
let negative = 0
let allCount = 0
ress.forEach(r => {
let positive = 0
let negative = 0
let allCount = 0
if (planId === 0) {
planId = r.run__plan
}

if (r.status__weight > 0) {
positive++
} else if (r.status__weight < 0) {
Expand All @@ -226,25 +230,34 @@ $(document).ready(function () {

if (r.run__plan !== planId) {
planId = r.run__plan
const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0
const failureRate = allCount > 0 ? (negative / allCount) : 0
res[planId] = {
completion_rate: allCount > 0 ? ((positive + negative) / allCount) : 0,
failure_rate: allCount > 0 ? (negative / allCount) : 0
completionRate: completionRate.toFixed(2),
failureRate: failureRate.toFixed(2)
}
positive = 0
negative = 0
allCount = 0
}
})
// add the last entry
const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0
const failureRate = allCount > 0 ? (negative / allCount) : 0
res[planId] = {
completionRate: completionRate.toFixed(2),
failureRate: failureRate.toFixed(2)
}

Object.entries(res).forEach(([runId, data]) => {
const executionRow = $(`#execution-for-plan-${runId}`)
executionRow.find('.completion-rate').html(data.completion_rate)
executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completion_rate) * 100}%`)
executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completion_rate) * 100}%`)
executionRow.find('.completion-rate').html(data.completionRate)
executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completionRate) * 100}%`)
executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completionRate) * 100}%`)

executionRow.find('.failure-rate').html(data.failure_rate)
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`)
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`)
executionRow.find('.failure-rate').html(data.failureRate)
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failureRate) * 100}%`)
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failureRate) * 100}%`)
})
})

Expand All @@ -259,4 +272,4 @@ $(document).ready(function () {

// executions treeview
treeViewBind()
})
})

0 comments on commit 78313c3

Please sign in to comment.