aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-02-08 19:48:04 +0100
committerMarvin Borner2021-02-08 19:48:04 +0100
commitfe7efde36a9e95d1257a103ca044b8b909b654df (patch)
tree383d238a0ef7fb0a1b3a5bf74b522bc41fa5b1af
parent75b04460c86df1a9b25340310f4a27c2417ec7db (diff)
Fat stats hats mad lads
-rwxr-xr-xcli.js28
-rw-r--r--db.js12
-rw-r--r--zeitung/main.tex4
-rw-r--r--zeitung/parts/questionnaire.tex7
-rw-r--r--zeitung/parts/stats/.gitkeep0
-rw-r--r--zeitung/parts/stats/perc.tex8
6 files changed, 56 insertions, 3 deletions
diff --git a/cli.js b/cli.js
index 3b1bb5e..707425f 100755
--- a/cli.js
+++ b/cli.js
@@ -139,6 +139,34 @@ if ((idx = params.indexOf("-r")) > -1) {
__dirname + "/zeitung/parts/students/" + user.class + "/" + user.username + ".tex",
textex,
);
+
+ // Fat stats hats mad lads
+ textex = "";
+ const questions = [...new Set(data.questions.map((a) => a[0].id))];
+ const statrad = 2.5;
+ const statxinc = 8,
+ statyinc = 6;
+ let statx = 0,
+ staty = 0;
+ questions.forEach((q) => {
+ const options = data.questions[q - 1].sort((a, b) => b.count - a.count);
+ textex += `\\node at (${statx}, ${staty + statrad / 2 + 1.5}) {${options[0].question}};`;
+ textex += `\\pie[hide number, sum=auto, text=inside, pos={${statx},${staty}}, radius=${statrad}]{`;
+ options.forEach((option, ind) => {
+ textex += `${option.count}/${sanitize(option.option)}`;
+ if (options[ind + 1]) textex += ", ";
+ });
+ textex += "}\n";
+
+ if (statx == statxinc) {
+ staty += statyinc;
+ statx = 0;
+ } else {
+ statx = statxinc;
+ }
+ });
+
+ await fs.writeFile(__dirname + "/zeitung/parts/stats/perc.tex", textex);
});
});
console.log("Probably finished?");
diff --git a/db.js b/db.js
index 556521e..d73bfa2 100644
--- a/db.js
+++ b/db.js
@@ -237,17 +237,27 @@ class DB {
const users = await this.query(
"SELECT u.id, u.username, u.name, u.middlename, u.surname, c.name class, t.name type FROM users u INNER JOIN class c ON u.class_id = c.id INNER JOIN types t ON u.type_id = t.id WHERE t.name = 'pupil'",
);
+
const profile = await this.query(
"SELECT q.question, a.answer, a.user_id FROM profile_questions q INNER JOIN profile_answers a ON a.question_id = q.id",
);
+ const rawQuestions = await this.query(
+ "SELECT q.id, q.question question, o.answer_option option, COUNT(a.user_id) count FROM question_questions q INNER JOIN question_options o ON q.id = o.question_id INNER JOIN question_answers a ON o.id = a.option_id GROUP BY o.id",
+ );
+ const questions = [];
+ rawQuestions.forEach((e) => {
+ if (!questions[e.id - 1]) questions[e.id - 1] = [];
+ questions[e.id - 1].push(e);
+ });
+
for (const user of users) {
user.comments = await this.query("SELECT comment from profile_comments where profile_id=" + user.id);
user.chars = await this.query("SELECT txt from profile_char where profile_id=" + user.id);
//user["comments"].forEach((comment) => console.log("Kommentar: " + comment.comment));
}
- return { users, profile };
+ return { users, profile, questions };
}
async query(query, params) {
diff --git a/zeitung/main.tex b/zeitung/main.tex
index 0ea6e37..20c9af9 100644
--- a/zeitung/main.tex
+++ b/zeitung/main.tex
@@ -16,6 +16,7 @@
\usepackage{background}
\usepackage{changepage}
\usepackage{tabularx}
+\usepackage{pgf-pie}
% Font
\setmainfont{"[tierra-nueva.otf]"}[BoldFont="[tierra-nueva-bold.otf]"]
@@ -76,6 +77,7 @@
\def\part#1{\input{parts/#1.tex}\newpage}
\def\student{\input{parts/studenttemplate.tex}}
+\def\stat#1{\input{parts/stats/#1.tex}}
%\maketitle
@@ -90,7 +92,7 @@
\part{teacherranking}
\part{secrets}
\part{classoverview}
-\part{studentprofiles}
+%\part{studentprofiles}
\part{studentranking}
\part{citations}
\part{photos}
diff --git a/zeitung/parts/questionnaire.tex b/zeitung/parts/questionnaire.tex
index dad999a..1c75b4c 100644
--- a/zeitung/parts/questionnaire.tex
+++ b/zeitung/parts/questionnaire.tex
@@ -1,2 +1,7 @@
\title{Prozent-Fragen}
-\lipsum[1-2]
+
+\begin{center}
+\hspace{-1.5cm}\begin{tikzpicture}
+ \stat{perc}
+\end{tikzpicture}
+\end{center}
diff --git a/zeitung/parts/stats/.gitkeep b/zeitung/parts/stats/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/zeitung/parts/stats/.gitkeep
diff --git a/zeitung/parts/stats/perc.tex b/zeitung/parts/stats/perc.tex
new file mode 100644
index 0000000..8042777
--- /dev/null
+++ b/zeitung/parts/stats/perc.tex
@@ -0,0 +1,8 @@
+\node at (0, 2.75) {Bist du Single/Vergeben?};\pie[hide number, scale font, sum=auto, text=inside, pos={0,0}, radius=2.5]{41/Single, 13/Vergeben}
+\node at (8, 2.75) {Wie kommst du hauptsächlich zur Schule?};\pie[hide number, scale font, sum=auto, text=inside, pos={8,0}, radius=2.5]{21/Bus, 21/Auto, 7/Bahn, 3/Fahrrad, 2/Fuß}
+\node at (0, 8.75) {Hast du schon einmal blau gemacht?};\pie[hide number, scale font, sum=auto, text=inside, pos={0,6}, radius=2.5]{35/Ja, 19/Nein}
+\node at (8, 8.75) {Was machst du nach der Schule?};\pie[hide number, scale font, sum=auto, text=inside, pos={8,6}, radius=2.5]{28/Studium, 10/Ausbildung, 7/Keine Ahnung, 4/Arbeit, 4/Pause, 1/Work \& Travel}
+\node at (0, 14.75) {Hast du Geschwister?};\pie[hide number, scale font, sum=auto, text=inside, pos={0,12}, radius=2.5]{53/Ja, 1/Nein}
+\node at (8, 14.75) {Rauchst du?};\pie[hide number, scale font, sum=auto, text=inside, pos={8,12}, radius=2.5]{40/Nein, 7/Ja, 7/Auf Partys}
+\node at (0, 20.75) {Hast du bewusstseinserweiternde Substanzen zu dir genommen?};\pie[hide number, scale font, sum=auto, text=inside, pos={0,18}, radius=2.5]{33/Nein, 21/Ja}
+\node at (8, 20.75) {Bist du noch Jungfrau (nicht Sternzeichen)?};\pie[hide number, scale font, sum=auto, text=inside, pos={8,18}, radius=2.5]{29/Nein, 21/Ja}