🔨 fix typing
This commit is contained in:
@@ -1,18 +1,8 @@
|
||||
import { getGithubUserContribution, Cell } from "@snk/github-user-contribution";
|
||||
import { setColor, createEmptyGrid, Color } from "@snk/compute/grid";
|
||||
import { getGithubUserContribution } from "@snk/github-user-contribution";
|
||||
import { createGif } from "@snk/gif-creator";
|
||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||
import { createSnake } from "@snk/compute/snake";
|
||||
|
||||
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;
|
||||
};
|
||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||
import { userContributionToGrid } from "./userContributionToGrid";
|
||||
|
||||
export const generateContributionSnake = async (userName: string) => {
|
||||
const { cells, colorScheme } = await getGithubUserContribution(userName);
|
||||
@@ -37,7 +27,7 @@ export const generateContributionSnake = async (userName: string) => {
|
||||
colorSnake: "purple",
|
||||
};
|
||||
|
||||
const gifOptions = { frameDuration: 10, step: 1 };
|
||||
const gifOptions = { frameDuration: 100, step: 2 };
|
||||
|
||||
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 { small as grid } from "../__fixtures__/grid";
|
||||
import { realistic as grid } from "../__fixtures__/grid";
|
||||
import { snake3 } from "../__fixtures__/snake";
|
||||
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();
|
||||
for (let k = m; k--; ) {
|
||||
const solutions = [];
|
||||
|
||||
getAvailableInterestingRoutes(
|
||||
grid,
|
||||
snake3,
|
||||
(snakes) => {
|
||||
solutions.push(snakes);
|
||||
return false;
|
||||
},
|
||||
2
|
||||
);
|
||||
getAvailableRoutes(grid, snake3, (snakes) => {
|
||||
solutions.push(snakes);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
console.log((performance.now() - s) / m, "ms");
|
||||
console.log("getAvailableRoutes", (performance.now() - s) / m, "ms");
|
||||
}
|
||||
|
||||
{
|
||||
const m = 10;
|
||||
const s = performance.now();
|
||||
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 { Grid, Color } from "./grid";
|
||||
|
||||
/**
|
||||
* get routes leading to non-empty cells until onSolution returns true
|
||||
*/
|
||||
export const getAvailableRoutes = (
|
||||
grid: Grid,
|
||||
snake0: Snake,
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
import { createCanvas } from "./canvas";
|
||||
import { Snake, snakeToCells } from "@snk/compute/snake";
|
||||
import { snakeToCells } from "@snk/compute/snake";
|
||||
import { GUI } from "dat.gui";
|
||||
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 { Snake } from "@snk/compute/snake";
|
||||
|
||||
//
|
||||
// compute
|
||||
|
||||
const routes: Snake[][] = [];
|
||||
getAvailableInterestingRoutes(
|
||||
grid,
|
||||
snake,
|
||||
(chain) => {
|
||||
routes.push(chain);
|
||||
return routes.length > 10;
|
||||
},
|
||||
2
|
||||
);
|
||||
getAvailableRoutes(grid, snake, (chain) => {
|
||||
routes.push(chain);
|
||||
return routes.length > 10;
|
||||
});
|
||||
|
||||
const config = { routeN: 0, routeK: 0 };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createCanvas } from "./canvas";
|
||||
import { Color, copyGrid } from "../compute/grid";
|
||||
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[];
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ const drawOptions = {
|
||||
colorSnake: "purple",
|
||||
};
|
||||
|
||||
const gifOptions = { frameDuration: 20, step: 1 };
|
||||
const gifOptions = { frameDuration: 200, step: 1 };
|
||||
|
||||
(async () => {
|
||||
const m = 3;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { createGif } from "..";
|
||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||
import * as grids from "@snk/compute/__fixtures__/grid";
|
||||
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
|
||||
import { createSnake, nextSnake } from "@snk/compute/snake";
|
||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||
|
||||
jest.setTimeout(20 * 1000);
|
||||
|
||||
@@ -18,7 +18,7 @@ const drawOptions = {
|
||||
colorSnake: "purple",
|
||||
};
|
||||
|
||||
const gifOptions = { frameDuration: 20, step: 1 };
|
||||
const gifOptions = { frameDuration: 200, step: 1 };
|
||||
|
||||
const dir = path.resolve(__dirname, "__snapshots__");
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ export const createGif = async (
|
||||
[
|
||||
"convert",
|
||||
["-loop", "0"],
|
||||
["-delay", gifOptions.frameDuration.toString()],
|
||||
["-delay", (gifOptions.frameDuration / 10).toString()],
|
||||
["-dispose", "2"],
|
||||
// ["-layers", "OptimizeFrame"],
|
||||
["-compress", "LZW"],
|
||||
|
||||
Reference in New Issue
Block a user