uno-q-local-log-storage.py
Local storage script that captures every physical interaction with the Modulino nodes and saves them to a CSV file on the UNO Q storage.
Ensure the UNO Q has persistent storage mounted. Modify the DEVICE_PATH to target the desired Modulino node. The script automatically creates the CSV file if it does not exist. Use this method for debugging or analyzing usage habits without network dependency.
uno-q-local-log-storage.py
#!/usr/bin/env python3
import csv
import time
import evdev
import os
LOG_FILE = 'modulino_interactions.csv'
DEVICE_PATH = '/dev/input/event2' # Exemple: Joystick
def log_event(event_type, event_code, value):
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
# Vérifie si le fichier existe pour écrire l'en-tête seulement au début
file_exists = os.path.isfile(LOG_FILE)
with open(LOG_FILE, 'a', newline='') as f:
writer = csv.writer(f)
if not file_exists:
writer.writerow(['timestamp', 'type', 'code', 'value'])
writer.writerow([timestamp, event_type, event_code, value])
def main():
try:
device = evdev.InputDevice(DEVICE_PATH)
print(f"Enregistrement des événements de {device.name} dans {LOG_FILE}")
for event in device.read_loop():
# Ignore les événements de synchronisation
if event.type == evdev.ecodes.EV_SYN:
continue
log_event(event.type, event.code, event.value)
print(f"Log: Type {event.type}, Code {event.code}, Value {event.value}")
except FileNotFoundError:
print("Périphérique introuvable.")
except KeyboardInterrupt:
print("\nArrêt de l'enregistrement.")
if __name__ == '__main__':
main()