Created
October 23, 2019 23:17
-
-
Save lucis/785118c687c5072b0c1ff476622c78f6 to your computer and use it in GitHub Desktop.
Gera CSV a partir da tabela de notas de uma turma do Controle Acadêmico na UFCG
This file contains hidden or 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
const getCSVNotas = table=>{ | |
const SEP = ';' | |
const quantasNotas = row=>[...row.querySelectorAll('th')].map(th=>th.innerText).reduce((count,text)=>count + (text.includes('Nota') ? 1 : 0), 0) | |
const arrayOf = n=>[...Array(n).keys()] | |
const getLinhaAluno = (row,notas)=>{ | |
const tds = row.querySelectorAll('td'); | |
const it = el=>el.innerText | |
const extractFromInput = td=>td.querySelector('input').value | |
const linhaNotas = arrayOf(notas).map((_,i)=>extractFromInput(tds[i + 3])) | |
return [it(tds[1]), it(tds[2]), ...linhaNotas].join(SEP) + SEP | |
} | |
const trs = table.querySelectorAll('tr') | |
const nNotas = quantasNotas(trs[0]) | |
const header = `matricula;nome;${arrayOf(nNotas).map((_,i)=>`nota${i + 1}`).join(SEP)}${SEP}final` | |
const linhasNotas = [...trs].splice(1).map(tr=>getLinhaAluno(tr, nNotas)) | |
return [header, ...linhasNotas].join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment