forge
Clone
https://git.tahinli.com/Tahinli/forge.git
0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits
| 1 | //! The geometry of the runner metrics graphs on the runner's admin page. Pure functions: samples go |
| 2 | //! in, plain numbers and SVG path data come out, and the view in `pages::admin_runners` writes the |
| 3 | //! markup. The plot covers the last hour in 30 s buckets (120 points). A bucket with no sample is |
| 4 | //! `None`, and a line breaks where two kept buckets are more than 30 s apart. |
| 5 | |
| 6 | use RunnerSample; |
| 7 | |
| 8 | /// The width of the chart's viewBox. The SVG scales to its container with the aspect kept. |
| 9 | pub const VIEW_W: f64 = 360.0; |
| 10 | /// The height of the chart's viewBox. |
| 11 | pub const VIEW_H: f64 = 110.0; |
| 12 | /// Where the plot starts and ends on the x axis, and its top and bottom on the y axis. |
| 13 | pub const X0: f64 = 40.0; |
| 14 | pub const X1: f64 = 356.0; |
| 15 | pub const Y0: f64 = 6.0; |
| 16 | pub const Y1: f64 = 94.0; |
| 17 | /// The time one bucket covers, in milliseconds. |
| 18 | pub const BUCKET_MS: i64 = 30_000; |
| 19 | /// The number of buckets across the hour. |
| 20 | pub const BUCKETS: usize = 120; |
| 21 | /// The longest gap between two samples that a line bridges, in milliseconds. |
| 22 | const GAP_MS: i64 = 30_000; |
| 23 | /// The hover tooltip's size and its distance from the crosshair, in viewBox units. |
| 24 | const TIP_W: f64 = 128.0; |
| 25 | const TIP_H: f64 = 40.0; |
| 26 | const TIP_GAP: f64 = 8.0; |
| 27 | |
| 28 | /// The averages of the samples in one bucket. |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | /// One line of the chart: its SVG path data and its CSS class. |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | /// The hover target of one bucket: a band over the bucket, a crosshair at its centre, and a tooltip |
| 55 | /// box beside the crosshair. |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// One line of a chart: how to read its value from a bucket, and its CSS class. |
| 69 | pub type Series = ; |
| 70 | |
| 71 | /// Everything one chart draws, apart from its axis labels. |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | /// Averages the samples of the last hour into `BUCKETS` buckets, oldest first. Samples before the |
| 85 | /// window or after `now_ms` are left out. |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | /// The smallest "nice" number (1, 2, 2.5 or 5 times a power of ten) that is at least `value`. |
| 138 | /// Zero gives 1. |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | /// The largest value of a series over the buckets, as a whole number of bytes per second, at least |
| 154 | /// 1 KiB/s so a quiet network gets a readable scale. |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | /// Builds the chart of `points`. `max` is the top of the y axis; `series` gives each line's value |
| 165 | /// and CSS class. `band` marks the buckets where jobs ran. |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | /// The path of one series. A line is one `M` and `L` run; a bucket with no sample, or a gap of more |
| 231 | /// than `GAP_MS` between two samples, starts a new `M`. |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 |