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
|
|
@ -69,6 +69,10 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
this.#prepareDataFiltersContext(ctx);
|
||||
break;
|
||||
};
|
||||
case `graph`: {
|
||||
this.#prepareGraphContext(ctx);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
|
|
@ -120,6 +124,26 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
};
|
||||
};
|
||||
|
||||
_graphData = {};
|
||||
async #prepareGraphContext(_ctx) {
|
||||
const datasets = CONFIG.StatsDatabase.getRows(
|
||||
`${this._selectedTable}/${this._selectedSubtable}`,
|
||||
this._selectedUsers,
|
||||
);
|
||||
|
||||
Logger.log(datasets);
|
||||
|
||||
const buckets = {};
|
||||
for (const row of datasets[game.user.id] ?? []) {
|
||||
buckets[row.value] ??= 0;
|
||||
buckets[row.value] += 1;
|
||||
};
|
||||
|
||||
const sorted = Object.entries(buckets).sort(([v1], [v2]) => Math.sign(v1 - v2));
|
||||
|
||||
Logger.log(sorted);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Event} event
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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