Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.10% covered (warning)
88.10%
37 / 42
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
TsumegoXPAndRating
88.10% covered (warning)
88.10%
37 / 42
75.00% covered (warning)
75.00%
3 / 4
15.38
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 render
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 renderJavascript
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
4
 getProgressDeletionMultiplier
44.44% covered (danger)
44.44%
4 / 9
0.00% covered (danger)
0.00%
0 / 1
9.29
1<?php
2
3class TsumegoXPAndRating
4{
5    public function __construct(array $tsumego, string $status)
6    {
7        if ($status == 'G')
8            $this->goldenTsumego = true;
9        elseif (TsumegoUtil::isRecentlySolved($status))
10            $this->solved = true;
11        elseif ($status == 'W')
12            $this->resolving = true;
13        $this->tsumegoRating = $tsumego['rating'];
14        $this->progressDeletionCount = TsumegoUtil::getProgressDeletionCount($tsumego);
15    }
16
17    public function render()
18    {
19        echo '<div align="center" id="xpDisplayDiv">
20        <table class="xpDisplayTable" border="0" width="70%">
21            <tr>
22            <td style="width:33%;">';
23        echo '
24    <div id="xpDisplay">
25        <span id="xpDisplayText"></span>
26        <span id="ratingHeader"></span>
27        <div class="eloTooltip"><span id="ratingGainShort"></span><span class="eloTooltiptext" id="ratingGainLong"></span></div>
28        <span id="ratingSeparator"></span><div class="eloTooltip"><span id="ratingLossShort"></span><span class="eloTooltiptext" id="ratingLossLong"></span></div>
29    </div>';
30        if (Auth::isInTimeMode())
31            echo '<div id="time-mode-countdown">10.0</div><div id="plus2">+2</div>';
32        echo '</td>
33            <td style="width:33%;">
34                <div id="status" align="center"></div>
35            </td>
36            <td style="width:33%;">
37                <div id="status2" align="center">
38                <font size="4">
39                ' . Rating::getReadableRankFromRating($this->tsumegoRating) . ' <font color="grey">(' . $this->tsumegoRating . ')</font>
40                </font>
41                </div>
42            </td>
43            </tr>
44        </table>
45    </div>';
46    }
47
48    public function renderJavascript()
49    {
50        if (!Auth::isLoggedIn())
51            return;
52        if (!Auth::XPisGainedInCurrentMode() && !Auth::ratingisGainedInCurrentMode())
53            return;
54        echo '
55    var xpStatus = new XPStatus(
56    {
57        solved: ' . Util::boolString($this->solved) . ',
58        sprintRemainingSeconds: ' . HeroPowers::getSprintRemainingSeconds() . ',
59        sprintMultiplier: ' . Constants::$SPRINT_MULTIPLIER . ',
60        goldenTsumego: ' . Util::boolString($this->goldenTsumego) . ',
61        goldenTsumegoMultiplier: ' . Constants::$GOLDEN_TSUMEGO_XP_MULTIPLIER . ',
62        resolving: ' . Util::boolString($this->resolving) . ',
63        resolvingMultiplier: ' . Constants::$RESOLVING_MULTIPLIER . ',
64        userRating: ' . Auth::getUser()['rating'] . ',
65        tsumegoRating: ' . $this->tsumegoRating . ',
66        progressDeletionCount: ' . $this->progressDeletionCount . '
67    });
68    xpStatus.update();
69';
70    }
71
72    // changes here must be reflected in the same method in util.js
73    public static function getProgressDeletionMultiplier($progressDeletionCount): float
74    {
75        if ($progressDeletionCount == 0)
76            return 1;
77        if ($progressDeletionCount == 1)
78            return 0.5;
79        if ($progressDeletionCount == 2)
80            return 0.2;
81        if ($progressDeletionCount == 3)
82            return 0.1;
83        return 0.01;
84    }
85
86    public bool $solved = false;
87    public bool $goldenTsumego = false;
88    public bool $resolving = false;
89
90    public float $tsumegoRating;
91    public float $progressDeletionCount;
92}