Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 6x 2x 2x 4x 2x 2x 2x 2x 8x 2x 2x 2x 5x 5x 20x 20x 20x 20x 20x 1x 1x 1x 4x 16x 16x 8x 4x 4x 1x | // public/js/helpers.js
// 格式化顯示成交量
function formatVolume(volume) {
if (volume >= 100000000) {
// 如果成交量大於億,則以1億為單位
const formattedVolume = (volume / 100000000).toFixed(2) + "億";
return formattedVolume;
} else if (volume >= 10000) {
// 如果成交量大於萬,則以萬為單位
const formattedVolume = (volume / 10000).toFixed(2) + "萬";
return formattedVolume;
} else {
// 如果成交量小於萬,顯示原始值
return volume;
}
}
// 排序功能
function sortResultsByVolume(allResultsVolume, isAscending) {
return allResultsVolume.sort((a, b) =>
isAscending
? a.quote_volume - b.quote_volume
: b.quote_volume - a.quote_volume
);
}
// 取得篩選條件
function extractFilterConditions() {
const parameterGroups = 4;
const intervalsData = [];
for (let i = 1; i <= parameterGroups; i++) {
const timeInterval = document.getElementById(`time-interval-${i}`).value;
for (let j = 1; j <= parameterGroups; j++) {
const maParamElement = document.getElementById(`MA${i}-${j}`);
const maParamValue = maParamElement.value;
Eif (maParamValue !== "") {
const maValueNum = parseInt(maParamValue);
if (
!Number.isInteger(maValueNum) ||
maValueNum <= 0 ||
maValueNum > 240
) {
alert("請輸入正整數,最多支援到240MA");
maParamElement.focus();
return null;
}
}
}
const maParameters = Array.from({ length: parameterGroups }, (_, j) => {
const maParamValue = document.getElementById(`MA${i}-${j + 1}`).value;
return { value: maParamValue ? parseInt(maParamValue) : null };
});
const comparisonOperator = Array.from({ length: 2 }, (_, j) => ({
comparisonOperator: document.getElementById(
`comparison-operator-${i}-${j + 1}`
).value,
}));
const logicalOperator = document.getElementById(
`logical-operator-${i}`
).value;
intervalsData.push({
time_interval: timeInterval,
param_1: maParameters[0].value,
param_2: maParameters[1].value,
param_3: maParameters[2].value,
param_4: maParameters[3].value,
comparison_operator_1: comparisonOperator[0].comparisonOperator,
comparison_operator_2: comparisonOperator[1].comparisonOperator,
logical_operator: logicalOperator,
});
}
return intervalsData;
}
export { extractFilterConditions, sortResultsByVolume, formatVolume };
|