Adds stats for the truth tree quiz

This commit is contained in:
2024-12-02 18:54:45 -05:00
parent 7ea891f3b3
commit cdbeec0af3
7 changed files with 113 additions and 103 deletions

3
.gitignore vendored
View File

@@ -16,4 +16,5 @@ error.log
!/html/composer.json
/html/composer.lock
/html/vendor/
.DS_STORE
.DS_STORE
.env

18
html/api/logic.php Executable file
View File

@@ -0,0 +1,18 @@
<?php
require_once "api.php";
require_once "../include/logic.php";
if (array_key_exists("solved", $_GET)) {
$solved = GetLogicSolved();
$complexity = GetLogicTotalComplexity();
$complexity += $_GET["solved"];
$solved++;
dbCommand("DELETE FROM information WHERE pointer='logicSolved'");
dbCommand("DELETE FROM information WHERE pointer='logicComplexity'");
dbCommand("INSERT INTO information VALUES ('logicComplexity', ?)", [$complexity]);
dbCommand("INSERT INTO information VALUES ('logicSolved', ?)", [$solved]);
echo json_encode([
"solved" => $solved,
"average" => GetLogicAverageComplexity()
]);
}

57
html/include/logic.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
/**
* Retrieves the number of logic problems solved from the database.
*
* Queries the 'information' table for the entry with the pointer 'logicSolved'.
* If no entry is found, returns 0. Otherwise, returns the first element of the
* result, which represents the number of logic problems solved.
*
* @return int The number of logic problems solved.
*/
function GetLogicSolved()
{
$result = dbRequest2("SELECT data FROM information WHERE pointer='logicSolved'", "data");
if (!$result) {
$result = 0;
} else {
$result = $result[0];
}
return $result;
}
/**
* Retrieves the total complexity of all logic problems solved from the database.
*
* Queries the 'information' table for the entry with the pointer 'logicComplexity'.
* If no entry is found, returns 0. Otherwise, returns the first element of the
* result, which represents the total complexity of all logic problems solved.
*
* @return int The total complexity of all logic problems solved.
*/
function GetLogicTotalComplexity()
{
$total = dbRequest2("SELECT data FROM information WHERE pointer='logicComplexity'", "data");
if (!$total) {
$total = 0;
} else {
$total = $total[0];
}
return $total;
}
/**
* Retrieves the average complexity of all logic problems solved from the database.
*
* Calculates the average complexity of all logic problems solved by dividing the
* total complexity of all logic problems solved by the number of logic problems
* solved.
*
* @return float The average complexity of all logic problems solved.
*/
function GetLogicAverageComplexity()
{
$solved = GetLogicSolved();
if ($solved == 0) {
return 0;
}
return GetLogicTotalComplexity() / $solved;
}

View File

