Skip to content

Commit

Permalink
Merge pull request #1 from TheWhite147/feature/stats-banner
Browse files Browse the repository at this point in the history
Feature/stats banner
  • Loading branch information
TheWhite147 authored Feb 20, 2018
2 parents 7fd6c8b + 67cada0 commit 6e5736b
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 77 deletions.
15 changes: 15 additions & 0 deletions api/get_games.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php header('Access-Control-Allow-Origin: *'); ?>

<?php
$pdo = new PDO('sqlite:/home/pi/pi-score-counter/pi-score-counter.db');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare("SELECT id, id_player_1, id_player_2, created_date FROM games");
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
$data = "id=" . $row[0] . "#id_player_1=" . $row[1] . "#id_player_2=" . $row[2] . "#created_date=" . $row[3] . "|";
print $data;
}
?>
2 changes: 1 addition & 1 deletion api/get_players.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare("SELECT id, name FROM players");
$stmt = $pdo->prepare("SELECT id, name FROM players ORDER BY name");
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
Expand Down
15 changes: 15 additions & 0 deletions api/get_scores.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php header('Access-Control-Allow-Origin: *'); ?>

<?php
$pdo = new PDO('sqlite:/home/pi/pi-score-counter/pi-score-counter.db');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare("SELECT id, id_game, id_serving_player, score_player_1, score_player_2, created_date FROM scores");
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
$data = "id=" . $row[0] . "#id_game=" . $row[1] . "#id_serving_player=" . $row[2] . "#score_player_1=" . $row[3] . "#score_player_2=" . $row[4] . "#created_date=" . $row[5] . "|";
print $data;
}
?>
2 changes: 1 addition & 1 deletion game/dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __db_get_all_player_ids():

conn = sqlite3.connect(DATABASE_NAME)
c = conn.cursor()
for row in c.execute('SELECT id FROM players'):
for row in c.execute('SELECT id FROM players ORDER BY name'):
ids.append(row[0])

conn.commit()
Expand Down
30 changes: 29 additions & 1 deletion game/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,32 @@

print("TEST 14: Wait 5 seconds then press any button to go back to main menu")
time.sleep(5)
handle_button(GPIO_INPUT_P1BB)
handle_button(GPIO_INPUT_P1BB)

#################################################################################################

print("TEST 15: Shutout")
handle_button(GPIO_INPUT_P1BA) # 1-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 2-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 3-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 4-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 5-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 6-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 7-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 8-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 9-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 10-0
time.sleep(1)
handle_button(GPIO_INPUT_P1BA) # 11-0 -> Game over!
time.sleep(5)

handle_button(GPIO_INPUT_P2BA) # Return to main menu
17 changes: 16 additions & 1 deletion web/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ h1 {
margin: 20px;
}

#banner-stats {
width: 100%;
height: 75px;
line-height: 75px;
font-size: 36px;
color: #FFF;
background-color: #444;
overflow-x: hidden;
overflow-y: hidden;
white-space: nowrap;
position: absolute;
bottom: 0px;
}

/* Main menu */

#view-main-menu .fixed-height {
Expand All @@ -38,9 +52,10 @@ h1 {

#players-list .card-panel {
margin: 0px;
padding: 10px;
}

#players-list .card-panel h1 {
#players-list .card-panel h3 {
margin: 0px;
}

Expand Down
13 changes: 12 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<!-- Materialize integration -->
<script src="js/jquery-3.3.1.min.js"></script>
<script src="materialize/js/materialize.min.js"></script>
<script src="js/script.js"></script>
<script src="js/api.js"></script>
<script src="js/script.js"></script>
<script src="js/stats.js"></script>
<link rel="stylesheet" type="text/css" href="materialize/css/materialize.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">

Expand Down Expand Up @@ -50,6 +52,15 @@ <h1 class="white-text">Joueur 2</h1>

<div id="view-in-game"></div>


<!-- +++++++++++++++++++++++++++ -->
<!-- STATS BANNER (STATIC) -->
<!-- +++++++++++++++++++++++++++ -->
<div class="row" id="banner-stats">
<marquee scrollamount=15>
<div class="col s12" id="banner-stats-content"></div>
</marquee>
</div>
</body>

</html>
79 changes: 79 additions & 0 deletions web/js/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

if (typeof Api === "undefined") { Api = {}; }
if (typeof Api.GetPlayersList === "undefined") { Api.GetPlayersList = {}; }
if (typeof Api.GetUIControls === "undefined") { Api.GetUIControls = {}; }

(function () {

// // Gets UI controls from database
Api.GetUIControls = function(callback) {
$.get("http://localhost/api/get_ui_controls.php", function(data) {
var objects = stripLastChar(data).split("|");
callback(objects);
});
}

// Gets the list of players from database
Api.GetPlayersList = function(callback){
var tmpLstPlayers = [];
$.get("http://localhost/api/get_players.php", function(data) {
var objects = stripLastChar(data).split("|");
for (var i = 0; i < objects.length; i++) {
var id = objects[i].split("=")[0];
var name = objects[i].split("=")[1];
tmpLstPlayers.push({ id: id, name: decodeURIComponent(name)});
}
callback(tmpLstPlayers);
});
}

// // Gets all games from database
Api.GetGames = function(callback) {
var tmpGames = [];
$.get("http://localhost/api/get_games.php", function(data) {
var objects = stripLastChar(data).split("|");

for (var i = 0; i < objects.length; i++) {
var newObject = {};

var columns = objects[i].split("#");
for (var j = 0; j < columns.length; j++) {
var keyValue = columns[j].split("=");
newObject[keyValue[0]] = keyValue[1];
}

tmpGames.push(newObject);
}

callback(tmpGames);
});
}

// // Gets all scores from database
Api.GetScores = function(callback) {
var tmpScores = [];
$.get("http://localhost/api/get_scores.php", function(data) {
var objects = stripLastChar(data).split("|");

for (var i = 0; i < objects.length; i++) {
var newObject = {};

var columns = objects[i].split("#");
for (var j = 0; j < columns.length; j++) {
var keyValue = columns[j].split("=");
newObject[keyValue[0]] = keyValue[1];
}

tmpScores.push(newObject);
}

callback(tmpScores);
});
}

// Strips last char of string
function stripLastChar(myString) {
return myString.substring(0, myString.length - 1).trim();
}

})();
Loading

0 comments on commit 6e5736b

Please sign in to comment.