Public
Edited
Mar 23, 2024
1 fork
1 star
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataStockSplitByElementByItem = {
// Extract all _primitive_ items.
// This is because aggregates already combine positives and negatives,
// so we have to re-derive them all.
const primaryItemCodes = new Set(itemGroupTypes.items);
let itemEntries = Array.from(
dataForSelectedYearByElementByItem.get("Stock Variation").entries()
).filter(([itemCode]) => primaryItemCodes.has(itemCode));
// the definition of the variable changes from 2010- (FBS), it's the opposite
itemEntries = itemEntries.map(([itemCode, d]) =>
d.year >= 2010 ? [itemCode, d] : [itemCode, { ...d, value: -d.value }]
);
// split into positive and negative
const [pos, neg] = lodash.partition(
itemEntries,
([itemCode, d]) => d.value >= 0
);
// remap negative values into positive
const [stored, used] = [
pos,
neg.map(([itemCode, d]) => [itemCode, { ...d, value: -d.value }])
];
// create new map
const copy = new Map(dataForSelectedYearByElementByItem);
copy.delete("Stock Variation");
copy.set("Stock Variation (stored)", new Map(stored));
copy.set("Stock Variation (used)", new Map(used));
return copy;
}
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
duckdb = {
const client = new DuckDBClient();
// await client.insertCSV(
// "scl_item_codes",
// encoder.encode(d3.csvFormat(scl_item_codes))
// );
await client.query(`
CREATE VIEW fbsc AS SELECT * FROM read_parquet('https://r2.gavrilov.co.uk/faostat_fbsc.parquet');
`);
return client;
}
Insert cell
Insert cell
import { DuckDBClient } from "@cmudig/duckdb"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more