mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-20 19:48:24 -07:00
bitview: reorg part 7 + fix hanging ?
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { serdeIndex } from "./serde";
|
||||
import { runWhenIdle } from "./idle";
|
||||
import { createPools } from "./pools";
|
||||
import { POOL_ID_TO_POOL_NAME } from "./generated/pools";
|
||||
import { createMetricToIndexes } from "./metrics";
|
||||
|
||||
const localhost = window.location.hostname === "localhost";
|
||||
@@ -11,7 +10,7 @@ const localhost = window.location.hostname === "localhost";
|
||||
export default function (signals) {
|
||||
const owner = signals.getOwner();
|
||||
|
||||
const pools = createPools();
|
||||
const pools = POOL_ID_TO_POOL_NAME;
|
||||
const metricToIndexes = createMetricToIndexes();
|
||||
|
||||
const defaultFrom = -10_000;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { INDEX_TO_WORD } from "./generated/metrics";
|
||||
|
||||
/** @type {Record<string, number>} */
|
||||
const WORD_TO_INDEX = {};
|
||||
|
||||
INDEX_TO_WORD.forEach((word, index) => {
|
||||
WORD_TO_INDEX[word] = index;
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} metric
|
||||
*/
|
||||
function compressMetric(metric) {
|
||||
return metric
|
||||
.split("_")
|
||||
.map((word) => {
|
||||
const index = WORD_TO_INDEX[word];
|
||||
return index !== undefined ? indexToLetters(index) : word;
|
||||
})
|
||||
.join("_");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} compressedMetric
|
||||
*/
|
||||
function decompressMetric(compressedMetric) {
|
||||
return compressedMetric
|
||||
.split("_")
|
||||
.map((code) => {
|
||||
const index = lettersToIndex(code);
|
||||
return INDEX_TO_WORD[index] || code; // Fallback to original if not found
|
||||
})
|
||||
.join("_");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} letters
|
||||
*/
|
||||
function lettersToIndex(letters) {
|
||||
let result = 0;
|
||||
for (let i = 0; i < letters.length; i++) {
|
||||
const value = charToIndex(letters.charCodeAt(i));
|
||||
result = result * 52 + value + 1;
|
||||
}
|
||||
return result - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} byte
|
||||
*/
|
||||
function charToIndex(byte) {
|
||||
if (byte >= 65 && byte <= 90) {
|
||||
// 'A' to 'Z'
|
||||
return byte - 65;
|
||||
} else if (byte >= 97 && byte <= 122) {
|
||||
// 'a' to 'z'
|
||||
return byte - 97 + 26;
|
||||
} else {
|
||||
return 255; // Invalid
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
*/
|
||||
function indexToLetters(index) {
|
||||
if (index < 52) {
|
||||
return indexToChar(index);
|
||||
}
|
||||
let result = [];
|
||||
while (true) {
|
||||
result.push(indexToChar(index % 52));
|
||||
index = Math.floor(index / 52);
|
||||
if (index === 0) break;
|
||||
index -= 1;
|
||||
}
|
||||
return result.reverse().join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
*/
|
||||
function indexToChar(index) {
|
||||
if (index <= 25) {
|
||||
return String.fromCharCode(65 + index); // A-Z
|
||||
} else {
|
||||
return String.fromCharCode(97 + index - 26); // a-z
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/**
|
||||
* @import { Signal, Signals, Accessor } from "../solidjs-signals/index";
|
||||
*
|
||||
* @import { Index } from "./metrics"
|
||||
* @import { Index } from "./generated/metrics"
|
||||
*
|
||||
* @typedef {[number, number, number, number]} OHLCTuple
|
||||
*
|
||||
* @typedef {typeof import("./generated/metrics")["COMPRESSED_METRIC_TO_INDEXES"]} MetricToIndexes
|
||||
* @typedef {string} Metric
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user