Public
Edited
Jun 8
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/2025-03-17/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

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