ifc_schedule/task/
schedule_time_control.rs1use ifc_model::{Entity, EntityId, Model, Value};
35
36use super::definition::{Task, TaskTimeAnomaly};
37use crate::release::ReadRelease;
38use crate::schedule::AuthoredDateTime;
39use crate::SchemaVersion;
40
41const ASSIGNS_TASKS: &str = "IFCRELASSIGNSTASKS";
42const TIME_CONTROL: &str = "IFCSCHEDULETIMECONTROL";
43
44#[derive(Debug, Clone, Copy)]
47pub struct ScheduleTimeControl<'m> {
48 id: EntityId,
49 entity: &'m Entity,
50 assignment: EntityId,
51 work_control: Option<EntityId>,
52 release: ReadRelease,
53}
54
55impl<'m> ScheduleTimeControl<'m> {
56 #[must_use]
58 pub fn id(&self) -> EntityId {
59 self.id
60 }
61
62 #[must_use]
64 pub fn assignment(&self) -> EntityId {
65 self.assignment
66 }
67
68 #[must_use]
71 pub fn work_control(&self) -> Option<EntityId> {
72 self.work_control
73 }
74
75 #[must_use]
77 pub fn release(&self) -> SchemaVersion {
78 self.release.version()
79 }
80
81 fn value(&self, attribute: &'static str) -> Option<&'m Value> {
82 self.release.value(TIME_CONTROL, self.entity, attribute)
83 }
84
85 fn date_time(&self, attribute: &'static str) -> Option<AuthoredDateTime<'m>> {
86 match self.value(attribute)? {
87 Value::Ref(record) => Some(AuthoredDateTime::Record(*record)),
88 value => value.unwrap_typed().as_text().map(AuthoredDateTime::Text),
89 }
90 }
91
92 fn measure(&self, attribute: &'static str) -> Option<f64> {
93 self.value(attribute)?.unwrap_typed().as_f64()
94 }
95
96 #[must_use]
98 pub fn global_id(&self) -> Option<&'m str> {
99 self.release.text(TIME_CONTROL, self.entity, "GlobalId")
100 }
101
102 #[must_use]
104 pub fn name(&self) -> Option<&'m str> {
105 self.release.text(TIME_CONTROL, self.entity, "Name")
106 }
107
108 #[must_use]
110 pub fn actual_start(&self) -> Option<AuthoredDateTime<'m>> {
111 self.date_time("ActualStart")
112 }
113
114 #[must_use]
116 pub fn early_start(&self) -> Option<AuthoredDateTime<'m>> {
117 self.date_time("EarlyStart")
118 }
119
120 #[must_use]
122 pub fn late_start(&self) -> Option<AuthoredDateTime<'m>> {
123 self.date_time("LateStart")
124 }
125
126 #[must_use]
128 pub fn schedule_start(&self) -> Option<AuthoredDateTime<'m>> {
129 self.date_time("ScheduleStart")
130 }
131
132 #[must_use]
134 pub fn actual_finish(&self) -> Option<AuthoredDateTime<'m>> {
135 self.date_time("ActualFinish")
136 }
137
138 #[must_use]
140 pub fn early_finish(&self) -> Option<AuthoredDateTime<'m>> {
141 self.date_time("EarlyFinish")
142 }
143
144 #[must_use]
146 pub fn late_finish(&self) -> Option<AuthoredDateTime<'m>> {
147 self.date_time("LateFinish")
148 }
149
150 #[must_use]
152 pub fn schedule_finish(&self) -> Option<AuthoredDateTime<'m>> {
153 self.date_time("ScheduleFinish")
154 }
155
156 #[must_use]
158 pub fn status_time(&self) -> Option<AuthoredDateTime<'m>> {
159 self.date_time("StatusTime")
160 }
161
162 #[must_use]
164 pub fn schedule_duration(&self) -> Option<f64> {
165 self.measure("ScheduleDuration")
166 }
167
168 #[must_use]
170 pub fn actual_duration(&self) -> Option<f64> {
171 self.measure("ActualDuration")
172 }
173
174 #[must_use]
176 pub fn remaining_time(&self) -> Option<f64> {
177 self.measure("RemainingTime")
178 }
179
180 #[must_use]
182 pub fn free_float(&self) -> Option<f64> {
183 self.measure("FreeFloat")
184 }
185
186 #[must_use]
188 pub fn total_float(&self) -> Option<f64> {
189 self.measure("TotalFloat")
190 }
191
192 #[must_use]
194 pub fn start_float(&self) -> Option<f64> {
195 self.measure("StartFloat")
196 }
197
198 #[must_use]
200 pub fn finish_float(&self) -> Option<f64> {
201 self.measure("FinishFloat")
202 }
203
204 #[must_use]
206 pub fn is_critical(&self) -> Option<bool> {
207 self.value("IsCritical")?.as_bool()
208 }
209
210 #[must_use]
212 pub fn completion(&self) -> Option<f64> {
213 self.measure("Completion")
214 }
215}
216
217impl<'m> Task<'m> {
218 #[must_use]
227 pub fn schedule_time_controls(
228 &self,
229 model: &'m Model,
230 ) -> (Vec<ScheduleTimeControl<'m>>, Vec<TaskTimeAnomaly>) {
231 let release = self.read_release();
232 let mut found = Vec::new();
233 let mut anomalies = Vec::new();
234 if !release.declares(ASSIGNS_TASKS) {
235 return (found, anomalies);
236 }
237 for assignment in release.instances_of(model, ASSIGNS_TASKS) {
238 let Some(relation) = model.get(assignment) else {
239 continue;
240 };
241 let mut related = false;
242 if let Some(objects) = release.value(ASSIGNS_TASKS, relation, "RelatedObjects") {
243 objects.for_each_ref(&mut |id| related |= id == self.id());
244 }
245 if !related {
246 continue;
247 }
248 let Some(target) = release.reference(ASSIGNS_TASKS, relation, "TimeForTask") else {
249 continue;
250 };
251 let Some(entity) = model.get(target) else {
252 continue;
253 };
254 if !release.is_a(&entity.type_name, TIME_CONTROL) {
255 anomalies.push(TaskTimeAnomaly::NotAScheduleTimeControl {
256 task: self.id(),
257 assignment,
258 target,
259 found: entity.type_name.to_string(),
260 });
261 continue;
262 }
263 found.push(ScheduleTimeControl {
264 id: target,
265 entity,
266 assignment,
267 work_control: release.reference(ASSIGNS_TASKS, relation, "RelatingControl"),
268 release,
269 });
270 }
271 (found, anomalies)
272 }
273}