STEP_INTERVAL = 5 # Predict every 5 seconds
data_buffer = deque(maxlen=BUFFER_SIZE)
last_prediction_time = time.time()
while True:
samples = fetch_from_firebase() # fetches new data batch (80 samples per second)
for sample in samples:
# Normalize and append each sensor sample to buffer
reading = np.array([
sample['ax'], sample['ay'], sample['az'],
sample['gx'], sample['gy'], sample['gz']
]) / 10000.0
data_buffer.append(reading)
# Prediction logic (every STEP_INTERVAL seconds, after buffer fills)
current_time = time.time()
if len(data_buffer) == BUFFER_SIZE and (current_time - last_prediction_time) >= STEP_INTERVAL:
window = np.array(data_buffer).reshape(1, -1)
window_scaled = scaler.transform(window)
prediction = model.predict(window_scaled)[0]
last_prediction_time = current_time
handle_prediction(prediction)
< /code>
- Ist dies die richtige Möglichkeit, kontinuierliche Schiebern für
Echtzeit-Sensordaten zu implementieren? Daten effektiv für Vorhersagen?