@@ -93,14 +93,39 @@ function firstOperation() {
complexity = 1000;
}
localStorage.firstOperationComplexity = complexity;
if (localStorage.solvedTruthTree == undefined) {
localStorage.solvedTruthTree = 0;
}
if (localStorage.complexityTruthTree == undefined) {
localStorage.complexityTruthTree = 0;
}
// Checks if the game has already been played and if this was a completed game sends the event.
if (firstOperationAttempts != 0) {
_paq.push(
["trackEvent", "Truth Tree", `Complexity : ${complexity}`],
`Attempts : ${firstOperationAttempts}`
);
_paq.push([
"trackEvent",
"Truth Tree",
`Complexity : ${complexity}`,
`Attempts : ${firstOperationAttempts}`,
]);
firstOperationAttempts = 0;
localStorage.solvedTruthTree++;
localStorage.complexityTruthTree =
parseInt(localStorage.complexityTruthTree) + complexity;
fetch(`/api/logic.php?solved=${complexity}`)
.then((r) => r.json())
.then((r) => {
$("#solvedTotal").text(r.solved);
$("#averageTotal").text(r.average);
});
}
$("#solved").text(parseInt(localStorage.solvedTruthTree));
$("#average").text(
parseInt(localStorage.solvedTruthTree) === 0
? 0
: parseInt(localStorage.complexityTruthTree) /
parseInt(localStorage.solvedTruthTree)
);
// Will generate the text for the truth sentence
function generateSentenceText(sentence, first) {
if (sentence.length == 2) {

View File

@@ -9,6 +9,7 @@
<?php
$DESCRIPTION = "This just contains a simple quiz that helps you decompose a truth tree.";
require_once '../include/all.php';
require_once "../include/logic.php";
?>
</head>
@@ -17,8 +18,10 @@
include '../include/menu.php';
echo "<div class='main'>";
?>
<script type='text/javascript' src='index.js?v=1.0.3'></script>
<script type='text/javascript' src='index.js?v=1.1.0'></script>
<h1>Truth Tree Quiz</h1>
<p>Everyone solved <c id='solvedTotal'><?php echo GetLogicSolved(); ?></c> question(s) with an average complexity of <c id='averageTotal'><?php echo GetLogicAverageComplexity(); ?></c>.</p>
<p>You solved <c id='solved'>0</c> question(s) with an average complexity of <c id='average'>0</c>.</p>
<p>Notes for all the logic symbols:</p>
<ul>
<li>Negation: ~</li>
@@ -28,10 +31,10 @@
<li>Biconditional(if and only if): ↔</li>
</ul>
<h3>Click on the first logical operation that should be decomposed in a truth tree.</h3>
<label for="firstOperationComplexity">Complexity of Sentence: </label><input id='firstOperationComplexity' value='4' type='number'>
<label for="firstOperationComplexity">Complexity of Sentence: </label><input id='firstOperationComplexity' value='4' type='number' onchange="firstOperation()">
<button id='firstOperationGenerate' onClick='firstOperation()'>Generate Sentence</button>
<p id='firstOperation'></p>
</div>
</body>
</html>
</html>

0
html/minecraft.php Normal file → Executable file
View File

View File

@@ -6,105 +6,11 @@ from urllib.request import urlopen
def loginInternet(): # Makes sure that the server is logged in
return
urlLogin = "http://192.168.1.254/cgi-bin/login.ha"
login = {
"nonce": "76d8f8d800112e9573bacb9c56f0ecf82c9f2ed23fa10a83",
"password": "@<*08<**89",
"Continue": "Continue",
}
loginCode = urlopen(urlLogin).read().decode("utf-8")
start = loginCode.find('<input type="hidden" name="nonce" value=')
end = loginCode.find("/>", start)
loginCode = loginCode[start + 41 : end - 2]
login["nonce"] = loginCode
login2 = requests.post(urlLogin, data=login)
return loginCode
def turnOnInternet(): # Turns on the internet
return True
code = loginInternet()
postObjectOff = {
"nonce": code,
"owl80211on": "on",
"ostandard": "bgn",
"obandwidth": "20",
"ochannelplusauto": "0",
"opower": "100",
"oussidenable": "off",
"ossidname": "ATT7MTctna",
"ohide": "off",
"osecurity": "defwpa",
"owpaversion": "2",
"owps": "on",
"omaxclients": "80",
"ogssidenable": "off",
"ossidname2": "ATT7MTctna_Guest",
"ohide2": "off",
"osecurity2": "wpa",
"owpaversion2": "2",
"omaxclients2": "10",
"owpspin": "",
"twl80211on": "on",
"tstandard": "ac",
"tbandwidth": "80",
"tchannelplusauto": "0",
"tpower": "100",
"tussidenable": "on",
"tssidname": "ATT7MTctna",
"thide": "off",
"tsecurity": "defwpa",
"twps": "on",
"tmaxclients": "80",
"twpspin": "",
"Restore": "Restore Defaults",
}
urlSet = "http://192.168.1.254/cgi-bin/wconfig-adv.ha"
turnOn = requests.post(urlSet, data=postObjectOff)
return True
def turnOffInternet(): # Turns of the internet
return False
code = loginInternet()
postObjectOn = {
"nonce": code,
"owl80211on": "off",
"ostandard": "bgn",
"obandwidth": "20",
"ochannelplusauto": "0",
"opower": "100",
"oussidenable": "off",
"ossidname": "ATT7MTctna",
"ohide": "off",
"osecurity": "defwpa",
"owpaversion": "2",
"owps": "on",
"omaxclients": "80",
"ogssidenable": "off",
"ossidname2": "ATT7MTctna_Guest",
"ohide2": "off",
"osecurity2": "wpa",
"owpaversion2": "2",
"omaxclients2": "10",
"owpspin": "",
"twl80211on": "off",
"tstandard": "ac",
"tbandwidth": "80",
"tchannelplusauto": "0",
"tpower": "100",
"tussidenable": "on",
"tssidname": "ATT7MTctna",
"thide": "off",
"tsecurity": "defwpa",
"twps": "on",
"tmaxclients": "80",
"twpspin": "",
}
warn = {"nonce": code, "ReturnWarned": "Continue"}
urlSet = "http://192.168.1.254/cgi-bin/wconfig-adv.ha"
urlWarn = "http://192.168.1.254/cgi-bin/wifiwarn-adv.ha"
turnOff1 = requests.post(urlSet, data=postObjectOn)
turnOff2 = urlopen(urlWarn).read().decode("utf-8")
turnOff3 = requests.post(urlSet, data=warn)
return False
return False