maths practicer

This commit is contained in:
DeaDvey 2024-11-19 17:07:11 +00:00
parent a980fc92b7
commit c92a0643a4
18 changed files with 197 additions and 30 deletions

View File

@ -1,4 +1,4 @@
boards = ["tech","gen","films","test"] boards = ["tech","gen","films","test","maths"]
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
module.exports = boards; module.exports = boards;

View File

@ -7,9 +7,15 @@ function secondsIntoDay(time) {
let second = time.getUTCSeconds(); let second = time.getUTCSeconds();
return ((hour * 3600) + (minute * 60) + second) return ((hour * 3600) + (minute * 60) + second)
} }
let pfps = [["deadvey","/images/pfp6.png"]]
let divText = document.getElementById("comments").innerHTML; let divText = document.getElementById("comments").innerHTML;
newPageHTML=""; newPageHTML="";
for (let comment = 0; comment < comments.length; comment++) { for (let comment = 0; comment < comments.length; comment++) {
for (let i = 0; i < pfps.length; i++) {
if (pfps[i][0] == comments[comment][0]) {
comments[comment][0] = `<img src="${pfps[i][1]}" height="20"> ` + comments[comment][0]
}
}
if (typeof comments[comment][2] == 'undefined') { if (typeof comments[comment][2] == 'undefined') {
newPageHTML+=`<b>${comments[comment][0]}</b>: <i>${comments[comment][1]}</i><br/>` newPageHTML+=`<b>${comments[comment][0]}</b>: <i>${comments[comment][1]}</i><br/>`
} }
@ -18,7 +24,7 @@ for (let comment = 0; comment < comments.length; comment++) {
let second = Math.round((secondsIntoDay(time) / (86400/65536))).toString(16); let second = Math.round((secondsIntoDay(time) / (86400/65536))).toString(16);
let day = daysIntoYear(time).toString(16); let day = daysIntoYear(time).toString(16);
let year = time.getUTCFullYear().toString(16); let year = time.getUTCFullYear().toString(16);
newPageHTML+=`[${second} ${day}/${year}] <b>${comments[comment][0]}</b>: <i>${comments[comment][1]}</i><br/>` newPageHTML+=`[${second} ${day}/${year}] <b>${comments[comment][0]}</b>: ${comments[comment][1]}<br/>`
} }
}; };
document.getElementById("comments").innerHTML = newPageHTML document.getElementById("comments").innerHTML = newPageHTML

View File

@ -2,7 +2,8 @@
<div id="main"> <div id="main">
<a href="/board/tech/">/tech/</a><br/> <a href="/board/tech/">/tech/</a><br/>
<a href="/board/gen/">/gen/</a><br/> <a href="/board/gen/">/gen/</a><br/>
<a href="/board/films/">/films/<a/> <a href="/board/films/">/films/<a/><br/>
<a href="/board/maths/">/maths/<a/>
</div> </div>
<div id="footer"><hr/><ul> Internal pages: <li><a href="/experiments" >Experiments <img height="30" src="/images/experience-green-liquid.gif" /></a></li> <li><a href="/isthistheyearofthelinuxdesktop" >Is this the year of the Linux Desktop? <img src="/images/penguin-dance-pengu.gif" height="20" alt="penguin dancing" /></a></li> <li><a href="/theunderland" >theunderland wiki <img src="/images/flashlight.gif" alt="torch scanning" height="30" /></a></li> <br/> External sites: <li><a href="https://git.javalsai.dynv6.net/deadvey" >Gitea</a></li><li><a href="https://javalsai.dynv6.net">Javlsai</a></li> </li> </ul><br/> <small width="300px">© DeaDvey 2023 - 2024<br/>This work is licensed under the terms of the <a href="/LICENSE">GNU General Public License, version 3.0</a>. You are free to copy, distribute, and modify this work under the terms of the <a href="/LICENSE">GPL 3.0 License</a>. Please see the full license text for details.</small></div><!--footer--> <div id="footer"><hr/><ul> Internal pages: <li><a href="/experiments" >Experiments <img height="30" src="/images/experience-green-liquid.gif" /></a></li> <li><a href="/isthistheyearofthelinuxdesktop" >Is this the year of the Linux Desktop? <img src="/images/penguin-dance-pengu.gif" height="20" alt="penguin dancing" /></a></li> <li><a href="/theunderland" >theunderland wiki <img src="/images/flashlight.gif" alt="torch scanning" height="30" /></a></li> <br/> External sites: <li><a href="https://git.javalsai.dynv6.net/deadvey" >Gitea</a></li><li><a href="https://javalsai.dynv6.net">Javlsai</a></li> </li> </ul><br/> <small width="300px">© DeaDvey 2023 - 2024<br/>This work is licensed under the terms of the <a href="/LICENSE">GNU General Public License, version 3.0</a>. You are free to copy, distribute, and modify this work under the terms of the <a href="/LICENSE">GPL 3.0 License</a>. Please see the full license text for details.</small></div><!--footer-->

