-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage-speed.php
executable file
·75 lines (66 loc) · 2.47 KB
/
average-speed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/php
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/average-speed-class.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$avgs = new Average_Speed(getenv('LOG_FILE_PATH'));
echo '===== Average speed measurement calculation =====' . PHP_EOL;
echo sprintf('First data recorded: %s', $avgs->first_record_date()) . PHP_EOL;
echo sprintf('Latest data recorded: %s', $avgs->latest_record_date()) . PHP_EOL;
$average_speed = $avgs->get_average_speed();
echo sprintf('Average speed (down / up): %s Mbps / %s Mbps', $average_speed->down, $average_speed->up) . PHP_EOL;
echo PHP_EOL . '===== Servers used =====' . PHP_EOL;
$table = new LucidFrame\Console\ConsoleTable();
$table->addHeader('Server name');
$items = $avgs->get_items();
foreach ( $avgs->get_servers() as $server ) {
$table->addRow()
->addColumn($server);
}
$table->display();
$table = $avgs->prepare_table('Hour');
$by_hour = $avgs->get_items_by_hour();
echo PHP_EOL . '===== Average speed grouped by hour =====' . PHP_EOL;
foreach ( $by_hour as $key => $value ) {
$table->addRow()
->addColumn($key)
->addColumn($value->count)
->addColumn($value->average->down)
->addColumn($value->average->up)
->addColumn($value->min_max->down->min)
->addColumn($value->min_max->down->max)
->addColumn($value->min_max->up->min)
->addColumn($value->min_max->up->max);
}
$table->display();
$table = $avgs->prepare_table('Weekday');
$by_weekday = $avgs->get_items_by_weekday();
echo PHP_EOL . '===== Average speed grouped by weekday =====' . PHP_EOL;
foreach ( $by_weekday as $key => $value ) {
$table->addRow()
->addColumn(jddayofweek($key-1, 1))
->addColumn($value->count)
->addColumn($value->average->down)
->addColumn($value->average->up)
->addColumn($value->min_max->down->min)
->addColumn($value->min_max->down->max)
->addColumn($value->min_max->up->min)
->addColumn($value->min_max->up->max);
}
$table->display();
$table = new LucidFrame\Console\ConsoleTable();
$table->addHeader('Datetime')
->addHeader('Speed down (Mbps)')
->addHeader('Speed up (Mbps)')
->addHeader('Server');
$items = $avgs->get_items();
echo PHP_EOL . '===== All measurements =====' . PHP_EOL;
foreach ( $items as $item ) {
$table->addRow()
->addColumn($item['datetime'])
->addColumn($item['download_speed'])
->addColumn($item['upload_speed'])
->addColumn($item['server']);
}
$table->display();