mirror of
https://github.com/Steffo99/registro-fermi.git
synced 2024-11-25 17:44:28 +00:00
237 lines
9.2 KiB
HTML
237 lines
9.2 KiB
HTML
|
<html>
|
||
|
<!--Copyright © 2016 Stefano Pigozzi, Emiliano Maccaferri
|
||
|
Released under the GPL v3 license-->
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
|
||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
|
||
|
<link rel="stylesheet" href="/style/style.css">
|
||
|
<script src="https://use.fontawesome.com/0a710f5b18.js"></script>
|
||
|
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
|
||
|
<script src="/lib/cookie.js"></script>
|
||
|
<script>
|
||
|
var voteList = [];
|
||
|
var reverseme = false;
|
||
|
var termname = "quadrimestre";
|
||
|
|
||
|
function sortMe()
|
||
|
{
|
||
|
$(".fa").removeClass("fa-sort-asc fa-sort-desc");
|
||
|
if(!reverseme)
|
||
|
{
|
||
|
$(this).addClass("fa-sort-asc");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$(this).addClass("fa-sort-desc");
|
||
|
}
|
||
|
tableSort("mark", "number");
|
||
|
}
|
||
|
|
||
|
function padNumber(string)
|
||
|
{
|
||
|
if(Number(string) < 10)
|
||
|
{
|
||
|
return "0" + string;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return string;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function stringifyDates()
|
||
|
{
|
||
|
for(var i = 0; i < voteList.length; i++)
|
||
|
{
|
||
|
var date = new Date(voteList[i].mark_date * 1000);
|
||
|
voteList[i].string_date = String(date.getFullYear()) + "-" + padNumber(String(date.getMonth() + 1)) + "-" + padNumber(String(date.getDate()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getTermList(list)
|
||
|
{
|
||
|
var termList = [];
|
||
|
|
||
|
for(var i = 0; i < list.length; i++)
|
||
|
{
|
||
|
if(termList.indexOf(list[i].term) === -1)
|
||
|
{
|
||
|
termList.push(list[i].term);
|
||
|
}
|
||
|
}
|
||
|
return termList;
|
||
|
}
|
||
|
|
||
|
function getSubjectList(list)
|
||
|
{
|
||
|
var subjectList = [];
|
||
|
|
||
|
for(var i = 0; i < list.length; i++)
|
||
|
{
|
||
|
if(subjectList.indexOf(list[i].subject) === -1)
|
||
|
{
|
||
|
subjectList.push(list[i].subject);
|
||
|
}
|
||
|
}
|
||
|
return subjectList;
|
||
|
}
|
||
|
|
||
|
function drawTable(list)
|
||
|
{
|
||
|
$("#marks tbody").html("");
|
||
|
|
||
|
//Tabella dei voti
|
||
|
for(var i = 0; i < list.length; i++)
|
||
|
{
|
||
|
$("#marks tbody").append("<tr id=\"voto" + String(i) + "\"></tr>");
|
||
|
$("#voto" + String(i)).append("<td class=\"subject\">" + list[i].subject + "</td>");
|
||
|
$("#voto" + String(i)).append("<td class=\"date\">" + list[i].string_date + "</td>");
|
||
|
$("#voto" + String(i)).append("<td class=\"voto\">" + list[i].mark + "</td>");
|
||
|
$("#voto" + String(i)).append("<td class=\"description\">" + list[i].description + "</td>");
|
||
|
$("#voto" + String(i)).append("<td class=\"term\">" + list[i].term + "</td>");
|
||
|
};
|
||
|
|
||
|
//Colore dei voti
|
||
|
$(".voto").each(function(i)
|
||
|
{
|
||
|
if(Number($(this).text()) < 5)
|
||
|
{
|
||
|
$(this).parent().addClass("grave");
|
||
|
}
|
||
|
else if(Number($(this).text() < 6))
|
||
|
{
|
||
|
$(this).parent().addClass("insuff");
|
||
|
}
|
||
|
else if(Number($(this).text() >= 10))
|
||
|
{
|
||
|
$(this).parent().addClass("perfect");
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function calcAndDrawAvg(list)
|
||
|
{
|
||
|
var subjectlist = getSubjectList(list);
|
||
|
var termlist = getTermList(list);
|
||
|
|
||
|
//Ho idea che si potrebbe ottimizzare un po'. Un po' molto. Magari con un oggetto. Ma non ora.
|
||
|
for(var t = 0; t < termlist.length; t++)
|
||
|
{
|
||
|
$(".container").append("<h1>Media " + termlist[t] + " " + termname + "</h1>");
|
||
|
//Date il benvenuto alla riga più lunga del secolo!
|
||
|
$(".container").append("<table id=\"medie-" + termlist[t] + "\" class=\"table table-responsive\"><thead><tr><th>Materia</th><th>Media</th></tr></thead><tbody></tbody></table>");
|
||
|
|
||
|
for(var i = 0; i < subjectlist.length; i++)
|
||
|
{
|
||
|
var total = 0;
|
||
|
var marks = 0;
|
||
|
for(var j = 0; j < list.length; j++)
|
||
|
{
|
||
|
if(list[j].subject === subjectlist[i] && list[j].term == termlist[t])
|
||
|
{
|
||
|
total += list[j].mark;
|
||
|
marks++;
|
||
|
}
|
||
|
}
|
||
|
$("#medie-" + termlist[t] + " tbody").append("<tr id=\"media-" + subjectlist[i] + "\"></tr>");
|
||
|
$("#medie-" + termlist[t] + " #media-" + subjectlist[i]).append("<td class=\"subject\">" + subjectlist[i] + "</td>");
|
||
|
$("#medie-" + termlist[t] + " #media-" + subjectlist[i]).append("<td class=\"average\">" + (total / marks).toFixed(2) + "</td>");
|
||
|
if(Number($("#medie-" + termlist[t] + " #media-" + subjectlist[i] + " .average").text()) < 5)
|
||
|
{
|
||
|
$("#medie-" + termlist[t] + " #media-" + subjectlist[i]).addClass("grave");
|
||
|
}
|
||
|
else if(Number($("#medie-" + termlist[t] + " #media-" + subjectlist[i] + " .average").text()) < 6)
|
||
|
{
|
||
|
$("#medie-" + termlist[t] + " #media-" + subjectlist[i]).addClass("insuff");
|
||
|
}
|
||
|
else if(Number($("#medie-" + termlist[t] + " #media-" + subjectlist[i] + " .average").text()) === 10)
|
||
|
{
|
||
|
$("#medie-" + termlist[t] + " #media-" + subjectlist[i]).addClass("perfect");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function tableSort(index, type)
|
||
|
{
|
||
|
/*Questo codice è un tantino hackeroso... Ma finchè funziona perchè cambiarlo, no?*/
|
||
|
if(type === "string")
|
||
|
{
|
||
|
voteList.sort(function(a, b) {
|
||
|
return a[index].localeCompare(b[index]);
|
||
|
});
|
||
|
}
|
||
|
else if(type === "number")
|
||
|
{
|
||
|
voteList.sort(function(a, b) {
|
||
|
return a[index]-b[index];
|
||
|
});
|
||
|
}
|
||
|
if(reverseme)
|
||
|
{
|
||
|
reverseme = false;
|
||
|
voteList.reverse();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
reverseme = true;
|
||
|
}
|
||
|
drawTable(voteList);
|
||
|
}
|
||
|
|
||
|
function enableSort()
|
||
|
{
|
||
|
$("#sort-subject").click(sortMe);
|
||
|
$("#sort-date").click(sortMe);
|
||
|
$("#sort-mark").click(sortMe);
|
||
|
$("#sort-term").click(sortMe);
|
||
|
}
|
||
|
|
||
|
//Ricevi i voti.
|
||
|
$.post("https://api.emilianomaccaferri.me/getMarks",
|
||
|
{
|
||
|
"sessionid": Cookies.get("sessionid")
|
||
|
},
|
||
|
function(data){
|
||
|
if(data.success)
|
||
|
{
|
||
|
voteList = data.list;
|
||
|
stringifyDates();
|
||
|
drawTable(voteList);
|
||
|
calcAndDrawAvg(voteList);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
console.log("Failure!");
|
||
|
console.log(data.error);
|
||
|
}
|
||
|
}, "json");
|
||
|
|
||
|
window.onload = enableSort;
|
||
|
|
||
|
</script>
|
||
|
</head>
|
||
|
<body id="marklist">
|
||
|
<div class="container">
|
||
|
<h1>
|
||
|
Voti
|
||
|
</h1>
|
||
|
<table id="marks" class="table table-responsive">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th><span class="fa fa-sort clickme" id="sort-subject"></span> Materia</th>
|
||
|
<th><span class="fa fa-sort clickme" id="sort-date"></span> Data</th>
|
||
|
<th><span class="fa fa-sort clickme" id="sort-mark"></span> Voto</th>
|
||
|
<th>Descrizione</th>
|
||
|
<th><span class="fa fa-sort clickme" id="sort-term"></span> Quadrimestre</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|