forked from ScoDoc/ScoDoc
api too slow (36k/student)
This commit is contained in:
parent
82b69ee885
commit
ee4741431b
@ -27,6 +27,6 @@ def feuille_preparation_jury_but(formsemestre_id: int):
|
||||
"but/jury_export.j2",
|
||||
datetime=datetime,
|
||||
formsemestre=formsemestre,
|
||||
dept = departement.acronym,
|
||||
dept=departement.acronym,
|
||||
sco=ScoData(formsemestre=formsemestre),
|
||||
)
|
||||
|
@ -20,18 +20,36 @@ getMarks(3) <= {"Alice": 13 }
|
||||
getMarks(4) <= {"Alice": 13 }
|
||||
*/
|
||||
|
||||
|
||||
async function do_export(api_root, formsemstre_id) {
|
||||
console.log('***************** start *****************');
|
||||
const students = await api.getStudents(api_root, formsemstre_id);
|
||||
console.log('***************** got students *****************');
|
||||
console.log(students)
|
||||
console.log('***************** seeking sems *****************');
|
||||
const student_requests = students.map((student) => {
|
||||
return api.getStudentSems(api_root, student.id);
|
||||
});
|
||||
const sems = await Promise.all(student_requests);
|
||||
debugger;
|
||||
console.log('***************** got sems *****************');
|
||||
const set_sem = new Set(sems.flat());
|
||||
console.log(set_sem)
|
||||
console.log('***************** seeking marks *****************');
|
||||
const studentsGrades = await Promise.all([...set_sem].map(sem => api.getMarks(sem)));
|
||||
debugger;
|
||||
// Expected output: "resolved"
|
||||
}
|
||||
|
||||
|
||||
const api = {
|
||||
getStudents() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(studentsdemo);
|
||||
}, 500);
|
||||
});
|
||||
getStudents(api_root, formsemestre_id) {
|
||||
return fetch(`${api_root}/formsemestre/${formsemestre_id}/etudiants`)
|
||||
.then(response => response.json())
|
||||
},
|
||||
getStudentSems(student) {
|
||||
return new Promise(
|
||||
resolve => { setTimeout(resolve, student.wait, student.sems); }
|
||||
);
|
||||
getStudentSems(api_root, etudid) {
|
||||
return fetch(`${api_root}/etudiant/etudid/${etudid}/formsemestres`)
|
||||
.then(response => response.json())
|
||||
},
|
||||
getMarks(sem_id) {
|
||||
return new Promise(
|
||||
@ -40,80 +58,6 @@ const api = {
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#ok").click(function(){
|
||||
do_export();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function getData() {
|
||||
// let students = api.getStudents()
|
||||
// console.log(students);
|
||||
// let promises =
|
||||
// students.map((student) => api.getStudentSems(student));
|
||||
// return Promise.all(promises);
|
||||
}
|
||||
|
||||
async function asyncCall() {
|
||||
// const sem_requests = new Map();
|
||||
console.log('***************** start *****************');
|
||||
const students = await api.getStudents();
|
||||
console.log('***************** got students *****************');
|
||||
console.log(students)
|
||||
console.log('***************** seeking sems and marks *****************');
|
||||
const student_requests = students.map((student) => {
|
||||
return api.getStudentSems(student);
|
||||
});
|
||||
const sems = await Promise.all(student_requests);
|
||||
const full_sem = sems.flat();
|
||||
const set_sem = [...new Set(full_sem)];
|
||||
const studentsGrades = await Promise.all(set_sem.map(sem => api.getMarks(sem)));
|
||||
debugger;
|
||||
/*
|
||||
console.log("lookup for " + student.name + "'s sems.");
|
||||
const sems = api.getStudentSems(student)
|
||||
console.log(`***************** got ${student.name}'s sems *****************`);
|
||||
console.log(sems);
|
||||
return sems;
|
||||
});
|
||||
const sems.forEach((sem) => {
|
||||
console.log(`looking for mark for sem ${sem}`);
|
||||
console.log("** current sems requests");
|
||||
console.log(sem_requests)
|
||||
if (sem_requests[sem] === 'undefined') {
|
||||
console.log(`seeking ${sem} marks`)
|
||||
|
||||
sem_requests[sem] = api.getMarks(sem);
|
||||
}
|
||||
})
|
||||
|
||||
sems.forEach((sem) => {
|
||||
console.log(`looking for mark for sem ${sem}`);
|
||||
console.log("** current sems requests");
|
||||
console.log(sem_requests)
|
||||
if (sem_requests[sem] === 'undefined') {
|
||||
console.log(`seeking ${sem} marks`)
|
||||
|
||||
sem_requests[sem] = api.getMarks(sem);
|
||||
}
|
||||
})
|
||||
|
||||
let result_sems = await Promise.all(sem_requests)
|
||||
console.log('***************** sems ok *****************');
|
||||
console.log(result_sems);
|
||||
console.log('***************** stop *****************');
|
||||
*/
|
||||
// Expected output: "resolved"
|
||||
}
|
||||
|
||||
function do_export() {
|
||||
event.preventDefault();
|
||||
// students = getData();
|
||||
// console.log(students);
|
||||
asyncCall();
|
||||
}
|
||||
|
||||
// let loaded_sems = [];
|
||||
//
|
||||
// async function doit() {
|
||||
|
@ -9,19 +9,23 @@
|
||||
|
||||
<H1>Export xlsx de fichier de jury</H1>
|
||||
|
||||
<form>
|
||||
<form type="button">
|
||||
<p>Formsemestre: {{ formsemestre.id }}</p><br/>
|
||||
<p>API root: /ScoDoc/{{dept}}/api/</p><br/>
|
||||
<button id="ok">Exporter</button>
|
||||
<button id="ok" type="button">Exporter</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{{super()}}
|
||||
|
||||
<script>
|
||||
let formsemestre_id = {{ formsemestre.id }};
|
||||
let dept = "{{ dept }}";
|
||||
$(document).ready(function() {
|
||||
$("#ok").click(function(){
|
||||
do_export("/ScoDoc/{{dept}}/api", {{formsemestre.id}});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="{{scu.STATIC_DIR}}/js/export-jury-but.js"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user