1class SpeedTest { 2 3 chart; 4 elemento_pai; 5 elemento_filho; 6 elemento_legend; 7 blob = false; 8 start; 9 stop; 10 speed; 11 time; 12 d; 13 sum_size = 0; 14 sum_time = 0; 15 pingMS = 0; 16 downloadMBPS = 0; 17 uploadMBPS = 0; 18 server = null; 19 server_ping = null; 20 executando = false; 21 22 pingFunction = function () { 23 }; 24 dowloadFunction = function () { 25 }; 26 uploadFunction = function () { 27 }; 28 29 constructor(elemento, server, serverPing, pingFunction, dowloadFunction, uploadFunction) { 30 try { 31 this.elemento_pai = elemento; 32 this.server = server; 33 this.server_ping = serverPing; 34 this.blob = this.generateRandomData(102 * 1024); 35 36 this.pingFunction = pingFunction; 37 this.dowloadFunction = dowloadFunction; 38 this.uploadFunction = uploadFunction; 39 } catch (e) { 40 throw e; 41 } 42 } 43 44 generateRandomData(len) { 45 var chars = "!@#$%*()-_=+][{}|;:'~`<>.,/?\\\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; 46 var randomstring = ''; 47 for (var i = 0; i < len; i++) { 48 var rnum = Math.floor(Math.random() * chars.length); 49 randomstring += chars.substring(rnum, rnum + 1); 50 } 51 return randomstring; 52 } 53 54 speedTestInit() { 55 try { 56 if (this.elemento_pai.getAttribute('id')) { 57 this.createSpeedTest(); 58 } 59 } catch (e) { 60 throw e; 61 } 62 } 63 64 createSpeedTest() { 65 try { 66 this.createElementProperties(); 67 return this.createChartOptions(); 68 } catch (e) { 69 throw e; 70 } 71 } 72 73 createElementProperties() { 74 try { 75 this.elemento_filho = document.createElement("div"); 76 this.elemento_filho.id = "speedTest"; 77 this.elemento_filho.style = "min-width: 310px; max-width: 450px; height: 450px; margin: 0 auto;"; 78 this.elemento_pai.appendChild(this.elemento_filho); 79 } catch (e) { 80 throw e; 81 } 82 } 83 84 createChartOptions() { 85 try { 86 this.chart = new Highcharts.chart(this.elemento_filho, { 87 chart: { 88 type: 'gauge',
89 plotBackgroundColor: null, 90 plotBackgroundImage: null, 91 plotBorderWidth: 0, 92 plotShadow: false, 93 height: 450 94 }, 95 title: { 96 text: 'Download' 97 }, 98 exporting: { 99 enabled: false 100 }, 101 pane: { 102 startAngle: -150, 103 endAngle: 150, 104 background: [{ 105 backgroundColor: { 106 linearGradient: {x1: 0, y1: 0, x2: 0, y2: 1}, 107 stops: [ 108 [0, '#141526'] 109 ] 110 }, 111 borderWidth: 0, 112 outerRadius: '109%' 113 }] 114 }, 115 yAxis: { 116 min: 0, 117 max: 20, 118 minorTickInterval: 'none', 119 tickPixelInterval: 40, 120 tickWidth: 0, 121 tickPosition: 'inside', 122 tickLength: 10, 123 tickColor: '#666', 124 labels: { 125 step: 2, 126 rotation: 'auto', 127 style: { 128 color: 'white' 129 } 130 }, 131 title: { 132 text: 'Mbps', 133 style: { 134 color: 'white' 135 } 136 }, 137 plotBands: [{ 138 from: 0, 139 to: 20, 140 color: { 141 linearGradient: {x1: 0, y1: 0, x2: 1, y2: 1}, 142 stops: [ 143 [0, '#00C9A7'], 144 [1, '#845EC2'] 145 ] 146 }, 147 thickness: '13%', 148 outerRadius: '109%' 149 }], 150 lineWidth: 0 151 }, 152 plotOptions: { 153 gauge: { 154 dial: { 155 radius: '100%', 156 backgroundColor: 'silver', 157 borderWidth: 0, 158 baseWidth: 10, 159 topWidth: 3, 160 baseLength: '90%', // of radius 161 rearLength: '50%' 162 } 163 } 164 }, 165 series: [{ 166 name: 'Download: ', 167 data: [0], 168 tooltip: { 169 valueSuffix: ' Mbps' 170 }, 171 dataLabels: { 172 align: 'center', 173 borderWidth: 2, 174 padding: 5, 175 shadow: false, 176 y: 75, 177 style: { 178 fontWeight: 'bold', 179 color: 'white' 180 } 181 } 182 }], 183 credits: { 184 enabled: false 185 } 186 }); 187 } catch (e) { 188 throw e; 189 } 190 } 191 192 execPing() { 193 try { 194 this.clearConstants(); 195 return this.pingTestInit(); 196 } catch (e) { 197 throw e; 198 } 199 } 200 201 execDownload() { 202 try { 203 this.clearConstants(); 204 return this.downloadTestInit(1, 0); 205 } catch (e) { 206 throw e; 207 } 208 } 209 210 execUpload() { 211 try { 212 this.clearConstants(); 213 return this.uploadTestInit(1, 0); 214 } catch (e) { 215 throw e; 216 } 217 } 218 219 downloadTestInit(size, repeat) { 220 try { 221 var speed = this; 222 speed.chart.series[0].name = 'Download'; 223 speed.chart.setTitle({text: "Download"}); 224 speed.d = new Date(); 225 speed.start = speed.d.getTime(); 226 227 $.get("https://" + speed.server + "/blob/" + size, function () { 228 speed.d = new Date(); 229 speed.stop = speed.d.getTime(); 230 speed.time = speed.stop - speed.start; 231 speed.speed = (1000 / speed.time * size); 232 233 var point = speed.chart.series[0].points[0]; 234 point.update(0); 235 236 var point2 = speed.chart.yAxis[0]; 237 point2.plotLinesAndBands[0].options.to = 0;
238 point2.update(); 239 240 if (speed.time <= 500 && repeat == 0) { 241 speed.downloadTestInit(size * 2, 0); 242 } else { 243 speed.sum_size += size; 244 speed.sum_time += speed.time; 245 246 var valor = parseFloat((speed.sum_size / speed.sum_time * 1000 * 8).toFixed(2)); 247 speed.bandsValidation(valor); 248 249 point.update(valor); 250 point2.plotLinesAndBands[0].options.to = valor; 251 point2.update(); 252 253 if (repeat == 20) { 254 speed.downloadMBPS = valor; 255 256 speed.sum_size = 0; 257 speed.sum_time = 0; 258 259 point.update(0); 260 point2.plotLinesAndBands[0].options.to = 0; 261 point2.update(); 262 263 speed.dowloadFunction(speed); 264 } else speed.downloadTestInit(size, repeat + 1); 265 } 266 }).fail(function (e) { 267 throw e; 268 }); 269 } catch (e) { 270 throw e; 271 } 272 } 273 274 bandsValidation(speed) { 275 try { 276 var point = this.chart.yAxis[0]; 277 var totalSpeed = point.max; 278 279 if (speed > totalSpeed) { 280 point.update({max: parseInt(speed) + 10}); 281 } 282 } catch (e) { 283 throw e; 284 } 285 } 286 287 uploadTestInit(size, repeat) { 288 try { 289 var speed = this; 290 speed.chart.series[0].name = 'Upload'; 291 speed.chart.setTitle({text: "Upload"}); 292 293 speed.d = new Date(); 294 speed.start = speed.d.getTime(); 295 296 var upload_data = speed.blob; 297 for (var i = 1; i < size; i++) upload_data += speed.blob; 298 $.ajax({ 299 type: "POST", url: "https://" + speed.server + "/blob/", contentType: 'application/octet-stream', 300 data: upload_data, processData: false 301 }).done(function (data) { 302 speed.d = new Date(); 303 speed.stop = speed.d.getTime(); 304 speed.time = speed.stop - speed.start; 305 speed.speed = (1000 / speed.time * size / 10); 306 307 var point = speed.chart.series[0].points[0]; 308 point.update(0); 309 310 var point2 = speed.chart.yAxis[0]; 311 point2.plotLinesAndBands[0].options.color.stops[0] = [0, '#F500F5']; 312 point2.plotLinesAndBands[0].options.to = 0; 313 point2.update(); 314 315 if (speed.time <= 500 && repeat == 0) { 316 speed.uploadTestInit(size * 2, 0); 317 } else { 318 speed.sum_size += size; 319 speed.sum_time += speed.time; 320 321 var valor = parseFloat((speed.sum_size / 10 / speed.sum_time * 1000 * 8).toFixed(2)); 322 speed.bandsValidation(valor); 323 324 point.update(valor); 325 point2.plotLinesAndBands[0].options.to = valor; 326 point2.update(); 327 328 if (repeat == 20) { 329 speed.uploadMBPS = valor; 330 331 speed.sum_size = 0; 332 speed.sum_time = 0; 333 334 point.update(0); 335 point2.plotLinesAndBands[0].options.color.stops[0] = [0, '#00C9A7']; 336 point2.plotLinesAndBands[0].options.to = 0; 337 point2.update(); 338 339 speed.uploadFunction(speed); 340 } else speed.uploadTestInit(size, repeat + 1); 341 } 342 }).fail(function () { 343 throw e; 344 }); 345 } catch (e) { 346 throw e; 347 } 348 } 349 350 pingTestInit() { 351 try { 352 var speed = this; 353 $.get("https://" + speed.server + "/ping/" + speed.server_ping, function (data) { 354 var retorno = { 355 ping: data, 356 speed: speed 357 }; 358 speed.pingFunction(retorno); 359 }).fail(function (e) { 360 throw e; 361 }); 362 } catch (e) { 363 throw e; 364 } 365 } 366 367 rmSpeedTest() { 368 try { 369 this.elemento_filho.remove(); 370 this.chart = null; 371 this.elemento_pai = null; 372 this.elemento_filho = null; 373 this.elemento_legend = null; 374 this.blob = false;
375 this.start = null; 376 this.stop = null; 377 this.speed = null; 378 this.time = null; 379 this.d = null; 380 this.sum_size = 0; 381 this.sum_time = 0; 382 this.pingMS = 0; 383 this.downloadMBPS = 0; 384 this.uploadMBPS = 0; 385 this.server = null; 386 this.server_ping = null; 387 this.executando = false; 388 } catch (e) { 389 throw e; 390 } 391 } 392 393 clearConstants() { 394 try { 395 this.start = null; 396 this.stop = null; 397 this.speed = null; 398 this.time = null; 399 this.d = null; 400 this.sum_size = 0; 401 this.sum_time = 0; 402 } catch (e) { 403 throw e; 404 } 405 } 406 407 /** INSERIR O RESULTADO DO TESTE NO BANCO **/ 408 insertResult(dadosSpeedTest){ 409 var data = { 410 ACTION: 'inserirDadosSpeedTest', 411 dadosSpeedTest: dadosSpeedTest 412 }; 413 $.get(__SERVER__ + "/model/speed_test/speed_test.php", data); 414 415 } catch (e) { 416 throw e; 417 } 418}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.