Published
Edited
Jun 14, 2021
1 fork
Importers
Insert cell
Insert cell
clientes_cell=clientes
.derive({cell:aq.escape(d=>random_cell_number()),
nascimento:d=>op.format_utcdate(d.nascimento,false)})
Insert cell
Inputs.table(clientes_cell)
Insert cell
download_csv(clientes_cell,"clientes_cell.csv")
Insert cell
clientes = aq.fromCSV(await FileAttachment("clientes_final.csv").text(),{delimiter:";"})
Insert cell
viewof estados_count = clientes
.groupby('estado')
.count()
.view()
Insert cell
ref_estados=aq.table({estado:clientes.groupby('estado').count().columnArray('estado').sort()})
Insert cell
download_csv(ref_estados,'ref_estados.csv')
Insert cell
JSON.stringify(estados_count.columnArray('estado').sort())
Insert cell
ref_cidades=aq.table({cidade:clientes.groupby('cidade').count().columnArray('cidade').sort()})
Insert cell
download_csv(ref_cidades,'ref_cidades.csv')
Insert cell
Insert cell
ddds = aq.loadCSV(gs_ddds)
Insert cell
Insert cell
Insert cell
Inputs.table(clients_dirty.objects())
Insert cell
random_cell_number()
Insert cell
random_cell_number = function() {
// (21) 21 46 46 32
// (21) 9 33 44 11 44
// +55 21 933223344
// 5521 933223344
// 92345-2222
const i_ddd = Math.floor(Math.random()*ddds.numRows())
const ddd = ddds.column('prefixo').get(i_ddd);
let digs = [];
for(let i = 0; i < 8; i++)
digs.push(1+Math.floor(Math.random()*9));
const digs_join = digs.join('');
const cell = `(${ddd}) 9${digs_join.slice(0,4)}-${digs_join.slice(-4)}`;
return cell;
}
Insert cell
Insert cell
dt_clients =aq.loadCSV(gs_clients)
Insert cell
dt_clients_cpf=dt_clients
.derive({cpf:aq.escape(d=>Math.random()<.01?null:Math.random()<.05?cpf.novo_invalido(Math.random()<.3):cpf.novo(Math.random()<.3))})
Insert cell
Inputs.table(dt_clients_cpf.objects())
Insert cell
download_csv(dt_clients_cpf,'dt_clients.csv')
Insert cell
Insert cell
remove_non_digits = function(str) {
return str.replace(/\D/g,'');
}
Insert cell
cpf = class {
static gera_random(n) {
var ranNum = Math.round(Math.random()*n);
return ranNum;
}

static mod(dividendo,divisor) {
return Math.round(dividendo - (Math.floor(dividendo/divisor)*divisor));
}
static novo_invalido(separadores) {
var n = 9;
var n1 = this.gera_random(n);
var n2 = this.gera_random(n);
var n3 = this.gera_random(n);
var n4 = this.gera_random(n);
var n5 = this.gera_random(n);
var n6 = this.gera_random(n);
var n7 = this.gera_random(n);
var n8 = this.gera_random(n);
var n9 = this.gera_random(n);
var d1 = this.gera_random(n);
var d2 = this.gera_random(n);

if (separadores)
return ''+n1+n2+n3+'.'+n4+n5+n6+'.'+n7+n8+n9+'-'+d1+d2;
else
return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+d1+d2;
}
static novo(separadores) {
var n = 9;
var n1 = this.gera_random(n);
var n2 = this.gera_random(n);
var n3 = this.gera_random(n);
var n4 = this.gera_random(n);
var n5 = this.gera_random(n);
var n6 = this.gera_random(n);
var n7 = this.gera_random(n);
var n8 = this.gera_random(n);
var n9 = this.gera_random(n);
var d1 = n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
d1 = 11 - (this.mod(d1,11));
if (d1>=10) d1 = 0;
var d2 = d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
d2 = 11 - (this.mod(d2,11));
if (d2>=10) d2 = 0;

if (separadores)
return ''+n1+n2+n3+'.'+n4+n5+n6+'.'+n7+n8+n9+'-'+d1+d2;
else
return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+d1+d2;
}
static validar(cpf) {
if (cpf===null)
return false;
cpf = remove_non_digits(cpf);
if (cpf.length != 11 || ["00000000000","11111111111","22222222222","33333333333",
"44444444444","55555555555","66666666666","77777777777",
"88888888888","99999999999"].includes(cpf))
return false;

let add = 0;

for (let i = 0; i < 9; i++)
add += parseInt(cpf.charAt(i)) * (10 - i);
let rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (let i = 0; i < 10; i++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
alert('O CPF INFORMADO É VÁLIDO.');
return true;
}
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more