Published
Edited
Nov 25, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
/* normally, you would set the API key like:
* apiKey: Secret("ods-exchange-se")
* using this more-elaborate structure to enable
* interactive validation of the client
*/
client = new ods.ApiClient({
domain: "exchange-schneider-electric",
apiKey: (() => {
try {
return Secret("ods-exchange-se");
} catch {
return "";
}
})()
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
respTop = client.get("")
Insert cell
Insert cell
Insert cell
client.defaultConfig.baseUrl
Insert cell
Insert cell
respDatasets = client.get("catalog/datasets/")
Insert cell
Insert cell
Insert cell
Insert cell
queryDatasets = ods.fromCatalog().datasets()
Insert cell
Insert cell
queryDatasets.toString()
Insert cell
Insert cell
client.get(queryDatasets)
Insert cell
Insert cell
queryRecordsBuilding = ods
.fromCatalog()
.dataset("building-energy-consumption-prediction")
.records()
.orderBy("datetime")
.limit(100)
Insert cell
Insert cell
queryRecordsBuilding.toString()
Insert cell
Insert cell
respBuilding = client.get(queryRecordsBuilding)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof notebookSecretValid = isNotebookSecretValid()
Insert cell
notebookSecretValid
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof clientValid = odsPlus.isClientValid(client)
Insert cell
clientValid
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
q = odsPlus.queryCreate(
"https://documentation-resources.opendatasoft.com/api/v2/catalog/aggregates?select=count(*)&group_by=features"
)
Insert cell
Insert cell
q.orderBy("-count(*)")
Insert cell
Insert cell
queryDatasets.toString()
Insert cell
Insert cell
respDatasets // called using client.get("catalog/datasets/")
Insert cell
Insert cell
respDatasets.datasets
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getPageMeta = odsPlus.makeGetPageMeta(client)
Insert cell
getPageMeta(queryDatasets)
Insert cell
Insert cell
getPageBind = odsPlus.makeGetPageBind(client)
Insert cell
Insert cell
bindDatasets = getPageBind(queryDatasets)
Insert cell
bindRecordsBuiding = getPageBind(queryRecordsBuilding, 1000) // limit to 1000 records
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
extractDataset(bindDatasets[0])
Insert cell
Insert cell
bindDatasets.map(odsPlus.extractDataset)
Insert cell
bindRecordsBuiding.map(odsPlus.extractRecord)
Insert cell
Insert cell
Insert cell
Insert cell
fields = bindDatasets[0].dataset.fields
Insert cell
fields.map((x) => x.type)
Insert cell
fields.map(odsPlus.isTypeTemporal)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
clientStatus(client) // if client is valid, returns "working"
Insert cell
{
const clientBadKey = new ods.ApiClient({
domain: "https://schneider-electric.opendatasoft.com",
apiKey: ""
});
return clientStatus(clientBadKey);
}
Insert cell
Insert cell
Insert cell
Insert cell
baseUrl = "https://foo.opendatasoft.com/api/v2/"
Insert cell
Insert cell
clientMessage(baseUrl, "working")
Insert cell
clientMessage(baseUrl, "auth")
Insert cell
clientMessage(baseUrl, "fetch")
Insert cell
clientMessage(baseUrl, "default")
Insert cell
Insert cell
Insert cell
Insert cell
notebookSecretStatus()
Insert cell
Insert cell
Insert cell
Insert cell
notebookSecretMessage(true)
Insert cell
notebookSecretMessage(false)
Insert cell
Insert cell
Insert cell
Insert cell
queryParse("catalog/datasets?limit=100")
Insert cell
queryParse("https://foo.opendatasoft.com/catalog/datasets?limit=100")
Insert cell
Insert cell
Insert cell
Insert cell
isPagedResponse(respDatasets)
Insert cell
isPagedResponse(respTop)
Insert cell
Insert cell
Insert cell
import { toc } from "@nebrius/indented-toc"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ods = import("https://cdn.skypack.dev/@opendatasoft/api-client@0.3.0")
Insert cell
Insert cell
odsPlus = ({
isClientValid: isClientValid,
isNotebookSecretValid: isNotebookSecretValid,
queryCreate: queryCreate,
makeGetPageMeta: makeGetPageMeta,
makeGetPageBind: makeGetPageBind,
extractDataset: extractDataset,
extractRecord: extractRecord,
isTypeTemporal: isTypeTemporal
})
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