File size: 2,068 Bytes
c99df4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
import numpy as np
import pandas as pd
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QTimer
import pyqtgraph as pg

# Add project root to path
sys.path.append(os.getcwd())

from src.ui.chart_widget import ChartWidget

def verify_chart_render():
    app = QApplication(sys.argv)
    widget = ChartWidget()
    widget.resize(800, 600)
    widget.show()
    
    print("Widget shown. Generating dummy data...")
    
    # 1. Simulate Tick Data
    now = pd.Timestamp.now()
    dates = pd.date_range(start=now, periods=100, freq='1s')
    bids = np.linspace(100, 105, 100) + np.random.normal(0, 0.1, 100)
    asks = bids + 0.2
    
    df = pd.DataFrame({
        'datetime': dates,
        'bid': bids,
        'ask': asks
    })
    
    # Update ticks
    widget.update_ticks(df)
    print("Ticks updated.")
    
    # Check if curves have data
    x, y = widget.bid_curve.getData()
    if x is not None and len(x) == 100:
        print("PASS: Bid curve has data.")
    else:
        print(f"FAIL: Bid curve data mismatch. Len: {len(x) if x is not None else 0}")
        
    # 2. Simulate Levels
    # timestamps for 10 min
    level_times = [dates[i].timestamp() for i in range(0, 100, 10)]
    level_vah = np.linspace(101, 104, 10)
    level_val = np.linspace(99, 102, 10)
    level_poc = np.linspace(100, 103, 10)
    
    widget.update_levels(level_times, level_vah, level_val, level_poc)
    print("Levels updated.")
    
    x_vah, y_vah = widget.curve_vah.getData()
    if x_vah is not None and len(x_vah) == 10:
        print("PASS: VAH curve has data.")
    else:
        print(f"FAIL: VAH curve data mismatch. Len: {len(x_vah) if x_vah is not None else 0}")

    # Set a timer to close the app automatically after a few seconds if running in automation
    # QTimer.singleShot(2000, app.quit)
    
    # For now, just quit immediately to verify logic
    app.quit()
    print("Test finished.")

if __name__ == "__main__":
    verify_chart_render()