Issues (87)

static/telemetry/js/testing/execution-trends.js (3 issues)

1
$(document).ready(() => {
2
  $('[data-toggle="tooltip"]').tooltip()
3
4
  loadInitialProduct()
5
6
  document.getElementById('id_product').onchange = () => {
7
    updateVersionSelectFromProduct()
8
    // note: don't pass drawChart as callback to avoid calling it twice
9
    // b/c update_version_select... triggers .onchange()
10
    updateTestPlanSelectFromProduct()
11
  }
12
13
  document.getElementById('id_version').onchange = () => {
14
    drawChart()
15
    updateBuildSelectFromVersion(true)
16
  }
17
  document.getElementById('id_build').onchange = drawChart
18
  document.getElementById('id_test_plan').onchange = drawChart
19
20
  $('#id_after').on('dp.change', drawChart)
21
  $('#id_before').on('dp.change', drawChart)
22
23
  drawChart()
24
})
25
26
function drawChart () {
27
  const query = {}
28
29
  const productIds = $('#id_product').val()
30
  if (productIds.length) {
31
    query.run__plan__product__in = productIds
32
  }
33
34
  const versionIds = $('#id_version').val()
35
  if (versionIds.length) {
36
    query.run__plan__product_version__in = versionIds
37
  }
38
39
  const buildIds = $('#id_build').val()
40
  if (buildIds.length) {
41
    query.build_id__in = buildIds
42
  }
43
44
  const testPlanIds = $('#id_test_plan').val()
45
  if (testPlanIds.length) {
46
    query.run__plan__in = testPlanIds
47
  }
48
49
  const dateBefore = $('#id_before')
50
  if (dateBefore.val()) {
51
    query.stop_date__lte = dateBefore.data('DateTimePicker').date().format('YYYY-MM-DD 23:59:59')
52
  }
53
54
  const dateAfter = $('#id_after')
55
  if (dateAfter.val()) {
56
    query.stop_date__gte = dateAfter.data('DateTimePicker').date().format('YYYY-MM-DD 00:00:00')
57
  }
58
59
  const totalKey = $('.main').data('total-key')
60
61
  jsonRPC('Testing.execution_trends', query, data => {
62
    drawPassingRateSummary(data.status_count)
63
64
    const chartData = Object.entries(data.data_set).map(entry => [entry[0], ...entry[1]])
65
    const categories = data.categories.map(testRunId => `TR-${testRunId}`)
66
67
    $('#chart > svg').remove()
68
69
    const c3ChartDefaults = $().c3ChartDefaults()
70
    const config = c3ChartDefaults.getDefaultAreaConfig()
71
    config.axis = {
72
      x: {
73
        categories: categories,
74
        type: 'category',
75
        tick: {
76
          fit: false,
77
          multiline: false
78
        }
79
      },
80
      y: {
81
        tick: {
82
          format: showOnlyRoundNumbers
83
        }
84
      }
85
    }
86
    config.bindto = '#chart'
87
    config.color = {
88
      pattern: data.colors
89
    }
90
    config.data = {
91
      columns: chartData,
92
      type: 'area-spline',
93
      order: null
94
    }
95
    config.bar = {
96
      width: {
97
        ratio: 1
98
      }
99
    }
100
    config.tooltip = {
101
      format: {
102
        value: (value, _ratio, _id, _index) => value || undefined
0 ignored issues
show
The parameter _index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter _ratio is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter _id is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
103
      }
104
    }
105
    config.legend = {
106
      hide: [totalKey]
107
    }
108
    c3.generate(config)
109
110
    // hide the total data point
111
    $(`.c3-target-${totalKey}`).addClass('hidden')
112
  })
113
}
114
115
function drawPassingRateSummary (statusCount) {
116
  const allCount = statusCount.positive + statusCount.negative + statusCount.neutral
117
  $('.passing-rate-summary .total').text(allCount)
118
119
  const positivePercent = statusCount.positive ? roundDown(statusCount.positive / allCount * 100) : 0
120
  const positiveBar = $('.progress > .progress-bar-success')
121
  const positiveRateText = `${positivePercent}%`
122
  positiveBar.css('width', positiveRateText)
123
  positiveBar.text(positiveRateText)
124
  $('.passing-rate-summary .positive').text(statusCount.positive)
125
126
  const neutralPercent = statusCount.neutral ? roundDown(statusCount.neutral / allCount * 100) : 0
127
  const neutralRateText = `${neutralPercent}%`
128
  const neutralBar = $('.progress > .progress-bar-remaining')
129
  neutralBar.css('width', neutralRateText)
130
  neutralBar.text(neutralRateText)
131
  $('.passing-rate-summary .neutral').text(statusCount.neutral)
132
133
  const negativePercent = statusCount.negative ? roundDown(statusCount.negative / allCount * 100) : 0
134
  const negativeRateText = `${negativePercent}%`
135
  const negativeBar = $('.progress > .progress-bar-danger')
136
  negativeBar.css('width', negativeRateText)
137
  negativeBar.text(negativeRateText)
138
  $('.passing-rate-summary .negative').text(statusCount.negative)
139
}
140
141
// we need this function, because the standard library does not have
142
// one that rounds the number down, which means that the sum
143
// of the percents may become more than 100% and that breaksg the chart
144
function roundDown (number) {
145
  return Math.floor(number * 100) / 100
146
}
147