mirror of
https://github.com/morten-olsen/bob.git
synced 2026-02-08 01:46:29 +01:00
feat: improved plugin structure
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
|
||||
@@ -14,7 +14,7 @@ type BlockProps = {
|
||||
presenter?: React.FC<any>;
|
||||
};
|
||||
|
||||
const id = (function* () {
|
||||
const id = (function*() {
|
||||
let i = 0;
|
||||
while (true) {
|
||||
yield i++;
|
||||
@@ -57,6 +57,7 @@ const Block: React.FC<BlockProps> = ({
|
||||
});
|
||||
} catch (error) {
|
||||
setError(error);
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
setRunning(false);
|
||||
@@ -75,6 +76,7 @@ const Block: React.FC<BlockProps> = ({
|
||||
}
|
||||
if (type === 'error') {
|
||||
setError(payload);
|
||||
console.error(payload);
|
||||
}
|
||||
};
|
||||
worker.addEventListener('message', listener);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { calulation, plugins } from '@bob-the-algorithm/core';
|
||||
import { Bob, plugins } from '@bob-the-algorithm/core';
|
||||
import { createWorker } from '../../features/runner/worker';
|
||||
import { convertResult } from '../../utils/graph';
|
||||
|
||||
@@ -6,141 +6,149 @@ const MIN = 1000 * 60;
|
||||
const HOUR = 1000 * 60 * 60;
|
||||
|
||||
const getTravelTime = async () => 30 * MIN;
|
||||
const transport = plugins.transport({
|
||||
getTravelTime,
|
||||
});
|
||||
|
||||
const realistic = async () => {
|
||||
const result = await calulation({
|
||||
location: 'home',
|
||||
time: 0,
|
||||
heuristic: ({ completed }) => completed.length >= 3,
|
||||
plugins: [
|
||||
plugins.transport({
|
||||
getTravelTime,
|
||||
}),
|
||||
],
|
||||
planables: [
|
||||
{
|
||||
id: `Brush teeth`,
|
||||
duration: 2 * MIN,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 8 * HOUR,
|
||||
},
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
},
|
||||
score: 1,
|
||||
try {
|
||||
const bob = new Bob({
|
||||
plugins: { transport },
|
||||
});
|
||||
const result = await bob.run({
|
||||
context: {
|
||||
location: 'home',
|
||||
},
|
||||
{
|
||||
id: 'Drop off kids',
|
||||
duration: 30 * MIN,
|
||||
attributes: {
|
||||
locations: ['daycare'],
|
||||
start: 0,
|
||||
heuristic: ({ completed }) => completed.length >= 3,
|
||||
planables: [
|
||||
{
|
||||
id: `Brush teeth`,
|
||||
duration: 2 * MIN,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 8 * HOUR,
|
||||
},
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
},
|
||||
score: 1,
|
||||
},
|
||||
score: 1,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 9 * HOUR,
|
||||
{
|
||||
id: 'Drop off kids',
|
||||
duration: 30 * MIN,
|
||||
attributes: {
|
||||
locations: ['daycare'],
|
||||
},
|
||||
score: 1,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 9 * HOUR,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Pickup the kids',
|
||||
duration: 30 * MIN,
|
||||
attributes: {
|
||||
locations: ['daycare'],
|
||||
{
|
||||
id: 'Pickup the kids',
|
||||
duration: 30 * MIN,
|
||||
attributes: {
|
||||
locations: ['daycare'],
|
||||
},
|
||||
score: 1,
|
||||
start: {
|
||||
min: 15 * HOUR,
|
||||
max: 15.5 * HOUR,
|
||||
},
|
||||
},
|
||||
score: 1,
|
||||
start: {
|
||||
min: 15 * HOUR,
|
||||
max: 15.5 * HOUR,
|
||||
{
|
||||
id: `Eat breakfast`,
|
||||
duration: 15 * MIN,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 9 * HOUR,
|
||||
},
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
},
|
||||
score: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: `Eat breakfast`,
|
||||
duration: 15 * MIN,
|
||||
start: {
|
||||
min: 7 * HOUR,
|
||||
max: 9 * HOUR,
|
||||
{
|
||||
id: 'Do work',
|
||||
duration: 1 * HOUR,
|
||||
count: 5,
|
||||
attributes: {
|
||||
locations: ['work'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 18 * HOUR,
|
||||
},
|
||||
},
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
{
|
||||
id: 'Read book',
|
||||
duration: 0.5 * HOUR,
|
||||
attributes: {
|
||||
locations: ['home', 'work'],
|
||||
},
|
||||
score: 3,
|
||||
count: 2,
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 22 * HOUR,
|
||||
},
|
||||
},
|
||||
score: 1,
|
||||
},
|
||||
{
|
||||
id: 'Do work',
|
||||
duration: 1 * HOUR,
|
||||
count: 5,
|
||||
attributes: {
|
||||
locations: ['work'],
|
||||
{
|
||||
id: 'Meditate',
|
||||
duration: 10 * MIN,
|
||||
score: 1,
|
||||
attributes: {},
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 22 * HOUR,
|
||||
},
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 18 * HOUR,
|
||||
{
|
||||
id: 'Meeting 1',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['work', 'work'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 10 * HOUR,
|
||||
max: 10 * HOUR,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Read book',
|
||||
duration: 0.5 * HOUR,
|
||||
attributes: {
|
||||
locations: ['home', 'work'],
|
||||
{
|
||||
id: 'Meeting 2',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['work', 'work'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 12 * HOUR,
|
||||
max: 12 * HOUR,
|
||||
},
|
||||
},
|
||||
score: 3,
|
||||
count: 2,
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 22 * HOUR,
|
||||
{
|
||||
id: 'Play playstation',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 16 * HOUR,
|
||||
max: 24 * HOUR,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Meditate',
|
||||
duration: 10 * MIN,
|
||||
score: 1,
|
||||
attributes: {},
|
||||
start: {
|
||||
min: 8 * HOUR,
|
||||
max: 22 * HOUR,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Meeting 1',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['work', 'work'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 10 * HOUR,
|
||||
max: 10 * HOUR,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Meeting 2',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['work', 'work'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 12 * HOUR,
|
||||
max: 12 * HOUR,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'Play playstation',
|
||||
duration: 1 * HOUR,
|
||||
attributes: {
|
||||
locations: ['home'],
|
||||
},
|
||||
score: 10,
|
||||
start: {
|
||||
min: 16 * HOUR,
|
||||
max: 24 * HOUR,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
return convertResult(result);
|
||||
],
|
||||
});
|
||||
return convertResult(result);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
createWorker({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import './script.ts';
|
||||
const worker = new Worker(new URL('./script.ts', import.meta.url), {
|
||||
type: 'module',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user