|
| 1 | +// TODO: account for more users |
| 2 | +const colors = [ |
| 3 | + 'blue', |
| 4 | + 'red', |
| 5 | + 'gold', |
| 6 | + 'orange', |
| 7 | + 'green', |
| 8 | + 'cyan', |
| 9 | + 'purple', |
| 10 | + 'black', |
| 11 | + 'lightBlue', |
| 12 | + 'lightGreen' |
| 13 | +] |
| 14 | + |
| 15 | +$(document).ready(() => { |
| 16 | + $('.selectpicker').selectpicker() |
| 17 | + $('[data-toggle="tooltip"]').tooltip() |
| 18 | + |
| 19 | + loadInitialProduct(reloadCharts) |
| 20 | + |
| 21 | + $('#id_after').on('dp.change', reloadCharts) |
| 22 | + $('#id_before').on('dp.change', reloadCharts) |
| 23 | + document.getElementById('id_test_plan').onchange = reloadCharts |
| 24 | + document.getElementById('id_product').onchange = () => { |
| 25 | + updateTestPlanSelectFromProduct(reloadCharts) |
| 26 | + } |
| 27 | +}) |
| 28 | + |
| 29 | +function reloadCharts () { |
| 30 | + const query = {} |
| 31 | + |
| 32 | + const testPlanIds = $('#id_test_plan').val() |
| 33 | + const productIds = $('#id_product').val() |
| 34 | + |
| 35 | + if (testPlanIds.length) { |
| 36 | + query.plan__in = testPlanIds |
| 37 | + } else if (productIds.length) { |
| 38 | + query.category__product_id__in = productIds |
| 39 | + } |
| 40 | + |
| 41 | + const dateBefore = $('#id_before') |
| 42 | + if (dateBefore.val()) { |
| 43 | + query.create_date__lte = dateBefore.data('DateTimePicker').date().format('YYYY-MM-DD 23:59:59') |
| 44 | + } |
| 45 | + |
| 46 | + const dateAfter = $('#id_after') |
| 47 | + if (dateAfter.val()) { |
| 48 | + query.create_date__gte = dateAfter.data('DateTimePicker').date().format('YYYY-MM-DD 00:00:00') |
| 49 | + } |
| 50 | + |
| 51 | + jsonRPC('Management.performance', query, result => { |
| 52 | + console.log(result) |
| 53 | + |
| 54 | + // the actual result is in the same format, only it can be much bigger |
| 55 | + // and the chart may break |
| 56 | + const r = { |
| 57 | + 1: { |
| 58 | + 1: 1, |
| 59 | + 3: 2 |
| 60 | + }, |
| 61 | + 2: { |
| 62 | + 1: 1, |
| 63 | + 4: 2 |
| 64 | + }, |
| 65 | + 3: { |
| 66 | + 1: 1, |
| 67 | + 3: 1, |
| 68 | + 5: 1 |
| 69 | + }, |
| 70 | + 4: { |
| 71 | + 3: 1, |
| 72 | + 2: 1 |
| 73 | + }, |
| 74 | + 5: { |
| 75 | + 1: 5, |
| 76 | + 3: 2, |
| 77 | + 4: 1 |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + drawChart(r) |
| 82 | + }, true) |
| 83 | +} |
| 84 | + |
| 85 | +function drawChart (data) { |
| 86 | + // the X axis of the chart - run IDs |
| 87 | + const groupedCategories = [] |
| 88 | + // map of user ID -> table column. we use map here for faster lookup by user ID. |
| 89 | + const groupedColumnsDataMap = {} |
| 90 | + const userIds = new Set() |
| 91 | + |
| 92 | + // collect all the testers so that we know how much columns we will have |
| 93 | + Object.entries(data).forEach(([_testRunId, asigneeCount]) => { |
| 94 | + Object.entries(asigneeCount).forEach(([userId, _executionCount]) => userIds.add(userId)) |
| 95 | + }) |
| 96 | + |
| 97 | + userIds.forEach(userId => (groupedColumnsDataMap[userId] = [`User ${userId}`])) |
| 98 | + |
| 99 | + Object.entries(data).forEach(([testRunId, _asigneeCount]) => { |
| 100 | + groupedCategories.push(testRunId) |
| 101 | + |
| 102 | + const asigneesCount = data[testRunId] |
| 103 | + |
| 104 | + // for each user in the groupedColumnsDataMap check if that user |
| 105 | + // is assigned any executions for this run. |
| 106 | + Object.entries(groupedColumnsDataMap).forEach(([userId, data]) => { |
| 107 | + const count = asigneesCount[userId] |
| 108 | + if (count) { |
| 109 | + data.push(count) |
| 110 | + } else { |
| 111 | + // TODO: find a way to hide the 0 valued-columns |
| 112 | + data.push(0) |
| 113 | + } |
| 114 | + }) |
| 115 | + }) |
| 116 | + |
| 117 | + // C3 does not need a map, but an array of values |
| 118 | + // get rid of the keys, because we do not need them anymore |
| 119 | + const groupedColumnsData = Object.values(groupedColumnsDataMap) |
| 120 | + |
| 121 | + const chartConfig = $().c3ChartDefaults().getDefaultGroupedBarConfig() |
| 122 | + chartConfig.bindto = '#performance-chart' |
| 123 | + chartConfig.axis = { |
| 124 | + x: { |
| 125 | + categories: groupedCategories, |
| 126 | + type: 'category' |
| 127 | + }, |
| 128 | + y: { |
| 129 | + tick: { |
| 130 | + format: showOnlyRoundNumbers |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + chartConfig.data = { |
| 135 | + type: 'bar', |
| 136 | + columns: groupedColumnsData |
| 137 | + } |
| 138 | + chartConfig.color = { |
| 139 | + pattern: colors |
| 140 | + } |
| 141 | + c3.generate(chartConfig) |
| 142 | +} |
0 commit comments