Grafic Temperatura Frigider Magazin Alimentar ((new)) Info

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

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() grafic temperatura frigider magazin alimentar

@app.route('/api/temperatures') def get_temps(): fridge_id = request.args.get('fridge_id', 1) hours = int(request.args.get('hours', 24)) conn = sqlite3.connect('fridge.db') c = conn.cursor() since = datetime.now() - timedelta(hours=hours) c.execute('''SELECT recorded_at, temp FROM temperature_logs WHERE fridge_id = ? AND recorded_at > ? ORDER BY recorded_at''', (fridge_id, since)) data = ['time': row[0], 'temp': row[1] for row in c.fetchall()] conn.close() return jsonify(data) max_temp) VALUES (?

Indietro
Alto Basso