JsonProject.loadProfile#

Reads per-bucket load and capacity of resources on the solved baseline of a JsonProject. The project isn't modified. Needs a solved project with no edits applied since the last solve or level. For the load of hypothetical dates, use preview with a profile query instead.

Signature#

loadProfile(options_json: string): string

Synchronous and read-only. Bad input comes back as an error envelope. The call doesn't throw.

Request#

Argument Payload Required Description
options_json LoadProfileOptions yes Range, resources, bucket size, task lists and an optional baseline check

LoadProfileOptions#

The options object for loadProfile. All fields sit at the top level. from and to are required, every other field can be omitted. Unknown fields are rejected with a parse error.

Field Type Required Default Description
from DateValue yes - Start of the range. A bucket is included when its start is at or after from
to DateValue yes - End of the range, exclusive. Must be after from
resources Id[] no all resources, in input order Resource ids to measure, in the order given
basis "hour" | "day" no derived from config.duration_unit Bucket size: "hour" or "day"
tasks string no "none" Task ids per bucket: "none" (no tasks field), "overallocated" (ids only in buckets with load > capacity, [] elsewhere) or "all" (every booked task)
baselineId string no absent (not checked) Must name the current baseline, or the call fails with stale-baseline

null on any optional field reads as its default. Dates follow the wire format.

preview takes the same fields as its profile query, a ProfileQuery, except baselineId.

Response#

The success envelope carries a LoadProfile: the basis used and one entry per resource with its buckets. Envelope shape: Wire format.

Errors#

Kind Code When
project no-baseline The project has never been solved, or apply ran since the last solve
project stale-baseline baselineId doesn't name the current baseline
validation null to isn't after from, or the range has more than 100 000 buckets per resource (path to); an unknown resource id (path resources); a tasks or basis value outside its list, or an invalid date (path null)
parse null Malformed JSON, a missing from or to, or an unknown field

Example#

Print the overloaded days of a resource that works on two tasks at once, with the tasks that fill them.

const { JsonProject } = require("./pkg-node/plen_wasm.js");

const data = {
  config: { use_calendars: false },
  tasks: [
    { id: "a", start_date: "2026-01-01", duration: 2 },
    { id: "b", start_date: "2026-01-02", duration: 2 },
  ],
  resources: [{ id: "dev" }],
  assignments: [
    { task: "a", resource: "dev", value: 1 },
    { task: "b", resource: "dev", value: 1 },
  ],
};

const project = new JsonProject("{}");
try {
  const solved = JSON.parse(project.solve(JSON.stringify(data), "{}")).result;

  const options = {
    baselineId: solved.baselineId,
    from: "2026-01-01",
    to: "2026-01-05",
    tasks: "overallocated",
  };
  const response = JSON.parse(project.loadProfile(JSON.stringify(options)));

  if (response.ok) {
    for (const { resource, buckets } of response.result.resources) {
      for (const bucket of buckets.filter((b) => b.load > b.capacity)) {
        console.log(`${resource} at ${bucket.start}: ${bucket.load} of ${bucket.capacity}`, bucket.tasks);
      }
    }
    // dev at 2026-01-02 00:00: 2 of 1 [ 'a', 'b' ]
  } else {
    const { kind, code, message, path } = response.error;
    console.error(kind, code, message, path);
  }
} finally {
  project.free();
}

options_json (the token comes from the solve result):

{ "baselineId": "1-b0605af8cba3d7c9", "from": "2026-01-01", "to": "2026-01-05", "tasks": "overallocated" }

Response:

{
  "ok": true,
  "result": {
    "basis": "day",
    "resources": [
      {
        "buckets": [
          { "capacity": 1, "load": 1, "start": "2026-01-01 00:00", "tasks": [] },
          { "capacity": 1, "load": 2, "start": "2026-01-02 00:00", "tasks": ["a", "b"] },
          { "capacity": 1, "load": 1, "start": "2026-01-03 00:00", "tasks": [] },
          { "capacity": 1, "load": 0, "start": "2026-01-04 00:00", "tasks": [] }
        ],
        "capacityMode": "flat",
        "resource": "dev"
      }
    ]
  }
}