remove ws, fix predictions
This commit is contained in:
@@ -554,7 +554,12 @@ class ChartManager {
|
||||
};
|
||||
|
||||
const layout = {
|
||||
title: '',
|
||||
title: {
|
||||
text: `${timeframe} (Europe/Sofia Time)`,
|
||||
font: { size: 12, color: '#9ca3af' },
|
||||
xanchor: 'left',
|
||||
x: 0.01
|
||||
},
|
||||
showlegend: false,
|
||||
xaxis: {
|
||||
rangeslider: { visible: false },
|
||||
@@ -562,7 +567,13 @@ class ChartManager {
|
||||
color: '#9ca3af',
|
||||
showgrid: true,
|
||||
zeroline: false,
|
||||
fixedrange: false
|
||||
fixedrange: false,
|
||||
type: 'date',
|
||||
// NOTE: Plotly.js always displays times in browser's local timezone
|
||||
// Timestamps are stored as UTC but displayed in local time
|
||||
// This is expected behavior - users see times in their timezone
|
||||
// tickformat: '%Y-%m-%d %H:%M:%S',
|
||||
// hoverformat: '%Y-%m-%d %H:%M:%S'
|
||||
},
|
||||
yaxis: {
|
||||
title: {
|
||||
@@ -3031,38 +3042,53 @@ class ChartManager {
|
||||
if (!chart || !chart.data) return;
|
||||
|
||||
const lastIdx = chart.data.timestamps.length - 1;
|
||||
const lastTimestamp = new Date(chart.data.timestamps[lastIdx]);
|
||||
const lastTimestamp = chart.data.timestamps[lastIdx]; // Keep as ISO string
|
||||
const currentPrice = chart.data.close[lastIdx];
|
||||
|
||||
// Calculate target point
|
||||
// steepness is [0, 1], angle is in degrees
|
||||
// Project ahead based on timeframe to avoid zoom issues
|
||||
// Project ahead based on timeframe
|
||||
// For 1s: 30s ahead, 1m: 2min ahead, 1h: 30min ahead
|
||||
const projectionSeconds = timeframe === '1s' ? 30 :
|
||||
timeframe === '1m' ? 120 :
|
||||
timeframe === '1h' ? 1800 : 300;
|
||||
const targetTime = new Date(lastTimestamp.getTime() + projectionSeconds * 1000);
|
||||
|
||||
// CRITICAL FIX: Format targetTime as ISO string with 'Z' to match chart data format
|
||||
// This prevents the 2-hour timezone offset issue
|
||||
const targetTimeMs = new Date(lastTimestamp).getTime() + projectionSeconds * 1000;
|
||||
const targetTime = new Date(targetTimeMs).toISOString();
|
||||
|
||||
let targetPrice = currentPrice;
|
||||
|
||||
if (trendVector.price_delta) {
|
||||
// If model provided explicit price delta (denormalized ideally)
|
||||
// Note: backend sends price_delta as normalized value usually?
|
||||
// But trend_vector dict constructed in model usually has raw value if we didn't normalize?
|
||||
// Actually, checking model code, it returns raw tensor value.
|
||||
// If normalized, it's small. If real price, it's big.
|
||||
// Heuristic: if delta is < 1.0 and price is > 100, it's likely normalized or percentage.
|
||||
// CRITICAL FIX: Check if price_delta is normalized (< 1.0) or real price change
|
||||
if (trendVector.price_delta !== undefined && trendVector.price_delta !== null) {
|
||||
const priceDelta = parseFloat(trendVector.price_delta);
|
||||
|
||||
// Safer to use angle/steepness if delta is ambiguous, but let's try to interpret direction
|
||||
const direction = trendVector.direction === 'up' ? 1 : (trendVector.direction === 'down' ? -1 : 0);
|
||||
const steepness = trendVector.steepness || 0; // 0 to 1
|
||||
// If price_delta is very small (< 1.0), it's likely normalized - scale it
|
||||
if (Math.abs(priceDelta) < 1.0) {
|
||||
// Normalized value - treat as percentage of current price
|
||||
targetPrice = currentPrice * (1 + priceDelta);
|
||||
} else {
|
||||
// Real price delta - add directly
|
||||
targetPrice = currentPrice + priceDelta;
|
||||
}
|
||||
} else {
|
||||
// Fallback: Use direction and steepness
|
||||
const direction = trendVector.direction === 'up' ? 1 :
|
||||
(trendVector.direction === 'down' ? -1 : 0);
|
||||
const steepness = parseFloat(trendVector.steepness) || 0; // 0 to 1
|
||||
|
||||
// Estimate price change based on steepness (max 2% move in 5 mins)
|
||||
const maxChange = 0.02 * currentPrice;
|
||||
// Estimate price change based on steepness (max 1% move per projection period)
|
||||
const maxChange = 0.01 * currentPrice;
|
||||
const projectedChange = maxChange * steepness * direction;
|
||||
targetPrice = currentPrice + projectedChange;
|
||||
}
|
||||
|
||||
// Sanity check: Don't let target price go to 0 or negative
|
||||
if (targetPrice <= 0 || !isFinite(targetPrice)) {
|
||||
console.warn('Invalid target price calculated:', targetPrice, 'using current price instead');
|
||||
targetPrice = currentPrice;
|
||||
}
|
||||
|
||||
// Draw trend ray
|
||||
shapes.push({
|
||||
type: 'line',
|
||||
@@ -3081,7 +3107,7 @@ class ChartManager {
|
||||
annotations.push({
|
||||
x: targetTime,
|
||||
y: targetPrice,
|
||||
text: `Target<br>${targetPrice.toFixed(2)}`,
|
||||
text: `Target<br>$${targetPrice.toFixed(2)}`,
|
||||
showarrow: true,
|
||||
arrowhead: 2,
|
||||
ax: 0,
|
||||
|
||||
Reference in New Issue
Block a user