Begin work on getting the graph data prepared
This commit is contained in:
parent
65856b650c
commit
3796687a72
3 changed files with 74 additions and 2 deletions
|
|
@ -1,6 +1,22 @@
|
|||
/* eslint-disable no-unused-vars */
|
||||
import { Table } from "./model.mjs";
|
||||
|
||||
const { randomID } = foundry.utils;
|
||||
|
||||
function generateRow(value, isPrivate = false) {
|
||||
return {
|
||||
id: randomID(),
|
||||
timestamp: Date.now(),
|
||||
value,
|
||||
isPrivate,
|
||||
};
|
||||
};
|
||||
|
||||
function getNormalDistributionHeight(x, a, b) {
|
||||
const maxHeight = b;
|
||||
return Math.round(Math.exp(-( ((x - a) ** 2) / b )) * maxHeight);
|
||||
};
|
||||
|
||||
export class MemoryDatabase {
|
||||
static getTables() {
|
||||
/** @type {Array<{ name: string; }>} */
|
||||
|
|
@ -18,11 +34,39 @@ export class MemoryDatabase {
|
|||
|
||||
static createRow(table, user, row) {};
|
||||
|
||||
static getRows(tableId, ...users) {
|
||||
if (users.length === 0) { users = [game.user] };
|
||||
static #cache = {};
|
||||
|
||||
static getRows(tableID, users) {
|
||||
if (users.length === 0) {
|
||||
return {};
|
||||
};
|
||||
|
||||
const datasets = {};
|
||||
|
||||
for (const user of users) {
|
||||
if (this.#cache[user]?.[tableID]) {
|
||||
datasets[user] = this.#cache[user][tableID];
|
||||
} else {
|
||||
|
||||
const [table, subtable] = tableID.split(`/`);
|
||||
if (!subtable) {
|
||||
continue;
|
||||
}
|
||||
const size = Number.parseInt(subtable.slice(1));
|
||||
const rows = [];
|
||||
|
||||
for (let i = 1; i <= size; i++) {
|
||||
const count = getNormalDistributionHeight(i, size / 2, size);
|
||||
console.table({ count, i });
|
||||
const temp = new Array(count).fill(null).map(() => generateRow(i));
|
||||
rows.push(...temp);
|
||||
};
|
||||
|
||||
this.#cache[user] ??= {};
|
||||
datasets[user] = this.#cache[user][tableID] = rows;
|
||||
}
|
||||
}
|
||||
|
||||
return datasets;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue