Grafic Temperatura Frigider | Magazin Alimentar |work|

if (chart) chart.destroy(); const ctx = document.getElementById('tempChart').getContext('2d'); chart = new Chart(ctx, type: 'line', data: labels: times, datasets: [ label: 'Temperature (°C)', data: temps, borderColor: 'rgb(75, 192, 192)', backgroundColor: 'rgba(75, 192, 192, 0.1)', tension: 0.2, pointBackgroundColor: temps.map(t => (t > 4 ] , options: responsive: true, plugins: tooltip: callbacks: label: (ctx) => `$ctx.raw°C` , annotation: annotations: safeZone: type: 'box', yMin: 0, yMax: 4, backgroundColor: 'rgba(0,255,0,0.1)' , scales: y: title: display: true, text: 'Temperature (°C)' , min: -2, max: 8, grid: color: (ctx) => ctx.tick.value === 0 , x: title: display: true, text: 'Time' ); // Count violations const violations = temps.filter(t => t > 4 );

@app.route('/api/log', methods=['POST']) def log_temp(): fridge_id = request.json['fridge_id'] temp = request.json['temperature'] conn = sqlite3.connect('fridge.db') c = conn.cursor() c.execute("INSERT INTO temperature_logs (fridge_id, temp, recorded_at) VALUES (?,?,?)", (fridge_id, temp, datetime.now().isoformat())) conn.commit() conn.close() return jsonify('status': 'ok') grafic temperatura frigider magazin alimentar

@app.route('/') def index(): return render_template('graph.html') if (chart) chart

def init_db(): conn = sqlite3.connect('fridge.db') c = conn.cursor() c.execute('''CREATE TABLE IF NOT EXISTS fridge_sensors (id INTEGER PRIMARY KEY, name TEXT, min_temp REAL, max_temp REAL)''') c.execute('''CREATE TABLE IF NOT EXISTS temperature_logs (id INTEGER PRIMARY KEY, fridge_id INTEGER, temp REAL, recorded_at TEXT)''') # Insert demo fridge if empty c.execute("SELECT COUNT(*) FROM fridge_sensors") if c.fetchone()[0] == 0: c.execute("INSERT INTO fridge_sensors (name, min_temp, max_temp) VALUES (?,?,?)", ('Dairy Cooler', 0.0, 4.0)) conn.commit() conn.close() if (chart) chart.destroy()

function fetchAndRender() const fridgeId = $('#fridgeSelect').val(); const hours = $('#periodSelect').val(); $.get( /api/temperatures?fridge_id=$fridgeId&hours=$hours , function(data) const times = data.map(d => new Date(d.time).toLocaleTimeString([], hour:'2-digit', minute:'2-digit')); const temps = data.map(d => d.temp);