Skip to content

Commit 9bd4cdc

Browse files
committed
Fix calculation bug
- fix mismatched divs
1 parent ec62206 commit 9bd4cdc

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

tcms/templates/include/tc_executions.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ <h2 class="card-pf-title">
2828
<a href="{% url 'test_plan_url_short' execution.run.plan.pk %}">TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}</a>
2929
</div>
3030
<div class="list-group-item-text">
31-
<div class="completion-rate-container">{% trans 'Completion rate' %}: <span class="completion-rate"></span>
31+
<div class="completion-rate-container">{% trans 'Completion rate' %}: <span class="completion-rate"></div>
3232
<div class="progress">
3333
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
3434
<div class="progress-bar progress-bar-success" role="progressbar"></div>
3535
</div>
3636
</div>
37-
<div class="failure-rate-container">{% trans 'Failure rate' %}:<span class="failure-rate"></span>
37+
<div>
38+
<div class="failure-rate-container">{% trans 'Failure rate' %}:<span class="failure-rate"></div>
3839
<div class="progress">
3940
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
4041
<div class="progress-bar progress-bar-success" role="progressbar"></div>
4142
</div>
42-
</div>
4343
</div>
4444
</div>
4545
</div>
4646
</div> <!-- /main info -->
4747
</div> <!-- /header -->
48+
</div>
4849
{% endifchanged %}
4950
<!-- start caseruns -->
5051
<div class="list-group-item-container container-fluid">

tcms/testcases/static/testcases/js/get.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,14 @@ $(document).ready(function () {
213213
jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => {
214214
const res = {}
215215
let planId = 0
216+
let positive = 0
217+
let negative = 0
218+
let allCount = 0
216219
ress.forEach(r => {
217-
let positive = 0
218-
let negative = 0
219-
let allCount = 0
220+
if (planId === 0) {
221+
planId = r.run__plan
222+
}
223+
220224
if (r.status__weight > 0) {
221225
positive++
222226
} else if (r.status__weight < 0) {
@@ -226,25 +230,34 @@ $(document).ready(function () {
226230

227231
if (r.run__plan !== planId) {
228232
planId = r.run__plan
233+
const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0
234+
const failureRate = allCount > 0 ? (negative / allCount) : 0
229235
res[planId] = {
230-
completion_rate: allCount > 0 ? ((positive + negative) / allCount) : 0,
231-
failure_rate: allCount > 0 ? (negative / allCount) : 0
236+
completionRate: completionRate.toFixed(2),
237+
failureRate: failureRate.toFixed(2)
232238
}
233239
positive = 0
234240
negative = 0
235241
allCount = 0
236242
}
237243
})
244+
// add the last entry
245+
const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0
246+
const failureRate = allCount > 0 ? (negative / allCount) : 0
247+
res[planId] = {
248+
completionRate: completionRate.toFixed(2),
249+
failureRate: failureRate.toFixed(2)
250+
}
238251

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

245-
executionRow.find('.failure-rate').html(data.failure_rate)
246-
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`)
247-
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`)
258+
executionRow.find('.failure-rate').html(data.failureRate)
259+
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failureRate) * 100}%`)
260+
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failureRate) * 100}%`)
248261
})
249262
})
250263

0 commit comments

Comments
 (0)