update server files
This commit is contained in:
parent
ac2df247fa
commit
b1298affe8
7 changed files with 577 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
build/*
|
||||
*.tar.gz
|
||||
*.zip
|
||||
/vendor/
|
||||
|
|
23
composer.json
Normal file
23
composer.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "asandikci/yurdle",
|
||||
"description": "yurdle package",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"yosymfony/toml": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"yosymfony/toml": "^1.0"
|
||||
},
|
||||
"license": "GPL3.0",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Asandikci\\Yurdle\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "asandikci",
|
||||
"email": "git@aliberksandikci.com.tr"
|
||||
}
|
||||
]
|
||||
}
|
129
composer.lock
generated
Normal file
129
composer.lock
generated
Normal file
|
@ -0,0 +1,129 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "add81bece92d883faaa7f717e5256419",
|
||||
"packages": [
|
||||
{
|
||||
"name": "yosymfony/parser-utils",
|
||||
"version": "v2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/yosymfony/parser-utils.git",
|
||||
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/yosymfony/parser-utils/zipball/00bec9a12722b21f2baf7f9db35f127e90c162c9",
|
||||
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yosymfony\\ParserUtils\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"description": "Parser utilities",
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"keywords": [
|
||||
"lexer",
|
||||
"parser"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/yosymfony/parser-utils/issues",
|
||||
"source": "https://github.com/yosymfony/parser-utils/tree/master"
|
||||
},
|
||||
"time": "2018-06-29T15:31:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "yosymfony/toml",
|
||||
"version": "v1.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/yosymfony/toml.git",
|
||||
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/yosymfony/toml/zipball/bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
|
||||
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"yosymfony/parser-utils": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yosymfony\\Toml\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Puertas",
|
||||
"email": "vpgugr@gmail.com",
|
||||
"homepage": "http://yosymfony.com"
|
||||
}
|
||||
],
|
||||
"description": "A PHP parser for TOML compatible with specification 0.4.0",
|
||||
"homepage": "http://github.com/yosymfony/toml",
|
||||
"keywords": [
|
||||
"mojombo",
|
||||
"parser",
|
||||
"toml"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/yosymfony/toml/issues",
|
||||
"source": "https://github.com/yosymfony/toml/tree/master"
|
||||
},
|
||||
"time": "2018-08-08T15:08:14+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
|
@ -10,23 +10,23 @@ MOUNT_PATH="/source" # binded mount path in nginx docker
|
|||
SCRIPT_NAME="dockerserver.sh" # name of the *this* file
|
||||
SCRIPT_DIR="Yurdle" # containing directory of the *this* file
|
||||
BUILD_DIR="." # build results of local source code (insert a dot (.) if you do not need to build your application)
|
||||
DATABASE_TYPE="postgresql" # database type, either mysql or postgresql
|
||||
# DATABASE_TYPE="postgresql" # database type, either mysql or postgresql
|
||||
MAIN_NAME="yurdle" # main program name
|
||||
PORT1="8000" # TODO what is the difference between 8000 and 80
|
||||
PORT2="80"
|
||||
|
||||
WEB_ROOT_DIR="/usr/share/nginx/html/" # public web root dir
|
||||
WEB_SERVER_DIR="/usr/share/nginx/server/" # private server root dir
|
||||
SECRET_SERVER="true" # add secret server to $WEB_ROOT_DIR/../$SECRET_SERVER_FOLDER
|
||||
SECRET_SERVER="false" # add secret server to $WEB_ROOT_DIR/../$SECRET_SERVER_FOLDER
|
||||
SECRET_SERVER_LOCAL_RELATIONAL_PATH="../YurdleBackend" # local path
|
||||
SERVER_BUILD_DIR="." # server build dir
|
||||
|
||||
__DB_NAME__="localdb"
|
||||
__DB_USER__="dbuser"
|
||||
__DB_PWD__="dbpass"
|
||||
# __DB_NAME__="localdb"
|
||||
# __DB_USER__="dbuser"
|
||||
# __DB_PWD__="dbpass"
|
||||
|
||||
PHP_VERSION="8.2"
|
||||
ACTIVE_SERVICES=("nginx" "php$PHP_VERSION-fpm" "postgresql") # services
|
||||
ACTIVE_SERVICES=("nginx" "php$PHP_VERSION-fpm") # services
|
||||
|
||||
############################
|
||||
############################
|
||||
|
@ -60,6 +60,7 @@ class Config
|
|||
const DB_NAME = '$__DB_NAME__';
|
||||
const DB_USERNAME = '$__DB_USER__';
|
||||
const DB_PASSWORD = '$__DB_PWD__';
|
||||
const DATAACCESS_TOKEN = 'LOCAL';
|
||||
}
|
||||
"""
|
||||
|
||||
|
@ -162,7 +163,7 @@ _restart() {
|
|||
|
||||
_reconf() {
|
||||
_head "RECONFIGURATION"
|
||||
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_SERVER_DIR/config.php"
|
||||
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_DIR/config.php"
|
||||
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
|
||||
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/$PHP_VERSION/fpm/pool.d/$MAIN_NAME.conf"
|
||||
_end "RECONFIGURATION"
|
||||
|
@ -192,8 +193,10 @@ _update_conf() {
|
|||
_refresh_folders() {
|
||||
rm -rf $WEB_ROOT_DIR
|
||||
mkdir -p $WEB_ROOT_DIR
|
||||
if [[ $SECRET_SERVER == "true" ]]; then
|
||||
rm -rf $WEB_SERVER_DIR
|
||||
mkdir -p $WEB_SERVER_DIR
|
||||
fi
|
||||
}
|
||||
|
||||
_setup_database() {
|
||||
|
@ -290,9 +293,10 @@ elif [[ $1 == "docker" ]]; then
|
|||
cp -r /server/$BUILD_DIR/* $WEB_SERVER_DIR/
|
||||
fi
|
||||
|
||||
apt install php php-fpm php-cli -y
|
||||
apt install php php-fpm php-cli composer -y
|
||||
locale-gen tr_TR
|
||||
|
||||
_setup_database
|
||||
# _setup_database
|
||||
|
||||
_reconf
|
||||
|
||||
|
|
233
index.php
233
index.php
|
@ -21,12 +21,18 @@
|
|||
|
||||
<article class="sections">
|
||||
<div class="section" style="height:100vh">
|
||||
<form class="centered" style="margin-top: 10vh;">
|
||||
<form class="centered" style="margin-top: 10vh;" action="index.php" method="post">
|
||||
<label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label>
|
||||
<input class="input" type="text" id="mainInput" name="mainInput" />
|
||||
<div><input style="width:80%;" class="input" type="text" id="mainInput" name="mainInput" placeholder="İsim Soyisim" /><input style="width:20%;" class="input" type="submit" value="Dene" /></div>
|
||||
</form>
|
||||
<div style="margin-top:auto;text-align:center;">Veri Sorumlusu: Ömer Arda Muratoğlu.<br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div>
|
||||
<div id="tahminler">
|
||||
|
||||
</div>
|
||||
<div style="margin-top:auto;text-align:center;">Veri Sorumlusu: Ömer Arda Muratoğlu.<br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div>
|
||||
<div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align: center;align-self:center;"><a href="https://asandikci.com/bagis/">Bana Bi' Kahve Ismarla ☕</a></div>
|
||||
</article>
|
||||
|
||||
<footer>
|
||||
|
@ -36,5 +42,226 @@
|
|||
|
||||
|
||||
</body>
|
||||
<script>
|
||||
function isSameDay(a, b) {
|
||||
return a.toDateString() == b.toDateString();
|
||||
}
|
||||
|
||||
// LOCAL STORAGE AND GUESS HANDLING
|
||||
date = new Date();
|
||||
if (localStorage.getItem("latest_visit") === null) {
|
||||
localStorage.setItem("latest_visit", date);
|
||||
} else {
|
||||
latest_visit = localStorage.getItem("latest_visit");
|
||||
if (isSameDay(new Date(latest_visit), date)) {
|
||||
console.log("same day!");
|
||||
} else {
|
||||
console.log("different day!");
|
||||
localStorage.removeItem("guesses");
|
||||
}
|
||||
localStorage.setItem("latest_visit", date);
|
||||
}
|
||||
<?php include './src/server.php'; ?>
|
||||
current_guess = "<?php
|
||||
if ($_POST['mainInput'] != null) {
|
||||
echo htmlspecialchars($_POST['mainInput']);
|
||||
}
|
||||
?>";
|
||||
flagSame = 0;
|
||||
if (localStorage.getItem("latest_guess") != null) {
|
||||
if (current_guess == localStorage.getItem("latest_guess")) {
|
||||
console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!!")
|
||||
flagSame = 1;
|
||||
}
|
||||
localStorage.setItem("latest_guess", current_guess);
|
||||
} else {
|
||||
localStorage.setItem("latest_guess", current_guess);
|
||||
}
|
||||
|
||||
const persons = <?php echo json_encode(getAllPersonNames(), JSON_UNESCAPED_UNICODE) ?>;
|
||||
if (persons.includes(current_guess) == false) {
|
||||
flagSame = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var gj = JSON.parse('{"Guesses":[], "Values":[]}'); // guess json
|
||||
if (localStorage.getItem("guesses") != null) {
|
||||
console.log("local storage get!");
|
||||
gj = JSON.parse(localStorage.getItem("guesses"));
|
||||
}
|
||||
console.log(gj);
|
||||
if (current_guess != "" && flagSame == 0) {
|
||||
gj["Guesses"].push(current_guess);
|
||||
console.warn(current_guess);
|
||||
gj["Values"].push(<?php
|
||||
if ($_POST['mainInput'] != null) {
|
||||
$inner_cg = htmlspecialchars($_POST['mainInput']);
|
||||
}
|
||||
echo json_encode(comparePerson($inner_cg));
|
||||
?>);
|
||||
localStorage.setItem("guesses", JSON.stringify(gj));
|
||||
}
|
||||
|
||||
|
||||
if (gj["Guesses"].length > 0) {
|
||||
const criterias = <?php echo json_encode(getAllCriterias(), JSON_UNESCAPED_UNICODE) ?>;
|
||||
|
||||
point = document.getElementById("tahminler");
|
||||
const table = document.createElement("table");
|
||||
const tr = document.createElement("tr");
|
||||
table.style.width = "100%";
|
||||
// tr.style.display = "flex";
|
||||
tr.style.textAlign = "center";
|
||||
tr.style.justifyContent = "space-evenly";
|
||||
tr.style.border = "red 1px solid";
|
||||
|
||||
table.appendChild(tr)
|
||||
point.appendChild(table);
|
||||
|
||||
for (const key in criterias) {
|
||||
|
||||
console.log(`${key} : ${criterias[key]}`)
|
||||
|
||||
const crit_node = document.createElement("th");
|
||||
const crit_text_node = document.createTextNode(criterias[key]);
|
||||
crit_node.style.border = "aliceblue 1px solid";
|
||||
crit_node.appendChild(crit_text_node);
|
||||
tr.appendChild(crit_node);
|
||||
}
|
||||
|
||||
for (let i = gj["Guesses"].length - 1; i >= 0; i--) {
|
||||
|
||||
revit = gj["Guesses"].length - i - 1;
|
||||
console.warn(revit);
|
||||
|
||||
console.log(gj["Values"][revit]);
|
||||
|
||||
const element = gj["Guesses"][i];
|
||||
point = document.getElementById("tahminler");
|
||||
const node = document.createElement("p");
|
||||
const textnode = document.createTextNode(element);
|
||||
node.appendChild(textnode);
|
||||
point.appendChild(node);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
// UPDATES
|
||||
const updates = <?php echo json_encode(sendDataDate()) ?>;
|
||||
document.getElementById("latest-data").innerHTML = updates[0];
|
||||
console.log("günün kişisi güncellenme zamanı: " + updates[1]);
|
||||
|
||||
|
||||
/// AUTOCOMPLETE ///
|
||||
|
||||
// TODO maybe fuzzy search: https://www.lucaspaganini.com/academy/autocomplete-with-fuzzy-search-and-fuse-js
|
||||
// https://www.fusejs.io/
|
||||
|
||||
|
||||
function autocomplete(inp, arr) {
|
||||
/*the autocomplete function takes two arguments,
|
||||
the text field element and an array of possible autocompleted values:*/
|
||||
var currentFocus;
|
||||
/*execute a function when someone writes in the text field:*/
|
||||
inp.addEventListener("input", function(e) {
|
||||
var a, b, i, val = this.value;
|
||||
/*close any already open lists of autocompleted values*/
|
||||
closeAllLists();
|
||||
if (!val) {
|
||||
return false;
|
||||
}
|
||||
currentFocus = -1;
|
||||
/*create a DIV element that will contain the items (values):*/
|
||||
a = document.createElement("DIV");
|
||||
a.setAttribute("id", this.id + "autocomplete-list");
|
||||
a.setAttribute("class", "autocomplete-items");
|
||||
/*append the DIV element as a child of the autocomplete container:*/
|
||||
this.parentNode.appendChild(a);
|
||||
/*for each item in the array...*/
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
/*check if the item starts with the same letters as the text field value:*/
|
||||
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
|
||||
/*create a DIV element for each matching element:*/
|
||||
b = document.createElement("DIV");
|
||||
/*make the matching letters bold:*/
|
||||
b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
|
||||
b.innerHTML += arr[i].substr(val.length);
|
||||
/*insert a input field that will hold the current array item's value:*/
|
||||
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
|
||||
/*execute a function when someone clicks on the item value (DIV element):*/
|
||||
b.addEventListener("click", function(e) {
|
||||
/*insert the value for the autocomplete text field:*/
|
||||
inp.value = this.getElementsByTagName("input")[0].value;
|
||||
/*close the list of autocompleted values,
|
||||
(or any other open lists of autocompleted values:*/
|
||||
closeAllLists();
|
||||
});
|
||||
a.appendChild(b);
|
||||
}
|
||||
}
|
||||
});
|
||||
/*execute a function presses a key on the keyboard:*/
|
||||
inp.addEventListener("keydown", function(e) {
|
||||
var x = document.getElementById(this.id + "autocomplete-list");
|
||||
if (x) x = x.getElementsByTagName("div");
|
||||
if (e.keyCode == 40) {
|
||||
/*If the arrow DOWN key is pressed,
|
||||
increase the currentFocus variable:*/
|
||||
currentFocus++;
|
||||
/*and and make the current item more visible:*/
|
||||
addActive(x);
|
||||
} else if (e.keyCode == 38) { //up
|
||||
/*If the arrow UP key is pressed,
|
||||
decrease the currentFocus variable:*/
|
||||
currentFocus--;
|
||||
/*and and make the current item more visible:*/
|
||||
addActive(x);
|
||||
} else if (e.keyCode == 13) {
|
||||
/*If the ENTER key is pressed, prevent the form from being submitted,*/
|
||||
e.preventDefault();
|
||||
if (currentFocus > -1) {
|
||||
/*and simulate a click on the "active" item:*/
|
||||
if (x) x[currentFocus].click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function addActive(x) {
|
||||
/*a function to classify an item as "active":*/
|
||||
if (!x) return false;
|
||||
/*start by removing the "active" class on all items:*/
|
||||
removeActive(x);
|
||||
if (currentFocus >= x.length) currentFocus = 0;
|
||||
if (currentFocus < 0) currentFocus = (x.length - 1);
|
||||
/*add class "autocomplete-active":*/
|
||||
x[currentFocus].classList.add("autocomplete-active");
|
||||
}
|
||||
|
||||
function removeActive(x) {
|
||||
/*a function to remove the "active" class from all autocomplete items:*/
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
x[i].classList.remove("autocomplete-active");
|
||||
}
|
||||
}
|
||||
|
||||
function closeAllLists(elmnt) {
|
||||
/*close all autocomplete lists in the document,
|
||||
except the one passed as an argument:*/
|
||||
var x = document.getElementsByClassName("autocomplete-items");
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
if (elmnt != x[i] && elmnt != inp) {
|
||||
x[i].parentNode.removeChild(x[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*execute a function when someone clicks in the document:*/
|
||||
document.addEventListener("click", function(e) {
|
||||
closeAllLists(e.target);
|
||||
});
|
||||
}
|
||||
|
||||
autocomplete(document.getElementById("mainInput"), persons);
|
||||
</script>
|
||||
|
||||
</html>
|
177
src/server.php
Normal file
177
src/server.php
Normal file
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
include 'todays.php';
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$parser = new Toml();
|
||||
|
||||
# Fetch remote data each 1 hour
|
||||
function updateRemoteData()
|
||||
{
|
||||
# PREREQUIRITIES Create a cronjob or a systemd service for update it regularly !
|
||||
|
||||
# GET FROM GIT WITH ACCESS TOKEN AND SAVE TO data.toml
|
||||
|
||||
# MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!!
|
||||
|
||||
|
||||
parseTOML(); # parse again after update
|
||||
}
|
||||
|
||||
|
||||
# Choose the todays person, everyday TSI 03:00
|
||||
function chooseTodayPerson()
|
||||
{
|
||||
# PREREQUIRIITES with cronjob or systemd, run this function everyday TSI 03.00
|
||||
|
||||
# parse toml
|
||||
|
||||
# get users array length
|
||||
|
||||
# get a random number
|
||||
|
||||
# make this person todays person, change $TODAYS_PERSON variable in today.php
|
||||
}
|
||||
|
||||
# Send all person names to frontend
|
||||
function getAllPersonNames()
|
||||
{
|
||||
# Parse Toml
|
||||
# get `users` array
|
||||
# get isim_soyisim of each user in `users` array and add to newArr
|
||||
# NewArr
|
||||
# send these as arry to frontend
|
||||
# aliberk_sandikci24 -> "Aliberk Sandıkçı
|
||||
|
||||
// APPROACH 1: (needs public-> users array)
|
||||
// $users = parseTOML()["public"]["users"];
|
||||
// $arr = array();
|
||||
// foreach ($users as $user) {
|
||||
// array_push($arr, parseTOML()["data"][$user]["isim_soyisim"]);
|
||||
// }
|
||||
// return $arr;
|
||||
|
||||
// APPROACH 2:
|
||||
$data = parseTOML()["data"];
|
||||
$arr = array();
|
||||
foreach ($data as $d) {
|
||||
array_push($arr, $d["isim_soyisim"]);
|
||||
}
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
function getAllCriterias() {
|
||||
$data = parseTOML()["public"];
|
||||
return $data["gozukecek_kriterler"];
|
||||
}
|
||||
|
||||
# send data update date and latest person update date
|
||||
function sendDataDate()
|
||||
{
|
||||
# 1: Get data.toml modified time
|
||||
# 2: Get latest person update, (should ebe TSI 03.00!)
|
||||
|
||||
date_default_timezone_set('Europe/Istanbul');
|
||||
setlocale(LC_ALL, 'tr_TR');
|
||||
$filename="data.toml";
|
||||
if (file_exists(__DIR__ . "/../" . $filename)) {
|
||||
$arr[0] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/../" . $filename));
|
||||
}
|
||||
$filename="todays.php";
|
||||
if (file_exists($filename)) {
|
||||
$arr[1] = date("d/m/Y H:i:s", filemtime($filename));
|
||||
}
|
||||
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
# compare a person with todays person, returns equalities (0-red, 1-orange, 2-green, 10-orange(küçük), 12-orange(büyük))
|
||||
function comparePerson($person)
|
||||
{
|
||||
global $TODAYS_PERSON;
|
||||
$statGuess = getAPersonStats($person);
|
||||
$statTodays = getAPersonStats($TODAYS_PERSON);
|
||||
$kriterler = parseTOML()["public"]["kriterler"];
|
||||
// $RESULT = array_fill(0, count($kriterler), 0);
|
||||
for ($i = 0; $i < count($kriterler); $i++) {
|
||||
$curCrit = array_keys($kriterler)[$i];
|
||||
switch (array_values($kriterler)[$i]) {
|
||||
case 'comp':
|
||||
$RESULT[$curCrit] = compareCOMP($statGuess[$curCrit], $statTodays[$curCrit]);
|
||||
break;
|
||||
case 'arr':
|
||||
$RESULT[$curCrit] = compareARR($statGuess[$curCrit], $statTodays[$curCrit], $curCrit);
|
||||
break;
|
||||
default:
|
||||
$RESULT[$curCrit] = compareEQ($statGuess[$curCrit], $statTodays[$curCrit]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $RESULT;
|
||||
}
|
||||
|
||||
# compare 2 data in EQ format
|
||||
function compareEQ($guess, $todays)
|
||||
{
|
||||
if ($guess == $todays) {
|
||||
return 2;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
# compare 2 data in COMP format
|
||||
function compareCOMP($guess, $todays)
|
||||
{
|
||||
if ($guess == $todays) {
|
||||
return 2;
|
||||
} else if ($guess <= $todays) {
|
||||
return 12;
|
||||
} else {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
# compare 2 data in ARR format
|
||||
function compareARR($guess, $todays, $krit)
|
||||
{
|
||||
$equalNum = 0;
|
||||
foreach ($guess as $key1 => $value1) {
|
||||
foreach ($todays as $key2 => $value2) {
|
||||
if ($value1 == $value2) {
|
||||
$equalNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($equalNum == 0) {
|
||||
return 0;
|
||||
} else if ($equalNum == count($todays)) {
|
||||
return 2;
|
||||
} else if ($equalNum >= 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
# get a person stat, can be used in other functions
|
||||
function getAPersonStats($person)
|
||||
{
|
||||
return parseTOML()["data"][$person];
|
||||
}
|
||||
|
||||
# parse toml
|
||||
function parseTOML()
|
||||
{
|
||||
global $parser;
|
||||
$array = $parser::ParseFile("data.toml");
|
||||
return $array;
|
||||
}
|
||||
|
||||
comparePerson('aliberk_sandikci24');
|
2
src/todays.php
Normal file
2
src/todays.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
$TODAYS_PERSON = "burak_sina_akbudak24";
|
Loading…
Reference in a new issue