forked from robocoder/rips-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrips_stats.compare.php
More file actions
105 lines (88 loc) · 1.82 KB
/
Copy pathrips_stats.compare.php
File metadata and controls
105 lines (88 loc) · 1.82 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Copyright (C) 2020 AnimalSoft Kft.
*/
declare(strict_types=1);
error_reporting(E_ALL);
chdir('c:/Users/User/PhpstormProjects/rips-scanner');
$old = json_decode(file_get_contents('old.json'), TRUE);
$new = json_decode(file_get_contents('new.json'), TRUE);
$keys = [];
foreach (array_unique(array_merge(array_keys($old), array_keys($new))) as $key) {
if (':' === $key[-1]) {
$newkey = substr($key, 0, -1);
}
if (isset($old[$key]) && !isset($old[$newkey])) {
$old[$newkey] = $old[$key];
}
if (isset($new[$key]) && !isset($new[$newkey])) {
$new[$newkey] = $new[$key];
}
$keys[] = $newkey;
}
$keys = array_unique($keys);
?>
<!doctype html>
<html lang="en" dir="ltr">
<head>
<title>Rips stats</title>
<style>
html {
font-family: sans-serif;
}
table, tr, td, th {
border: 1px solid black;
border-collapse: collapse;
}
td, th {
padding: 3px 5px;
}
tbody th {
font-weight: normal;
text-align: left;
}
tr:hover {
background: #eee;
}
td {
text-align: right;
}
td.no {
color: orange;
}
td.ok {
color: #63C763;
}
td.nok {
color: #c00;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Key</th>
<th>Old</th>
<th>New</th>
<th>Change</th>
</tr>
</thead>
<tbody>
<?php foreach ($keys as $key): ?>
<?php $oldvalue = $old[$key] ?? 0 ?>
<?php $newvalue = $new[$key] ?? 0 ?>
<?php $change = ($oldvalue - $newvalue) / max(1, $oldvalue) * -100 ?>
<tr>
<th><?= $key ?></th>
<td><?= $oldvalue ?></td>
<td><?= $newvalue ?></td>
<td class="<?= $change ? ($change < 0 ? 'ok' : 'nok') : 'no' ?>"><?php
printf('%+.02f%%', $change);
?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</body>
</html>