View File

@ -0,0 +1,4 @@
let comments = [["ADMIN","welcome to the maths board"],["deadvey","Welcome to MATHS","2024-11-18T22:20:49.857Z"],["deadvey","you <b>will</b> have fun!","2024-11-18T22:22:44.301Z"]]
if (typeof module !== "undefined" && module.exports) {
module.exports = comments;
}

1
board/maths/index.html Normal file
View File

@ -0,0 +1 @@
<!DOCTYPE html><div id="header"><head><meta charset="UTF-8"/><title>DeaDveys Domain</title><link rel="icon" href="/images/favicon.png"><link rel="stylesheet" type="text/css" href="/index.css"><meta name="viewport" content="width=device-width, initial-scale=1.0"> </head>Welcome to DEADVEY DOT COM!!!<br/><a href="/" onclick="history.back()"><img src="/images/return.png" width="20" />Return</a> / <a href="/">Home page</a> / <a href="/blog/index.html">Blogs</a> <a href="/blog/feed.xml"><img width="16" src="/images/feedIcon.png" class="feedicon" alt="Feed image"/></a> / <a href="/blog/reviews">Reviews</a> / <a href="/board/index.html">Boards</a> / <a href="https://git.javalsai.dynv6.net/deadvey/htdocs">Gitea <img class="rotate" height="15" src="/images/gitea.png" alt="Link to gitea page"/></a> / <a href="http://deadvey.com:3000">Invidious <img src="/images/invidious.png" height="15"/></a> / <a href="http://deadvey.com:8096">Jellyfin <img src="/images/jellyfin.png" height="15"/></a> / <a href="http://deadvey.com:7993">Monkeytype</a><img src="/images/monkeytype.png" height="15"> / <a href="/search">Search blogs</a><hr/></div><!--header--><div id="main"><div id="comments" class="maths"></div><form action="/board/submit-comment" id="commentForm" method="post"><input name="name" class="form-control" id="name" placeholder="Enter your name"><br/><input height="40px" name="comment" class="form-control input-comment" id="comment" placeholder="Enter your Comment..."><input type="hidden" name="pageID" value="maths"><button type="submit">Submit</button></form></div><!--main--><div id="footer"><hr/><ul> Internal pages: <li><a href="/experiments" >Experiments <img height="30" src="/images/experience-green-liquid.gif" /></a></li> <li><a href="/isthistheyearofthelinuxdesktop" >Is this the year of the Linux Desktop? <img src="/images/penguin-dance-pengu.gif" height="20" alt="penguin dancing" /></a></li> <li><a href="/theunderland" >theunderland wiki <img src="/images/flashlight.gif" alt="torch scanning" height="30" /></a></li> <br/> External sites: <li><a href="https://git.javalsai.dynv6.net/deadvey" >Gitea</a></li><li><a href="https://javalsai.dynv6.net">Javlsai</a></li> </li> </ul><br/> <small width="300px">© DeaDvey 2023 - 2024<br/>This work is licensed under the terms of the <a href="/LICENSE">GNU General Public License, version 3.0</a>. You are free to copy, distribute, and modify this work under the terms of the <a href="/LICENSE">GPL 3.0 License</a>. Please see the full license text for details.</small></div><!--footer--><script src="comments-database.js"></script><script src="/board/displayComments.js"></script>

