mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: adding semester + making coarser intervals computed instead of eager
This commit is contained in:
@@ -7,7 +7,7 @@ const LINE = "line";
|
||||
const CANDLE = "candle";
|
||||
|
||||
/**
|
||||
* @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "year" | "decade" } SerializedChartableIndex
|
||||
* @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "semester" | "year" | "decade" } SerializedChartableIndex
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -205,14 +205,17 @@ export function init({
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (index === /** @satisfies {WeekIndex} */ (22)) {
|
||||
if (index === /** @satisfies {WeekIndex} */ (23)) {
|
||||
date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));
|
||||
} else if (index === /** @satisfies {MonthIndex} */ (7)) {
|
||||
date.setUTCDate(1);
|
||||
} else if (index === /** @satisfies {QuarterIndex} */ (19)) {
|
||||
const month = date.getUTCMonth();
|
||||
date.setUTCMonth(month - (month % 3), 1);
|
||||
} else if (index === /** @satisfies {YearIndex} */ (23)) {
|
||||
} else if (index === /** @satisfies {SemesterIndex} */ (20)) {
|
||||
const month = date.getUTCMonth();
|
||||
date.setUTCMonth(month - (month % 6), 1);
|
||||
} else if (index === /** @satisfies {YearIndex} */ (24)) {
|
||||
date.setUTCMonth(0, 1);
|
||||
} else if (index === /** @satisfies {DecadeIndex} */ (1)) {
|
||||
date.setUTCFullYear(
|
||||
@@ -465,6 +468,7 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
|
||||
"d.epoch",
|
||||
"month",
|
||||
"quarter",
|
||||
"semester",
|
||||
"year",
|
||||
// "halving epoch",
|
||||
"decade",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @import * as _ from "../packages/ufuzzy/v1.0.18/types"
|
||||
* @import { SerializedChartableIndex } from "./chart";
|
||||
* @import { Signal, Signals, Accessor } from "../packages/solid-signals/wrapper";
|
||||
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes"
|
||||
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes"
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -1164,13 +1164,15 @@ function createUtils() {
|
||||
return "p2wshaddressindex";
|
||||
case /** @satisfies {QuarterIndex} */ (19):
|
||||
return "quarterindex";
|
||||
case /** @satisfies {TxIndex} */ (20):
|
||||
case /** @satisfies {SemesterIndex} */ (20):
|
||||
return "semesterindex";
|
||||
case /** @satisfies {TxIndex} */ (21):
|
||||
return "txindex";
|
||||
case /** @satisfies {UnknownOutputIndex} */ (21):
|
||||
case /** @satisfies {UnknownOutputIndex} */ (22):
|
||||
return "unknownoutputindex";
|
||||
case /** @satisfies {WeekIndex} */ (22):
|
||||
case /** @satisfies {WeekIndex} */ (23):
|
||||
return "weekindex";
|
||||
case /** @satisfies {YearIndex} */ (23):
|
||||
case /** @satisfies {YearIndex} */ (24):
|
||||
return "yearindex";
|
||||
}
|
||||
},
|
||||
@@ -1196,9 +1198,11 @@ function createUtils() {
|
||||
return "month";
|
||||
case /** @satisfies {QuarterIndex} */ (19):
|
||||
return "quarter";
|
||||
case /** @satisfies {WeekIndex} */ (22):
|
||||
case /** @satisfies {SemesterIndex} */ (20):
|
||||
return "semester";
|
||||
case /** @satisfies {WeekIndex} */ (23):
|
||||
return "week";
|
||||
case /** @satisfies {YearIndex} */ (23):
|
||||
case /** @satisfies {YearIndex} */ (24):
|
||||
return "year";
|
||||
default:
|
||||
return null;
|
||||
@@ -1215,15 +1219,17 @@ function createUtils() {
|
||||
case "date":
|
||||
return /** @satisfies {DateIndex} */ (0);
|
||||
case "week":
|
||||
return /** @satisfies {WeekIndex} */ (22);
|
||||
return /** @satisfies {WeekIndex} */ (23);
|
||||
case "d.epoch":
|
||||
return /** @satisfies {DifficultyEpoch} */ (2);
|
||||
case "month":
|
||||
return /** @satisfies {MonthIndex} */ (7);
|
||||
case "quarter":
|
||||
return /** @satisfies {QuarterIndex} */ (19);
|
||||
case "semester":
|
||||
return /** @satisfies {SemesterIndex} */ (20);
|
||||
case "year":
|
||||
return /** @satisfies {YearIndex} */ (23);
|
||||
return /** @satisfies {YearIndex} */ (24);
|
||||
case "decade":
|
||||
return /** @satisfies {DecadeIndex} */ (1);
|
||||
default:
|
||||
|
||||
@@ -406,6 +406,7 @@ function createSerializedIndexes() {
|
||||
/** @satisfies {VecId} */ ("inputindex"),
|
||||
/** @satisfies {VecId} */ ("monthindex"),
|
||||
/** @satisfies {VecId} */ ("opreturnindex"),
|
||||
/** @satisfies {VecId} */ ("semesterindex"),
|
||||
/** @satisfies {VecId} */ ("outputindex"),
|
||||
/** @satisfies {VecId} */ ("p2aaddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2msoutputindex"),
|
||||
@@ -437,21 +438,23 @@ function serializedIndexToIndex(serializedIndex) {
|
||||
case "dateindex":
|
||||
return /** @satisfies {DateIndex} */ (0);
|
||||
case "weekindex":
|
||||
return /** @satisfies {WeekIndex} */ (22);
|
||||
return /** @satisfies {WeekIndex} */ (23);
|
||||
case "difficultyepoch":
|
||||
return /** @satisfies {DifficultyEpoch} */ (2);
|
||||
case "monthindex":
|
||||
return /** @satisfies {MonthIndex} */ (7);
|
||||
case "quarterindex":
|
||||
return /** @satisfies {QuarterIndex} */ (19);
|
||||
case "semesterindex":
|
||||
return /** @satisfies {SemesterIndex} */ (20);
|
||||
case "yearindex":
|
||||
return /** @satisfies {YearIndex} */ (23);
|
||||
return /** @satisfies {YearIndex} */ (24);
|
||||
case "decadeindex":
|
||||
return /** @satisfies {DecadeIndex} */ (1);
|
||||
case "halvingepoch":
|
||||
return /** @satisfies {HalvingEpoch} */ (4);
|
||||
case "txindex":
|
||||
return /** @satisfies {TxIndex} */ (20);
|
||||
return /** @satisfies {TxIndex} */ (21);
|
||||
case "inputindex":
|
||||
return /** @satisfies {InputIndex} */ (6);
|
||||
case "outputindex":
|
||||
@@ -479,7 +482,7 @@ function serializedIndexToIndex(serializedIndex) {
|
||||
case "emptyoutputindex":
|
||||
return /** @satisfies {EmptyOutputIndex} */ (3);
|
||||
case "unknownoutputindex":
|
||||
return /** @satisfies {UnknownOutputIndex} */ (21);
|
||||
return /** @satisfies {UnknownOutputIndex} */ (22);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user