Public
Edited
Jan 12, 2024
Insert cell
Insert cell
viewof password = Inputs.password({label: "Password"})
Insert cell
viewof person = Inputs.select(googleSheet.personality.map(r => r.Person), {label: "Select person"})
Insert cell
html`
<div style="display: flex; justify-content: space-around;">
<img src="${await fetchAndDisplayImage("getsupport+demo@datylon.com", password, pageUuids[0], payload)}" style="max-width: 33%;">
<img src="${await fetchAndDisplayImage("getsupport+demo@datylon.com", password, pageUuids[1], payload)}" style="max-width: 33%;">
<img src="${await fetchAndDisplayImage("getsupport+demo@datylon.com", password, pageUuids[2], payload)}" style="max-width: 33%;">
</div>
`
Insert cell
xlsx = require("xlsx");
Insert cell
pageUuids = [
"c1236f1c-2029-4535-96af-039355fe3fca",
"936959ba-fbed-4900-a509-405a2d9ef9e0",
"b5602bd0-7bf5-49ac-ac4e-957a20713f89"
];
Insert cell
googleSheet = await loadGoogleSheet("https://docs.google.com/spreadsheets/d/1v5_4rp7zrflnroCLDvIHrDYXedX0GoJw/export?format=xlsx");
Insert cell
async function loadGoogleSheet(url) {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const workbook = xlsx.read(arrayBuffer, { type: 'buffer' });
const personality = xlsx.utils.sheet_to_json(workbook.Sheets.Personality);
const communication = xlsx.utils.sheet_to_json(workbook.Sheets.Communication);
const skill = xlsx.utils.sheet_to_json(workbook.Sheets.Skill);
const benchmarks = xlsx.utils.sheet_to_json(workbook.Sheets.Benchmarks);
return {
"personality": personality,
"communication": communication,
"skill": skill,
"benchmarks": benchmarks
}
}
Insert cell
function buildPayload2(googleSheet,selectedPerson) {
const payload = JSON.stringify(buildPayload(
googleSheet.personality,
googleSheet.benchmarks,
googleSheet.communication,
googleSheet.skill,
selectedPerson))
return payload;
}
Insert cell
payload = await buildPayload2(googleSheet,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
async function fetchAndDisplayImage(user, password, pageUuid, payload) {
const response = await fetch('https://insights.datylon.com/datyrender/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept' : 'image/png',
'Authorization': "Basic " + btoa(user + ":" + password),
'x-graph-template-id': pageUuid,
'x-api-key': '0C8EFCE1-9BE9-4CB9-A74C-14B8B3A28CD6'
},
body: payload
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

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


Insert cell
survey_data = FileAttachment("survey@1.xlsx").xlsx();
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
Inputs.table(personality_datal)
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