projekt/js/script.js

272 lines
14 KiB
JavaScript
Raw Normal View History

2024-10-16 10:18:43 +00:00
// Funkcja do wczytania pliku JSON
async function fetchJSONFile(filePath) {
try {
const response = await fetch(filePath);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error("Error fetching JSON file:", error);
}
}
2024-10-17 08:46:48 +00:00
// Obiekt do przechowywania danych klas i uczniów
const classData = {};
// Funkcja do wczytania pliku class.json i danych uczniów
2024-10-16 10:18:43 +00:00
async function loadClasses() {
const classFilePath = '/data/class.json';
const classes = await fetchJSONFile(classFilePath);
if (classes) {
2024-10-17 08:46:48 +00:00
const section_by_id = document.getElementById("select-class");
section_by_id.innerHTML = ""; // Wyczyść istniejące opcje
2024-10-16 10:42:08 +00:00
2024-10-16 10:18:43 +00:00
for (const classInfo of classes) {
2024-10-17 08:46:48 +00:00
const studentsFilePath = '/data/' + classInfo.file_path;
const studentsDataForClass = await fetchJSONFile(studentsFilePath);
2024-10-17 08:46:48 +00:00
const classKey = classInfo.class + "-" + classInfo.group;
2024-10-16 10:42:08 +00:00
2024-10-17 08:46:48 +00:00
// Utwórz i dodaj opcję do selecta
const option = document.createElement("option");
option.value = classKey;
option.text = "Klasa: " + classInfo.class + " Grupa: " + classInfo.group;
section_by_id.appendChild(option);
2024-10-16 10:42:08 +00:00
2024-10-17 08:46:48 +00:00
if (studentsDataForClass) {
processClassData(classInfo, studentsDataForClass);
2024-10-16 10:18:43 +00:00
}
}
}
}
// Funkcja do przetwarzania danych o klasach i uczniach
2024-10-17 08:46:48 +00:00
function processClassData(classInfo, studentsDataForClass) {
const classKey = classInfo.class + "-" + classInfo.group;
classData[classKey] = studentsDataForClass;
2024-10-16 10:18:43 +00:00
}
2024-10-17 08:46:48 +00:00
// Globalna tablica studentsData
let studentsData = [];
2024-10-17 08:46:48 +00:00
// Nasłuchiwanie na zmianę klasy i ładowanie uczniów
document.addEventListener('DOMContentLoaded', function() {
2024-10-17 08:46:48 +00:00
loadClasses().then(() => {
const selectClassElement = document.getElementById('select-class');
selectClassElement.addEventListener('change', function() {
var selectedClass = this.value;
console.log("Aktualnie wybrana klasa: ", selectedClass);
// Pobierz dane uczniów dla wybranej klasy
let classStudentsData = classData[selectedClass];
if (classStudentsData && classStudentsData.students) {
console.log("Dane uczniów dla klasy:", classStudentsData.students);
// Zaktualizuj tablicę studentsData
studentsData = classStudentsData.students.map(student => ({
name: student.first_name + " " + student.last_name,
behavior: {}
}));
// Wygeneruj tabelę
generateTable();
// Załaduj dane dla aktualnego dnia
loadDayData();
} else {
console.error("Nie znaleziono danych dla klasy: ", selectedClass);
}
});
2024-10-17 08:46:48 +00:00
// Automatycznie wywołaj 'change' dla pierwszej klasy w select
if (selectClassElement.options.length > 0) {
selectClassElement.selectedIndex = 0;
selectClassElement.dispatchEvent(new Event('change'));
}
});
});
2024-10-16 09:24:57 +00:00
function showTab(tabName) {
const tabs = document.querySelectorAll('.tab');
tabs.forEach(tab => tab.classList.remove('active'));
document.getElementById(tabName).classList.add('active');
if (tabName === 'criteria') {
loadDayData();
} else if (tabName === 'points') {
calculateStats();
}
}
function generateTable() {
const table = document.getElementById('student-table');
table.innerHTML = '';
studentsData.forEach(student => {
2024-10-17 08:46:48 +00:00
console.log("Przetwarzany student:", student);
const studentId = student.name.replace(/\s+/g, '-');
2024-10-16 09:24:57 +00:00
const row = document.createElement('tr');
row.innerHTML = `
<td>${student.name}</td>
2024-10-17 08:46:48 +00:00
<td><input type="checkbox" id="frekwencja-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="brak-godzin-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="min-85-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="etap-szkolny-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="etap-rejonowy-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="etap-wojewodzki-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="etap-ogolnopolski-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="udzial-konkurs-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="wyroznienie-konkurs-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="reprezentacja-indywidualna-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="reprezentacja-zespolowa-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="udzial-zawody-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="organizacja-imprez-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="funkcja-klasa-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="uroczystosci-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="poczta-sztandar-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="pomoc-nauczyciel-${studentId}" onchange="calculateStats()"></td>
<td><input type="checkbox" id="wolontariat-${studentId}" onchange="calculateStats()"></td>
2024-10-16 09:24:57 +00:00
`;
table.appendChild(row);
});
}
2024-10-17 08:46:48 +00:00
let currentDay = 0;
const baseDate = new Date();
// Zmiana dnia i ładowanie danych
2024-10-16 09:24:57 +00:00
function changeDay(direction) {
saveDayData();
currentDay += direction;
const newDate = new Date(baseDate);
newDate.setDate(baseDate.getDate() + currentDay);
document.getElementById('current-date').innerText = newDate.toLocaleDateString();
loadDayData();
}
function loadDayData() {
studentsData.forEach(student => {
2024-10-17 08:46:48 +00:00
const studentId = student.name.replace(/\s+/g, '-');
2024-10-16 09:24:57 +00:00
const behavior = student.behavior[`day${currentDay}`] || {};
document.getElementById(`frekwencja-${studentId}`).checked = behavior.frekwencja || false;
document.getElementById(`brak-godzin-${studentId}`).checked = behavior.brak_godzin || false;
document.getElementById(`min-85-${studentId}`).checked = behavior.min_85 || false;
document.getElementById(`etap-szkolny-${studentId}`).checked = behavior.etap_szkolny || false;
document.getElementById(`etap-rejonowy-${studentId}`).checked = behavior.etap_rejonowy || false;
document.getElementById(`etap-wojewodzki-${studentId}`).checked = behavior.etap_wojewodzki || false;
document.getElementById(`etap-ogolnopolski-${studentId}`).checked = behavior.etap_ogolnopolski || false;
document.getElementById(`udzial-konkurs-${studentId}`).checked = behavior.udzial_konkurs || false;
document.getElementById(`wyroznienie-konkurs-${studentId}`).checked = behavior.wyroznienie_konkurs || false;
document.getElementById(`reprezentacja-indywidualna-${studentId}`).checked = behavior.reprezentacja_indywidualna || false;
document.getElementById(`reprezentacja-zespolowa-${studentId}`).checked = behavior.reprezentacja_zespolowa || false;
document.getElementById(`udzial-zawody-${studentId}`).checked = behavior.udzial_zawody || false;
document.getElementById(`organizacja-imprez-${studentId}`).checked = behavior.organizacja_imprez || false;
document.getElementById(`funkcja-klasa-${studentId}`).checked = behavior.funkcja_klasa || false;
document.getElementById(`uroczystosci-${studentId}`).checked = behavior.uroczystosci || false;
document.getElementById(`poczta-sztandar-${studentId}`).checked = behavior.poczta_sztandar || false;
document.getElementById(`pomoc-nauczyciel-${studentId}`).checked = behavior.pomoc_nauczyciel || false;
document.getElementById(`wolontariat-${studentId}`).checked = behavior.wolontariat || false;
});
calculateStats();
}
function saveDayData() {
studentsData.forEach(student => {
2024-10-17 08:46:48 +00:00
const studentId = student.name.replace(/\s+/g, '-');
2024-10-16 09:24:57 +00:00
const behavior = {
frekwencja: document.getElementById(`frekwencja-${studentId}`).checked,
brak_godzin: document.getElementById(`brak-godzin-${studentId}`).checked,
min_85: document.getElementById(`min-85-${studentId}`).checked,
etap_szkolny: document.getElementById(`etap-szkolny-${studentId}`).checked,
etap_rejonowy: document.getElementById(`etap-rejonowy-${studentId}`).checked,
etap_wojewodzki: document.getElementById(`etap-wojewodzki-${studentId}`).checked,
etap_ogolnopolski: document.getElementById(`etap-ogolnopolski-${studentId}`).checked,
udzial_konkurs: document.getElementById(`udzial-konkurs-${studentId}`).checked,
wyroznienie_konkurs: document.getElementById(`wyroznienie-konkurs-${studentId}`).checked,
reprezentacja_indywidualna: document.getElementById(`reprezentacja-indywidualna-${studentId}`).checked,
reprezentacja_zespolowa: document.getElementById(`reprezentacja-zespolowa-${studentId}`).checked,
udzial_zawody: document.getElementById(`udzial-zawody-${studentId}`).checked,
organizacja_imprez: document.getElementById(`organizacja-imprez-${studentId}`).checked,
funkcja_klasa: document.getElementById(`funkcja-klasa-${studentId}`).checked,
uroczystosci: document.getElementById(`uroczystosci-${studentId}`).checked,
poczta_sztandar: document.getElementById(`poczta-sztandar-${studentId}`).checked,
2024-10-17 08:46:48 +00:00
pomoc_nauczyciel: document.getElementById(`pomoc-nauczyciel-${studentId}`).checked,
2024-10-16 09:24:57 +00:00
wolontariat: document.getElementById(`wolontariat-${studentId}`).checked
};
student.behavior[`day${currentDay}`] = behavior;
});
}
function calculateStats() {
const frekwencjaPoints = parseInt(document.getElementById('frekwencja-punkty').value);
const brakGodzinPoints = parseInt(document.getElementById('brak-godzin-punkty').value);
const min85Points = parseInt(document.getElementById('min-85-punkty').value);
const etapSzkolnyPoints = parseInt(document.getElementById('etap-szkolny-punkty').value);
const etapRejonowyPoints = parseInt(document.getElementById('etap-rejonowy-punkty').value);
const etapWojewodzkiPoints = parseInt(document.getElementById('etap-wojewodzki-punkty').value);
const etapOgolnopolskiPoints = parseInt(document.getElementById('etap-ogolnopolski-punkty').value);
const udzialKonkursPoints = 5; // stała wartość
const wyroznienieKonkursPoints = 10; // stała wartość
const reprezentacjaIndPoints = 5; // stała wartość
const reprezentacjaZesPoints = 10; // stała wartość
const udzialZawodyPoints = 15; // stała wartość
const organizacjaImprezPoints = 10; // stała wartość
const funkcjaKlasyPoints = 10; // stała wartość
const uroczystosciPoints = 10; // stała wartość
const pocztaSztandarPoints = 20; // stała wartość
const pomocNauczycielaPoints = 10; // stała wartość
const wolontariatPoints = 10; // stała wartość
let stats = '';
studentsData.forEach(student => {
let totalPoints = 0;
Object.keys(student.behavior).forEach(day => {
const behavior = student.behavior[day];
2024-10-17 08:46:48 +00:00
let dayPoints = 0;
2024-10-16 09:24:57 +00:00
if (behavior.frekwencja) dayPoints += frekwencjaPoints;
if (behavior.brak_godzin) dayPoints += brakGodzinPoints;
if (behavior.min_85) dayPoints += min85Points;
if (behavior.etap_szkolny) dayPoints += etapSzkolnyPoints;
if (behavior.etap_rejonowy) dayPoints += etapRejonowyPoints;
if (behavior.etap_wojewodzki) dayPoints += etapWojewodzkiPoints;
if (behavior.etap_ogolnopolski) dayPoints += etapOgolnopolskiPoints;
if (behavior.udzial_konkurs) dayPoints += udzialKonkursPoints;
if (behavior.wyroznienie_konkurs) dayPoints += wyroznienieKonkursPoints;
if (behavior.reprezentacja_indywidualna) dayPoints += reprezentacjaIndPoints;
if (behavior.reprezentacja_zespolowa) dayPoints += reprezentacjaZesPoints;
if (behavior.udzial_zawody) dayPoints += udzialZawodyPoints;
if (behavior.organizacja_imprez) dayPoints += organizacjaImprezPoints;
if (behavior.funkcja_klasa) dayPoints += funkcjaKlasyPoints;
if (behavior.uroczystosci) dayPoints += uroczystosciPoints;
if (behavior.poczta_sztandar) dayPoints += pocztaSztandarPoints;
2024-10-17 08:46:48 +00:00
if (behavior.pomoc_nauczyciel) dayPoints += pomocNauczycielaPoints;
2024-10-16 09:24:57 +00:00
if (behavior.wolontariat) dayPoints += wolontariatPoints;
totalPoints += dayPoints;
});
stats += `${student.name}: ${totalPoints} punktów (${getGrade(totalPoints)})\n`;
});
document.getElementById('stats').innerText = stats;
}
function getGrade(points) {
if (points >= 250) return "Wzorowe";
if (points >= 180) return "Bardzo dobre";
if (points >= 100) return "Dobre";
if (points >= 50) return "Poprawne";
if (points >= 0) return "Nieodpowiednie";
return "Naganne";
}
// Ustawienie daty na dziś
document.getElementById('current-date').innerText = baseDate.toLocaleDateString();