Skip to content

Commit

Permalink
Updated homepage with all gameweek stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
milanchheda committed Mar 6, 2017
1 parent 8a625ee commit dd8ee0b
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 53 deletions.
29 changes: 29 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,32 @@ header.card-header {
@keyframes love {
to {transform: scale(1.2);}
}
.navigation.navigation-next {
right: 0;
margin-right: -30px;
}
.navigation-prev {
margin-left: 10px;
}
.navigation {
position: absolute;
top: 50px;
bottom: 0;
margin: 0;
max-width: 150px;
min-width: 90px;
display: flex;
justify-content: center;
align-content: center;
flex-direction: column;
font-size: 40px;
color: #ccc;
text-align: center;
-webkit-transition: all 350ms ease;
-moz-transition: all 350ms ease;
-o-transition: all 350ms ease;
transition: all 350ms ease;
}
.page-content {
margin: 0 50px;
}
56 changes: 56 additions & 0 deletions getStats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
ini_set('display_errors', 'Off');
require_once __DIR__ . "/config.php";
require_once __DIR__ . "/stats.php";

if(isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
$gameweekNumber = $_REQUEST['id'];
$topStats = getGameweekStatsForPosition1($conn, $gameweekNumber);
$result = getGameweekStats($conn, $gameweekNumber);
$count = 1;
$html = '';
foreach ($result as $key => $value) {
if($count == 1 || $count == 5) {
$html .= '<div class="row">';
}
$label = str_replace('_', ' ', $key);
$label = ucwords($label);
$html .= '<div class="col-md-3">
<section class="widget widget-simple-sm">
<div class="widget-simple-sm-statistic">
<div class="number">' . $value . '</div>
<div class="caption color-blue">' . $label . ' </div>
</div>
</section>
</div>';
if($count == 4 || $count == 7) {
$html .= '</div>';
}
$count++;
}

$table = '';
$topHtml .= '<div class="row">';
foreach($topStats as $key => $value) {
$positionName = $value[0]['name'];
$table .= '<div class="col-md-3">
<section class="card">
<header class="card-header card-header-lg">
Top ' . $positionName . 's
</header>
<div class="card-block">
<table class="table table-hover">';
foreach($value as $k => $v) {
$table .= "<tr>
<td>" . $v['web_name'] . "</td>
<td>" . $v['total_points'] . "</td>
</tr>";
}
$table .= "</table></div></section></div>";
}
$topHtml .= $table . '</div>';
echo $html . $topHtml;
} else {
echo 0;
}
?>
Binary file added images/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 46 additions & 49 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,12 @@
<?php
ini_set('display_errors', 'Off');
require_once __DIR__ . "/config.php";
require_once __DIR__ . "/stats.php";

$getEnv = getenv('LOCAL_ENV');

$liveContent = explode("###", file_get_contents('live.txt'));
$lastGameweekNumber = $liveContent[1];
session_start();
unset($_SESSION['teamID']);
$topStats = getGameweekStatsForPosition1($conn);
$result = getGameweekStats($conn);
$count = 1;
$html = '';
foreach ($result as $key => $value) {
if($count == 1 || $count == 5) {
$html .= '<div class="row">';
}
$label = str_replace('_', ' ', $key);
$label = ucwords($label);
$html .= '<div class="col-md-3">
<section class="widget widget-simple-sm">
<div class="widget-simple-sm-statistic">
<div class="number">' . $value . '</div>
<div class="caption color-blue">' . $label . ' </div>
</div>
</section>
</div>';
if($count == 4 || $count == 7) {
$html .= '</div>';
}
$count++;
}

$table = '';
$topHtml .= '<div class="row">';
foreach($topStats as $key => $value) {
$positionName = $value[0]['name'];
$table .= '<div class="col-md-3">
<section class="card">
<header class="card-header card-header-lg">
Top ' . $positionName . 's
</header>
<div class="card-block">
<table class="table table-hover">';
foreach($value as $k => $v) {
$table .= "<tr>
<td>" . $v['web_name'] . "</td>
<td>" . $v['total_points'] . "</td>
</tr>";
}
$table .= "</table></div></section></div>";
}
$topHtml .= $table . '</div>';
?>
<!DOCTYPE html>
<html>
Expand All @@ -61,6 +17,7 @@
<meta name="title" content="FPL Analysis">
<meta name="description" content="FPL Analysis for Fantasy Premier League Managers">
<meta name="keywords" content="English Premier League, Fantasy Premier League, EPL, BPL, Barclays Premier League, Premier League">
<!-- <link rel="stylesheet" href="css/font-awesome.css"> -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/widgets.min.css">
<link rel="stylesheet" href="css/index.css">
Expand Down Expand Up @@ -101,7 +58,7 @@
<header class="site-header">
<div class="container-fluid">
<a href='index.php' class="logoClass">FPL Analysis</a>
<span class="gameweekHeaderNumber">Gameweek: <?php echo $liveContent[1]; ?></span>
<span class="gameweekHeaderNumber">Gameweek: <span class='gameweekNumber'><?php echo $lastGameweekNumber; ?></span></span>
<div class="site-header-content">
<div class="site-header-content-in">
<div class="site-header-collapsed">
Expand All @@ -123,9 +80,49 @@
</header>
<div class="page-content">
<div class="container-fluid">
<?php echo $html; ?>
<?php echo $topHtml; ?>

</div><!--.container-fluid-->
</div><!--.page-content-->

<a href="#" class="navigation navigation-prev" id=<?php echo $lastGameweekNumber-1; ?>>
<img src="images/left.png" height="45" width="45"/>
</a>
<a href="#" class="navigation navigation-next" id=<?php echo $lastGameweekNumber+1; ?> style="margin-right: 0px;">
<img src="images/right.png" height="45" width="45"/>
</a>

<script type="text/javascript" src="js/datatables.min.js?v=1.0.2"></script>
<script type="text/javascript">
$(document).ready(function(){
getData($(".gameweekNumber").text());
$(".navigation").on('click', function(){
$(".gameweekNumber").text($(this).attr("id"));
getData($(this).attr("id"));
if($(this).hasClass("navigation-prev")) {
$(this).attr("id", ($(this).attr("id")-1));
$(".navigation-next").attr('id', ($(this).attr("id")));
} else {
$(this).attr("id", ($(this).attr("id")+1));
$(".navigation-prev").attr('id', ($(this).attr("id")));
}
});
});

function getData(gw_no) {
$(".navigation").hide();
$(".page-content .container-fluid").html("<img src='images/loading.gif' style='margin:10% 37%;'/>");
$.ajax({
url: "getStats.php",
data: { id: gw_no },
datatype: 'html',
type: "post",
success: function(data, textStatus, jqXHR) {
$(".gameweekNumber").text(gw_no);
$(".page-content .container-fluid").html(data);
$(".navigation").show();
}
});
}
</script>
</body>
</html>
10 changes: 6 additions & 4 deletions stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,25 @@ function getLiveData($conn) {
return $table;
}

function getGameweekStats($conn) {
function getGameweekStats($conn, $gameweekNumber) {
$query = mysqli_query($conn, "SELECT sum(l.total_points) as total_points, sum(l.assists) as total_assists, sum(bonus) as total_bonus, sum(l.clean_sheets) as total_clean_sheets, sum(l.yellow_cards) as total_yellow_cards, sum(l.red_cards) as total_red_cards
, sum(l.goals_scored) as total_goals_scored
from live l
join players p on p.id = l.player_id");
join players p on p.id = l.player_id
WHERE l.gameweek_number = " . $gameweekNumber);
$result = mysqli_fetch_assoc($query);
return $result;
}

function getGameweekStatsForPosition1($conn) {
function getGameweekStatsForPosition1($conn, $gameweekNumber) {
for($i = 1; $i <= 4; $i++) {
$query = mysqli_query($conn, "SELECT web_name, l.total_points, et.name
from live l
join players p on p.id = l.player_id
join element_types et on et.id = p.element_type
where element_type = $i
order by l.total_points desc
AND l.gameweek_number = ".$gameweekNumber."
ORDER BY l.total_points desc
limit 5");
while($result = mysqli_fetch_assoc($query)) {
$row[$i][] = $result;
Expand Down

0 comments on commit dd8ee0b

Please sign in to comment.