-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetRush.php
More file actions
73 lines (63 loc) · 1.9 KB
/
getRush.php
File metadata and controls
73 lines (63 loc) · 1.9 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
<?php
// Read the contents of the JSON file into a string
$jsonString = file_get_contents('puzzleRush.json');
// Decode the JSON string into an associative array
$data = json_decode($jsonString, true);
// Check if the JSON decoding was successful
if ($data === null) {
die('Error decoding JSON file');
}
// Sort rush data by winrate
usort($data, function($a, $b) {
return $b["winrate"] - $a["winrate"];
});
// Chunkify function (Equivalent to the JavaScript function)
function chunkify($a, $n) {
if ($n < 2)
return [$a];
$len = count($a);
$out = [];
$i = 0;
if ($len % $n === 0) {
$size = floor($len / $n);
while ($i < $len) {
$out[] = array_slice($a, $i, $size);
$i += $size;
}
} else {
while ($i < $len) {
$size = ceil(($len - $i) / $n--);
$out[] = array_slice($a, $i, $size);
$i += $size;
}
}
return $out;
}
$rushSorted = chunkify($data, 5);
$sentRush = [];
foreach ($rushSorted as $i => $chunk) {
if ($i == 4) {
shuffle($chunk);
$shuffled = array_splice($chunk, 0, intval(count($chunk) / 1.25) - 1);
usort($shuffled, function($a, $b) {
return count($a["plays"]) - count($b["plays"]);
});
$shuffled = array_splice($shuffled, 0, intval(count($shuffled) / 1.75) - 1);
$sentRush = array_merge($sentRush, $shuffled);
} else {
shuffle($chunk);
$shuffled = array_splice($chunk, 0, 15);
usort($shuffled, function($a, $b) {
return count($a["plays"]) - count($b["plays"]);
});
$added = array_splice($shuffled, 0, 13);
$sentRush = array_merge($sentRush, $added);
}
}
// Sort the final rush data by winrate
usort($sentRush, function($a, $b) {
return $b["winrate"] - $a["winrate"];
});
// Return the modified rush data as JSON
echo json_encode($sentRush);
?>