hochalden ordner
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# dependencies (bun install)
|
||||
node_modules
|
||||
|
||||
# output
|
||||
out
|
||||
dist
|
||||
*.tgz
|
||||
|
||||
# code coverage
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# logs
|
||||
logs
|
||||
_.log
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# caches
|
||||
.eslintcache
|
||||
.cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
@@ -0,0 +1,92 @@
|
||||
import { Database } from "arangojs";
|
||||
const db = new Database({ url: "http://localhost:48529" });
|
||||
const kv = db.collection("kv");
|
||||
|
||||
const DB_NAME = "ArangoDB";
|
||||
|
||||
const N1 = 2000;
|
||||
const N2 = 300;
|
||||
|
||||
const region1Enemies = ["1", "2", "3", "11", "12", "13", "14"];
|
||||
const region1Items = ["1", "8", "21", "26"];
|
||||
|
||||
const playerObj = (i: number) => ({
|
||||
id: 1,
|
||||
name: "Jonas",
|
||||
health: 50 + (i % 50),
|
||||
stamina: 50 + (i % 50),
|
||||
level: 1 + (i % 20),
|
||||
region_id: 1,
|
||||
});
|
||||
|
||||
const enemyObj = { id: 0, name: "Benchmark Enemy", health: 1000, level: 20, damage: 50 };
|
||||
const itemObj = { id: 0, name: "Benchmark Item", gear_type: "weapon", gear_id: 1 };
|
||||
const regionObj = { id: 1, name: "Limgrave" };
|
||||
|
||||
async function getVal(key: string): Promise<any> {
|
||||
const doc = await kv.document(key, { graceful: true });
|
||||
return doc ? doc.value : null;
|
||||
}
|
||||
|
||||
async function setVal(key: string, value: any) {
|
||||
await kv.save({ _key: key, value }, { overwriteMode: "replace" });
|
||||
}
|
||||
|
||||
async function writeSingle(i: number) {
|
||||
await setVal("bench:player:1", playerObj(i));
|
||||
}
|
||||
|
||||
async function readSingle(_i: number) {
|
||||
await getVal("bench:player:1");
|
||||
}
|
||||
|
||||
async function readRegion(_i: number) {
|
||||
const region = await getVal("bench:region:1");
|
||||
void region?.name;
|
||||
const enemyIds = (await getVal("bench:region:1:enemies")) || [];
|
||||
const itemIds = (await getVal("bench:region:1:items")) || [];
|
||||
for (const id of enemyIds) await getVal(`bench:enemy:${id}`);
|
||||
for (const id of itemIds) await getVal(`bench:item:${id}`);
|
||||
}
|
||||
|
||||
async function writeRegion(_i: number) {
|
||||
await setVal("bench:region:1", regionObj);
|
||||
await setVal("bench:region:1:enemies", region1Enemies);
|
||||
await setVal("bench:region:1:items", region1Items);
|
||||
for (const id of region1Enemies) await setVal(`bench:enemy:${id}`, { ...enemyObj, id });
|
||||
for (const id of region1Items) await setVal(`bench:item:${id}`, { ...itemObj, id });
|
||||
}
|
||||
|
||||
async function timed(label: string, group: string, iters: number, opsPerIter: number, fn: (i: number) => Promise<void>) {
|
||||
const warmup = Math.min(50, iters);
|
||||
for (let i = 0; i < warmup; i++) await fn(i);
|
||||
const start = performance.now();
|
||||
for (let i = 0; i < iters; i++) await fn(i);
|
||||
const ms = performance.now() - start;
|
||||
const totalOps = iters * opsPerIter;
|
||||
const opsPerSec = totalOps / (ms / 1000);
|
||||
const avgMs = ms / totalOps;
|
||||
return { label, group, iters, opsPerIter, totalOps, ms, opsPerSec, avgMs };
|
||||
}
|
||||
|
||||
function fmt(r: any) {
|
||||
return ` ${r.label.padEnd(11)} | ${String(r.totalOps).padStart(6)} Ops | ${r.ms.toFixed(1).padStart(9)} ms | ${Math.round(r.opsPerSec).toString().padStart(9)} Ops/s | ${r.avgMs.toFixed(4)} ms/Op`;
|
||||
}
|
||||
|
||||
await db.version();
|
||||
|
||||
const w1 = await timed("Schreiben", "Anwendungsfall 1: Live-Player-Sync (1 Schluessel)", N1, 1, writeSingle);
|
||||
const r1 = await timed("Lesen", "Anwendungsfall 1: Live-Player-Sync (1 Schluessel)", N1, 1, readSingle);
|
||||
const r2 = await timed("Lesen", "Anwendungsfall 2: Region laden / Fast Travel (14 Schluessel)", N2, 14, readRegion);
|
||||
const w2 = await timed("Schreiben", "Anwendungsfall 2: Region laden / Fast Travel (14 Schluessel)", N2, 14, writeRegion);
|
||||
|
||||
console.log(`\n===== Benchmark: ${DB_NAME} =====`);
|
||||
console.log(w1.group);
|
||||
console.log(fmt(w1));
|
||||
console.log(fmt(r1));
|
||||
console.log(r2.group);
|
||||
console.log(fmt(r2));
|
||||
console.log(fmt(w2));
|
||||
|
||||
console.log("##RESULT## " + JSON.stringify({ db: DB_NAME, tests: [w1, r1, r2, w2] }));
|
||||
process.exit(0);
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 1,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "client-arangodb",
|
||||
"dependencies": {
|
||||
"arangojs": "^9.2.0",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5",
|
||||
},
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
"@types/bun": ["@types/bun@1.3.14", "", { "dependencies": { "bun-types": "1.3.14" } }, "sha512-h1hFqFVcvAvD9j9K7ZW7vd82aSA+rTdznZa+5bwvCwqSB1jmmfLcbIWhOLx1/+boy/xmjgCs/OMUL8hRJSmnPw=="],
|
||||
|
||||
"@types/node": ["@types/node@20.19.43", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA=="],
|
||||
|
||||
"arangojs": ["arangojs@9.3.0", "", { "dependencies": { "@types/node": "^20.11.26" } }, "sha512-+z/TxumH8ywsXAN0oyQAxMnBMtDbd4tjFhGXzygAHD8+YDzEC705STLBh38KGbwxWeekalu2XEHUtrJ/NONgTQ=="],
|
||||
|
||||
"bun-types": ["bun-types@1.3.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-4N0ig0fEomHt5R0KCFWjovxow98rIoRwKolrYdCcknNwMekCXRnWEUvgu5soYV8QXtVsrUD8B95MBOZGPvr6KQ=="],
|
||||
|
||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
||||
|
||||
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
||||
|
||||
"bun-types/@types/node": ["@types/node@26.1.0", "", { "dependencies": { "undici-types": "~8.3.0" } }, "sha512-O0A1G3xPGy4w7AgQdAQYUlQ+BKk2Oovw8eRpofyp5KdBZULnbe+WqaOVNrm705SHphCiG4XHsACrSmPu1f+Kgw=="],
|
||||
|
||||
"bun-types/@types/node/undici-types": ["undici-types@8.3.0", "", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="],
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Database } from "arangojs";
|
||||
import { effects, types, weapons, armors, shields, talismans, items, regions, enemies } from "../../data";
|
||||
const db = new Database({ url: "http://localhost:48529" });
|
||||
|
||||
console.log("Populating database with ~100 static Ringstats entries...");
|
||||
|
||||
async function waitForArango() {
|
||||
for (let i = 0; i < 30; i++) {
|
||||
try {
|
||||
await db.version();
|
||||
return;
|
||||
} catch {
|
||||
console.log("Waiting for ArangoDB to be ready...");
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
}
|
||||
throw new Error("ArangoDB not reachable on localhost:48529");
|
||||
}
|
||||
|
||||
await waitForArango();
|
||||
|
||||
const kv = db.collection("kv");
|
||||
if (!(await kv.exists())) {
|
||||
await kv.create();
|
||||
}
|
||||
|
||||
const docs: { _key: string; value: any }[] = [];
|
||||
|
||||
const collect = (prefix: string, list: any[]) => {
|
||||
for (const obj of list) {
|
||||
const { items, enemies, ...data } = obj;
|
||||
docs.push({ _key: `${prefix}:${obj.id}`, value: data });
|
||||
if (items && items.length > 0) {
|
||||
docs.push({ _key: `${prefix}:${obj.id}:items`, value: items });
|
||||
}
|
||||
if (enemies && enemies.length > 0) {
|
||||
docs.push({ _key: `${prefix}:${obj.id}:enemies`, value: enemies });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
collect("item_effect", effects);
|
||||
collect("item_type", types);
|
||||
collect("weapon", weapons);
|
||||
collect("armor", armors);
|
||||
collect("shield", shields);
|
||||
collect("talisman", talismans);
|
||||
collect("item", items);
|
||||
collect("region", regions);
|
||||
collect("enemy", enemies);
|
||||
|
||||
await kv.import(docs, { overwrite: true, onDuplicate: "replace" });
|
||||
|
||||
console.log(`Inserted ${effects.length + types.length + weapons.length + armors.length + shields.length + talismans.length + items.length + regions.length + enemies.length} primary entities into ArangoDB.`);
|
||||
console.log("Database successfully seeded.");
|
||||
process.exit(0);
|
||||
@@ -0,0 +1,8 @@
|
||||
services:
|
||||
arangodb:
|
||||
image: arangodb:latest
|
||||
environment:
|
||||
ARANGO_NO_AUTH: "1"
|
||||
ports:
|
||||
- "48529:8529"
|
||||
restart: always
|
||||
@@ -0,0 +1,168 @@
|
||||
import { Database } from "arangojs";
|
||||
const db = new Database({ url: "http://localhost:48529" });
|
||||
const kv = db.collection("kv");
|
||||
|
||||
const colors = {
|
||||
reset: "\x1b[0m",
|
||||
cyan: "\x1b[36m",
|
||||
green: "\x1b[32m",
|
||||
yellow: "\x1b[33m",
|
||||
magenta: "\x1b[35m",
|
||||
red: "\x1b[31m",
|
||||
gray: "\x1b[90m",
|
||||
bold: "\x1b[1m",
|
||||
};
|
||||
|
||||
let totalRequests = 0;
|
||||
|
||||
function log(msg: string, color: string = colors.reset) {
|
||||
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
||||
console.log(`${colors.gray}[${timestamp}]${colors.reset} ${color}${msg}${colors.reset}`);
|
||||
}
|
||||
|
||||
async function getVal(key: string): Promise<any> {
|
||||
const doc = await kv.document(key, { graceful: true });
|
||||
return doc ? doc.value : null;
|
||||
}
|
||||
|
||||
async function setVal(key: string, value: any) {
|
||||
await kv.save({ _key: key, value }, { overwriteMode: "replace" });
|
||||
}
|
||||
|
||||
const introMessage = "Starting Ringstats Desktop Application...";
|
||||
log(introMessage, colors.cyan);
|
||||
|
||||
const pingStart = performance.now();
|
||||
await db.version();
|
||||
totalRequests++;
|
||||
log(`Connected to Ringstats Database successfully. (Reqs: 1 | Total: ${totalRequests} | Time: ${(performance.now() - pingStart).toFixed(2)}ms)`, colors.green);
|
||||
|
||||
log("Looking for Elden Ring process...", colors.gray);
|
||||
await Bun.sleep(1500);
|
||||
log("Found Elden Ring process!", colors.green);
|
||||
|
||||
log("Equipping initial gear...", colors.gray);
|
||||
await setVal("player:1:weapon", ["1"]);
|
||||
await setVal("player:1:armor", ["11"]);
|
||||
await setVal("player:1:talisman", ["26"]);
|
||||
totalRequests += 3;
|
||||
|
||||
let playerHealth = 100;
|
||||
let playerStamina = 100;
|
||||
let playerLevel = 1;
|
||||
let currentRegionId = 1;
|
||||
|
||||
const CHANCE_LEVEL_UP = 0.10;
|
||||
const CHANCE_FAST_TRAVEL = 0.15;
|
||||
const CHANCE_GEAR_SWAP = 0.10;
|
||||
const CHANCE_TARGET_LOCK = 0.30;
|
||||
|
||||
log("Entering live sync loop (press Ctrl+C to exit)...", colors.gray);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
// Werte aktualisieren
|
||||
playerHealth = Math.floor(Math.max(10, playerHealth - (Math.random() * 10) + 5));
|
||||
playerStamina = Math.floor(Math.max(10, playerStamina - (Math.random() * 20) + 10));
|
||||
|
||||
if (Math.random() < CHANCE_LEVEL_UP) {
|
||||
playerLevel += 1;
|
||||
}
|
||||
|
||||
// Event: Schnellreise
|
||||
if (Math.random() < CHANCE_FAST_TRAVEL) {
|
||||
currentRegionId = Math.floor(Math.random() * 16) + 1;
|
||||
|
||||
const startTravel = performance.now();
|
||||
const region = await getVal(`region:${currentRegionId}`);
|
||||
const regionEnemiesIds = (await getVal(`region:${currentRegionId}:enemies`)) || [];
|
||||
const regionItemsIds = (await getVal(`region:${currentRegionId}:items`)) || [];
|
||||
|
||||
const enemyNames = await Promise.all(regionEnemiesIds.map(async (id: string) => (await getVal(`enemy:${id}`))?.name));
|
||||
const itemNames = await Promise.all(regionItemsIds.map(async (id: string) => (await getVal(`item:${id}`))?.name));
|
||||
|
||||
const queries = 3 + regionEnemiesIds.length + regionItemsIds.length;
|
||||
totalRequests += queries;
|
||||
const travelTime = (performance.now() - startTravel).toFixed(2);
|
||||
|
||||
console.log();
|
||||
log(`>>> Fast Traveled to: [ID: ${currentRegionId}] ${region?.name} <<<`, colors.magenta + colors.bold);
|
||||
log(`[Region Data] Enemies nearby: ${enemyNames.join(", ") || "None"}`, colors.magenta);
|
||||
log(`[Region Data] Items nearby: ${itemNames.join(", ") || "None"}`, colors.magenta);
|
||||
log(`[Stats] Query Time: ${travelTime}ms | Reqs in Block: ${queries} | Total Reqs: ${totalRequests}`, colors.gray);
|
||||
console.log();
|
||||
}
|
||||
|
||||
// Event: Gear-Swap
|
||||
if (Math.random() < CHANCE_GEAR_SWAP) {
|
||||
const newWeaponId = Math.floor(Math.random() * 10) + 1;
|
||||
const newArmorId = Math.floor(Math.random() * 10) + 11;
|
||||
const newTalismanId = Math.floor(Math.random() * 5) + 26;
|
||||
|
||||
const startSwap = performance.now();
|
||||
await setVal("player:1:weapon", [newWeaponId.toString()]);
|
||||
await setVal("player:1:armor", [newArmorId.toString()]);
|
||||
await setVal("player:1:talisman", [newTalismanId.toString()]);
|
||||
|
||||
const weaponName = (await getVal(`item:${newWeaponId}`))?.name;
|
||||
const armorName = (await getVal(`item:${newArmorId}`))?.name;
|
||||
const talismanName = (await getVal(`item:${newTalismanId}`))?.name;
|
||||
|
||||
totalRequests += 6;
|
||||
const swapTime = (performance.now() - startSwap).toFixed(2);
|
||||
|
||||
console.log();
|
||||
log(`>>> Gear Swapped <<<`, colors.cyan + colors.bold);
|
||||
log(`Equipped: ${weaponName} | ${armorName} | ${talismanName}`, colors.cyan);
|
||||
log(`[Stats] Query Time: ${swapTime}ms | Reqs in Block: 6 | Total Reqs: ${totalRequests}`, colors.gray);
|
||||
console.log();
|
||||
}
|
||||
|
||||
// Aktuellen Stand sichern
|
||||
const startSync = performance.now();
|
||||
await setVal("player:1", {
|
||||
id: 1,
|
||||
name: "Jonas",
|
||||
health: playerHealth,
|
||||
stamina: playerStamina,
|
||||
level: playerLevel,
|
||||
region_id: currentRegionId
|
||||
});
|
||||
totalRequests += 1;
|
||||
const syncTime = (performance.now() - startSync).toFixed(2);
|
||||
|
||||
log(`[Live Sync] [ID: 1] Jonas - Lvl: ${playerLevel} | HP: ${playerHealth} | Stamina: ${playerStamina}`, colors.green);
|
||||
log(`[Stats] Query Time: ${syncTime}ms | Reqs in Block: 1 | Total Reqs: ${totalRequests}`, colors.gray);
|
||||
|
||||
// Event: Gegner-Lock
|
||||
if (Math.random() < CHANCE_TARGET_LOCK) {
|
||||
const startLock = performance.now();
|
||||
const enemyIds = (await getVal(`region:${currentRegionId}:enemies`)) || [];
|
||||
totalRequests += 1;
|
||||
const randomEnemyId = enemyIds.length > 0 ? enemyIds[Math.floor(Math.random() * enemyIds.length)] : null;
|
||||
|
||||
if (randomEnemyId) {
|
||||
console.log();
|
||||
log("--- Target Lock Detected ---", colors.red + colors.bold);
|
||||
const enemyInfo = await getVal(`enemy:${randomEnemyId}`);
|
||||
|
||||
const dropItemIds = (await getVal(`enemy:${randomEnemyId}:items`)) || [];
|
||||
const dropItemNames = await Promise.all(dropItemIds.map(async (id: string) => (await getVal(`item:${id}`))?.name));
|
||||
|
||||
const queries = 2 + dropItemIds.length;
|
||||
totalRequests += queries;
|
||||
const lockTime = (performance.now() - startLock).toFixed(2);
|
||||
|
||||
log(`Overlay -> [ID: ${enemyInfo.id}] ${enemyInfo.name} | Lvl: ${enemyInfo.level} | HP: ${enemyInfo.health} | DMG: ${enemyInfo.damage}`, colors.yellow);
|
||||
log(`Drops -> ${dropItemNames.length > 0 ? dropItemNames.join(", ") : "None"}`, colors.yellow);
|
||||
log(`[Stats] Query Time: ${lockTime}ms | Reqs in Block: ${queries + 1} | Total Reqs: ${totalRequests}`, colors.gray);
|
||||
console.log();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log("Verbindungsabbruch zu ArangoDB!", colors.red);
|
||||
}
|
||||
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "client-arangodb",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"arangojs": "^9.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Environment setup & latest features
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user