|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Services; |
| 4 | + |
| 5 | +use App\Models\Result; |
| 6 | +use Illuminate\Support\Str; |
| 7 | + |
| 8 | +class SpeedtestFakeResultGenerator |
| 9 | +{ |
| 10 | + public static function completed(): Result |
| 11 | + { |
| 12 | + $data = [ |
| 13 | + 'isp' => 'Speedtest Communications', |
| 14 | + 'ping' => [ |
| 15 | + 'low' => 17.841, |
| 16 | + 'high' => 24.077, |
| 17 | + 'jitter' => 1.878, |
| 18 | + 'latency' => 19.133, |
| 19 | + ], |
| 20 | + 'type' => 'result', |
| 21 | + 'result' => [ |
| 22 | + 'id' => (string) Str::uuid(), |
| 23 | + 'url' => 'https://docs.speedtest-tracker.dev', |
| 24 | + 'persisted' => true, |
| 25 | + ], |
| 26 | + 'server' => [ |
| 27 | + 'id' => 1234, |
| 28 | + 'ip' => '127.0.0.1', |
| 29 | + 'host' => 'docs.speedtest-tracker.dev', |
| 30 | + 'name' => 'Speedtest', |
| 31 | + 'port' => 8080, |
| 32 | + 'country' => 'United States', |
| 33 | + 'location' => 'New York City, NY', |
| 34 | + ], |
| 35 | + 'upload' => [ |
| 36 | + 'bytes' => 124297377, |
| 37 | + 'elapsed' => 9628, |
| 38 | + 'latency' => [ |
| 39 | + 'iqm' => 341.111, |
| 40 | + 'low' => 16.663, |
| 41 | + 'high' => 529.86, |
| 42 | + 'jitter' => 37.587, |
| 43 | + ], |
| 44 | + 'bandwidth' => 113750000, |
| 45 | + ], |
| 46 | + 'download' => [ |
| 47 | + 'bytes' => 230789788, |
| 48 | + 'elapsed' => 14301, |
| 49 | + 'latency' => [ |
| 50 | + 'iqm' => 104.125, |
| 51 | + 'low' => 23.72, |
| 52 | + 'high' => 269.563, |
| 53 | + 'jitter' => 13.447, |
| 54 | + ], |
| 55 | + 'bandwidth' => 115625000, |
| 56 | + ], |
| 57 | + 'interface' => [ |
| 58 | + 'name' => 'eth0', |
| 59 | + 'isVpn' => false, |
| 60 | + 'macAddr' => '00:00:00:00:00:00', |
| 61 | + 'externalIp' => '127.0.0.1', |
| 62 | + 'internalIp' => '127.0.0.1', |
| 63 | + ], |
| 64 | + 'timestamp' => now()->toIso8601String(), |
| 65 | + 'packetLoss' => 11, |
| 66 | + ]; |
| 67 | + |
| 68 | + return new Result([ |
| 69 | + 'ping' => $data['ping']['latency'], |
| 70 | + 'ping_low' => $data['ping']['low'], |
| 71 | + 'ping_high' => $data['ping']['high'], |
| 72 | + 'ping_jitter' => $data['ping']['jitter'], |
| 73 | + 'packet_loss' => $data['packetLoss'], |
| 74 | + 'download' => $data['download']['bandwidth'], |
| 75 | + 'download_bits' => $data['download']['bandwidth'], |
| 76 | + 'download_bytes' => $data['download']['bytes'], |
| 77 | + 'download_elapsed' => $data['download']['elapsed'], |
| 78 | + 'download_latency_iqm' => $data['download']['latency']['iqm'], |
| 79 | + 'download_latency_low' => $data['download']['latency']['low'], |
| 80 | + 'download_latency_high' => $data['download']['latency']['high'], |
| 81 | + 'download_latency_jitter' => $data['download']['latency']['jitter'], |
| 82 | + 'upload' => $data['upload']['bandwidth'], |
| 83 | + 'upload_bits' => $data['upload']['bandwidth'], |
| 84 | + 'upload_bytes' => $data['upload']['bytes'], |
| 85 | + 'upload_elapsed' => $data['upload']['elapsed'], |
| 86 | + 'upload_latency_iqm' => $data['upload']['latency']['iqm'], |
| 87 | + 'upload_latency_low' => $data['upload']['latency']['low'], |
| 88 | + 'upload_latency_high' => $data['upload']['latency']['high'], |
| 89 | + 'upload_latency_jitter' => $data['upload']['latency']['jitter'], |
| 90 | + 'server_id' => $data['server']['id'], |
| 91 | + 'server_ip' => $data['server']['ip'], |
| 92 | + 'server_host' => $data['server']['host'], |
| 93 | + 'server_name' => $data['server']['name'], |
| 94 | + 'server_port' => $data['server']['port'], |
| 95 | + 'server_country' => $data['server']['country'], |
| 96 | + 'server_location' => $data['server']['location'], |
| 97 | + 'interface_name' => $data['interface']['name'], |
| 98 | + 'interface_is_vpn' => $data['interface']['isVpn'], |
| 99 | + 'interface_mac_addr' => $data['interface']['macAddr'], |
| 100 | + 'interface_internal_ip' => $data['interface']['internalIp'], |
| 101 | + 'ip_address' => $data['interface']['externalIp'], |
| 102 | + 'uuid' => $data['result']['id'], |
| 103 | + 'result_url' => $data['result']['url'], |
| 104 | + 'data' => $data, |
| 105 | + 'status' => 'completed', |
| 106 | + 'service' => 'faker', |
| 107 | + 'scheduled' => false, |
| 108 | + ]); |
| 109 | + } |
| 110 | + |
| 111 | + public static function failed(): Result |
| 112 | + { |
| 113 | + $data = [ |
| 114 | + 'type' => 'log', |
| 115 | + 'level' => 'error', |
| 116 | + 'message' => 'A faked error message.', |
| 117 | + 'timestamp' => now()->toIso8601String(), |
| 118 | + ]; |
| 119 | + |
| 120 | + return new Result([ |
| 121 | + 'data' => $data, |
| 122 | + 'status' => 'failed', |
| 123 | + 'service' => 'faker', |
| 124 | + 'scheduled' => false, |
| 125 | + ]); |
| 126 | + } |
| 127 | +} |
0 commit comments