Published
Edited
Nov 3, 2019
Importers
Insert cell
Insert cell
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
R = import('https://unpkg.com/ramda@0.25.0/es/index.js?module')
Insert cell
num = require('numeraljs')
Insert cell
Insert cell
computeNbOfListingsDistribution = R.compose(
R.map(([nbOfListings, nbOfAgents]) => ({ nbOfListings, nbOfAgents })),
R.toPairs,
R.mapObjIndexed(R.length),
R.groupBy(R.prop('nbOfListings'))
)
Insert cell
Insert cell
computePopulationPercentage = agents => (min = 0, max = Infinity) => R.compose(
R.divide(R.__, agents.length),
R.length,
R.filter(a => a.nbOfListings >= min && a.nbOfListings <= max)
)(agents)
Insert cell
runTiersProjection = ({
agents,
nbOfCustomers,
price: [p1,p2,p3,p4],
pricingTiers,
conversionRate: [cr1,cr2,cr3,cr4]
}) => R.map(([bp1,bp2,bp3]) => {
const cpp = computePopulationPercentage(agents)
return {
Pricing_Strategy: `${bp1}/${bp2}/${bp3}`,
Total_Revenue: num((
cpp(0, bp1) * cr1 * p1 +
cpp(bp1+1, bp2) * cr2 * p2 +
cpp(bp2+1, bp3) * cr3 * p3 +
cpp(bp3+1) * cr4 * p4
) * nbOfCustomers).format('$0,0'),
Tier1: num(cpp(0, bp1)).format('0.0%'),
Tier1_$: num(cpp(0, bp1) * nbOfCustomers * cr1 * p1).format('$0,0'),
Tier2: num(cpp(bp1+1, bp2)).format('0.0%'),
Tier2_$: num(cpp(bp1+1, bp2) * nbOfCustomers * cr2 * p2).format('$0,0'),
Tier3: num(cpp(bp2+1, bp3)).format('0.0%'),
Tier3_$: num(cpp(bp2+1, bp3) * nbOfCustomers * cr3 * p3).format('$0,0'),
Tier4: num(cpp(bp3+1)).format('0.0%'),
Tier4_$: num(cpp(bp3+1) * nbOfCustomers * cr4 * p4).format('$0,0')
}
})(pricingTiers)
Insert cell
computeMinMaxPerSpace = ({price: [p1,p2,p3,p4], pricingTiers}) => R.map(([bp1,bp2,bp3]) => {
return {
Pricing_Strategy: `${bp1}/${bp2}/${bp3}`,
Tier1_Max_$: num(p1).format('$0,0.00'),
Tier1_Min_$: num(p1 / bp1).format('$0,0.00'),
Tier2_Max_$: num(p2 / bp1+1).format('$0,0.00'),
Tier2_Min_$: num(p2 / bp2).format('$0,0.00'),
Tier3_Max_$: num(p3 / bp2+1).format('$0,0.00'),
Tier3_Min_$: num(p3 / bp3).format('$0,0.00'),
Tier4_Max_$: num(p4 / bp3+1).format('$0,0.00')
}
})(pricingTiers)
Insert cell
Insert cell
plot = agents => vl.markBar()
.data(agents)
.encode(
vl.y().count().title('Nb of agents'),
vl.x().fieldQ('nbOfListings').title('Nb of listings per agent'),
vl.tooltip([
{ field: 'nbOfListings', title: 'Nb of listings' },
{aggregate: 'count', title: 'Nb of agents'}
])
)
.width(2000)
.height(400)
.render()
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