Class stats - getting data
This commit is contained in:
parent
f26dc099d8
commit
8d0aa3aeda
5 changed files with 143 additions and 2 deletions
60
app/API/stats.py
Normal file
60
app/API/stats.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import json
|
||||
import requests
|
||||
|
||||
def get_partial(register_id, students, oun, s):
|
||||
cookies = s
|
||||
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{students['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{students['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{students['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyDziennikWychowankowie": f"{students['data'][0]['IdWychowankowieDziennik']}",
|
||||
"idBiezacyUczen": f"{students['data'][0]['IdUczen']}"
|
||||
})
|
||||
else:
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{students['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{students['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{students['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyUczen": f"{students['data'][0]['IdUczen']}"
|
||||
})
|
||||
|
||||
headers = {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': '*/*',
|
||||
'Connection': 'keep-alive',
|
||||
"User-Agent": "Wulkanowy-web :)"
|
||||
}
|
||||
|
||||
partial = requests.post(oun+'/Statystyki.mvc/GetOcenyCzastkowe', headers=headers, cookies=cookies, json={'idOkres': register_id})
|
||||
|
||||
return partial.json()
|
||||
|
||||
def get_year(register_id, students, oun, s):
|
||||
cookies = s
|
||||
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{students['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{students['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{students['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyDziennikWychowankowie": f"{students['data'][0]['IdWychowankowieDziennik']}",
|
||||
"idBiezacyUczen": f"{students['data'][0]['IdUczen']}"
|
||||
})
|
||||
else:
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{students['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{students['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{students['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyUczen": f"{students['data'][0]['IdUczen']}"
|
||||
})
|
||||
|
||||
headers = {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': '*/*',
|
||||
'Connection': 'keep-alive',
|
||||
"User-Agent": "Wulkanowy-web :)"
|
||||
}
|
||||
|
||||
year = requests.post(oun+'/Statystyki.mvc/GetOcenyRoczne', headers=headers, cookies=cookies, json={'idOkres': register_id})
|
||||
|
||||
return year.json()
|
30
app/views.py
30
app/views.py
|
@ -20,6 +20,7 @@ from .API.mobile_access import get_registered_devices, register_device
|
|||
from .API.school_data import get_school_data
|
||||
from .API.dashboard import get_dashboard
|
||||
from .API.student_data import get_student_data
|
||||
from .API.stats import get_partial, get_year
|
||||
from .decrypt import decrypt_cookies
|
||||
import datetime
|
||||
|
||||
|
@ -387,6 +388,35 @@ def student_data(request, *args, **kwargs):
|
|||
else:
|
||||
return redirect('../')
|
||||
|
||||
#STATS
|
||||
def partial(request, *args, **kwargs):
|
||||
if request.session.has_key('is_logged'):
|
||||
data = json.loads(request.body)
|
||||
register_id = data['data']['register_id']
|
||||
students = data['data']['students']
|
||||
oun = data['data']['oun']
|
||||
s = data['data']['s']
|
||||
key = bytes(request.session[request.session.session_key], 'utf-8')
|
||||
s = decrypt_cookies(s, key)
|
||||
partial_stats = get_partial(register_id, students, oun, s)
|
||||
return JsonResponse(partial_stats)
|
||||
else:
|
||||
return redirect('../')
|
||||
|
||||
def year(request, *args, **kwargs):
|
||||
if request.session.has_key('is_logged'):
|
||||
data = json.loads(request.body)
|
||||
register_id = data['data']['register_id']
|
||||
students = data['data']['students']
|
||||
oun = data['data']['oun']
|
||||
s = data['data']['s']
|
||||
key = bytes(request.session[request.session.session_key], 'utf-8')
|
||||
s = decrypt_cookies(s, key)
|
||||
year_stats = get_year(register_id, students, oun, s)
|
||||
return JsonResponse(year_stats)
|
||||
else:
|
||||
return redirect('../')
|
||||
|
||||
def log_out(request, *args, **kwargs):
|
||||
del request.session[request.session.session_key]
|
||||
del request.session['is_logged']
|
||||
|
|
46
frontend/static/frontend/js/stats.js
Normal file
46
frontend/static/frontend/js/stats.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const stats_ = document.querySelector('#stats_');
|
||||
|
||||
myStorage = window.sessionStorage;
|
||||
|
||||
const showMenu = () => {
|
||||
document.querySelector('#content').innerHTML = '<button id="partial" class="waves-light waves-effect btn red darken-1">OCENY CZĄSTKOWE</button>';
|
||||
document.querySelector('#content').innerHTML += '<button id="year" class="waves-light waves-effect btn red darken-1">OCENY ROCZNE</button>';
|
||||
const partial_ = document.querySelector('#partial');
|
||||
const year_ = document.querySelector('#year');
|
||||
partial_.addEventListener('click', getPartial);
|
||||
year_.addEventListener('click', getYear);
|
||||
}
|
||||
|
||||
const getPartial = () => {
|
||||
cookies_data = sessionStorage.getItem('cookies_data');
|
||||
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||
fetch(url = '../api/stats/partial', {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfcookie_
|
||||
},
|
||||
body: cookies_data
|
||||
}).then(response => response.json()).then(data => {
|
||||
console.log(data)
|
||||
})
|
||||
}
|
||||
|
||||
const getYear = () => {
|
||||
cookies_data = sessionStorage.getItem('cookies_data');
|
||||
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||
fetch(url = '../api/stats/year', {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfcookie_
|
||||
},
|
||||
body: cookies_data
|
||||
}).then(response => response.json()).then(data => {
|
||||
console.log(data)
|
||||
})
|
||||
}
|
||||
|
||||
stats_.addEventListener('click', showMenu);
|
|
@ -41,6 +41,7 @@
|
|||
<li><a id="exams_" class='option'><i class="material-icons">event</i>Sprawdziany</a></li>
|
||||
<li><a id="homeworks_" class='option'><i class="material-icons">class</i>Zadania Domowe</a></li>
|
||||
<li><a id="attendance_" class='option'><i class="material-icons">date_range</i>Frekwencja</a></li>
|
||||
<li><a id="stats_" class='option'><i class="material-icons">insert_chart_outlined</i>Uczeń na Tle Klasy</a></li>
|
||||
<li><a id="notes_" class='option'><i class="material-icons">emoji_events</i>Uwagi i Osiągnięcia</a></li>
|
||||
<li><a id="mobile_access_" class='option'><i class="material-icons">devices</i>Dostęp Mobilny</a></li>
|
||||
<li><a id="school_data_" class='option'><i class="material-icons">business</i>Szkoła i Nauczyciele</a></li>
|
||||
|
@ -93,6 +94,7 @@
|
|||
<script src="{% static 'frontend/js/mobile_access.js' %}" type="text/javascript" defer></script>
|
||||
<script src="{% static 'frontend/js/school_data.js' %}" type="text/javascript" defer></script>
|
||||
<script src="{% static 'frontend/js/student_data.js' %}" type="text/javascript" defer></script>
|
||||
<script src="{% static 'frontend/js/stats.js' %}" type="text/javascript" defer></script>
|
||||
<script src="{% static 'frontend/js/log-out.js' %}" type="text/javascript" defer></script>
|
||||
</body>
|
||||
</html>
|
|
@ -17,14 +17,14 @@ from django.urls import path
|
|||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
from frontend.views import default_view, content_view, account_manager_view
|
||||
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content, student_data, log_out
|
||||
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content, student_data, log_out, partial, year
|
||||
|
||||
urlpatterns = [
|
||||
#views
|
||||
path('', default_view, name='home'),
|
||||
path('content/', content_view, name='content'),
|
||||
path('account-manager/', account_manager_view, name='account_manager'),
|
||||
#api
|
||||
#API
|
||||
path('api/login', login, name='login'),
|
||||
path('api/grades', grades, name='grades'),
|
||||
path('api/timetable', timetable, name='timetable'),
|
||||
|
@ -36,6 +36,9 @@ urlpatterns = [
|
|||
path('api/dashboard', dashboard, name='dashboard'),
|
||||
path('api/student_data', student_data, name='student_data'),
|
||||
path('api/log_out', log_out, name='log_out'),
|
||||
#STATS
|
||||
path('api/stats/partial', partial, name='partial'),
|
||||
path('api/stats/year', year, name='year'),
|
||||
#MOBILE ACCESS
|
||||
path('api/mobile/registered', registered_devices, name='registered_devices'),
|
||||
path('api/mobile/register', register_device_, name='register_device'),
|
||||
|
|
Loading…
Reference in a new issue