Project::load_profile#

Reads per-bucket load and capacity of resources on the solved baseline of a Project. Read-only. For the load of hypothetical dates, use preview with a profile query instead.

Signature#

pub fn load_profile(&self, options: &LoadProfileOptions) -> Result<LoadProfile, Error>

Takes &self. Synchronous and CPU-only.

Parameters#

Name Type Description
options &LoadProfileOptions Range, resources, basis, task lists and an optional baseline check. A ProfileQuery converts into it with .into().

Returns#

A LoadProfile.

Errors#

Error When
Error::Project(ProjectError::NoBaseline) The project is unsolved, including after apply
Error::Project(ProjectError::StaleBaseline) options.baseline_id doesn't name the current baseline
Error::Input to <= from, or more than 100 000 buckets per resource (path to); an unknown resource (path resources)

Example#

Print the overloaded days of a resource that works on two tasks at once.

use plen_core::{
    AssignmentData, DateTime, ProfileQuery, Project, ProjectData, ResourceData, SolveOptions,
    TaskData,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let day = |d| DateTime::from_ymd_hm(2026, 1, d, 0, 0).ok_or("invalid date");
    let assign = |task: &str| AssignmentData {
        id: None,
        task: task.into(),
        resource: "dev".into(),
        value: 1.0,
        offset: None,
        duration: None,
    };
    let mut data = ProjectData {
        tasks: vec![
            TaskData { start_date: Some(day(1)?), duration: Some(2.0), ..TaskData::new("a") },
            TaskData { start_date: Some(day(2)?), duration: Some(2.0), ..TaskData::new("b") },
        ],
        resources: vec![ResourceData { id: "dev".into(), capacity: None, calendar_id: None }],
        assignments: vec![assign("a"), assign("b")],
        ..Default::default()
    };
    data.config.use_calendars = false;

    let mut project = Project::default();
    project.solve(Some(data), &SolveOptions::default())?;

    let profile = project.load_profile(&ProfileQuery::new(day(1)?, day(5)?).into())?;
    for resource in &profile.resources {
        for bucket in resource.buckets.iter().filter(|b| b.load > b.capacity) {
            println!("{} at {}: {} of {}", resource.resource, bucket.start, bucket.load, bucket.capacity);
        }
    }
    Ok(())
}