-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from eastanganelli/feature-fullasistancetable
feature complete
- Loading branch information
Showing
7 changed files
with
256 additions
and
259 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
Oops, something went wrong.