View File

@ -1,17 +0,0 @@
let div = document.getElementById('main');
divText = ""
console.log(boards)
for (let i = 0; i < boards.length; i++) {
divText += `<a href="/${boards[i]}">/${boards[i]}/</a><br/>`
}
console.log(divText);
let newPageHTML = `${pageTop}${divText}${pageBottom}`
document.body.innerHTML = newPageHTML
function goToLink(link) {
window.location.href = link
}

View File

@ -56,10 +56,10 @@ ul {
margin: auto; margin: auto;
} }
/*
img { img {
border: 2px solid #7c6f64; border: 2px solid #7c6f64;
} }*/
img:not(.feedicon) { img:not(.feedicon) {
max-width: 100% max-width: 100%
@ -241,7 +241,7 @@ body {
width: 400px; width: 400px;
} }
.rotate, img { .rotate {
display: flex; display: flex;
position: relative; position: relative;
animation: spin 5s linear infinite; animation: spin 5s linear infinite;

28
maths/forms.js Normal file
View File

@ -0,0 +1,28 @@
let selected_topic = document.getElementById("topic-selection")
let subtopic_selection_div = document.getElementById("subtopic-selection-div")
let subtopic_selection_div_text = subtopic_selection_div.innerHTML
let subtopics = [
["any"],
["any","basic_algebra","combine_like_terms","complex_quadratic","compound_interest","distance_two_points","expanding","factoring","intersection_of_two_lines","invert_matrix","linear_equations","line_equation_from_2_points","log","matrix_multiplication","midpoint_of_two_points","multiply_complex_numbers","quadratic_equation","simple_interest","system_of_equations","vector_cross","vector_dot","orthogonal_projection"],
["any","absolute_difference","addition","compare_fractions","cube_root","divide_fractions","division","exponentiation","factorial","fraction_multiplication","fraction_to_decimal","greatest_common_division","is_composite","is_prime","multiplication","percentage","percentage_difference","percentage_error","power_of_powers","square","square_root","simplify_square_root","subtraction"],
["any","definite_integral","power_rule_differentiation","power_rule_integration","stationary_points","trig_differentiation"],
["any","bcd_to_decimal","binary_2s_complement","binary_complement_1s","binary_to_decimal","binary_to_hex","decimal_to_bcd","decimal_to_binary","decimal_to_hexadeci","decimal_to_octal","fibonacci_series","modulo_division","nth_fibonacci_number"],
["any","angle_btw_vectors","angle_regular_polygon","arc_length"],
["any","arithmatic_progression_sum","arithmatic_progression_term","base_conversion"],
["any","combinations","conditional_probability"]]
function onChange() {
let value = selected_topic.value;
let text = selected_topic.options[selected_topic.selectedIndex].text;
value = Number(value)
console.log(value);
let selection_text = "<select name='subtopic' id='subtopic-selection'>"
for (let i = 0; i < subtopics[value].length; i++) {
selection_text += `<option value='${subtopics[value][i]}'>${subtopics[value][i]}</option>`
}
selection_text += "</select>"
subtopic_selection_div.innerHTML = selection_text;
}
selected_topic.onchange = onChange;
onChange();

29
maths/index.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<div id="header"><head><meta charset="UTF-8"/><title>DeaDveys Domain</title><link rel="icon" href="/images/favicon.png"><link rel="stylesheet" type="text/css" href="/index.css"><meta name="viewport" content="width=device-width, initial-scale=1.0"> </head>Welcome to DEADVEY DOT COM!!!<br/><a href="/" onclick="history.back()"><img src="/images/return.png" width="20" />Return</a> / <a href="/">Home page</a> / <a href="/blog/index.html">Blogs</a> <a href="/blog/feed.xml"><img width="16" src="/images/feedIcon.png" class="feedicon" alt="Feed image"/></a> / <a href="/blog/reviews">Reviews</a> / <a href="/board/index.html">Boards</a> / <a href="https://git.javalsai.dynv6.net/deadvey/htdocs">Gitea <img class="rotate" height="15" src="/images/gitea.png" alt="Link to gitea page"/></a> / <a href="http://deadvey.com:3000">Invidious <img src="/images/invidious.png" height="15"/></a> / <a href="http://deadvey.com:8096">Jellyfin <img src="/images/jellyfin.png" height="15"/></a> / <a href="http://deadvey.com:7993">Monkeytype</a><img src="/images/monkeytype.png" height="15"> / <a href="/search">Search blogs</a><hr/></div><!--header-->
<div id="main">
<h1>Maths practice!</h1>
<form action="/maths/submit-topics" method="post" id="selections">
<div id="topic">
<h4>Choose a topic:</h4>
<select name="topic" id="topic-selection">
<option value="0">Any</option>
<option value="1">Algebra</option>
<option value="2">Basic Math</option>
<option value="3">Calculus</option>
<option value="4">Computer Science</option>
<option value="5">Geometry</option>
<option value="6">Misc</option>
<option value="7">Statistics</option>
</select>
</div>
<div name="subtopic" id="subtopic">
<h4>Choose a subtopic:</h4>
<div id="subtopic-selection-div">
</div>
</div>
<button type="submit">Submit</button>
</form>
</div><!--main-->
Questions cuertesy of <a href=https://lukew3.github.io/mathgenerator>Lukew3s Mathgenerator</a>
<div id="footer"><hr/><ul> Internal pages: <li><a href="/experiments" >Experiments <img height="30" src="/images/experience-green-liquid.gif" /></a></li> <li><a href="/isthistheyearofthelinuxdesktop" >Is this the year of the Linux Desktop? <img src="/images/penguin-dance-pengu.gif" height="20" alt="penguin dancing" /></a></li> <li><a href="/theunderland" >theunderland wiki <img src="/images/flashlight.gif" alt="torch scanning" height="30" /></a></li> <br/> External sites: <li><a href="https://git.javalsai.dynv6.net/deadvey" >Gitea</a></li><li><a href="https://javalsai.dynv6.net">Javlsai</a></li> </li> </ul><br/> <small width="300px">© DeaDvey 2023 - 2024<br/>This work is licensed under the terms of the <a href="/LICENSE">GNU General Public License, version 3.0</a>. You are free to copy, distribute, and modify this work under the terms of the <a href="/LICENSE">GPL 3.0 License</a>. Please see the full license text for details.</small></div><!--footer-->
<script src="forms.js"></script>

1
maths/questions.html Normal file
View File

@ -0,0 +1 @@
hi

View File

@ -1 +1 @@
artist = ' Queen'; name = ' Bicycle Race - Remastered 2011' artist = ' Eurythmics'; name = ' Greetings From A Dead Man'

View File

@ -1,10 +1,10 @@
<div id='info'> <div id='info'>
Name: Bicycle Race - Remastered 2011<br/> Name: Greetings From A Dead Man<br/>
Artist: Queen<br/> Artist: Eurythmics<br/>
</div> </div>
<audio controls autoplay><source src='song.mp3' type='audio/mpeg'></audio> <audio controls autoplay><source src='song.mp3' type='audio/mpeg'></audio>
<form action='/music/prev' id='media-control' method='post'><button>previous</button></form> <form action='/music/prev' id='media-control' method='post'><button>previous</button></form>
<form action='/music/playpause' id='media-control' method='post'><button>play/pause</button></form> <form action='/music/playpause' id='media-control' method='post'><button>play/pause</button></form>
<form action='/music/next' id='media-control' method='post'><button>next</button></form> <form action='/music/next' id='media-control' method='post'><button>next</button></form>
<script>let name = " Bicycle Race - Remastered 2011"; let artist = " Queen"</script> <script>let name = " Greetings From A Dead Man"; let artist = " Eurythmics"</script>
<script>let counter = 0; setInterval(function () {var script = document.createElement('script'); script.src = 'data.js'; document.body.appendChild(script); let div = document.getElementById('info'); let newText = `Name: ${name}<br/>Artist: ${artist}`; div.innerHTML = newText; counter=counter+1; if (counter == 10000) { window.location.reload(); counter=0 }}, 1000)</script> <script>let counter = 0; setInterval(function () {var script = document.createElement('script'); script.src = 'data.js'; document.body.appendChild(script); let div = document.getElementById('info'); let newText = `Name: ${name}<br/>Artist: ${artist}`; div.innerHTML = newText; counter=counter+1; if (counter == 10000) { window.location.reload(); counter=0 }}, 1000)</script>

View File

@ -7,6 +7,7 @@ const fs = require("fs")
const validator = require('validator'); const validator = require('validator');
const rootPath = "/var/www/html/" const rootPath = "/var/www/html/"
const { exec } = require("child_process"); const { exec } = require("child_process");
const { execSync } = require("child_process");
const escapeHtml = (unsafe) => { const escapeHtml = (unsafe) => {
return unsafe return unsafe
@ -54,6 +55,54 @@ app.post("/music/prev",(req,res) => {
}, 1000); }, 1000);
}); });
app.post("/maths/submit-topics", (req,res) => {
console.log("Quesion page")
console.log(req.body.topic)
console.log(req.body.subtopic)
let topic = Number(req.body.topic)
let subtopic = validator.escape(req.body.subtopic)
let script = "";
try {
script = execSync(`./maths.sh ${topic} ${subtopic}`, { encoding: 'utf-8' }); // 'utf-8' to get the output as a string
} catch (error) {
console.error('Error executing command:', error);
}
output = script.split(/\r?\n/);
let topic_str = output[0]
let subtopic_str = output[1]
let problem = output[2]
let solution = output[3]
console.log("Topic: ", topic_str)
console.log("Subtopic: ", subtopic_str)
console.log("Problem: ", problem)
console.log("Solution: ", solution)
res.send(`${topic_str}<br/>
${subtopic_str}<br/>
${problem}
<form action="/maths/answer" method="post">
<input type="hidden" name="solution" value="${solution}">
<input type="hidden" name="topic" value="${topic}">
<input type="hidden" name="subtopic" value="${subtopic}">
<button type="submit">Answer</button>
</form>`)
});
app.post("/maths/answer", (req,res) => {
console.log("Answer page")
console.log(req.body.topic)
console.log(req.body.subtopic)
let topic = Number(req.body.topic)
let subtopic = validator.escape(req.body.subtopic)
res.send(`${req.body.solution}
<form action="/maths/submit-topics" method="post">
<input type="hidden" name="topic" value="${topic}">
<input type="hidden" name="subtopic" value="${subtopic}">
<button type="submit">Next</button>
</form>
<button onclick="window.location.href='https://deadvey.com/maths'">Back</button>`)
});
app.post("/board/submit-comment", (req,res) => { app.post("/board/submit-comment", (req,res) => {
res.redirect(302, req.get("referer")); res.redirect(302, req.get("referer"));
let comments = require(`${rootPath}/board/${req.body.pageID}/comments-database.js`) let comments = require(`${rootPath}/board/${req.body.pageID}/comments-database.js`)

View File

@ -15,7 +15,7 @@ for (let board = 0; board < boards.length; board++) {
} else { } else {
console.log(`Directory /${boards[board]}/ doesn't exist... Creating`) console.log(`Directory /${boards[board]}/ doesn't exist... Creating`)
fs.mkdirSync(boardPath); fs.mkdirSync(boardPath);
fs.appendFile(`${serverPath}/board/${boards[board]}/index.html`,`<!DOCTYPE html><div id="header"></div><!--header--><div id="main"><div id="comments" class="${boards[board]}"></div><form action="/board/submit-comment" id="commentForm" method="post"><input name="name" class="form-control" id="name" placeholder="Enter your name"><br/><input height="40px" name="comment" class="form-control input-comment" id="comment" placeholder="Enter your Comment..."><input type="hidden" name="pageID" value="${boards[board]}"><button type="submit">Submit</button></form></div><!--main--><div id="footer"></div><!--footer--><script src="comments-database.js"></script><script src="displayComments.js"></script>`, function (err) { fs.appendFile(`${serverPath}/board/${boards[board]}/index.html`,`<!DOCTYPE html><div id="header"></div><!--header--><div id="main"><div id="comments" class="${boards[board]}"></div><form action="/board/submit-comment" id="commentForm" method="post"><input name="name" class="form-control" id="name" placeholder="Enter your name"><br/><input height="40px" name="comment" class="form-control input-comment" id="comment" placeholder="Enter your Comment..."><input type="hidden" name="pageID" value="${boards[board]}"><button type="submit">Submit</button></form></div><!--main--><div id="footer"></div><!--footer--><script src="comments-database.js"></script><script src="/board/displayComments.js"></script>`, function (err) {
if (err) throw err; if (err) throw err;
console.log('Created page'); console.log('Created page');
}); });

48
node/maths.py Executable file
View File

@ -0,0 +1,48 @@
import sys
import random
import mathgenerator as mg
#print(mg.genList)
#print(sys.argv)
goodArray = [[],[],[],[],[],[],[]];
for x in mg.genList:
if x[4] == "algebra":
goodArray[0].append(x)
elif x[4] == "basic_math":
goodArray[1].append(x)
elif x[4] == "calculus":
goodArray[2].append(x)
elif x[4] == "computer_science":
goodArray[3].append(x)
elif x[4] == "geometry":
goodArray[4].append(x)
elif x[4] == "misc":
goodArray[5].append(x)
elif x[4] == "statistics":
goodArray[6].append(x)
topics = ["any","algebra","basic_math","calculus","computer_science","geometry","misc","statistics"]
rand_num = random.randint(0,len(mg.getGenList())-1)
if sys.argv[2] == "any":
if sys.argv[1] != "0":
while (mg.genList[rand_num][4] != topics[int(sys.argv[1])]):
rand_num = random.randint(0,len(mg.getGenList())-1)
problem, solution = mg.genById(rand_num)
topic = mg.genList[rand_num][4]
subtopic = mg.genList[rand_num][3]
else:
for i in range(len(mg.genList)):
if mg.genList[i][3] == sys.argv[2]:
problem, solution = mg.genById(i)
topic = mg.genList[i][4]
subtopic = mg.genList[i][3]
print(topic)
print(subtopic)
print(problem)
print(solution)

6
node/maths.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
source $HOME/venv/bin/activate
python3 maths.py $1 $2
deactivate

11
node/run.py Normal file
View File

@ -0,0 +1,11 @@
import subprocess
# Path to a Python interpreter that runs any Python script
# under the virtualenv /path/to/virtualenv/
python_bin = "/home/max/venv/bin/activate"
# Path to the script that must run under the virtualenv
script_file = "/home/max/maths/maths.py"
subprocess.Popen([python_bin, script_file])

View File

@ -1,6 +1,6 @@
const fs = require("fs"); const fs = require("fs");
const serverPath = require("./serverPath.js") const serverPath = require("./serverPath.js")
const pages = ["/index.html", "/blog/index.html", "/blog/reviews/index.html", "/project/index.html", "/board/index.html", "/board/tech/index.html", "/board/gen/index.html", "/board/films/index.html"]; const pages = ["/index.html", "/blog/index.html", "/blog/reviews/index.html", "/project/index.html", "/board/index.html", "/board/tech/index.html", "/board/gen/index.html", "/board/films/index.html", "/board/maths/index.html","/maths/index.html"];
const { header, footer} = require(serverPath+"/html.js") const { header, footer} = require(serverPath+"/html.js")
const { exec } = require('child_process'); const { exec } = require('child_process');