-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilityprocess_rankdistribution_players.php
101 lines (73 loc) · 2.39 KB
/
utilityprocess_rankdistribution_players.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
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
<?php
/*
* Utility Process Rank Distribution
*/
namespace Fizzik;
require_once 'includes/include.php';
use Fizzik\Database\MySqlDatabase;
use Fizzik\Utility\AssocArray;
set_time_limit(0);
date_default_timezone_set(HotstatusPipeline::REPLAY_TIMEZONE);
$db = new MysqlDatabase();
$creds = Credentials::getCredentialsForUser(Credentials::USER_REPLAYPROCESS);
HotstatusPipeline::hotstatus_mysql_connect($db, $creds);
$db->setEncoding(HotstatusPipeline::DATABASE_CHARSET);
//Constants and qol
const E = PHP_EOL;
//Prepare statements
//Player Rank Distribution
$t_players_mmr = HotstatusPipeline::$table_pointers['players_mmr'];
$db->prepare("GetRatings", "SELECT `rating` FROM `$t_players_mmr` WHERE `season` = ?");
$db->bind("GetRatings", "s", $r_season);
$r_season = "2018 Season 1";
$stepsize = 1;
$ratings = [];
$result = $db->execute("GetRatings");
$result_rows = $db->countResultRows($result);
if ($result_rows > 0) {
while ($row = $db->fetchArray($result)) {
$step = [
HotstatusPipeline::getFixedMMRStep($row['rating'], $stepsize) => 1,
];
AssocArray::aggregate($ratings, $step, $null = null, AssocArray::AGGREGATE_SUM);
}
}
$db->freeResult($result);
$db->close();
//Output ratings step distribution
echo "players: $result_rows\n\n";
/*foreach ($ratings as $rstep => $rstepcount) {
$stepinc = $stepsize + intval($rstep) - 1;
echo "$rstep -> $stepinc: $rstepcount\n";
}*/
echo "\n\n";
//Build ratings normal array
$ratingsarr = [];
foreach ($ratings as $rkey => $robj) {
$ratingsarr[] = $rkey;
}
sort($ratingsarr);
//top function
$toppercent = function(&$arr, $ratingcount, &$ratingsassoc, $percent, $name) {
$pct = $ratingcount * $percent;
$count = 0;
for ($i = count($arr) - 1; $i > 0; $i--) {
$step = $arr[$i];
$count += $ratingsassoc[$step];
if ($count >= $pct) {
return "$name >= Rating($step)\n";
}
}
return "$name >= UNKNOWN\n";
};
//Top 1.1% (Master)
echo $toppercent($ratingsarr, $result_rows, $ratings, .011, "Master");
//Top 5.1% (Diamond)
echo $toppercent($ratingsarr, $result_rows, $ratings, .051, "Diamond");
//Top 17.1% (Platinum)
echo $toppercent($ratingsarr, $result_rows, $ratings, .171, "Platinum");
//Top 52.1% (Gold)
echo $toppercent($ratingsarr, $result_rows, $ratings, .521, "Gold");
//Top 82.1% (Silver)
echo $toppercent($ratingsarr, $result_rows, $ratings, .821, "Silver");
?>