Public
Edited
Jan 23, 2024
Insert cell
Insert cell
R00000 = GenerateReqest(DataRequestHeader.map(d=>d.Field), form.threshold);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
basedata
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
CategoryTable
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
// Calculate the privacy profile of all the fields
PrivacyProfile = (function(){
return {
"hashed": null,
table: Object.entries(fields1).map(d=>{
let key = d[0];
d = d[1];
let total = d.total;
let categories = Object.values(d.values).length;
let privFactor = Object.values(d.values)
.map(freq=>1-(1/freq))
.reduce((a,d)=>a+d,0)
/categories
;
let shannon = Object.values(d.values)
.map(freq=>Math.log(freq)/Math.LN2)
.reduce((a,d)=>a+d,0)
/categories
;
let hart = Object.values(d.values)
.map(freq=>Math.log(freq)/Math.LN10)
.reduce((a,d)=>a+d,0)
/categories
;
return {
"Field": key,
"PrivacyFactor": privFactor,
"Shannons": shannon,
"Harts": hart,
"Probability": 1-privFactor,
"Values": total,
"Categories" : categories,
};
})
}
})();
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
PrivacyProfile.table.reduce((a,d)=>{
return a * d.PrivacyFactor
},0);
Insert cell
Insert cell
function GenerateReqest(req = null, threshold = 0.5){
// if nothing specific was requested, make this a randomized selection
if(!req){
let fldprob = Math.ceil(PrivacyProfile.table.length * Math.random()) / PrivacyProfile.length;
req = PrivacyProfile.table.filter(d=>(Math.random()<fldprob)).map(d=>d.Field);
}
// select only the items that actually exist
req = PrivacyProfile.table.filter(d=>req.includes(d.Field)).map(d=>d.Field);

// prepare the return
let rtn = {
req: req
};
// calculate the privacy factor
rtn.score = rtn.req.reduce((a,d)=>a*PrivacyProfile.hashed[d]['PrivacyFactor'],1);
// if the factor is so small as to require a scientific notation, let's just call it zero
// This convention is only in place to make reading the results easier
rtn.score = rtn.score.toString().includes('e') ? 0 : rtn.score;

rtn.threshold = threshold ?? 0.5;
rtn.threshold = Math.max(rtn.threshold,0);
rtn.threshold = Math.min(rtn.threshold,1);
if(rtn.score < rtn.threshold){
rtn.data = null;
return rtn;
}
// get the filtered dataset
rtn.data = basedata.map(d=>{
d = rtn.req.reduce((a,f)=>{
a[f] = d[f];
return a;
},{});
// generate a random id for each record
d = Object.assign({
id: Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(32)
},d);
return d;
});
return rtn;
}

Insert cell
Insert cell
R00001 = GenerateReqest(['gender','age','hobbies']);
Insert cell
Insert cell
R00002 = GenerateReqest(['state','municipality','registered']);
Insert cell
Insert cell
RandomCustomers = Array(100).fill(GenerateReqest).map(d=>d());
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more