Public
Edited
Dec 18
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
html`<div class="inline-buttons"><em>&nbsp;If you get a status message indicating <code>Job still processing</code> just wait a few seconds and press this button. &nbsp;<br><br></em></div>${viewof requestResult}`
Insert cell
Insert cell
kpiStats = {
let deliveryCount = 0;
checkStatus.result.routes.forEach((rte, rteidx) => {
rte.steps.forEach((step, index) => {
if (step.id && step.id != 99) {
++deliveryCount;
}
});
});
return {
totalDistance: `${(checkStatus.result.summary.distance/1000).toFixed(1)} km`,
totalTime: `${(checkStatus.result.summary.duration/60).toFixed(1)} mn`,
nbrRoutes: checkStatus.result.summary.routes,
avgStops: (deliveryCount/checkStatus.result.summary.routes).toFixed(1)
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
return geoviewer(routesFiltered, {
width: 550,
height: 550,
col: "#8058a0",
fillOpacity: 0.9,
lineWidth: 3,
style: "nbai",
apiKey: apiKey
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { nextbillion, cities, secret2 } from "@nbai/nextbillion-ai-dependencies"
Insert cell
Insert cell
geoviewer = require("https://d12qcqjlhp2ahm.cloudfront.net/nb_geoverview2.js").then((f) => f.view)
Insert cell
html`${viewof requestResult}`
Insert cell
viewof requestResult = Inputs.button("Request Result")
Insert cell
mutable inputData_a = null
Insert cell
useCases = [{ name: "Service Worker", value: "service" }]
Insert cell
vehicle_profile2 = ["mini_van", "car"]
Insert cell
vehicle_profile1 = ["Light Duty Truck", "Medium Duty Truck", "Heavy Duty Truck"]
Insert cell
hazmat_type = ["general", "circumstantial", "explosive", "harmful_to_water"]
Insert cell
objectives = [
{name: "Minimize Time", value: "duration"},
{name: "Minimize Distance", value: "distance"}
]
Insert cell
inputs = {
const offset = new Date().getTimezoneOffset();
let newBase = new Date(new Date().getTime() + 86400 * 1000);

let tmrwStart = new Date(
`${newBase.toLocaleDateString("en-US")} 06:00:00 GMT${
offset >= 0 ? "+" : ""
}${Math.round(offset / 60)}${
Math.abs(offset % 60) ? Math.abs(offset % 60) : ""
}`
);

let tmrwEnd = new Date(
`${newBase.toLocaleDateString("en-US")} 09:00:00 GMT${
offset >= 0 ? "+" : ""
}${Math.round(offset / 60)}${
Math.abs(offset % 60) ? Math.abs(offset % 60) : ""
}`
);

console.log(tmrwEnd.toISOString().slice(0, -5));
const inputs = {
city: Inputs.select(cities, {
label: "Select city",
format: (x) => x.name,
value: cities.find((t) => t.name === "Los Angeles")
}),

truck: Inputs.text({
readonly: false,
label: "Number of Vehicles",
placeholder: "Count"
}),
truck_profile: Inputs.select(vehicle_profile1, {
readonly: false,
label: "Vehicle Profile1"
}),

minivan: Inputs.text({
readonly: false,
label: "Number of Vehicles",
placeholder: "Count"
}),
minivan_profile: Inputs.select(vehicle_profile2, {
readonly: false,
label: "Vehicle Profile2"
}),

jobs: Inputs.text({
readonly: false,
label: "Number of jobs",
value: "10"
}),

trucksize: Inputs.text({
readonly: false,
label: "Truck Size",
placeholder: "centimeters, in the format of “H,W,L”"
}),

truckweight: Inputs.number({
readonly: false,
label: "Truck Weight",
placeholder: "in kilograms"
}),

hazmat_type: Inputs.select(hazmat_type, {
readonly: false,
label: "hazmat_type",
placeholder: "select hazardous type"
}),

shiftStart: Inputs.datetime({
label: "Shift Start",
value: tmrwStart.toISOString().slice(0, -1)
}),

shiftEnd: Inputs.datetime({
label: "Shift End",
value: `${tmrwEnd.toISOString().slice(0, -1)}`
}),

useCase: Inputs.select(useCases, {
label: "Use Case",
format: (x) => x.name,
value: useCases.find((t) => t.name === "service")
}),

objectiveFunction: Inputs.select(objectives, {
label: "Objective Function",
format: (x) => x.name,
value: objectives.find((t) => t.name === "Minimize Time")
}),

serviceTime: Inputs.text({
label: "Service Time at Each Stop",
value: "300"
})
};
return inputs;
}
Insert cell
routesGeoJson = {
let routesGeoJson = {
type: 'FeatureCollection',
features: []
};

// we create a geojson object to send to our mapview elements
// It will be a feature collection of all the route polylines
checkStatus.result.routes.forEach((rte,idx) => {
//console.log(rte);
let feature = {
type: 'Feature',
properties: {
id: rte.vehicle,
vin: rte.description
},
geometry: {
coordinates: nextbillion.utils.polyline.decode(rte.geometry,5)
.map((c) => c.reverse()),
type: 'LineString'
}
}
routesGeoJson.features.push(feature);
rte.steps.forEach((st,stIdx) => {
let stop = {
type: 'Feature',
properties: {
id: rte.vehicle,
vin: rte.description,
description: st.description,
stop_idx: stIdx,
arrival: st.arrival,
type: st.type,
pointType: ((st.type == "start"|st.type == "end")?16:255)
},
geometry: {
coordinates: [st.location[1],st.location[0]],
type: 'Point'
}
}
routesGeoJson.features.push(stop);
})
});
console.log(routesGeoJson);
return routesGeoJson;
}
Insert cell
routesFiltered = Object({
type: 'FeatureCollection',
features: routesGeoJson.features.filter(f => f.properties.vin === routeSelector.properties.vin)
});
Insert cell
import { toc } from "@nebrius/indented-toc" // This component generates the Table of Contents
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