Py.Cafe

Grascochon/

18holeVizrotest

last try

DocsPricing
  • 18hole_125_allData_cleaned.csv
  • app.py
  • requirements.txt
app.py
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
86
87
88
89
90
91
92
93
94
import vizro.models as vm
from vizro import Vizro
from vizro.models import capture # Re-import capture from vizro.models
import pandas as pd
import plotly.graph_objects as go

# Load the data
df = pd.read_csv(
    "18hole_125_allData_cleaned.csv",
    delimiter=";"
)

# Convert ElapsedTime to seconds for plotting
df["ElapsedTimeSeconds"] = pd.to_timedelta(df["ElapsedTime"]).dt.total_seconds()

# --- Create Custom Multi-Axis Plot ---
@capture('graph') # Re-add the decorator
def create_custom_multi_axis_plot(data_frame=None):
    if data_frame is None:
        data_frame = df # Use the globally loaded df if none is passed
    fig = go.Figure()

    # Add traces, assigning to appropriate y-axes
    # Y-axis 1: Temperatures
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["temperature1"], name="Temperature 1", yaxis="y1"))
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["temperature2"], name="Temperature 2", yaxis="y1"))
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["targetTemp"], name="Target Temp", yaxis="y1", line=dict(dash='dash'))) # Dashed line for target

    # Y-axis 2: Fan Percentages
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["fanPercent1"], name="Fan 1 %", yaxis="y2"))
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["fanPercent2"], name="Fan 2 %", yaxis="y2"))

    # Y-axis 3: Auto Mode
    fig.add_trace(go.Scatter(x=data_frame["ElapsedTimeSeconds"], y=data_frame["autoMode"], name="Auto Mode", yaxis="y3"))

    # Configure layout for multiple axes
    fig.update_layout(
        xaxis=dict(domain=[0.1, 0.9]), # Adjust domain slightly for 3 axes

        yaxis=dict(
            title="Temperature (°C)",
            titlefont=dict(color="#1f77b4"),
            tickfont=dict(color="#1f77b4"),
            side="left",
            position=0.0
        ),
        yaxis2=dict(
            title="Fan Percentage (%)",
            titlefont=dict(color="#ff7f0e"),
            tickfont=dict(color="#ff7f0e"),
            side="right",
            overlaying="y",
            anchor="x",
            position=0.95 # Position on the right
        ),
        yaxis3=dict(
            title="Auto Mode",
            titlefont=dict(color="#2ca02c"),
            tickfont=dict(color="#2ca02c"),
            side="right",
            overlaying="y",
            anchor="free",
            position=1.0, # Further right
            showgrid=False # Often good to hide grid for binary/mode axes
        ),

        xaxis_title="Elapsed Time (seconds)",
        title="Sensor Data and Control Status",
        legend_title="Variables",
        height=600
    )
    return fig
# --- End Custom Multi-Axis Plot ---

# Define the page with the graph
page = vm.Page(
    title="Fire Data Analysis - Custom Plot",
    components=[
        vm.Graph(
            id="custom_multi_axis_plot",
            figure=create_custom_multi_axis_plot # Pass the function reference again
        ),
    ],
)

# Create the dashboard
dashboard = vm.Dashboard(pages=[page])

# Build and run the app
app = Vizro().build(dashboard)

if __name__ == "__main__":
    app.run()