mirror of
https://github.com/unanmed/ginka-generator.git
synced 2026-05-20 17:22:41 +08:00
feat: review
This commit is contained in:
parent
be20925fc8
commit
cc2fc3e96c
@ -7,6 +7,7 @@
|
|||||||
"ginka": "tsx ./src/ginka.ts",
|
"ginka": "tsx ./src/ginka.ts",
|
||||||
"minamo": "tsx ./src/minamo.ts",
|
"minamo": "tsx ./src/minamo.ts",
|
||||||
"merge": "tsx ./src/merge.ts",
|
"merge": "tsx ./src/merge.ts",
|
||||||
|
"review": "tsx ./src/review.ts",
|
||||||
"test:topo": "tsx ./src/topology/test.ts",
|
"test:topo": "tsx ./src/topology/test.ts",
|
||||||
"test:vision": "tsx ./src/vision/test.ts"
|
"test:vision": "tsx ./src/vision/test.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
import { writeFile } from 'fs-extra';
|
import { writeFile } from 'fs-extra';
|
||||||
import { FloorData, readOne, getAllFloors, parseTowerInfo } from './utils';
|
import {
|
||||||
|
FloorData,
|
||||||
|
readOne,
|
||||||
|
getAllFloors,
|
||||||
|
parseTowerInfo,
|
||||||
|
chooseFrom
|
||||||
|
} from './utils';
|
||||||
import { compareMap } from './topology/compare';
|
import { compareMap } from './topology/compare';
|
||||||
import { mirrorMapX, mirrorMapY, rotateMap } from './topology/transform';
|
import { mirrorMapX, mirrorMapY, rotateMap } from './topology/transform';
|
||||||
import { directions, tileType } from './topology/graph';
|
import { directions, tileType } from './topology/graph';
|
||||||
@ -34,15 +40,6 @@ function parseAssigned(arg: string): [number, number] {
|
|||||||
return [parseInt(a) || 100, parseInt(b) || 100];
|
return [parseInt(a) || 100, parseInt(b) || 100];
|
||||||
}
|
}
|
||||||
|
|
||||||
function chooseFrom<T>(arr: T[], n: number): T[] {
|
|
||||||
const copy = arr.slice();
|
|
||||||
for (let i = copy.length - 1; i > 0; i--) {
|
|
||||||
let randIndex = Math.floor(Math.random() * (i + 1));
|
|
||||||
[copy[i], copy[randIndex]] = [copy[randIndex], copy[i]];
|
|
||||||
}
|
|
||||||
return copy.slice(0, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
function chooseN(maxCount: number, n: number) {
|
function chooseN(maxCount: number, n: number) {
|
||||||
return chooseFrom(
|
return chooseFrom(
|
||||||
Array(maxCount)
|
Array(maxCount)
|
||||||
|
|||||||
38
data/src/review.ts
Normal file
38
data/src/review.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { readFile, writeFile } from 'fs-extra';
|
||||||
|
import { chooseFrom, DatasetMergable, mergeDataset } from './utils';
|
||||||
|
|
||||||
|
const [target, ...review] = process.argv.slice(2);
|
||||||
|
const n = getNum();
|
||||||
|
|
||||||
|
function getNum() {
|
||||||
|
const last = review.at(-1);
|
||||||
|
if (!last) return 1000;
|
||||||
|
else {
|
||||||
|
const n = parseInt(last);
|
||||||
|
if (!n) return 1000;
|
||||||
|
else {
|
||||||
|
review.pop();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const datas = await Promise.all(
|
||||||
|
review.map(async v => {
|
||||||
|
const file = await readFile(v, 'utf-8');
|
||||||
|
return JSON.parse(file) as DatasetMergable<any>;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const targetFile = await readFile(target, 'utf-8');
|
||||||
|
const targetData = JSON.parse(targetFile) as DatasetMergable<any>;
|
||||||
|
const merged = mergeDataset(...datas);
|
||||||
|
const keys = Object.keys(merged.data);
|
||||||
|
const toReview = chooseFrom(keys, n);
|
||||||
|
const reviewData: DatasetMergable<any> = {
|
||||||
|
datasetId: Math.floor(Math.random() * 1e12),
|
||||||
|
data: Object.fromEntries(toReview.map(v => [v, merged.data[v]]))
|
||||||
|
};
|
||||||
|
const reviewed = mergeDataset(targetData, reviewData);
|
||||||
|
await writeFile(target, JSON.stringify(reviewed), 'utf-8');
|
||||||
|
})();
|
||||||
@ -17,6 +17,9 @@ export interface FloorData {
|
|||||||
export function mergeDataset<T>(
|
export function mergeDataset<T>(
|
||||||
...datasets: DatasetMergable<T>[]
|
...datasets: DatasetMergable<T>[]
|
||||||
): DatasetMergable<T> {
|
): DatasetMergable<T> {
|
||||||
|
if (datasets.length === 1) {
|
||||||
|
return datasets[0];
|
||||||
|
}
|
||||||
const data: Record<string, T> = {};
|
const data: Record<string, T> = {};
|
||||||
datasets.forEach(v => {
|
datasets.forEach(v => {
|
||||||
for (const [key, value] of Object.entries(v.data)) {
|
for (const [key, value] of Object.entries(v.data)) {
|
||||||
@ -175,3 +178,12 @@ export async function fromJSON(path: string) {
|
|||||||
}
|
}
|
||||||
return floorMap;
|
return floorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function chooseFrom<T>(arr: T[], n: number): T[] {
|
||||||
|
const copy = arr.slice();
|
||||||
|
for (let i = copy.length - 1; i > 0; i--) {
|
||||||
|
let randIndex = Math.floor(Math.random() * (i + 1));
|
||||||
|
[copy[i], copy[randIndex]] = [copy[randIndex], copy[i]];
|
||||||
|
}
|
||||||
|
return copy.slice(0, n);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user