Querying Accounting Data
Overview
Sales Data
The sale data consists of a series of records that contains the salesperson and a dollar amount of sales.
Categorizing and Querying Categorical Data
Once we have a tree of sales people and managers, we can now easily query the data for information that we
desire. For instance, consider a set of sales data, such as the follwoing:
const $tree = await import("/lib/tree/v1.0.0/tree-map.mjs");
let treemap = $tree.fromArray(salesteam, p=>p.name, p=>p.manager);
Next, we can use the standard array function, filter, to get a list of all the sales that attributable to gary.
In addition, we use the treemap created above to filter for all sales that roll up to jane as the sales manager.
let garySales = sales.filter(p=>p.name === 'gary');
let janeSales = sales.filter(p=>{
let salesperson = treemap[p.name];
if(salesperson.ancestors["jane"] !== undefined) return true;
return false;
});
Try it!