Public
Edited
Jan 29, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
survey_data = FileAttachment("survey.xlsx").xlsx();
Insert cell
survey_data.sheet("Personality",{headers:true})
Insert cell
personality_data = survey_data.sheet("Personality",{headers:true})
Insert cell
communication_data = survey_data.sheet("Communication",{headers:true})
Insert cell
skill_data = survey_data.sheet("Skill",{headers:true})
Insert cell
benchmarks_data = survey_data.sheet("Benchmarks",{headers:true})
Insert cell
Insert cell
payload = await JSON.stringify(buildPayload(personality_data, benchmarks_data,communication_data,skill_data,person));
Insert cell
function buildPayload(personality,benchmarks,communication,skill,name) {
const r = personality.filter(d => d.Person === name)[0];
const b = benchmarks.filter(r => r.Group === "Personality");
const c = communication.filter(d => d.Person === name)[0];
const s = skill.filter(d => d.Person === name)[0];
const b2 = benchmarks.filter(r => r.Group === "Skill");
const overallSkill = Object.values(s).filter(value => typeof value === 'number').reduce((acc, val, _, arr) => acc + val / arr.length, 0).toFixed(0) + '%';
const summary = JSON.stringify(c.Summary);
return JSON.parse(`{
"main template datasheet container": {
"p1-dot-plot": [
[ "Personality Trait", "color", "${name}" ],
[ "Assertive", "score", "${r.Assertive}" ],
[ "Resilient", "score", "${r.Resilient}" ],
[ "Adaptable", "score", "${r.Adaptable}" ],
[ "Empathetic", "score", "${r.Empathetic}" ],
[ "Creative", "score", "${r.Creative}" ],
[ "Proactive", "score", "${r.Proactive}" ],
[ "Analytical", "score", "${r.Analytical}" ],
[ "Meticulous", "score", "${r.Meticulous}" ],
[ "Emotionally intelligent", "score", "${r['Emotionally intelligent']}" ],
[ "Reliable", "score", "${r.Reliable}" ],
[ "Organized", "score", "${r.Organized}" ],
[ "Diplomatic", "score", "${r.Diplomatic}" ],
[ "Inspirational", "score", "${r.Inspirational}" ],
[ "Ethical", "score", "${r.Ethical}" ],
[ "Inclusive", "score", "${r.Inclusive}" ],
[ "Assertive", "BM", "${b.filter(r => r.Characteristic === 'Assertive')[0].Benchmark}" ],
[ "Resilient", "BM", "${b.filter(r => r.Characteristic === 'Resilient')[0].Benchmark}" ],
[ "Adaptable", "BM", "${b.filter(r => r.Characteristic === 'Adaptable')[0].Benchmark}" ],
[ "Empathetic", "BM", "${b.filter(r => r.Characteristic === 'Empathetic')[0].Benchmark}" ],
[ "Creative", "BM", "${b.filter(r => r.Characteristic === 'Creative')[0].Benchmark}" ],
[ "Proactive", "BM", "${b.filter(r => r.Characteristic === 'Proactive')[0].Benchmark}" ],
[ "Analytical", "BM", "${b.filter(r => r.Characteristic === 'Analytical')[0].Benchmark}" ],
[ "Meticulous", "BM", "${b.filter(r => r.Characteristic === 'Meticulous')[0].Benchmark}" ],
[ "Emotionally intelligent", "BM", "${b.filter(r => r.Characteristic === 'Emotionally intelligent')[0].Benchmark}" ],
[ "Reliable", "BM", "${b.filter(r => r.Characteristic === 'Reliable')[0].Benchmark}" ],
[ "Organized", "BM", "${b.filter(r => r.Characteristic === 'Organized')[0].Benchmark}" ],
[ "Diplomatic", "BM", "${b.filter(r => r.Characteristic === 'Diplomatic')[0].Benchmark}" ],
[ "Inspirational", "BM","${b.filter(r => r.Characteristic === 'Inspirational')[0].Benchmark}" ],
[ "Ethical", "BM", "${b.filter(r => r.Characteristic === 'Ethical')[0].Benchmark}" ],
[ "Inclusive", "BM", "${b.filter(r => r.Characteristic === 'Inclusive')[0].Benchmark}" ]
],
"p2-pie-top": [
[ "category", "${name}" ],
[ "Graphic", "${c.Graphic}" ],
[ "Data-driven", "${c['Data driven']}" ],
[ "Storytelling", "${c.Storytelling}" ]
],
"p2-pie right": [
[ "category", "${name}" ],
[ "Direct", "${c.Direct}" ],
[ "Diplomatic", "${c.Diplomatic}" ],
[ "Expressive", "${c.Expressive}" ]
],
"p2-pie left": [
[ "category", "${name}" ],
[ "Formal", "${c.Formal}" ],
[ "Informal", "${c.Informal}" ]
],
"p3-left": [
[ "Category", "Capacity to effectively persuade and influence", "Skill in handling sensitive or delicate situations tactfully", "Skill in building and maintaining professional relationships", "Capacity to work effectively in a team environment", "Ability to manage and resolve conflicts in a constructive manner", "Skill in presenting compelling arguments and supporting evidence" ],
[ "benchmark", "${b2.filter(r =>r.Characteristic === 'Persuasion')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Tactfulness')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Relationship building')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Teamwork')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Conflict resolution')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Argumentation')[0].Benchmark}" ],
[ "score", "${s.Persuasion}", "${s.Tactfulness}", "${s['Relationship building']}", "${s.Teamwork}", "${s['Conflict resolution']}", "${s.Argumentation}" ]
],
"p3-right": [
[ "Category", "Skill in negotiating and finding mutually beneficial solutions", "Willingness to share knowledge and resources with colleagues", "Ability to see situations from different perspectives", "Ability to provide appropriate feedback and ask relevant questions", "Ability to leverage networks for personal and organizational growth", "Ability to build consensus and gain support for ideas or initiatives" ],
[ "benchmark", "${b2.filter(r =>r.Characteristic === 'Persuasion')[0].Negotiation}", "${b2.filter(r =>r.Characteristic === 'Collaboration')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Empathy')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Inquiry')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Networking')[0].Benchmark}", "${b2.filter(r =>r.Characteristic === 'Consensus building')[0].Benchmark}" ],
[ "score", "${s.Negotiation}", "${s.Collaboration}", "${s.Empathy}", "${s.Inquiry}", "${s.Networking}", "${s['Consensus building']}" ]
],
"Text": [
[ "Employee", "Year", "Job Match", "Top pie label", "Left Pie label", "Right pie label", "Communication Styles", "Interpersonal skills" ],
[ "${name}", "2023", "${overallSkill}", "Visual", "Verbal", "Written", ${summary} ],
[ "", "", "", "", "", "", "", "" ],
[ "", "", "", "", "", "", "", "" ]
]
}
}`);
}
Insert cell
Insert cell
async function renderWithDatylonServer(user, password, pageUuid, payload, accept = 'image/png') {
const response = await fetch('https://insights.datylon.com/datyrender/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept' : accept,
'Authorization': "Basic " + btoa(user + ":" + password),
'x-graph-template-id': pageUuid,
'x-api-key': '0C8EFCE1-9BE9-4CB9-A74C-14B8B3A28CD6'
},
body: payload
});

