parser: add 0 and 1 constant datasets

This commit is contained in:
k
2024-07-12 12:55:46 +02:00
parent 46f8e3bafd
commit 68700925b0
3 changed files with 19 additions and 11 deletions
@@ -1,9 +1,7 @@
import { averages } from "/src/scripts/datasets/date";
import { colors } from "/src/scripts/utils/colors";
export function createPresets(): PartialPresetFolder {
const scale: ResourceScale = "date";
export function createPresets(scale: ResourceScale): PartialPresetFolder {
return {
name: "Averages",
tree: [
@@ -55,7 +53,7 @@ function createPresetFolder({
{
title: `SMA`,
color,
datasetPath: `/date-to-price-${key}-sma`,
datasetPath: `/${scale}-to-price-${key}-sma`,
},
],
},
@@ -64,19 +62,24 @@ function createPresetFolder({
name: "Ratio",
description: "",
icon: IconTablerMathXDivideY,
title: `${name} Moving Average Ratio`,
title: `Market Price To ${name} Moving Average Ratio`,
top: [
{
title: `SMA`,
color,
datasetPath: `/date-to-price-${key}-sma`,
datasetPath: `/${scale}-to-price-${key}-sma`,
},
],
bottom: [
{
title: `Ratio`,
color,
datasetPath: `/date-to-market-price-to-price-${key}-sma-ratio`,
datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio`,
},
{
title: `Even`,
color: colors.white,
datasetPath: `/${scale}-to-1`,
},
],
},
+1 -1
View File
@@ -28,9 +28,9 @@ export function createPresets(scale: ResourceScale) {
},
],
},
createAveragesPresets(scale),
...(scale === "date"
? ([
createAveragesPresets(),
createReturnsPresets(),
createIndicatorsPresets(),
] satisfies PartialPresetTree)
+8 -3
View File
@@ -9,6 +9,8 @@ pub struct ConstantDataset {
min_initial_states: MinInitialStates,
// Computed
pub _0: BiMap<u16>,
pub _1: BiMap<u16>,
pub _50: BiMap<u16>,
pub _100: BiMap<u16>,
}
@@ -20,6 +22,8 @@ impl ConstantDataset {
let mut s = Self {
min_initial_states: MinInitialStates::default(),
_0: BiMap::new_bin(1, &f("0")),
_1: BiMap::new_bin(1, &f("1")),
_50: BiMap::new_bin(1, &f("50")),
_100: BiMap::new_bin(1, &f("100")),
};
@@ -31,8 +35,9 @@ impl ConstantDataset {
}
pub fn compute(&mut self, &ComputeData { heights, dates }: &ComputeData) {
self._0.multi_insert_const(heights, dates, 0);
self._1.multi_insert_const(heights, dates, 1);
self._50.multi_insert_const(heights, dates, 50);
self._100.multi_insert_const(heights, dates, 100);
}
}
@@ -43,10 +48,10 @@ impl AnyDataset for ConstantDataset {
}
fn to_computed_bi_map_vec(&self) -> Vec<&(dyn AnyBiMap + Send + Sync)> {
vec![&self._50, &self._100]
vec![&self._0, &self._1, &self._50, &self._100]
}
fn to_computed_mut_bi_map_vec(&mut self) -> Vec<&mut dyn AnyBiMap> {
vec![&mut self._50, &mut self._100]
vec![&mut self._0, &mut self._1, &mut self._50, &mut self._100]
}
}