🔨 fix typing
This commit is contained in:
@@ -1,18 +1,8 @@
|
|||||||
import { getGithubUserContribution, Cell } from "@snk/github-user-contribution";
|
import { getGithubUserContribution } from "@snk/github-user-contribution";
|
||||||
import { setColor, createEmptyGrid, Color } from "@snk/compute/grid";
|
|
||||||
import { createGif } from "@snk/gif-creator";
|
import { createGif } from "@snk/gif-creator";
|
||||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
|
||||||
import { createSnake } from "@snk/compute/snake";
|
import { createSnake } from "@snk/compute/snake";
|
||||||
|
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||||
export const userContributionToGrid = (cells: Cell[]) => {
|
import { userContributionToGrid } from "./userContributionToGrid";
|
||||||
const width = Math.max(0, ...cells.map((c) => c.x)) + 1;
|
|
||||||
const height = Math.max(0, ...cells.map((c) => c.y)) + 1;
|
|
||||||
|
|
||||||
const grid = createEmptyGrid(width, height);
|
|
||||||
for (const c of cells) if (c.k) setColor(grid, c.x, c.y, c.k as Color);
|
|
||||||
|
|
||||||
return grid;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const generateContributionSnake = async (userName: string) => {
|
export const generateContributionSnake = async (userName: string) => {
|
||||||
const { cells, colorScheme } = await getGithubUserContribution(userName);
|
const { cells, colorScheme } = await getGithubUserContribution(userName);
|
||||||
@@ -37,7 +27,7 @@ export const generateContributionSnake = async (userName: string) => {
|
|||||||
colorSnake: "purple",
|
colorSnake: "purple",
|
||||||
};
|
};
|
||||||
|
|
||||||
const gifOptions = { frameDuration: 10, step: 1 };
|
const gifOptions = { frameDuration: 100, step: 2 };
|
||||||
|
|
||||||
const chain = getBestRoute(grid0, snake0)!;
|
const chain = getBestRoute(grid0, snake0)!;
|
||||||
|
|
||||||
|
|||||||
13
packages/action/userContributionToGrid.ts
Normal file
13
packages/action/userContributionToGrid.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { setColor, createEmptyGrid } from "@snk/compute/grid";
|
||||||
|
import type { Cell } from "@snk/github-user-contribution";
|
||||||
|
import type { Color } from "@snk/compute/grid";
|
||||||
|
|
||||||
|
export const userContributionToGrid = (cells: Cell[]) => {
|
||||||
|
const width = Math.max(0, ...cells.map((c) => c.x)) + 1;
|
||||||
|
const height = Math.max(0, ...cells.map((c) => c.y)) + 1;
|
||||||
|
|
||||||
|
const grid = createEmptyGrid(width, height);
|
||||||
|
for (const c of cells) if (c.k) setColor(grid, c.x, c.y, c.k as Color);
|
||||||
|
|
||||||
|
return grid;
|
||||||
|
};
|
||||||
@@ -1,33 +1,29 @@
|
|||||||
import { getAvailableInterestingRoutes } from "../getAvailableRoutes";
|
import { realistic as grid } from "../__fixtures__/grid";
|
||||||
import { small as grid } from "../__fixtures__/grid";
|
|
||||||
import { snake3 } from "../__fixtures__/snake";
|
import { snake3 } from "../__fixtures__/snake";
|
||||||
import { performance } from "perf_hooks";
|
import { performance } from "perf_hooks";
|
||||||
import { getAvailableRoutes } from "../getAvailableRoutes2";
|
import { getAvailableRoutes } from "../getAvailableRoutes";
|
||||||
|
import { getBestRoute } from "../getBestRoute";
|
||||||
|
|
||||||
const m = 1000;
|
|
||||||
{
|
{
|
||||||
|
const m = 100;
|
||||||
const s = performance.now();
|
const s = performance.now();
|
||||||
for (let k = m; k--; ) {
|
for (let k = m; k--; ) {
|
||||||
const solutions = [];
|
const solutions = [];
|
||||||
|
|
||||||
getAvailableInterestingRoutes(
|
getAvailableRoutes(grid, snake3, (snakes) => {
|
||||||
grid,
|
solutions.push(snakes);
|
||||||
snake3,
|
return false;
|
||||||
(snakes) => {
|
});
|
||||||
solutions.push(snakes);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
2
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
console.log((performance.now() - s) / m, "ms");
|
console.log("getAvailableRoutes", (performance.now() - s) / m, "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
const m = 10;
|
||||||
const s = performance.now();
|
const s = performance.now();
|
||||||
for (let k = m; k--; ) {
|
for (let k = m; k--; ) {
|
||||||
getAvailableRoutes(grid, snake3, 2);
|
getBestRoute(grid, snake3);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log((performance.now() - s) / m, "ms");
|
console.log("getBestRoute", (performance.now() - s) / m, "ms");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { sortPush } from "./utils/sortPush";
|
|||||||
import type { Snake } from "./snake";
|
import type { Snake } from "./snake";
|
||||||
import type { Grid, Color } from "./grid";
|
import type { Grid, Color } from "./grid";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get routes leading to non-empty cells until onSolution returns true
|
||||||
|
*/
|
||||||
export const getAvailableRoutes = (
|
export const getAvailableRoutes = (
|
||||||
grid: Grid,
|
grid: Grid,
|
||||||
snake0: Snake,
|
snake0: Snake,
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
import { createCanvas } from "./canvas";
|
import { createCanvas } from "./canvas";
|
||||||
import { Snake, snakeToCells } from "@snk/compute/snake";
|
import { snakeToCells } from "@snk/compute/snake";
|
||||||
import { GUI } from "dat.gui";
|
import { GUI } from "dat.gui";
|
||||||
import { grid, snake } from "./sample";
|
import { grid, snake } from "./sample";
|
||||||
import { getAvailableInterestingRoutes } from "@snk/compute/getAvailableRoutes";
|
import { getAvailableRoutes } from "@snk/compute/getAvailableRoutes";
|
||||||
import type { Point } from "@snk/compute/point";
|
import type { Point } from "@snk/compute/point";
|
||||||
|
import type { Snake } from "@snk/compute/snake";
|
||||||
|
|
||||||
//
|
//
|
||||||
// compute
|
// compute
|
||||||
|
|
||||||
const routes: Snake[][] = [];
|
const routes: Snake[][] = [];
|
||||||
getAvailableInterestingRoutes(
|
getAvailableRoutes(grid, snake, (chain) => {
|
||||||
grid,
|
routes.push(chain);
|
||||||
snake,
|
return routes.length > 10;
|
||||||
(chain) => {
|
});
|
||||||
routes.push(chain);
|
|
||||||
return routes.length > 10;
|
|
||||||
},
|
|
||||||
2
|
|
||||||
);
|
|
||||||
|
|
||||||
const config = { routeN: 0, routeK: 0 };
|
const config = { routeN: 0, routeK: 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCanvas } from "./canvas";
|
import { createCanvas } from "./canvas";
|
||||||
import { Color, copyGrid } from "../compute/grid";
|
import { Color, copyGrid } from "../compute/grid";
|
||||||
import { grid, snake } from "./sample";
|
import { grid, snake } from "./sample";
|
||||||
import { pruneLayer } from "@snk/compute/getBestRoute-layer";
|
import { pruneLayer } from "@snk/compute/pruneLayer";
|
||||||
|
|
||||||
const colors = [1, 2, 3] as Color[];
|
const colors = [1, 2, 3] as Color[];
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const drawOptions = {
|
|||||||
colorSnake: "purple",
|
colorSnake: "purple",
|
||||||
};
|
};
|
||||||
|
|
||||||
const gifOptions = { frameDuration: 20, step: 1 };
|
const gifOptions = { frameDuration: 200, step: 1 };
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const m = 3;
|
const m = 3;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { createGif } from "..";
|
import { createGif } from "..";
|
||||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
|
||||||
import * as grids from "@snk/compute/__fixtures__/grid";
|
import * as grids from "@snk/compute/__fixtures__/grid";
|
||||||
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
|
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
|
||||||
import { createSnake, nextSnake } from "@snk/compute/snake";
|
import { createSnake, nextSnake } from "@snk/compute/snake";
|
||||||
|
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||||
|
|
||||||
jest.setTimeout(20 * 1000);
|
jest.setTimeout(20 * 1000);
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ const drawOptions = {
|
|||||||
colorSnake: "purple",
|
colorSnake: "purple",
|
||||||
};
|
};
|
||||||
|
|
||||||
const gifOptions = { frameDuration: 20, step: 1 };
|
const gifOptions = { frameDuration: 200, step: 1 };
|
||||||
|
|
||||||
const dir = path.resolve(__dirname, "__snapshots__");
|
const dir = path.resolve(__dirname, "__snapshots__");
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export const createGif = async (
|
|||||||
[
|
[
|
||||||
"convert",
|
"convert",
|
||||||
["-loop", "0"],
|
["-loop", "0"],
|
||||||
["-delay", gifOptions.frameDuration.toString()],
|
["-delay", (gifOptions.frameDuration / 10).toString()],
|
||||||
["-dispose", "2"],
|
["-dispose", "2"],
|
||||||
// ["-layers", "OptimizeFrame"],
|
// ["-layers", "OptimizeFrame"],
|
||||||
["-compress", "LZW"],
|
["-compress", "LZW"],
|
||||||
|
|||||||
Reference in New Issue
Block a user