Add: ranking hour, day, month record php

This commit is contained in:
2018-05-18 09:52:58 +09:00
parent 8fe5c72987
commit 60bd151c92
18 changed files with 404 additions and 158 deletions
+11
View File
@@ -37,6 +37,17 @@ let sessionStorageManager = new SessionStorageManager();
console.log("score : " + sessionStorageManager.score);
console.log("highscore : " + sessionStorageManager.highScore);
}
function isTypingGame() {
if(sessionStorageManager.playingAppName === null)
return false;
if(sessionStorageManager.playingAppName.indexOf("typing") < 0)
return false;
return true;
}
let appInfoManager = new AppInfoManager();
let textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
+90 -2
View File
@@ -71,6 +71,12 @@ class DBConnectManager {
parseJSONtoHistoryRecord(json) {
let historyRecordManager = new HistoryRecordManager();
if(typeof json === "undefined")
return historyRecordManager;
if(typeof json.history === "undefined")
return historyRecordManager;
let count = json.history.length;
for(let i = 0; i < count; i++) {
let record = new HistoryRecord(
@@ -108,16 +114,98 @@ class DBConnectManager {
requestRanking(type, listener) {
let rankingRecordManager = new RankingRecordManager();
/*
if(isDebugMode()) {
this.loadTempPlayerHistory(historyRecordManager);
this.loadTempRanking(rankingRecordManager);
if(listener !== null)
listener(historyRecordManager);
listener(rankingRecordManager);
return;
}
*/
let self = this;
let xhr = new XMLHttpRequest();
xhr.open("POST", this.getPHPUrl(type), true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
let jsonData = JSON.parse(xhr.responseText);
if(jsonData != null) {
listener(type, self.parseJSONtoRankingRecord(type, jsonData));
}
else
onFailedListener(jsonData);
}
};
let params = "UserID=" + sessionStorageManager.playerUserID
+ "&AppName=" + sessionStorageManager.playingAppName;
console.log(params);
xhr.send(params);
}
getPHPUrl(type) {
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
return "../../web/server/record/ranking_hour_record.php";
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
return "../../web/server/record/ranking_day_record.php";
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
return "../../web/server/record/ranking_month_record.php";
}
return "";
}
parseJSONtoRankingRecord(type, json) {
let rankingRecordManager = new RankingRecordManager();
if(typeof json === "undefined")
return rankingRecordManager;
let jsonData = null;
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
jsonData = json.rankingHour;
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
jsonData = json.rankingDay;
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
jsonData = json.rankingMonth;
break;
}
if(jsonData === null)
return rankingRecordManager;
let count = jsonData.length;
for(let i = 0; i < count; i++) {
let record = new RankingRecord(
i + 1,
jsonData[i]["Name"],
jsonData[i]["HighScore"]
);
rankingRecordManager.push(record);
}
return rankingRecordManager;
}
onFailed(errorMessage) {
console.log("failed : " + errorMessage);
}
+10
View File
@@ -8,4 +8,14 @@ class NumberUtil {
return Math.floor(Math.log(number) / Math.LN10 + 1); // bug : 1000 -> expected 4 but 3
}
static getScoreText(value) {
let number = Math.floor(value);
let numberWithCommas = NumberUtil.numberWithCommas(number);
if(isTypingGame())
return numberWithCommas + " 타";
else
return numberWithCommas + " 점";
}
}
+23
View File
@@ -0,0 +1,23 @@
class StringUtil {
static printMonthDay(date) {
let dateTime = new Date(date);
return (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일";
}
static getScoreTextWithoutUnit(value) {
let number = Math.floor(value);
return NumberUtil.numberWithCommas(number);
}
static getScoreTextWithUnit(value) {
let number = Math.floor(value);
let numberWithCommas = NumberUtil.numberWithCommas(number);
if(isTypingGame())
return numberWithCommas + " 타";
else
return numberWithCommas + " 점";
}
}
+10 -8
View File
@@ -14,12 +14,17 @@ class HistoryBoard {
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
this.dbConnectManager.requestPlayerHistory( historyRecordManager => {
let maxIndex = historyRecordManager.count;
if(maxIndex > 6)
maxIndex = 6;
for(let i = 0; i < historyRecordManager.count; i++) {
if(i > 6)
break;
let data = historyRecordManager.getAt(i);
let data = historyRecordManager.getAt(maxIndex);
this.printRecord(i, data.date, data.score);
maxIndex--;
}
});
}
@@ -39,13 +44,12 @@ class HistoryBoard {
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
style.boundsAlignH = "center";
game.add.text(posX, posY, date, style)
game.add.text(posX, posY, StringUtil.printMonthDay(date), style)
.setTextBounds(0, 0, 100, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
let numberWithCommas = NumberUtil.numberWithCommas(score);
style.boundsAlignH = "right";
game.add.text(posX + 80, posY, numberWithCommas, style)
game.add.text(posX + 80, posY, StringUtil.getScoreTextWithoutUnit(score), style)
.setTextBounds(0, 0, 100, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
@@ -61,14 +65,12 @@ class HistoryBoard {
.setTextBounds(0, 0, 40, 40)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
let typingAppName = appName;
game.add.text(posX + 60, posY, typingAppName, style)
game.add.text(posX + 60, posY, appName, style)
.setTextBounds(0, 0, 60, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
let numberWithCommas = NumberUtil.numberWithCommas(score);
style.boundsAlignH = "right";
game.add.text(posX + 120, posY, numberWithCommas, style)
game.add.text(posX + 120, posY, StringUtil.getScoreTextWithoutUnit(score), style)
.setTextBounds(0, 0, 80, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
+10 -8
View File
@@ -7,13 +7,15 @@ class RankingBoard {
this.dbConnectManager = new DBConnectManager();
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
// this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
// this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
}
requestRanking(type, rankingRecordManager) {
this.dbConnectManager.requestRanking(type, rankingRecordManager => {
this.dbConnectManager.requestRanking(type, (type, rankingRecordManager) => {
console.log(type);
console.log(rankingRecordManager);
for(let i = 0; i < rankingRecordManager.count; i++) {
if(i > 6)
break;
@@ -40,9 +42,9 @@ class RankingBoard {
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// score
let numberWithCommas = NumberUtil.numberWithCommas(data.score);
let score = StringUtil.getScoreTextWithoutUnit(data.score);
style.boundsAlignH = "right";
game.add.text(this.getPosX(type) + 120, this.getPosY(index), numberWithCommas, style)
game.add.text(this.getPosX(type) + 120, this.getPosY(index), score, style)
.setTextBounds(0, 0, 80, 60)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
@@ -53,17 +55,17 @@ class RankingBoard {
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
posX = 340;
posX = 320;
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
posX = 560;
posX = 540;
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
posX = 780;
posX = 760;
}
return posX;
+5 -5
View File
@@ -15,7 +15,7 @@ class RecordBoard {
printRecordBoardHeader() {
let posX = 40;
let posX = 60;
let posY = game.world.height / 2 + 20;
var bar = game.add.graphics();
@@ -25,14 +25,14 @@ class RecordBoard {
const style = { font: "32px Arial", fill: "#ffc", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
this.printHeader(posX, posY, "최근의 내 기록", style);
posX = 340;
posX = 320;
style.fill = "#fff";
this.printHeader(posX, posY, "수업시간 순위", style);
posX = 560;
posX = 550;
this.printHeader(posX, posY, "오늘의 순위", style);
posX = 780;
posX = 770;
this.printHeader(posX, posY, "이달의 순위", style);
}
@@ -43,7 +43,7 @@ class RecordBoard {
}
printSeperator() {
const posX = 300;
const posX = 290;
const posY = 480;
this.chartGraphics.lineStyle(3, 0x444444, 1);
+8 -8
View File
@@ -80,18 +80,18 @@ class Start {
const CHART_HEIGHT = 120;
const style = { font: "24px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
let dateTime = new Date(date);
console.log(dateTime);
console.log((dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일");
let monthDay = (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일";
let dateText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 140, monthDay, style);
let dateText = game.add.text(
100 + index * CHART_GAP_PX, game.world.height - 140,
StringUtil.printMonthDay(date), style
);
dateText.setTextBounds(0, 0, 100, 100);
dateText.stroke = "#333";
dateText.strokeThickness = 1;
let numberWithCommas = NumberUtil.numberWithCommas(Math.floor(score));
let scoreText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 300, numberWithCommas, style);
let scoreText = game.add.text(
100 + index * CHART_GAP_PX, game.world.height - 300,
StringUtil.getScoreTextWithUnit(score), style
);
scoreText.setTextBounds(0, 0, 100, 100);
scoreText.stroke = "#333";
scoreText.strokeThickness = 1;
+1
View File
@@ -16,6 +16,7 @@
<!-- library source files -->
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/string_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/ranking_record_manager.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
+1
View File
@@ -16,6 +16,7 @@
<!-- library source files -->
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/string_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
<script src="../../game/lib/input_type_text.js"></script>
+9 -9
View File
@@ -1,12 +1,12 @@
<?php
header('Content-Type: application/json');
include "./../send_error_code.php";
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../connect_db.php";
include "./../setup/connect_db.php";
// my ranking
@@ -25,15 +25,15 @@ $stmt->execute();
$stmt->bind_result($date, $score, $app_name);
$bestRecordArray = array();
$history_record_array = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['HighScore'] = $score;
$best_record['AppName'] = $app_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
$history_record['Date'] = $date;
$history_record['HighScore'] = $score;
$history_record['AppName'] = $app_name;
array_push($history_record_array, $history_record);
array_push($return_array, $history_record);
}
$return_array['history'] = $bestRecordArray;
$return_array['history'] = $history_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
@@ -0,0 +1,49 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking day
/*
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
*/
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE('2018-05-16') AND AppName = 'korean_word'
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingDay'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,49 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking hour
/*
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND HOUR(D.DateTime) = HOUR(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
*/
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.Score) AS HighScore
FROM moty_record D, moty_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE('2018-05-16') AND HOUR(D.DateTime) = HOUR('13:05:05') AND AppName = 'korean_word'
GROUP BY D.userID
ORDER BY max(D.Score) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingHour'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,40 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.score) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $high_score);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record);
}
$return_array['rankingMonth'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
+88
View File
@@ -0,0 +1,88 @@
<?php
header('Content-Type: application/json');
include "./../lib/send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../setup/connect_db.php";
// ranking hour
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.score) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND HOUR(D.DateTime) = HOUR(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingHour'] = $score_record_array;
// ranking day
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingDay'] = $score_record_array;
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $app_name);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$score_record_array = array();
while($stmt->fetch()) {
$score_record['UserID'] = $userID;
$score_record['Name'] = $name;
$score_record['HighScore'] = $record;
array_push($score_record_array, $score_record);
}
$return_array['rankingMonth'] = $score_record_array;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
-118
View File
@@ -1,118 +0,0 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
$user_id = $_POST["UserID"];
$language = $_POST["language"];
$stageNameDetail = $_POST["stageName"];
$stageName = $language."_".$stageNameDetail;
include "connect_db.php";
// my ranking
$query = "
SELECT DATE(RecordDateTime) AS Date, MAX(Record) AS BestRecord, StageName AS StageName
FROM afterschool_record D
WHERE UserID = ?
GROUP BY DATE(RecordDateTime)
ORDER BY RecordDateTime DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $user_id);
$stmt->execute();
$stmt->bind_result($date, $record, $stage_name);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['BestRecord'] = $record;
$best_record['StageName'] = $stage_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
}
$return_array['myRanking'] = $bestRecordArray;
// ranking hour
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingHour'] = $bestRecordArray;
// ranking day
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingDay'] = $bestRecordArray;
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingMonth'] = $bestRecordArray;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>