|
| 1 | +<template> |
| 2 | + <div class="panel panel-default"> |
| 3 | + <div class="panel-heading"><i class="bi bi-activity"></i> Spikes</div> |
| 4 | + <div class="panel-body"> |
| 5 | + <div class="parameters-section"> |
| 6 | + <div class="row"> |
| 7 | + <div class="col-md-3"> |
| 8 | + <div class="form-group"> |
| 9 | + <label |
| 10 | + >Min reports with non-empty comments: |
| 11 | + <strong>{{ minCommentsFilter }}</strong></label |
| 12 | + > |
| 13 | + <input |
| 14 | + type="range" |
| 15 | + class="form-control-range" |
| 16 | + v-model.number="minCommentsFilter" |
| 17 | + :min="0" |
| 18 | + :max="maxCommentsCount" |
| 19 | + step="1" |
| 20 | + /> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + <div class="col-md-3"> |
| 24 | + <div class="form-group"> |
| 25 | + <label |
| 26 | + >Short Window (days): <strong>{{ shortWindow }}</strong></label |
| 27 | + > |
| 28 | + <input |
| 29 | + type="range" |
| 30 | + class="form-control-range" |
| 31 | + v-model.number="shortWindow" |
| 32 | + :min="1" |
| 33 | + :max="14" |
| 34 | + step="1" |
| 35 | + v-on:change="reloadSpikes" |
| 36 | + /> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + <div class="col-md-3"> |
| 40 | + <div class="form-group"> |
| 41 | + <label |
| 42 | + >Long Window (days): <strong>{{ longWindow }}</strong></label |
| 43 | + > |
| 44 | + <input |
| 45 | + type="range" |
| 46 | + class="form-control-range" |
| 47 | + v-model.number="longWindow" |
| 48 | + :min="7" |
| 49 | + :max="90" |
| 50 | + step="1" |
| 51 | + v-on:change="reloadSpikes" |
| 52 | + /> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + <div v-if="selectedPeriod"> |
| 58 | + <p> |
| 59 | + {{ filteredSpikes.length }} spikes in window |
| 60 | + <strong>{{ shortWindowPeriod }}</strong> |
| 61 | + </p> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div v-if="loading" class="text-center"> |
| 65 | + <i class="bi bi-hourglass-split"></i> Loading... |
| 66 | + </div> |
| 67 | + <div v-else-if="filteredSpikes.length === 0" class="text-muted"> |
| 68 | + No spikes detected with selected parameters. |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + <div v-if="!loading && filteredSpikes.length > 0" class="table-responsive"> |
| 72 | + <table class="table table-condensed table-bordered table-db"> |
| 73 | + <thead> |
| 74 | + <tr> |
| 75 | + <th>Bucket</th> |
| 76 | + <th>Domain</th> |
| 77 | + <th class="text-right"># of reports</th> |
| 78 | + <th class="text-right"># of reports with comments</th> |
| 79 | + <th class="text-right">Short Avg</th> |
| 80 | + <th class="text-right">Long Avg</th> |
| 81 | + <th class="text-right">Ratio</th> |
| 82 | + <th>Comments</th> |
| 83 | + </tr> |
| 84 | + </thead> |
| 85 | + <tbody> |
| 86 | + <tr v-for="spike in filteredSpikes" :key="spike.id"> |
| 87 | + <td> |
| 88 | + <a :href="spike.bucket_view_url">{{ spike.bucket_id }}</a> |
| 89 | + </td> |
| 90 | + <td>{{ spike.bucket_domain || "(no domain)" }}</td> |
| 91 | + <td class="text-right">{{ spike.short_count }}</td> |
| 92 | + <td class="text-right">{{ spike.short_count_with_comments }}</td> |
| 93 | + <td class="text-right">{{ spike.short_average.toFixed(2) }}</td> |
| 94 | + <td class="text-right">{{ spike.long_average.toFixed(2) }}</td> |
| 95 | + <td class="text-right">{{ spike.ratio.toFixed(2) }}</td> |
| 96 | + <td class="comments-cell"> |
| 97 | + <ol |
| 98 | + v-if="spike.report_comments && spike.report_comments.length > 0" |
| 99 | + > |
| 100 | + <li |
| 101 | + v-for="(comment, index) in spike.report_comments" |
| 102 | + :key="index" |
| 103 | + > |
| 104 | + {{ comment }} |
| 105 | + </li> |
| 106 | + </ol> |
| 107 | + <span v-else>—</span> |
| 108 | + </td> |
| 109 | + </tr> |
| 110 | + </tbody> |
| 111 | + </table> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | +</template> |
| 115 | + |
| 116 | +<script> |
| 117 | +import * as api from "../../api"; |
| 118 | +
|
| 119 | +export default { |
| 120 | + name: "SpikesList", |
| 121 | + data() { |
| 122 | + return { |
| 123 | + loading: false, |
| 124 | + selectedPeriod: null, |
| 125 | + spikes: [], |
| 126 | + minCommentsFilter: 3, |
| 127 | + shortWindow: 2, |
| 128 | + longWindow: 60, |
| 129 | + threshold: 1.5, |
| 130 | + minTotalReports: 10, |
| 131 | + }; |
| 132 | + }, |
| 133 | + computed: { |
| 134 | + shortWindowPeriod() { |
| 135 | + if (!this.selectedPeriod) return "No period selected"; |
| 136 | + return `${this.selectedPeriod.short_window_start} to ${this.selectedPeriod.short_window_end}`; |
| 137 | + }, |
| 138 | + filteredSpikes() { |
| 139 | + return this.spikes.filter( |
| 140 | + (spike) => spike.short_count_with_comments >= this.minCommentsFilter, |
| 141 | + ); |
| 142 | + }, |
| 143 | + maxCommentsCount() { |
| 144 | + if (this.spikes.length === 0) return 0; |
| 145 | + return Math.max(...this.spikes.map((s) => s.short_count_with_comments)); |
| 146 | + }, |
| 147 | + }, |
| 148 | + async mounted() { |
| 149 | + await this.fetchLatestRun(); |
| 150 | + }, |
| 151 | + methods: { |
| 152 | + async fetchLatestRun() { |
| 153 | + this.loading = true; |
| 154 | + try { |
| 155 | + const params = { |
| 156 | + short_window: this.shortWindow, |
| 157 | + long_window: this.longWindow, |
| 158 | + threshold: this.threshold, |
| 159 | + min_reports: this.minTotalReports, |
| 160 | + }; |
| 161 | +
|
| 162 | + const data = await api.getCurrentBucketSpikes(params); |
| 163 | +
|
| 164 | + if (data) { |
| 165 | + this.selectedPeriod = { |
| 166 | + short_window_start: data.short_window_start, |
| 167 | + short_window_end: data.short_window_end, |
| 168 | + }; |
| 169 | + this.spikes = data.spikes || []; |
| 170 | + } |
| 171 | + } catch (err) { |
| 172 | + console.error("Error fetching spikes:", err); |
| 173 | + } |
| 174 | + this.loading = false; |
| 175 | + }, |
| 176 | + async reloadSpikes() { |
| 177 | + clearTimeout(this._reloadTimeout); |
| 178 | + this._reloadTimeout = setTimeout(() => { |
| 179 | + this.fetchLatestRun(); |
| 180 | + }, 500); |
| 181 | + }, |
| 182 | + }, |
| 183 | +}; |
| 184 | +</script> |
| 185 | + |
| 186 | +<style scoped> |
| 187 | +.parameters-section { |
| 188 | + background-color: #f7f7f7; |
| 189 | + padding: 15px; |
| 190 | + border-radius: 5px; |
| 191 | + margin-bottom: 20px; |
| 192 | +} |
| 193 | +
|
| 194 | +.form-control-range { |
| 195 | + width: 100%; |
| 196 | +} |
| 197 | +
|
| 198 | +.comments-cell { |
| 199 | + max-width: 400px; |
| 200 | + white-space: normal; |
| 201 | + word-break: break-word; |
| 202 | + font-size: 0.9em; |
| 203 | +} |
| 204 | +
|
| 205 | +.comments-cell ol { |
| 206 | + margin: 0; |
| 207 | + padding-left: 20px; |
| 208 | +} |
| 209 | +
|
| 210 | +.comments-cell li { |
| 211 | + margin-bottom: 5px; |
| 212 | +} |
| 213 | +</style> |
0 commit comments