Skip to content

Commit

Permalink
Merge pull request #13 from eastanganelli/feature-fullasistancetable
Browse files Browse the repository at this point in the history
feature complete
  • Loading branch information
eastanganelli authored Sep 5, 2023
2 parents 9df8d69 + 4c59061 commit 3905219
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 259 deletions.
67 changes: 0 additions & 67 deletions controllers/addmember/addmember.html

This file was deleted.

31 changes: 0 additions & 31 deletions controllers/addmember/addmember.js

This file was deleted.

2 changes: 1 addition & 1 deletion controllers/github/github.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { iri, lpii } = require('./../subjects.controller');
const { iri, lpii } = require('./../student/subjects.controller');
const GitHubInvite = (req, res) => {
const subjectFilter = Number(req.query.subject);
const mailFilter = req.query.mail;
Expand Down
50 changes: 44 additions & 6 deletions controllers/status/status.controller.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
const { iri, lpii } = require('./../subjects.controller');
const { iri, lpii } = require('./../student/subjects.controller');

const StudentStatus = (req, res) => {
const subjectFilter = Number(req.query.subject);
const studentFilter = req.query.student;

console.log('Hello Api');
const streaming = false //|| process.env.STREAMING;

let subject_ = null;

switch(subjectFilter) {
case 1: {
subject_ = new iri();
subject_.studentData(studentFilter).then((data) => {
res.status(200).send(data);
subject_.studentData(studentFilter).then((student) => {
res.status(200).send(`
<div class="card">
<div class="card-header">
<h5 ${streaming ? 'aria-hidden="true"' : ''} class="card-title placeholder-glow"><span class="${streaming ? 'placeholder' : ''}"">${student['name']} ${student['lastname']}</span></h5>
<h6 ${streaming ? 'aria-hidden="true"' : ''} class="card-subtitle mb-2 text-body-secondary placeholder-glow"><span class="${streaming ? 'placeholder' : ''}">${student['dni']}</span></h6>
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>Notas</p>
<footer class="blockquote-footer">${student['notes']['exam_i']} ${student['notes']['exam_ii']} ${student['notes']['final_tp']}</footer>
</blockquote>
<blockquote class="blockquote mb-0">
<p>Porcentaje de Asistencia Teórica: ${student['assistance']['asist_t']['porcent']}</p>
<footer class="blockquote-footer">${student['assistance']['asist_t']['table']}</footer>
</blockquote>
<blockquote class="blockquote mb-0">
<p>Porcentaje de Asistencia Práctica: ${student['assistance']['asist_p']['porcent']}</p>
<footer class="blockquote-footer">${student['assistance']['asist_p']['table']}</footer>
</blockquote>
</div>
</div>
`);
}).catch((err) => {
res.status(403).send(err);
});
break;
}
case 2: {
subject_ = new lpii();
subject_.studentData(studentFilter).then((data) => {
res.status(200).send(data);
subject_.studentData(studentFilter).then((student) => {
res.status(200).send(`
<div class="card">
<div class="card-header">
<h5 ${streaming ? 'aria-hidden="true"' : ''} class="card-title placeholder-glow"><span class="${streaming ? 'placeholder' : ''}"">${student['name']} ${student['lastname']}</span></h5>
<h6 ${streaming ? 'aria-hidden="true"' : ''} class="card-subtitle mb-2 text-body-secondary placeholder-glow"><span class="${streaming ? 'placeholder' : ''}">${student['dni']}</span></h6>
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>Notas</p>
<footer class="blockquote-footer">${student['notes']['exam_i']} ${student['notes']['exam_ii']} ${student['notes']['final_tp']}</footer>
</blockquote>
<blockquote class="blockquote mb-0">
<p>Porcentaje de Asistencia: ${student['asistance']['asist']['porcent']}</p>
<footer class="blockquote-footer">${student['asistance']['asist']['table']}</footer>
</blockquote>
</div>
</div>
`);
}).catch((err) => {
res.status(403).send(err);
});
Expand Down
74 changes: 74 additions & 0 deletions controllers/student/subject.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const { GoogleSpreadsheet, GoogleSpreadsheetRow } = require('google-spreadsheet');
const { Octokit } = require("octokit");

const SheetsOfInterest = ["Estados", "Teoria", "Practica"];

class materia {
constructor() {
this._MySheets = new Array(); // Array of Worksheets
}
static async _getSheets(idSheets = []) {
let returnSheets = [];
for (let idSheet of idSheets) {
const doc = new GoogleSpreadsheet(idSheet, { apiKey: process.env.GKEY });
await doc.loadInfo();
for (let hoja of SheetsOfInterest) {
let hojaTrabajo = doc.sheetsByTitle[hoja];
if (hojaTrabajo != undefined)
returnSheets.push(hojaTrabajo);
}
}
return returnSheets;
}
static _badgeExam(note, name) {
const status = note == 'A' ? 'success' : note == 'I' ? 'danger' : 'info';
const noteStr = note == 'A' ? 'Aprobado' : 'Desaprobado';

return `<span class="badge text-bg-${status}">${name}: ${note == '' ? 'Sin Nota' : noteStr}</span>`;
}
static _badgeAsis(porcen) {
const aux = Number(porcen.slice(0, porcen.length - 1));
const status = aux >= 93.75 ? 'success' : aux >= 81.25 ? 'warning' : 'danger';

return `<span class="badge text-bg-${status}">${aux} %</span>`;
}
static _GitHubInviteOrg(org, year, studentmail) {
return new Promise((resolve, reject) => {
const octokit = new Octokit({
auth: process.env.GHKEY
});

octokit.request('GET /orgs/{org}/teams/{team_slug}', {
org: `UF-${org}`,
team_slug: `Alumnos-${year}`
}).then((organization) => {
octokit.request('POST /orgs/{org}/invitations', {
org: `UF-${org}`,
email: studentmail,
team_ids: [ organization['data']['id'] ]
}).then((invite) => {
resolve(invite);
}).catch(err => { reject(err); });
}).catch(err => { reject(err); });
});
}
static _asistanceTable(asistRow) {
let asistlist = new Array();

try {
Object.entries(asistRow.toObject()).reverse().forEach(([key, value]) => {
if (key === '%')
throw 'break';

const status = value == 'P' ? 'success' : value == 'A' ? 'danger' : value == 'J' ? 'info' : 'light';

asistlist.push(`<span class="badge text-bg-${status}">${key == undefined ? 'Sin Datos' : key}</span>`);
});
} catch (e) {
//console.log(e);
}
return asistlist.reverse().toString().split(',').join(' ');
}
};

module.exports = materia;
137 changes: 137 additions & 0 deletions controllers/student/subjects.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const materia = require('./subject.controller');

class iri extends materia {
constructor() {
super();
this._MySheets = materia._getSheets((String(process.env.IRI)).split(' '));
}
studentData(data) {
return new Promise((resolve, reject) => {

let myStudent = {
'status': null,
'assistance_t': null,
'assistance_p': null
};

this._MySheets.then(async hojas => {
const sheetEstado = hojas[0],
sheetAsisT = hojas[1],
sheetAsisP = hojas[2];

(await sheetEstado.getRows()).find((row) => {
if (row.get('DNI') == data || row.get('Mail') == data) {
myStudent['status'] = row;
return true;
}
});

(await sheetAsisT.getRows()).find((row) => {
if (row.get('DNI') == data || row.get('Mail') == data) {
myStudent['assistance_t'] = row;
return true;
}
});

(await sheetAsisP.getRows()).find((row) => {
if (row.get('DNI') == data || row.get('Mail') == data) {
myStudent['assistance_p'] = row;
return true;
}
});

if (myStudent.status == null)
reject(`No se encontró el estudiante`);

resolve({
'name': myStudent['status'].get('Nombre'),
'lastname': myStudent['status'].get('Apellido'),
'dni': myStudent['status'].get('DNI'),
'notes': {
'exam_i': materia._badgeExam(myStudent['status'].get('1er Parcial'), '1er Parcial'),
'exam_ii': materia._badgeExam(myStudent['status'].get('2do Parcial'), '2do Parcial'),
'final_tp': materia._badgeExam(myStudent.status.get('TP Final'), 'TP Final')
},
'assistance': {
'asist_t': {
'porcent': materia._badgeAsis(myStudent['status'].get('T Asist')),
'table': materia._asistanceTable(myStudent['assistance_t'])
},
'asist_p':{
'porcent': materia._badgeAsis(myStudent['status'].get('P Asist')),
'table': materia._asistanceTable(myStudent['assistance_p'])
}
}
});
});

});
}
InviteToOrg(Mail) {
return materia._GitHubInviteOrg('IRI', (new Date()).getFullYear(), Mail);
}
};

class lpii extends materia {
constructor() {
super();
this._MySheets = materia._getSheets((String(process.env.LPII)).split(' '));
}
studentData(data) {
return new Promise((resolve, reject) => {

let myStudent = {
'status': null,
'assistance': null
};

this._MySheets.then(async hojas => {
const sheetEstado = hojas[0],
sheetAsis = hojas[1];

(await sheetEstado.getRows()).find((row) => {
if (row.get('DNI') == data || row.get('Mail') == data) {
myStudent['status'] = row;
return true;
}
});

(await sheetAsis.getRows()).find((row) => {
if (row.get('DNI') == data || row.get('Mail') == data) {
myStudent['assistance'] = row;
return true;
}
});

if (myStudent == null)
reject(`No se encontró el estudiante`);

resolve({
'name': myStudent['status'].get('Nombre'),
'lastname': myStudent['status'].get('Apellido'),
'dni': myStudent['status'].get('DNI'),
'notes': {
'exam_i': materia._badgeExam(myStudent['status'].get('1er Parcial'), '1er Parcial'),
'exam_ii': materia._badgeExam(myStudent['status'].get('2do Parcial'), '2do Parcial'),
'final_tp': materia._badgeExam(myStudent['status'].get('TP Final'), 'TP Final')
},
'asistance': {
'asist': {
'porcent': materia._badgeAsis(myStudent['status'].get('Asist')),
'table': materia._asistanceTable(myStudent['assistance'])
}
}
});
});

});
}
InviteToOrg(Mail) {
return materia._GitHubInviteOrg('LP2', (new Date()).getFullYear(), Mail);
}
};

module.exports = {
iri,
lpii
};
Loading

0 comments on commit 3905219

Please sign in to comment.