Skip to content

Commit

Permalink
Restoring Images
Browse files Browse the repository at this point in the history
Slowly creating new compilations of images to replace the images which I removed when I removed pChart.
Specifically:
The average players per day image on the server page has been further improved.
The maps played pie chart has been recreated.

To do: add players per day chart back into server banner image.
  • Loading branch information
tyger07 committed Mar 28, 2021
1 parent afc2697 commit b84530d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 49 deletions.
Binary file added common/maps/images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 77 additions & 34 deletions common/maps/maps-played.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
// https://myrcon.net/topic/162-chat-guid-stats-and-mapstats-logger-1003/

// include required files
require_once("../pchart/class/pData.class.php");
require_once("../pchart/class/pDraw.class.php");
require_once("../pchart/class/pPie.class.php");
require_once("../pchart/class/pImage.class.php");
require_once('../../config/config.php');
require_once('../connect.php');
require_once('../constants.php');
Expand All @@ -19,12 +15,21 @@
if(!empty($sid))
{
$query = "
SELECT `MapName`, SUM(`NumberofRounds`) AS number
SELECT `MapName`, SUM(`NumberofRounds`) AS number, sub.`total`
FROM `tbl_mapstats`
LEFT JOIN
(
SELECT SUM(`NumberofRounds`) AS total
FROM `tbl_mapstats`
WHERE `ServerID` = {$sid}
AND `Gamemode` != ''
LIMIT 0, 1
) sub ON sub.`total` = `total`
WHERE `ServerID` = {$sid}
AND `Gamemode` != ''
GROUP BY `MapName`
ORDER BY number DESC
LIMIT 20
";
$result = @mysqli_query($BF4stats, $query);
}
Expand All @@ -34,20 +39,53 @@
// merge server IDs array into a variable
$ids = join(',',$ServerIDs);
$query = "
SELECT `MapName`, SUM(`NumberofRounds`) AS number
SELECT `MapName`, SUM(`NumberofRounds`) AS number, sub.`total`
FROM `tbl_mapstats`
LEFT JOIN
(
SELECT SUM(`NumberofRounds`) AS total
FROM `tbl_mapstats`
WHERE `ServerID` in ({$ids})
AND `Gamemode` != ''
LIMIT 0, 1
) sub ON sub.`total` = `total`
WHERE `ServerID` in ({$ids})
AND `Gamemode` != ''
GROUP BY `MapName`
ORDER BY number DESC
LIMIT 20
";
$result = @mysqli_query($BF4stats, $query);
}
if($result)
// initialize timestamp values
$now_timestamp = time();
// start outputting the image
header('Pragma: public');
header('Cache-Control: max-age=10800');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', $now_timestamp + 10800));
header("Content-type: image/png");
// base image
$base = imagecreatefrompng('./images/background.png');
// color
$dark = imagecolorallocate($base, 20, 20, 20);
$faded = imagecolorallocate($base, 150, 150, 150);
$yellow = imagecolorallocate($base, 255, 250, 200);
$orange = imagecolorallocate($base, 200, 150, 000);
if(@mysqli_num_rows($result) != 0)
{
$legend_y_position = 19;
$loop_count = 0;
$previous_end = 0;
$num_rows = @mysqli_num_rows($result);
$color_steps = round(250 / $num_rows, 0);
while($row = mysqli_fetch_assoc($result))
{
$key = $row['MapName'];
$number = $row['number'];
$total_rounds = $row['total'];
$fraction = round(($number / $total_rounds * 100), 0);
$degrees = 360 * ($number / $total_rounds);
$wedge_color = imagecolorallocate($base, abs(-200 + $loop_count * $color_steps), abs(-200 + $loop_count * $color_steps), abs(-255 + $loop_count * $color_steps));
// convert map to friendly name
// first find if this map name is even in the map array
if(in_array($key,$map_array))
Expand All @@ -59,35 +97,40 @@
{
$MapName = $key;
}
$maps[] = $MapName;
$number[] = $row['number'];
imagefilledrectangle($base, 457, $legend_y_position + 1, 462, $legend_y_position + 6, $wedge_color);
imagestring($base, 1, 467, $legend_y_position, $MapName, $faded);
if($num_rows > 1)
{
if(strlen((string)$fraction) < 2)
{
imagestring($base, 1, 439, $legend_y_position, " " . $fraction . "%", $faded);
}
else
{
imagestring($base, 1, 439, $legend_y_position, $fraction . "%", $faded);
}
}
else
{
imagestring($base, 1, 433, $legend_y_position, $fraction . "%", $faded);
}
ImageFilledArc($base, 300, 150, 200, 200, $previous_end - 90, $degrees + $previous_end - 90, $wedge_color, IMG_ARC_PIE);
ImageFilledArc($base, 300, 150, 200, 200, $previous_end - 90, $degrees + $previous_end - 90, $dark, IMG_ARC_EDGED | IMG_ARC_NOFILL);
$legend_y_position += 10;
$loop_count++;
$previous_end += $degrees;
}
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($number,"ScoreA");
$MyData->setSerieDescription("ScoreA","Application A");
/* Define the absissa serie */
$MyData->addPoints($maps,"Labels");
$MyData->setAbscissa("Labels");
/* Create the pChart object */
$myPicture = new pImage(600,300,$MyData,TRUE);
/* Write the picture title */
$myPicture->setFontProperties(array("FontName"=>"../pchart/fonts/Forgotte.ttf","FontSize"=>12));
$myPicture->drawText(170,24,"Maps played in percent from greatest to least.",array("R"=>150,"G"=>150,"B"=>150));
/* Set the default font properties */
$myPicture->setFontProperties(array("FontName"=>"../pchart/fonts/pf_arma_five.ttf","FontSize"=>6,"R"=>150,"G"=>150,"B"=>150));
/* Create the pPie object */
$PieChart = new pPie($myPicture,$MyData);
/* Draw an AA pie chart */
$PieChart->draw2DRing(300,150,array("WriteValues"=>TRUE,"ValueR"=>150,"ValueG"=>150,"ValueB"=>150,"Border"=>TRUE));
/* Set the default font properties */
$myPicture->setFontProperties(array("FontName"=>"../pchart/fonts/pf_arma_five.ttf","FontSize"=>6,"R"=>150,"G"=>150,"B"=>150));
/* Write the legend box */
$myPicture->setShadow(FALSE);
$PieChart->drawPieLegend(480,10,array("Alpha"=>0));
/* Render the picture */
$myPicture->stroke($BrowserExpire=TRUE);
imagestring($base, 2, 250, 15, 'Maps Played Most', $faded);
}
else
{
imagestring($base, 4, 170, 135, 'The query returned no results.', $faded);
}
// compile image
imagealphablending($base, false);
imagesavealpha($base, true);
imagepng($base);
imagedestroy($base);
}
// php GD extension doesn't exist. show error image
else
Expand Down
11 changes: 11 additions & 0 deletions common/maps/maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@
}
else
{
echo '
<div class="subsection">
<br/><center><div class="embed"><img src="./common/maps/maps-played.png';
if(!empty($ServerID))
{
echo '?sid=' . $ServerID;
}
echo '" style="height: 300px; width: 600px;" alt="maps played" title="maps played" /></div></center><br/>
</div>
<br/>
';
// create empty array for storing values in
$game_modes = array();
// break the data up into individual game modes
Expand Down
28 changes: 15 additions & 13 deletions common/server/players-by-date.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
header("Content-type: image/png");
// base image
$base = imagecreatefrompng('./images/background.png');
// text color
$light = imagecolorallocate($base, 255, 255, 255);
// color
$faded = imagecolorallocate($base, 150, 150, 150);
$yellow = imagecolorallocate($base, 255, 250, 200);
$orange = imagecolorallocate($base, 255, 100, 000);
$orange = imagecolorallocate($base, 200, 150, 000);
if(@mysqli_num_rows($result) != 0)
{
$numrows = @mysqli_num_rows($result);
Expand Down Expand Up @@ -84,23 +84,25 @@
{
imageline($base, $x_start, $day_average, $x_finish, $day_average, $orange);
}
imagestring($base, 2, $x_start + 10, $height + 15 + $top_offset, $date, $yellow);
imageline($base, $x_finish, $height + $top_offset, $x_finish, $height + 10 + $top_offset, $light);
imagestring($base, 1, $x_start + 12, $height + 15 + $top_offset, $date, $faded);
imageline($base, $x_finish, $height + $top_offset, $x_finish, $height + 10 + $top_offset, $faded);
$last_average = $day_average;
$loop_count++;
}
imagestring($base, 2, 15, $height - ($y_max_display * $y_division) + $top_offset, $y_max_display, $yellow);
imagestring($base, 1, 15, $top_offset - 4, $y_max_display, $faded);
$middle = round(($y_max / 2), 0);
imagestring($base, 2, 15, $height - ($middle * $y_division) + $top_offset, $middle, $yellow);
imagestring($base, 2, 15, $height + $top_offset, "0", $yellow);
imageline($base, 40, $top_offset + 10, 50, $top_offset + 10, $light);
imageline($base, 40, $height + $top_offset, $width + 50, $height + $top_offset, $light);
imageline($base, 50, 10 + $top_offset, 50, $height + 10 + $top_offset, $light);
imagestring($base, 4, 90, 15, 'Average Players per Day on Days with Server Acitivity', $light);
imagestring($base, 1, 15, $height - ($middle * $y_division) + $top_offset - 4, $middle, $faded);
imagestring($base, 1, 15, $height + $top_offset - 4, "0", $faded);
imageline($base, 40, $top_offset, 50, $top_offset, $faded);
imageline($base, 40, $height + $top_offset, $width + 50, $height + $top_offset, $faded);
imageline($base, 50, $top_offset, 50, $height + 10 + $top_offset, $faded);
imagestring($base, 2, 140, 15, 'Average Players per Day on Days with Server Acitivity', $faded);
imagefilledrectangle($base, 527, 20, 532, 25, $orange);
imagestring($base, 1, 537, 19, 'Average', $faded);
}
else
{
imagestring($base, 4, 170, 135, 'The query returned no results.', $light);
imagestring($base, 4, 170, 135, 'The query returned no results.', $faded);
}
// compile image
imagealphablending($base, false);
Expand Down
2 changes: 1 addition & 1 deletion common/server/serverstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{
echo '
<ul>
<li><a href="#tabs-1">Graphs / Info</a></li>
<li><a href="#tabs-1">Graph / Info</a></li>
<li><a href="./common/server/server-tab.php?sid=' . $ServerID . '&amp;gid=' . $GameID . '">Banners</a></li>
</ul>
';
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
$xmlData = @file_get_contents('https://github.com/tyger07/BF4-Server-Stats/releases.atom');
$xml=@simplexml_load_string($xmlData);
$releaseVersion = $xml->entry[0]->id;
if((!empty($releaseVersion)) && (stripos($releaseVersion, '3-26-21') === false))
if((!empty($releaseVersion)) && (stripos($releaseVersion, '3-28-21') === false))
{
echo '
<div class="subsection">
Expand Down

0 comments on commit b84530d

Please sign in to comment.