Add: app highest record

This commit is contained in:
2018-10-23 22:29:24 +09:00
parent e384627c54
commit d45e44c6b2
12 changed files with 295 additions and 20 deletions
+1
View File
@@ -33,6 +33,7 @@ let sessionStorageManager = new SessionStorageManager();
console.log("playingAppKoreanName : " + sessionStorageManager.getPlayingAppKoreanName()); console.log("playingAppKoreanName : " + sessionStorageManager.getPlayingAppKoreanName());
console.log("record : " + sessionStorageManager.getRecord()); console.log("record : " + sessionStorageManager.getRecord());
console.log("bestRecord : " + sessionStorageManager.getBestRecord()); console.log("bestRecord : " + sessionStorageManager.getBestRecord());
console.log("appHighestRecord : " + sessionStorageManager.getAppHighestRecord());
} }
if(sessionStorageManager.getMaestroID() === null && !isLogin()) { if(sessionStorageManager.getMaestroID() === null && !isLogin()) {
+33
View File
@@ -379,6 +379,18 @@ DBConnectManager.prototype.updateTodayBestRecord = function(maestroID, playerID,
); );
} }
DBConnectManager.prototype.updateAppHighestRecord = function(maestroID, playerID, appID, record) {
var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/record/update_app_highest_record.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(
"MaestroID=" + maestroID
+ "&PlayerID=" + playerID
+ "&AppID=" + appID
+ "&Record=" + record
);
}
DBConnectManager.prototype.requestTodayBestRecord = function(maestroID, playerID, appID, onSucceededListener, onFailedListener) { DBConnectManager.prototype.requestTodayBestRecord = function(maestroID, playerID, appID, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/record/request_best_record.php", true); xhr.open("POST", this.phpPath + "server/record/request_best_record.php", true);
@@ -400,6 +412,27 @@ DBConnectManager.prototype.requestTodayBestRecord = function(maestroID, playerID
); );
} }
DBConnectManager.prototype.requestAppHighestRecord = function(maestroID, playerID, appID, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/record/request_app_highest_record.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
if(replyJSON != null && replyJSON["AppHighestRecord"] != null)
onSucceededListener(replyJSON);
else
onFailedListener(replyJSON);
}
};
xhr.send(
"MaestroID=" + maestroID
+ "&PlayerID=" + playerID
+ "&AppID=" + appID
);
}
DBConnectManager.prototype.requestAppRanking = function(maestroID, appID, onSucceededListener, onFailedListener) { DBConnectManager.prototype.requestAppRanking = function(maestroID, appID, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/record/app_ranking.php", true); xhr.open("POST", this.phpPath + "server/record/app_ranking.php", true);
+1 -1
View File
@@ -65,7 +65,7 @@ ScreenBottomUI.prototype.printText = function(textObject, text, align) {
ScreenBottomUI.prototype.printLeftTextWithBestRecord = function(bestRecord) { ScreenBottomUI.prototype.printLeftTextWithBestRecord = function(bestRecord) {
var roundUpBestRecord = Math.round(bestRecord); var roundUpBestRecord = Math.round(bestRecord);
var highScoreWithCommas = NumberUtil.numberWithCommas(roundUpBestRecord); var highScoreWithCommas = NumberUtil.numberWithCommas(roundUpBestRecord);
this.printLeftText("오늘의 최고 기록 : " + highScoreWithCommas); this.printLeftText("최고 기록 : " + highScoreWithCommas);
} }
ScreenBottomUI.prototype.getFontStyle = function() { ScreenBottomUI.prototype.getFontStyle = function() {
+11 -2
View File
@@ -80,7 +80,7 @@ SessionStorageManager.prototype.setRecord = function(value) {
sessionStorage.setItem("record", value); sessionStorage.setItem("record", value);
} }
SessionStorageManager.prototype.getRecord = function() { SessionStorageManager.prototype.getRecord = function() {
return sessionStorage.getItem("record"); return Number(sessionStorage.getItem("record"));
} }
// best record // best record
@@ -88,7 +88,15 @@ SessionStorageManager.prototype.setBestRecord = function(value) {
sessionStorage.setItem("bestRecord", value); sessionStorage.setItem("bestRecord", value);
} }
SessionStorageManager.prototype.getBestRecord = function() { SessionStorageManager.prototype.getBestRecord = function() {
return sessionStorage.getItem("bestRecord"); return Number(sessionStorage.getItem("bestRecord"));
}
// best record
SessionStorageManager.prototype.setAppHighestRecord = function(value) {
sessionStorage.setItem("appHighestRecord", value);
}
SessionStorageManager.prototype.getAppHighestRecord = function() {
return Number(sessionStorage.getItem("appHighestRecord"));
} }
// best record // best record
@@ -105,6 +113,7 @@ SessionStorageManager.prototype.resetPlayingAppData = function() {
this.removeItem("playingAppKoreanName"); this.removeItem("playingAppKoreanName");
this.removeItem("record"); this.removeItem("record");
this.removeItem("bestRecord"); this.removeItem("bestRecord");
this.removeItem("appHighestRecord");
} }
+21 -8
View File
@@ -55,7 +55,7 @@ var Result = {
// bottom ui // bottom ui
var screenBottomUI = new ScreenBottomUI(); var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.getBestRecord())); screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.getAppHighestRecord()));
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
}, },
@@ -131,17 +131,23 @@ var Result = {
bestRecordText.stroke = "#333"; bestRecordText.stroke = "#333";
bestRecordText.strokeThickness = 5; bestRecordText.strokeThickness = 5;
if(sessionStorageManager.getBestRecord() === 'undefined') // if(sessionStorageManager.getBestRecord() == 'undefined' || sessionStorageManager.getBestRecord() == null)
sessionStorageManager.setBestRecord(0); // sessionStorageManager.setBestRecord(0);
if(sessionStorageManager.getAppHighestRecord() == 'undefined' || sessionStorageManager.getAppHighestRecord() == null)
sessionStorageManager.setAppHighestRecord(0);
var todayBestRecord = 0; var todayBestRecord = 0;
var flooredBestRecord = Math.floor(sessionStorageManager.getBestRecord()); // var flooredBestRecord = Math.floor(sessionStorageManager.getBestRecord());
var flooredBestRecord = Math.floor(sessionStorageManager.getAppHighestRecord());
var bestRecordWithCommas = NumberUtil.numberWithCommas(flooredBestRecord); var bestRecordWithCommas = NumberUtil.numberWithCommas(flooredBestRecord);
if(sessionStorageManager.getRecord() >= sessionStorageManager.getBestRecord()) { // if(sessionStorageManager.getRecord() >= sessionStorageManager.getBestRecord()) {
sessionStorageManager.setBestRecord(sessionStorageManager.getRecord()); // sessionStorageManager.setBestRecord(sessionStorageManager.getRecord());
if(sessionStorageManager.getRecord() > sessionStorageManager.getAppHighestRecord()) {
sessionStorageManager.setAppHighestRecord(sessionStorageManager.getRecord());
bestRecordText.text = "! : . 오늘 최고 기록 . : !"; bestRecordText.text = "! : . 최고 기록 갱신 . : !";
newRecordEmitter.start(true, 2000, null, 20); newRecordEmitter.start(true, 2000, null, 20);
} else { } else {
bestRecordText.text = ""; bestRecordText.text = "";
@@ -153,7 +159,14 @@ var Result = {
return; return;
} }
this.dbConnectManager.updateTodayBestRecord( // this.dbConnectManager.updateTodayBestRecord(
// sessionStorageManager.getMaestroID(),
// sessionStorageManager.getPlayerID(),
// sessionStorageManager.getPlayingAppID(),
// sessionStorageManager.getRecord()
// );
this.dbConnectManager.updateAppHighestRecord(
sessionStorageManager.getMaestroID(), sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(), sessionStorageManager.getPlayingAppID(),
+25 -6
View File
@@ -50,21 +50,40 @@ var Start = {
// bottom ui // bottom ui
var screenBottomUI = new ScreenBottomUI(); var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftText("오늘의 최고 기록 : "); screenBottomUI.printLeftText("");
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.dbConnectManager.requestTodayBestRecord( // this.dbConnectManager.requestTodayBestRecord(
// sessionStorageManager.getMaestroID(),
// sessionStorageManager.getPlayerID(),
// sessionStorageManager.getPlayingAppID(),
// (function(replyJSON) {
// sessionStorageManager.setBestRecord(Number(replyJSON["BestRecord"]));
// screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord());
// }).bind(this),
// (function(replyJSON) { // no data
// sessionStorageManager.setBestRecord(0);
// screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord());
// }).bind(this)
// );
this.dbConnectManager.requestAppHighestRecord(
sessionStorageManager.getMaestroID(), sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(), sessionStorageManager.getPlayingAppID(),
(function(replyJSON) { (function(replyJSON) {
sessionStorageManager.setBestRecord(Number(replyJSON["BestRecord"])); var appHighestRecord = replyJSON["AppHighestRecord"];
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); console.log("appHighestRecord : " + appHighestRecord);
// sessionStorageManager.setBestRecord(Number(appHighestRecord));
sessionStorageManager.setAppHighestRecord(Number(appHighestRecord));
screenBottomUI.printLeftTextWithBestRecord(appHighestRecord);
}).bind(this), }).bind(this),
(function(replyJSON) { // no data (function(replyJSON) { // no data
sessionStorageManager.setBestRecord(0); var appHighestRecord = replyJSON["AppHighestRecord"];
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); console.log("appHighestRecord : " + appHighestRecord);
sessionStorageManager.setAppHighestRecord(0);
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getAppHighestRecord());
}).bind(this) }).bind(this)
); );
}, },
@@ -101,10 +101,10 @@ function get_high_score_list($maestro_id, $player_id, $appList) {
$app_id_list = $appList[$i]['AppID']; $app_id_list = $appList[$i]['AppID'];
$query = " $query = "
SELECT MAX(BR.BestRecord) SELECT MAX(AHR.HighestRecord)
FROM app AS A FROM app AS A
INNER JOIN best_record AS BR INNER JOIN app_highest_record AS AHR
ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ? ON A.AppID = ? AND A.AppID = AHR.AppID AND AHR.MaestroID = ? AND AHR.PlayerID = ?
ORDER BY A.AppID ASC"; ORDER BY A.AppID ASC";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id); $stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id);
+52
View File
@@ -0,0 +1,52 @@
<?php
function get_app_highest_record($maestro_id, $app_id, $player_id) {
global $db_conn;
$query = "
SELECT HighestRecord
FROM app_highest_record
WHERE MaestroID = ? AND AppID = ? AND PlayerID = ?;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
$stmt->execute();
$stmt->bind_result($highest_record);
$stmt->fetch();
$stmt->close();
return $highest_record;
echo "\nget_app_highest_record : $highest_record";
}
function remove_app_highest_record($maestro_id, $app_id, $player_id) {
global $db_conn;
$query = "
DELETE FROM app_highest_record
WHERE MaestroID = ? AND AppID = ? AND PlayerID = ?;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
$stmt->execute();
echo "\ndelete_app_highest_record";
}
function insert_app_highest_record($maestro_id, $app_id, $player_id, $highest_record) {
global $db_conn;
$query = "
INSERT INTO app_highest_record (MaestroID, PlayerID, AppID, HighestRecord, RecordDateTime)
VALUES (?, ?, ?, ?, NOW());
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $highest_record);
$stmt->execute();
echo "\ninsert_app_highest_record";
}
?>
@@ -0,0 +1,23 @@
<?php
header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"];
$app_id = $_POST["AppID"];
include "./../setup/connect_db.php";
include "./../lib/app_highest_record.php";
$replyJSON = array();
$replyJSON["AppHighestRecord"] = get_app_highest_record($maestro_id, $app_id, $player_id);
if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음");
$db_conn->close();
exit;
}
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,101 @@
<?php
header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"];
$player_id = $_POST["PlayerID"];
$app_id = $_POST["AppID"];
$record = $_POST["Record"];
// echo $record." / ";
include "./../setup/connect_db.php";
include "./../lib/app_highest_record.php";
// best record is for the saved data by every hour
$prev_best_record_id = -1;
$prev_best_record = 0;
$prev_best_record_id = get_best_record($maestro_id, $app_id, $player_id);
echo "id : ".$prev_best_record_id." ".$prev_best_record;
if($prev_best_record_id === null || $prev_best_record_id < 0) {
// echo "insert";
insert_best_record($maestro_id, $app_id, $player_id, $record);
} else {
// echo $record." ".$prev_best_record;
if($record > $prev_best_record) {
// echo "update";
update_best_record($prev_best_record_id, $record);
}
}
// highest record is the highest record
$app_highest_record = get_app_highest_record($maestro_id, $app_id, $player_id);
echo "\napp_highest_record : $app_highest_record";
echo "\nrecord : $record";
if($app_highest_record == null) {
insert_app_highest_record($maestro_id, $app_id, $player_id, $record);
echo "\ninsert_app_highest_record : $record";
}
else if($record > $app_highest_record) {
remove_app_highest_record($maestro_id, $app_id, $player_id);
echo "\nremove_app_highest_record";
insert_app_highest_record($maestro_id, $app_id, $player_id, $record);
echo "\ninsert_app_highest_record : $record";
}
$db_conn->close();
function get_best_record($maestro_id, $app_id, $player_id) {
global $db_conn;
global $prev_best_record_id, $prev_best_record;
$query = "
SELECT BestRecordID, BestRecord
FROM best_record
WHERE MaestroID = ? AND AppID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW())
/*AND HOUR(RecordDateTime) = HOUR(NOW())*/
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
$stmt->execute();
$stmt->bind_result($prev_best_record_id, $prev_best_record);
$stmt->fetch();
$stmt->close();
$GLOBALS["prev_best_record_id"] = $prev_best_record_id;
$GLOBALS["prev_best_record"] = $prev_best_record;
return $prev_best_record_id;
}
function insert_best_record($maestro_id, $app_id, $player_id, $record) {
global $db_conn;
$query = "
INSERT INTO best_record (MaestroID, PlayerID, AppID, BestRecord, RecordDateTime)
VALUES (?, ?, ?, ?, NOW());
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $record);
$stmt->execute();
}
function update_best_record($prev_best_record_id, $record) {
global $db_conn;
$query = "
UPDATE best_record
SET BestRecord = ?, RecordDateTime = NOW()
WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW())
/* AND HOUR(RecordDateTime) = HOUR(NOW()) */
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('di', $record, $prev_best_record_id);
$stmt->execute();
}
?>
@@ -8,6 +8,8 @@ $best_record = $_POST["BestRecord"];
// echo $best_record." / "; // echo $best_record." / ";
include "./../setup/connect_db.php"; include "./../setup/connect_db.php";
include "./../lib/app_highest_record.php";
$prev_best_record_id = -1; $prev_best_record_id = -1;
$prev_best_record = 0; $prev_best_record = 0;
@@ -26,6 +28,15 @@ if($prev_best_record_id === null || $prev_best_record_id < 0) {
} }
} }
$app_highest_record = get_app_highest_record($maestro_id, $app_id, $player_id);
if($app_highest_record == null) {
insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record);
}
else if($best_record > $app_highest_record) {
remove_app_highest_record($maestro_id, $app_id, $player_id);
insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record);
}
$db_conn->close(); $db_conn->close();
+13
View File
@@ -76,6 +76,19 @@ CREATE TABLE best_record (
FOREIGN KEY (PlayerID) REFERENCES player(PlayerID) FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)
); );
CREATE TABLE app_highest_record (
AppHighestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
MaestroID INT UNSIGNED NOT NULL,
AppID INT UNSIGNED NOT NULL,
PlayerID INT UNSIGNED NOT NULL,
HighestRecord FLOAT NOT NULL,
RecordDateTime DATETIME NOT NULL,
FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
FOREIGN KEY (AppID) REFERENCES app(AppID),
FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)
);
CREATE TABLE ranking ( CREATE TABLE ranking (
RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
MaestroID INT UNSIGNED NOT NULL, MaestroID INT UNSIGNED NOT NULL,