mirror of
https://github.com/morten-olsen/bob-the-algorithm.git
synced 2026-02-08 00:46:25 +01:00
init
This commit is contained in:
40
src/features/planner/algorithm/construct-day.ts
Normal file
40
src/features/planner/algorithm/construct-day.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user