Skip to content

Commit 4882811

Browse files
porthos. Count tier_id from STDIN
1 parent c35ed4b commit 4882811

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

porthos/root/srv/porthos/script/calc-tierid.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,31 @@
2020
* along with Dartagnan. If not, see COPYING.
2121
*/
2222

23-
$hash = 0;
23+
$tier_hits = [0,0,0];
24+
25+
while($system_id = trim(fgets(STDIN))) {
26+
27+
$hash = 0;
28+
29+
foreach(str_split($system_id) as $c) {
30+
$hash += ord($c);
31+
}
32+
$hash = $hash % 256;
33+
if($hash < 26) { // 10%
34+
$tier_id = 0;
35+
} elseif($hash < 77) { // +20% = 30%
36+
$tier_id = 1;
37+
} else { // +70% = 100%
38+
$tier_id = 2;
39+
}
40+
41+
$tier_hits[$tier_id]++;
2442

25-
foreach(str_split($argv[1]) as $c) {
26-
$hash += ord($c);
27-
}
28-
$hash = $hash % 256;
29-
if($hash < 26) { // 10%
30-
$tier_id = 0;
31-
} elseif($hash < 77) { // +20% = 30%
32-
$tier_id = 1;
33-
} else { // +70% = 100%
34-
$tier_id = 2;
3543
}
3644

37-
echo $tier_id . "\n";
45+
$total_hits = array_sum($tier_hits);
46+
47+
printf("Total: %d\n", $total_hits);
48+
foreach($tier_hits as $tier_id => $hits) {
49+
printf("Tier %d, hits %4d - %.2f\n", $tier_id, $hits, 100*$hits/$total_hits);
50+
}

0 commit comments

Comments
 (0)