|
| 1 | +<!-- |
| 2 | +Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 | +
|
| 4 | +This program is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU General Public License |
| 15 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +--> |
| 17 | + |
| 18 | +<template> |
| 19 | + <v-row |
| 20 | + no-gutters |
| 21 | + class="c-table flex-grow-1 position-relative" |
| 22 | + > |
| 23 | + <v-col |
| 24 | + cols="12" |
| 25 | + class="mh-100 position-relative" |
| 26 | + > |
| 27 | + <v-container |
| 28 | + fluid |
| 29 | + class="pa-0" |
| 30 | + > |
| 31 | + <v-data-table |
| 32 | + :headers="shownHeaders" |
| 33 | + :items="tasks" |
| 34 | + :sort-by="sortBy" |
| 35 | + density="compact" |
| 36 | + v-model:items-per-page="itemsPerPage" |
| 37 | + > |
| 38 | + <!-- Use custom format for values in columns that have a specified formatter: --> |
| 39 | + <!-- Used to make durations human readable --> |
| 40 | + <!-- Durations of 0 will be undefined unless allowZeros is true --> |
| 41 | + <template |
| 42 | + v-for="header in shownHeaders" |
| 43 | + v-slot:[`item.${header.key}`]="{ item }" |
| 44 | + > |
| 45 | + {{ formatCell(item, header) }} |
| 46 | + </template> |
| 47 | + <template v-slot:bottom> |
| 48 | + <v-data-table-footer :itemsPerPageOptions="$options.itemsPerPageOptions" /> |
| 49 | + </template> |
| 50 | + </v-data-table> |
| 51 | + </v-container> |
| 52 | + </v-col> |
| 53 | + </v-row> |
| 54 | +</template> |
| 55 | + |
| 56 | +<script> |
| 57 | +import { formatDuration } from '@/utils/tasks' |
| 58 | +
|
| 59 | +export default { |
| 60 | + name: 'AnalysisTableComponent', |
| 61 | +
|
| 62 | + props: { |
| 63 | + tasks: { |
| 64 | + type: Array, |
| 65 | + required: true |
| 66 | + }, |
| 67 | + timingOption: { |
| 68 | + type: String, |
| 69 | + required: true |
| 70 | + } |
| 71 | + }, |
| 72 | +
|
| 73 | + data () { |
| 74 | + return { |
| 75 | + itemsPerPage: 50, |
| 76 | + sortBy: [ |
| 77 | + { key: 'name', order: 'asc' } |
| 78 | + ], |
| 79 | + headers: [ |
| 80 | + { |
| 81 | + title: 'Task', |
| 82 | + key: 'name' |
| 83 | + }, |
| 84 | + { |
| 85 | + title: 'Platform', |
| 86 | + key: 'platform' |
| 87 | + }, |
| 88 | + { |
| 89 | + title: 'Count', |
| 90 | + key: 'count' |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + }, |
| 95 | +
|
| 96 | + computed: { |
| 97 | + shownHeaders () { |
| 98 | + let times |
| 99 | + if (this.timingOption === 'totalTimes') { |
| 100 | + times = 'Total' |
| 101 | + } else if (this.timingOption === 'runTimes') { |
| 102 | + times = 'Run' |
| 103 | + } else if (this.timingOption === 'queueTimes') { |
| 104 | + times = 'Queue' |
| 105 | + } else { |
| 106 | + return this.headers |
| 107 | + } |
| 108 | + const timingHeaders = [ |
| 109 | + { |
| 110 | + title: `Mean T-${times}`, |
| 111 | + key: `mean${times}Time`, |
| 112 | + formatter: formatDuration, |
| 113 | + allowZeros: false |
| 114 | + }, |
| 115 | + { |
| 116 | + title: `Std Dev T-${times}`, |
| 117 | + key: `stdDev${times}Time`, |
| 118 | + formatter: formatDuration, |
| 119 | + allowZeros: true |
| 120 | + }, |
| 121 | + { |
| 122 | + title: `Min T-${times}`, |
| 123 | + key: `min${times}Time`, |
| 124 | + formatter: formatDuration, |
| 125 | + allowZeros: false |
| 126 | + }, |
| 127 | + { |
| 128 | + title: `Q1 T-${times}`, |
| 129 | + key: `${times.toLowerCase()}Quartiles.0`, |
| 130 | + formatter: formatDuration, |
| 131 | + allowZeros: false |
| 132 | + }, |
| 133 | + { |
| 134 | + title: `Median T-${times}`, |
| 135 | + key: `${times.toLowerCase()}Quartiles.1`, |
| 136 | + formatter: formatDuration, |
| 137 | + allowZeros: false |
| 138 | + }, |
| 139 | + { |
| 140 | + title: `Q3 T-${times}`, |
| 141 | + key: `${times.toLowerCase()}Quartiles.2`, |
| 142 | + formatter: formatDuration, |
| 143 | + allowZeros: false |
| 144 | + }, |
| 145 | + { |
| 146 | + title: `Max T-${times}`, |
| 147 | + key: `max${times}Time`, |
| 148 | + formatter: formatDuration, |
| 149 | + allowZeros: false |
| 150 | + } |
| 151 | + ] |
| 152 | + return this.headers.concat(timingHeaders) |
| 153 | + } |
| 154 | + }, |
| 155 | +
|
| 156 | + methods: { |
| 157 | + formatCell (item, header) { |
| 158 | + const arrayMatch = header.key.match(/^(.+)\.(\d+)$/) |
| 159 | + const key = arrayMatch?.[1] ?? header.key |
| 160 | + let value = item.value[key] |
| 161 | + if (arrayMatch) { |
| 162 | + const index = arrayMatch[2] |
| 163 | + value = value[index] |
| 164 | + } |
| 165 | + if (header.formatter) { |
| 166 | + return header.formatter(value, header.allowZeros) |
| 167 | + } |
| 168 | + return value |
| 169 | + } |
| 170 | + }, |
| 171 | +
|
| 172 | + itemsPerPageOptions: [ |
| 173 | + { value: 10, title: '10' }, |
| 174 | + { value: 20, title: '20' }, |
| 175 | + { value: 50, title: '50' }, |
| 176 | + { value: 100, title: '100' }, |
| 177 | + { value: 200, title: '200' }, |
| 178 | + { value: -1, title: 'All' } |
| 179 | + ], |
| 180 | +} |
| 181 | +</script> |
0 commit comments