general: snapshot

This commit is contained in:
k
2024-06-25 14:46:23 +02:00
parent 7604787fbb
commit 20a51f980b
27 changed files with 342 additions and 225 deletions

View File

@@ -0,0 +1,40 @@
import { createResourceDataset } from "./resource";
export { averages } from "./consts/averages";
export function createScaleDatasets<Scale extends ResourceScale>({
scale,
setActiveResources,
groupedKeysToURLPath,
}: {
scale: Scale;
setActiveResources: Setter<Set<ResourceDataset<any, any>>>;
groupedKeysToURLPath: GroupedKeysToURLPath[Scale];
}) {
type Key = keyof typeof groupedKeysToURLPath;
type ResourceData = ReturnType<typeof createResourceDataset<Scale>>;
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as unknown as Exclude<Key, "ohlc">] = createResourceDataset({
scale,
path: groupedKeysToURLPath[key as Key] as any,
setActiveResources,
});
}
}
const price = createResourceDataset<Scale, OHLC>({
scale,
path: `/${scale}-to-ohlc`,
setActiveResources,
});
Object.assign(datasets, { price });
return datasets;
}

View File

@@ -14,33 +14,27 @@ export function createDateDatasets({
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
for (const _key in groupedKeysToURLPath) {
const key = _key as Key;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
if (key !== "ohlc") {
const path = groupedKeysToURLPath[key];
(groupedKeysToURLPath as any as ResourceDatasets)[key] =
createResourceDataset<"date">({
scale: "date",
path,
setActiveResources,
});
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"date">({
scale: "date",
path: groupedKeysToURLPath[key as Key],
setActiveResources,
});
}
}
const resourceDatasets = groupedKeysToURLPath as any as ResourceDatasets;
const price = createResourceDataset<"date", OHLC>({
scale: "date",
path: "/date-to-ohlc",
setActiveResources,
});
const datasets = {
price,
...resourceDatasets,
};
Object.assign(datasets, { price });
return datasets;
return datasets as ResourceDatasets & {
price: ResourceDataset<"date", OHLC>;
};
}

View File

@@ -12,31 +12,27 @@ export function createHeightDatasets({
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
for (const _key in groupedKeysToURLPath) {
const key = _key as Key;
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
if (key !== "ohlc") {
const path = groupedKeysToURLPath[key];
(groupedKeysToURLPath as any as ResourceDatasets)[key] =
createResourceDataset<"height">({
scale: "height",
path,
setActiveResources,
});
for (const key in groupedKeysToURLPath) {
if ((key as Key) !== "ohlc") {
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"height">({
scale: "height",
path: groupedKeysToURLPath[key as Key],
setActiveResources,
});
}
}
const resourceDatasets = groupedKeysToURLPath as any as ResourceDatasets;
const price = createResourceDataset<"height", OHLC>({
scale: "height",
path: "/height-to-ohlc",
setActiveResources,
});
return {
...resourceDatasets,
price,
Object.assign(datasets, { price });
return datasets as ResourceDatasets & {
price: ResourceDataset<"height", OHLC>;
};
}

View File

@@ -21,13 +21,6 @@ export function createResourceDataset<
path: string;
setActiveResources: Setter<Set<ResourceDataset<any, any>>>;
}) {
const baseURL = `${
// location.hostname === "localhost"
// ? "http://localhost:3110"
// : "https://api.satonomics.xyz"
"https://api.satonomics.xyz"
}${path}`;
type Dataset = Scale extends "date"
? FetchedDateDataset<Type>
: FetchedHeightDataset<Type>;
@@ -36,6 +29,13 @@ export function createResourceDataset<
Type extends number ? SingleValueData : CandlestickData
>;
const baseURL = `${
// location.hostname === "localhost"
// ? "http://localhost:3110"
// : "https://api.satonomics.xyz"
"https://api.satonomics.xyz"
}${path}`;
const fetchedJSONs = new Array(
(new Date().getFullYear() - new Date("2009-01-01").getFullYear() + 2) *
(scale === "date" ? 1 : 6),
@@ -51,12 +51,12 @@ export function createResourceDataset<
vec: createMemo(() => {
const map = json()?.dataset.map || null;
const chunkId = json()?.chunk.id!;
if (!map) {
return null;
}
const chunkId = json()?.chunk.id!;
if (Array.isArray(map)) {
return map.map(
(value, index) =>