Public
Edited
Oct 7, 2023
Insert cell
Insert cell
// rlju2 = require(`${localUrl}?${refresh}${Date.now()}`)
Insert cell
rlju = require("@robinl/record_linkage_javascript_utilities@0.0.8")
Insert cell
viewof refresh = Inputs.button("refresh splink_vis_utils javascript lib")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function createColouredTable(arrayOfDicts, colourMapping) {
const rgbaMapping = {};

colourMapping.domain.forEach((key, i) => {
rgbaMapping[key] = [
hexToRgba(colourMapping.range[i], 0.35),
hexToRgba(colourMapping.range[i], 0.1)
];
});

// Create header
const headerKeys = Object.keys(arrayOfDicts[0]);
const thead = `<tr>${headerKeys
.map((key) => {
const colorKey = colourMapping.domain.find((d) => key.includes(d));
const bgColor = colorKey ? rgbaMapping[colorKey][0] : "";
return `<th style='background-color:${bgColor};'>${key}</th>`;
})
.join("")}</tr>`;

const rows = arrayOfDicts
.map((row) => {
return `<tr>${headerKeys
.map((key) => {
const value = row[key];
let bgColor = "";

if (key.includes("final_match_weight")) {
bgColor = getColorForFinalMatchWeight(value);
} else if (key.includes("match_probability")) {
bgColor = getColorForMatchProbability(value);
} else {
const colorKey = colourMapping.domain.find((d) => key.includes(d));
bgColor = colorKey ? rgbaMapping[colorKey][1] : "";
}

return `<td style='background-color:${bgColor};'>${value}</td>`;
})
.join("")}</tr>`;
})
.join("");

return `<table>${thead}${rows}</table>`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cv_with_model_params
Insert cell
cv_with_model_params = rlju.addModelParametersToComparisonVector(
comparison_vector,
settings
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
prior_ω = rlju.convertMatchScoreMetrics.calcPartialMatchWeightFromProbability(
settings.probability_two_random_records_match
)
Insert cell
settings = rlju.tutorial_partial_match_weights_settings
Insert cell
function getColorForFinalMatchWeight(value) {
const normalizedValue = Math.max(Math.min(value, 10), -10) / 10;
const greenComponent = Math.floor(128 + 127 * normalizedValue);
const redComponent = Math.floor(128 - 127 * normalizedValue);
return `rgba(${redComponent}, ${greenComponent}, 128, 0.35)`;
}
Insert cell
function getColorForMatchProbability(value) {
const normalizedValue = Math.max(Math.min(value, 1), 0);
const greenComponent = Math.floor(128 * 127 * normalizedValue);
const redComponent = Math.floor(128 * 127 * (1 - normalizedValue));
return `rgba(${redComponent}, ${greenComponent}, 128, 0.35)`;
}
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