mirror of
https://github.com/morten-olsen/bob-the-algorithm.git
synced 2026-02-08 00:46:25 +01:00
41 lines
975 B
TypeScript
41 lines
975 B
TypeScript
import { GraphNode } from "#/types/graph";
|
|
import { PlanItem } from "#/types/plans";
|
|
|
|
const constructDay = (node: GraphNode) => {
|
|
let current: GraphNode | undefined = node;
|
|
const plans: PlanItem[] = [];
|
|
|
|
while(current) {
|
|
if (current.task) {
|
|
plans.push({
|
|
type: 'task',
|
|
name: current.task?.name || 'start',
|
|
external: current.task?.external,
|
|
start: new Date(
|
|
current.time.start.getTime()
|
|
+ (current.transition?.time || 0),
|
|
),
|
|
end: current.time.end,
|
|
score: current.score,
|
|
})
|
|
}
|
|
if (current.transition) {
|
|
plans.push({
|
|
type: 'transition',
|
|
start: current.time.start,
|
|
end: new Date(
|
|
current.time.start.getTime()
|
|
+ current.transition.time,
|
|
),
|
|
from: current.transition.from,
|
|
to: current.transition.to,
|
|
})
|
|
}
|
|
current = current.parent;
|
|
}
|
|
|
|
return plans.reverse();
|
|
}
|
|
|
|
export { constructDay };
|