<!DOCTYPE html>
<html>
<head>
    <title>Machine Status Over Time</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
    <div style="width: 80%; margin: 0 auto;">
        <canvas id="timeSeriesChart"></canvas>
    </div>

    <script>
        // Convert timestamps to JavaScript Date objects
        const dates = {{ timestamps|tojson }};

        // Create the time series chart
        const ctx = document.getElementById('timeSeriesChart').getContext('2d');
        const timeSeriesChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: dates,
                datasets: [{
                    label: 'Machine Status',
                    data: {{ status|tojson }},
                    borderColor: 'rgba(75, 192, 192, 1)',
                    backgroundColor: 'rgba(75, 192, 192, 0.2)',
                    fill: true,
                    pointRadius: 5,
                    pointHoverRadius: 7,
                }]
            },
            options: {
                scales: {
                    x: {
                        type: 'time',
                        time: {
                            unit: 'hour', // You can set the desired unit for the time axis (hour, day, week, etc.)
                            displayFormats: {
                                hour: 'YYYY-MM-DD HH:mm:ss' // Format for the tooltip and axis labels
                            }
                        },
                        distribution: 'linear',
                        ticks: {
                            source: 'auto',
                        }
                    },
                    y: {
                        beginAtZero: true,
                        suggestedMax: 1, // The maximum value of the y-axis (1 for up, 0 for down)
                        suggestedMin: 0, // The minimum value of the y-axis (1 for up, 0 for down)
                        stepSize: 1, // The step size for y-axis ticks
                    }
                },
                plugins: {
                    legend: {
                        position: 'top',
                    },
                },
            }
        });
    </script>
</body>
</html>