console.log(payload);
if (!response.ok) {
console.log(`Renderserver call failed:${response.status}`);
throw new Error(`Failed to render Datylon design. Verify user, password and uuid parameters`);
}

const imageBlob = await response.blob();
const imageUrl = URL.createObjectURL(imageBlob);
return imageUrl;
}

Insert cell
Insert cell
async function fetchAsPdf(datylonUser, datylonPassword, payload) {
let p1 = await renderWithDatylonServer(datylonUser, datylonPassword, datylonUuid1, payload, 'application/pdf');
let p2 = await renderWithDatylonServer(datylonUser, datylonPassword, datylonUuid2, payload, 'application/pdf');
let p3 = await renderWithDatylonServer(datylonUser, datylonPassword, datylonUuid3, payload, 'application/pdf');
let res = await concatenatePDFs([p1,p2,p3], PDFLib.PDFDocument);
concatenatePDFs([p1,p2,p3], PDFLib.PDFDocument).then(url => {
const a = document.createElement('a');
a.href = url;
a.download = person +'.pdf';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
document.body.removeChild(a);
});
}
Insert cell
PDFLib = require('pdf-lib@1.16.0/dist/pdf-lib.min.js');

Insert cell
async function concatenatePDFs(urls, PDFDocument) {
const concatenatedPdfDoc = await PDFDocument.create();

for (const url of urls) {
const pdfBytes = await fetch(url).then(res => res.arrayBuffer());
const pdfDoc = await PDFDocument.load(pdfBytes);
const pages = await concatenatedPdfDoc.copyPages(pdfDoc, pdfDoc.getPageIndices());
pages.forEach(page => concatenatedPdfDoc.addPage(page));
}

const mergedPdfBytes = await concatenatedPdfDoc.save();
const pdfBlob = new Blob([mergedPdfBytes], { type: 'application/pdf' });
const pdfUrl = URL.createObjectURL(pdfBlob);

return pdfUrl;
}
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